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

Gammon Software Solutions forum

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

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

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: miniwindows--python
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Sun 10 May 2009 07:47 AM (UTC)  quote  ]

Amended on Sun 10 May 2009 07:49 AM (UTC) by LupusFatalis

Message
I updated this version to include word wrapping. Huzzah!
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, April 24, 2009, 7:01 PM -->
<!-- MuClient version 4.40 -->

<!-- Plugin "Most_Recent_Text" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Most_Recent_Text"
   id="5857d039eaa8c30c4c813ec8"
   language="Python"
   purpose="Miniwindow displaying up to date information while scrolling back the main window"
   date_written="2009-04-24 19:01:01"
   requires="4.40"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.pys"/>

<!--  Script  -->


<script>
<![CDATA[

LinesList = []
winTMargin = 1
winLMargin = 1
win = world.GetPluginID
fontHeight = 16
wrapWidth = 107

def OnPluginDisconnect():
	world.WindowShow (win, 0)


def OnPluginClose():
	world.WindowShow (win, 0)


def OnPluginDisable():
	world.WindowShow (win, 0)


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

	world.WindowCreate (win, 0, 0, winWidth, winHeight, 4, 0, 0x000000)
	world.WindowRectOp (win, 2, 1, 1, -1, -1, 0x000000, 0x000000)
	world.WindowLine (win, 0, winHeight, winWidth, winHeight, 0xCCCCCC, 0, 5)

	world.WindowShow (win, 1)


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

	world.WindowFont (win, 'body', 'Dina', 10, 0, 0, 0, 0, 1, 0)
	if not world.WindowFontInfo(win, 'body', 1):
		fontHeight = 16
	else:
		fontHeight = int(world.WindowFontInfo(win, 'body', 1))

	mLines = winHeight / fontHeight
	
	while len(LinesList) > mLines:
		LinesList.pop(0)

	DisplayText()
	
def OnPluginScreendraw(type, log, line):
	temp = world.GetWorldWindowPosition.split(',')
	winHeight = int((int(temp[3]) - int(temp[1])) * 0.25)
	winWidth = int(temp[2]) - int(temp[0]) - 29

	world.WindowFont (win, 'body', 'Dina', 10, 0, 0, 0, 0, 1, 0)
	if not world.WindowFontInfo(win, 'body', 1):
		fontHeight = 16
	else:
		fontHeight = int(world.WindowFontInfo(win, 'body', 1))

	mLines = winHeight / fontHeight

	nLine = line
	while len(nLine) > wrapWidth:
		sChar = nLine[0:wrapWidth].rfind(' ')
		aLine = str(nLine[0:sChar])

		if len(LinesList) >= mLines:
			LinesList.pop(0)
		LinesList.append (aLine)

		nLine = ' ' + nLine[sChar:len(nLine)].lstrip()

	if len(LinesList) >= mLines:
		LinesList.pop(0)
	LinesList.append (nLine)

	DisplayText()
	return 0

def DisplayText():

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

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

	for i in range(0, len(LinesList)):
		localTMargin = winTMargin + int(fontHeight)*i
		world.WindowText (win, 'body', LinesList[\i], winLMargin, localTMargin, 0, 0, 0xCCCCCC, 1)

	world.WindowLine (win, 0, winHeight, winWidth, winHeight, 0xCCCCCC, 0, 5)

	world.WindowShow (win, 1)

]]>
</script>


</muclient>
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Tue 05 May 2009 11:05 PM (UTC)  quote  ]

Amended on Tue 05 May 2009 11:07 PM (UTC) by LupusFatalis

Message
Ok, I found 2 bugs in it. If you resize the window, your miniwindow can become lagged as the list has more things than can be displayed. Also, when loading at first, for some reason the world.WindowFontInfo(win, 'body', 1) will register as None... so an if statement has been included to account for that. I still want to preform the aforementioned upgrades if anyone has any ideas as to how. Here is the new code.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, April 24, 2009, 7:01 PM -->
<!-- MuClient version 4.40 -->

<!-- Plugin "Most_Recent_Text" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Most_Recent_Text"
   id="5857d039eaa8c30c4c813ec8"
   language="Python"
   purpose="Miniwindow displaying up to date information while scrolling back the main window"
   date_written="2009-04-24 19:01:01"
   requires="4.40"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.pys"/>

<!--  Script  -->


