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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Miniwindows
. . -> [Subject]  miniwindows--python

miniwindows--python

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 Fri 24 Apr 2009 11:20 PM (UTC)
Message
Ok... I've been struggling with this for a while now, I figure its time... I'm just trying to get the syntax down for miniwindows. I use python so here is what I have...
def OnPluginInstall():

	win = world.GetPluginID
	world.WindowCreate (win, 0, 0, 200, 200, 6, 0, #333333)
	world.WindowShow (win, 'true')


I get the following error:
Script error
Plugin: Most_Recent_Text (called from world: Dartmud)
Execution of line 158 column 32
Immediate execution
invalid syntax
Line in error: 
 world.WindowShow (win, 'true')
Error context in script:
 154 : def OnPluginInstall():
 155 : 
 156 :  win = world.GetPluginID
 157 :  world.WindowCreate (win, 0, 0, 200, 200, 6, 0, #333333)
 158*:  world.WindowShow (win, 'true')
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Fri 24 Apr 2009 11:55 PM (UTC)
Message
This:
world.WindowCreate (win, 0, 0, 200, 200, 6, 0, #333333)

is causing your problem because Python sees "#" as a comment delimiter, so really it's seeing your code as:

world.WindowCreate (win, 0, 0, 200, 200, 6, 0,
world.WindowShow (win, 'true')


which is wrong.

You need to replace #333333 with 0x333333.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sat 25 Apr 2009 12:03 AM (UTC)
Message
Quote:

world.WindowShow (win, 'true')


Does this really work in Python? The second argument is supposed to be a boolean (actually 0 for false and 1 for true), so what looks to me like a string with the value "true" won't really work. It may possible work for true, as it is non-zero, but I doubt "false" will work. Unless Python works in a stranger way than I imagine.

- Nick Gammon

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

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #3 on Sat 25 Apr 2009 02:57 AM (UTC)
Message
Yes, "false" would be true in Python for basically the same reason it's true in Lua. Whereas in Lua the only false values are the literal false constant and nil, in Python, many other things are treated as false: 0, empty lists, empty containers, etc. But Python doesn't do as much type coercion in general. For instance "3" * 3 won't result in 9.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #4 on Sat 25 Apr 2009 04:20 AM (UTC)
Message
That is odd... your change did work... but I don't see why that worked and the following works in another script:

world.ColourNote('#FFFFFF', '', ']')

(I tried it with the '' in the previous one as well)

Thanks a lot though, now I can continue working out that plugin tomorrow when I have time.
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #5 on Sat 25 Apr 2009 05:09 AM (UTC)
Message
Alright, so tinkering around a little before bed. Here is what I've got so far...
def OnPluginInstall():

	win = world.GetPluginID

	winHeight = 200
	winWidth = 300
	winRMargin = 5
	winLMargin =5

	world.WindowCreate (win, 0, 0, winWidth, winHeight, 6, 0, 0x000000)
	world.WindowRectOp (win, 1, 1, 1, -1, -1, 0x0000FF, 0xFFFFFF)
	world.WindowRectOp (win, 1, 2, 2, -2, -2, 0x0000FF, 0xFFFFFF)
	world.WindowFont (win, 'body', 'Dina', 9, 0, 0, 0, 0, 1, 0)
	world.WindowText (win, 'body', world.GetRecentLines(10), winLMargin, winRMargin, 0, 0, 0xFFFFFF, 1)
	world.WindowShow (win, 1)


Is there a function like 'on output updated' etc... that I can send to the miniwindow... i.e. the same thing displayed in my output window. I'll worry about scrolling it later when I'm operating on the correct thing, I suppose. I suppose I can use on packet recieved to update it, but I still need something to get the same output I see visually rather than recent lines. (it would be idea if it could store all the colors, etc...)
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Sat 25 Apr 2009 05:41 AM (UTC)
Message
Quote:

your change did work... but I don't see why that worked and the following works in another script:


In that one, you had the "#" inside quotes.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sat 25 Apr 2009 05:43 AM (UTC)
Message
Quote:

Is there a function like 'on output updated' etc... that I can send to the miniwindow


OnPluginScreendraw is probably pretty close. It gives you the line too, unfortunately without the colour codes.

- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #8 on Sat 25 Apr 2009 08:18 AM (UTC)
Message
Ok, have a few things here... Got a bit carried away and started that plugin to show the last lines... Well, I have the miniwindow resizing--sort of. It resizes when the little window is changed in size, however the little window doesn't count as resizing when maximized... Despite the large window resizing... so it doesn't work properly there. Also, the OnScreenDraw doesn't seem to ever get set off.
def OnPluginInstall():

	win = world.GetPluginID

	temp = world.GetWorldWindowPosition.split(',')
	winHeight = int((int(temp[3]) - int(temp[1])) * 0.25)
	winWidth= int(temp[2]) - int(temp[0]) - 28

	world.WindowCreate (win, 0, 0, winWidth, winHeight, 4, 0, 0x000000)
	world.WindowRectOp (win, 1, 1, 1, -1, -1, 0x0000FF, 0xFFFFFF)
	world.WindowRectOp (win, 1, 2, 2, -2, -2, 0x0000FF, 0xFFFFFF)

	world.WindowShow (win, 1)


def OnPluginWorldOutputResized():

	win = world.GetPluginID

	temp = world.GetWorldWindowPosition.split(',')
	winHeight = int((int(temp[3]) - int(temp[1])) * 0.25)
	winWidth= int(temp[2]) - int(temp[0]) - 28

	world.WindowCreate (win, 0, 0, winWidth, winHeight, 4, 0, 0x000000)
	world.WindowRectOp (win, 1, 1, 1, -1, -1, 0x0000FF, 0xFFFFFF)
	world.WindowRectOp (win, 1, 2, 2, -2, -2, 0x0000FF, 0xFFFFFF)

	world.WindowShow (win, 1)


def OnPluginScreendraw(type, log, line):

	world.note (type)
	world.note (log)
	world.note (line)

	win = world.GetPluginID

	temp = world.GetWorldWindowPosition.split(',')
	winHeight = int((int(temp[3]) - int(temp[1])) * 0.25)
	winWidth= int(temp[2]) - int(temp[0]) - 28

	world.WindowCreate (win, 0, 0, winWidth, winHeight, 4, 0, 0x000000)
	world.WindowRectOp (win, 1, 1, 1, -1, -1, 0x0000FF, 0xFFFFFF)
	world.WindowRectOp (win, 1, 2, 2, -2, -2, 0x0000FF, 0xFFFFFF)

	winRMargin = 5
	winLMargin = 5

	world.WindowCreate (win, 0, 0, winWidth, winHeight, 4, 0, 0x000000)
	world.WindowFont (win, 'body', 'Dina', 9, 0, 0, 0, 0, 1, 0)
	world.WindowText (win, 'body', line, winLMargin, winRMargin, 0, 0, 0xCCCCCC, 1)

	world.WindowShow (win, 1)


And just so you know where I'm going with this...
I would like this to be hidden unless the user is scrolling back, if everything is up to date, then the miniwindow won't be shown at all.

Any ideas?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Sat 25 Apr 2009 09:53 PM (UTC)
Message
Quote:

OnScreenDraw doesn't seem to ever get set off.


You mean OnPluginScreendraw I take it?

Quote:

world.note (type)
world.note (log)
world.note (line)


You know, the function is world.Note, not world.note, perhaps it is firing but the notes are failing.

- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #10 on Sun 26 Apr 2009 01:10 AM (UTC)
Message
strange, I got no error messages about that... I made the modification, still no go... Even tried taking the notes out entirely. I don't get an error or anything it doesn't even seem to get to the script...
def OnPluginScreenDraw(type, log, line):

	world.Note (str(type))
	world.Note (str(log))
	world.Note (str(line))

	win = world.GetPluginID

	temp = world.GetWorldWindowPosition.split(',')
	winHeight = int((int(temp[3]) - int(temp[1])) * 0.25)
	winWidth= int(temp[2]) - int(temp[0]) - 28

	world.WindowCreate (win, 0, 0, winWidth, winHeight, 4, 0, 0x000000)
	world.WindowRectOp (win, 1, 1, 1, -1, -1, 0x0000FF, 0xFFFFFF)
	world.WindowRectOp (win, 1, 2, 2, -2, -2, 0x0000FF, 0xFFFFFF)

	winRMargin = 5
	winLMargin = 5

	world.WindowCreate (win, 0, 0, winWidth, winHeight, 4, 0, 0x000000)
	world.WindowFont (win, 'body', 'Dina', 9, 0, 0, 0, 0, 1, 0)
	world.WindowText (win, 'body', line, winLMargin, winRMargin, 0, 0, 0xCCCCCC, 1)

	world.WindowShow (win, 1)

[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #11 on Sun 26 Apr 2009 07:29 AM (UTC)
Message
Quote:
Nick said:
You mean OnPluginScreendraw I take it?

Note that your plugin function is OnPluginScreenDraw -- difference in capitalization changes fundamental meaning.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #12 on Sun 26 Apr 2009 01:26 PM (UTC)

Amended on Sun 26 Apr 2009 01:42 PM (UTC) by LupusFatalis

Message
yep, I was trying it both ways, in case I screwed that up and nick typoed... since everything else seems to have each word capitalized. But it fails both ways. And the correct one is definitely?
def OnPluginScreendraw(type, log, line):
Because it acts as if that line is incorrect. I've commented out all the code and tried things that I know for a fact work. I get nothing.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Sun 26 Apr 2009 09:51 PM (UTC)
Message
"OnPluginScreendraw" is the spelling from the code.

I'm not sure how finicky Python is with matching subs. Try returning a value at the end of the script (eg. return 0, or whatever the syntax is). The way it is called it expects a return code.

- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Reply #14 on Tue 28 Apr 2009 02:43 AM (UTC)
Message
it was the return 0 afterall... lol

I have to figure out how to deal with the resizing, and getting multiple lines yet, but don't have the time to work on that tonight. Thanks again Nick.
[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.


47,043 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 HostDash]