[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Toggle Switches for Plugins
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Toggle Switches for Plugins

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Wed 10 Jun 2009 08:07 PM (UTC)
Message
I am currently working on a plugin which I will be toggling on and off very frequently. I am wondering whether there is a way to make a toggle style button on the main menu bar to enable/disable this plugin. Its in python, if that matters. Any assistance in this matter would be greatly appreciated.
[Go to top] top

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Reply #1 on Wed 10 Jun 2009 11:15 PM (UTC)
Message
I use EnablePlugin() in an alias when I need to do that.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Thu 11 Jun 2009 01:22 AM (UTC)
Message
Yes I would use that.

http://www.gammon.com.au/scripts/doc.php?function=EnablePlugin

If you really want to click an icon, see:

http://www.gammon.com.au/forum/?id=9280

(You would still need to use EnablePlugin in the script for a button).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #3 on Fri 12 Jun 2009 10:30 PM (UTC)

Amended on Sat 13 Jun 2009 06:42 AM (UTC) by LupusFatalis

Message
ok... here is my button
  -- button 1
 {
  icon = "Compass_32x32.png",
  tooltip = "Underdark Mapper",
  script = function ()   -- script to execute when clicked
				if world.GetPluginInfo("aba6daf3fb30699071cb5d05", 17) == 1 then world.EnablePlugin("aba6daf3fb30699071cb5d05", 0) end
				if world.GetPluginInfo("aba6daf3fb30699071cb5d05", 17) == 0 then world.EnablePlugin("aba6daf3fb30699071cb5d05", 1) end
			end,  -- script function
            
    cooldown = 0,  -- 10 minute cooldown
  }, -- end of button 1


doesn't work... i'm kind of just bumbling around in lua and hoping for the best. lol

I guess the other bit is to edit the cooldown function to handle if cooldown = 0... it should count it as toggleable
[Go to top] top

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Reply #4 on Fri 12 Jun 2009 11:32 PM (UTC)
Message
Not sure if this is what you intended, but you basically wrote 'if plugin is enabled, disable; if plugin is disabled, disable'.
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #5 on Sat 13 Jun 2009 06:42 AM (UTC)
Message
fixed... but didn't fix the problem.
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #6 on Sat 13 Jun 2009 07:17 AM (UTC)
Message
Scripts inside a plugin won't run while the plugin is disabled. So clicking a miniwindow used by the same plugin to enable it again won't work.

I usually get this kind of functionality working with an extra plugin that is used solely for enabling/disabling.
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #7 on Sat 13 Jun 2009 05:21 PM (UTC)
Message
Oh, this is a completely separate plugin. I'm just trying to edit nick's Icon_Bar plugin to work for me. I'm having trouble with it because its Lua. The plugin I'm enabling/disabling is a different one entirely, and written in python. Its likely that I'll put in these toggle buttons for quite a few plugins if I can get them working. Just trying to get the one working for now.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Sun 14 Jun 2009 09:23 PM (UTC)

Amended on Sun 14 Jun 2009 09:24 PM (UTC) by Nick Gammon

Message
I tried your test on an existing plugin:


/print (GetPluginInfo("391192793248409895090099", 17))  --> true


In Lua, true is not the same as 1, one is a boolean value, one is a number. Thus the tests "== 1" and "== 0" will always fail, as the function returns true and false.

The documentation for GetPluginInfo correctly states it returns a boolean:


17: Enabled? (boolean)


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #9 on Mon 15 Jun 2009 03:40 AM (UTC)
Message
Thanks guys, here is what worked...
  -- button 1
 {
  icon = "Compass_32x32.png",
  tooltip = "Underdark Mapper",
  script = function ()   -- script to execute when clicked
				if world.GetPluginInfo("aba6daf3fb30699071cb5d05", 17) == true then
					world.EnablePlugin("aba6daf3fb30699071cb5d05", false)
				elseif world.GetPluginInfo("aba6daf3fb30699071cb5d05", 17) == false then
					world.EnablePlugin("aba6daf3fb30699071cb5d05", true)
				end
			end,  -- script function
  }, -- end of button 1
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Mon 15 Jun 2009 04:05 AM (UTC)

Amended on Mon 15 Jun 2009 04:06 AM (UTC) by Nick Gammon

Message
Now to make it shorter:


-- button 1
 {
  icon = "Compass_32x32.png",
  tooltip = "Underdark Mapper",
  script = function ()   -- script to execute when clicked
      local id = "aba6daf3fb30699071cb5d05"
      EnablePlugin(id, not GetPluginInfo (id, 17))
      end,  -- script function
  }, -- end of button 1


Doing a "not" on a boolean reverses the sense of it (ie. not true is false, not false is true).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #11 on Mon 15 Jun 2009 04:40 AM (UTC)
Message
heh, that's a lot better

Is there any way to have it change icons to distinguish whether it is enabled or disabled? Or gray out the entire bit, like you do with the cooldown? I was thinking maybe altering the cooldown code to accept 0 and act as if it were infinite. But looking at it, its beyond the scope by my bumbling abilities in lua.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Mon 15 Jun 2009 05:20 AM (UTC)
Message
I'm not sure exactly which plugin you borrowed from now, but to make it visually show it is disabled, you could probably lower the contrast of the icon (of course, then you have to put it back again later). See:

http://www.gammon.com.au/mushclient/mw_images.htm

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #13 on Mon 15 Jun 2009 08:49 PM (UTC)
Message
Oh, I'm working on the IconBar plugin.

And this seems to work, not exactly what I was intended (grays the area around the icon instead of the icon itself), but it does convey whether its enabled/disabled. At least after the first click--not ideal, but good enough I suppose.
  -- button 1
 {
  icon = "search_32.png",
  tooltip = "Underdark Mapper",
  script = function ()   -- script to execute when clicked
	local id = "aba6daf3fb30699071cb5d05"
	local id2 = GetPluginID()
	if GetPluginInfo (id, 17) then WindowFilter (id2, 2, 2, 41, 42, 8, 2)
	elseif not GetPluginInfo (id, 17) then WindowFilter (id2, 2, 2, 41, 42, 8, .5) end
	EnablePlugin(id, not GetPluginInfo (id, 17))
	end,  -- script function
  }, -- end of button 1
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #14 on Mon 15 Jun 2009 11:42 PM (UTC)

Amended on Mon 15 Jun 2009 11:45 PM (UTC) by Nick Gammon

Message
Well you have got me going on this one now ...

I am still not sure which plugin you used, the page I mentioned had two on it, but I'll assume you used the lower one, which lets you have horizontal and vertical icons, and be dragged around.

The code below lets you grey out the whole icon, by reloading the image, and decreasing its contrast if the target plugin is not enabled:


 -- button 1
 {
  icon = "search_32.png",
  tooltip = "Underdark Mapper",
  target_plugin = "aba6daf3fb30699071cb5d05",
  script = function (n) 
            
            local id = buttons [n].target_plugin
            
            local f = frames [n]  -- where is image?
            local x1, y1, x2, y2 = f.x1, f.y1, f.x2, f.y2
            
            -- redraw the image
            WindowDrawImage(win, n, 
                    x1 + 1, y1 + 1,   -- left, top
                    x2 - 1, y2 - 1,  -- right, bottom
                    2)  -- mode - stretch or shrink
                    
            -- toggle enable flag for target plugin
            EnablePlugin(id, not GetPluginInfo (id, 17))
            
            -- grey out if disabled now
            if not GetPluginInfo (id, 17) then 
               WindowFilter (win, x1, y1, x2, y2, 8, .4)
            end  -- if
  
            end,  -- function

  },   -- end of button 3


I've fiddled around a bit to make it more readable. For one thing, you don't need to test if something elseif not something. For example:


if GetPluginInfo (id, 17) then
  -- do something
elseif not GetPluginInfo (id, 17) then
  -- do something else
end -- if


A simple else will do that, you don't need to test again, ie.


if GetPluginInfo (id, 17) then
  -- do something
else
  -- do something else
end -- if


Also it seems more logical to me to test if the plugin is enabled *after* you have toggled its enable flag.

My code above simply reloads the image (I wasn't sure if changing its contrast would be symmetrical, the image might have eventually degraded). Fortunately all the images are still in memory. Also the current plugin's window is stored in the variable "win" already.

The only problem I then found was if you reloaded the plugin (after testing) and the target plugin (the mapper) was already disabled, the icon would be drawn the wrong way around. So I added a couple more lines further down where the image is originally loaded. That is, after:


   -- where to draw the icon
    if horizontal then
      x1, y1 = (n - 1) * (ICON_SIZE + OFFSET) + OFFSET, OFFSET
      x2, y2 = n * (ICON_SIZE + OFFSET), ICON_SIZE + OFFSET
    else
      x1, y1 = OFFSET, (n - 1) * (ICON_SIZE + OFFSET) + OFFSET
      x2, y2 = ICON_SIZE + OFFSET, n * (ICON_SIZE + OFFSET)
    end -- if
        
    -- draw the image
    WindowDrawImage(win, n, 
                    x1, y1,   -- left, top
                    x2, y2,  -- right, bottom
                    2)  -- mode - stretch or shrink


Add:



    if v.target_plugin then                    
      -- grey out if disabled now
      if not GetPluginInfo (v.target_plugin, 17) then 
         WindowFilter (win, x1, y1, x2, y2, 8, .4)
      end  -- if
    end -- if


This is why the variable which contained the target plugin's ID had to be moved from a local variable to be inside the table.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


15,135 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]