<script>
<![CDATA[

LinesList = []
winTMargin = 1
winLMargin = 1
win = world.GetPluginID
fontHeight = 16

def OnPluginDisconnect():
	world.WindowShow (win, 0)


def OnPluginClose():
	world.WindowShow (win, 0)


def OnPluginDisable():
	world.WindowShow (win, 0)


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

	world.WindowCreate (win, 0, 0, winWidth, winHeight, 4, 0, 0x000000)
	world.WindowRectOp (win, 2, 1, 1, -1, -1, 0x000000, 0x000000)
	world.WindowLine (win, 0, winHeight, winWidth, winHeight, 0xCCCCCC, 0, 5)

	world.WindowShow (win, 1)


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

	world.WindowFont (win, 'body', 'Dina', 10, 0, 0, 0, 0, 1, 0)
	if not world.WindowFontInfo(win, 'body', 1):
		fontHeight = 16
	else:
		fontHeight = int(world.WindowFontInfo(win, 'body', 1))

	mLines = winHeight / fontHeight
	
	while len(LinesList) > mLines:
		LinesList.pop(0)

	DisplayText()
	
def OnPluginScreendraw(type, log, line):
	temp = world.GetWorldWindowPosition.split(',')
	winHeight = int((int(temp[3]) - int(temp[1])) * 0.25)
	winWidth = int(temp[2]) - int(temp[0]) - 29

	world.WindowFont (win, 'body', 'Dina', 10, 0, 0, 0, 0, 1, 0)
	if not world.WindowFontInfo(win, 'body', 1):
		fontHeight = 16
	else:
		fontHeight = int(world.WindowFontInfo(win, 'body', 1))

	mLines = winHeight / fontHeight
	
	if len(LinesList) >= mLines:
		LinesList.pop(0)
	LinesList.append (line)

	DisplayText()
	return 0

def DisplayText():

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

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

	for i in range(0, len(LinesList)):
		localTMargin = winTMargin + int(fontHeight)*i
		world.WindowText (win, 'body', LinesList[i], winLMargin, localTMargin, 0, 0, 0xCCCCCC, 1)

	world.WindowLine (win, 0, winHeight, winWidth, winHeight, 0xCCCCCC, 0, 5)

	world.WindowShow (win, 1)

]]>
</script>


</muclient>
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Sun 03 May 2009 03:34 AM (UTC)  quote  ]

Amended on Mon 04 May 2009 01:59 PM (UTC) by David Haley

Message
Ok... I Have a piece of code I think is psuedo worthy of actually sharing... as well as a few improvements I'd like to make but have no idea as to how to do so.
LinesList = []

def OnPluginConnect():
	win = world.GetPluginID

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

	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 OnPluginDisconnect():
	win = world.GetPluginID
	world.WindowShow (win, 0)


def OnPluginClose():
	win = world.GetPluginID
	world.WindowShow (win, 0)


def OnPluginDisable():
	win = world.GetPluginID
	world.WindowShow (win, 0)


def OnPluginEnable():
	win = world.GetPluginID

	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]) - 29

	world.WindowFont (win, 'body', 'Dina', 10, 0, 0, 0, 0, 1, 0)
	fontHeight = int(world.WindowFontInfo(win, 'body', 1))
	mLines = winHeight / fontHeight
	
	world.WindowCreate (win, 0, 0, winWidth, winHeight, 4, 0, 0x000000)
	world.WindowRectOp (win, 1, 1, 1, -1, -1, 0x0000FF, 0x0000FF)
	world.WindowRectOp (win, 1, 2, 2, -2, -2, 0x0000FF, 0x0000FF)

	winTMargin = 5
	winLMargin = 5

	for i in range(0, len(LinesList)):
		localTMargin = winTMargin + 16*i
		world.WindowText (win, 'body', LinesList[i], winLMargin, localTMargin, 0, 0, 0xCCCCCC, 1)

	world.WindowShow (win, 1)


def OnPluginScreendraw(type, log, 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]) - 29

	world.WindowFont (win, 'body', 'Dina', 10, 0, 0, 0, 0, 1, 0)
	fontHeight = int(world.WindowFontInfo(win, 'body', 1))
	mLines = winHeight / fontHeight
	
	if len(LinesList) >= mLines:
		LinesList.pop(0)
		world.WindowRectOp (win, 1, 2, 2, -2, -2, 0x0000FF, 0x0000FF)
	LinesList.append (line)

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

	winTMargin = 5
	winLMargin = 5

	for i in range(0, len(LinesList)):
		localTMargin = winTMargin + 16*i
		world.WindowText (win, 'body', LinesList[i], winLMargin, localTMargin, 0, 0, 0xCCCCCC, 1)

	world.WindowShow (win, 1)
	return 0


It will display the most recent lines. Any number of lines based on a percentage of your screen. Now... Here is where things get dicey. The world screen size isn't updated when maximized, any idea how to extract that, so as to use it in the resizing function here.

And the other improvement I want to make is. I want this window to be displayed ONLY when I am scrolling back in the main window. Any ideas?



(EDIT by David: I took the liberty of fixing the [i] tags in the post so as to not italicize the entire post.)
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Tue 28 Apr 2009 02:43 AM (UTC)  quote  ]
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

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sun 26 Apr 2009 09:51 PM (UTC)  quote  ]
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 Sun 26 Apr 2009 01:26 PM (UTC)  quote  ]

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 David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sun 26 Apr 2009 07:29 AM (UTC)  quote  ]
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 Sun 26 Apr 2009 01:10 AM (UTC)  quote  ]
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 Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sat 25 Apr 2009 09:53 PM (UTC)  quote  ]
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 Sat 25 Apr 2009 08:18 AM (UTC)  quote  ]
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  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sat 25 Apr 2009 05:43 AM (UTC)  quote  ]
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 Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sat 25 Apr 2009 05:41 AM (UTC)  quote  ]
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 LupusFatalis   (154 posts)  [Biography] bio
Date Sat 25 Apr 2009 05:09 AM (UTC)  quote  ]
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 LupusFatalis   (154 posts)  [Biography] bio
Date Sat 25 Apr 2009 04:20 AM (UTC)  quote  ]
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 David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sat 25 Apr 2009 02:57 AM (UTC)  quote  ]
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

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.


5,427 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]