miniwindows--python

Posted by LupusFatalis on Fri 24 Apr 2009 11:20 PM — 18 posts, 72,948 views.

#0
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')
USA #1
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.
Australia Forum Administrator #2
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.
USA #3
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.
#4
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.
#5
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...)
Australia Forum Administrator #6
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.
Australia Forum Administrator #7
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.
#8
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?
Australia Forum Administrator #9
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.
#10
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)

USA #11
Quote:
Nick said:
You mean OnPluginScreendraw I take it?

Note that your plugin function is OnPluginScreenDraw -- difference in capitalization changes fundamental meaning.
#12
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.
Amended on Sun 26 Apr 2009 01:42 PM by LupusFatalis
Australia Forum Administrator #13
"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.
#14
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.
#15
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.)
Amended on Mon 04 May 2009 01:59 PM by David Haley
#16
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>
Amended on Tue 05 May 2009 11:07 PM by LupusFatalis
#17
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>