| View previous topic :: View next topic |
| Author |
Message |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sat Nov 20, 2004 1:27 pm Post subject: Modeless window with controls in Python |
|
|
Here is an example of how to create a top level window with controls in Python. The window has controls such as....
Buttons
Checkbox
Text field
Combo boxes in three different styles.
Image button
List box
...and the controls have listeners attached so that when you click or operate some of the controls, they actually modify other controls in the window.
By publishing this code, it is not my intention to plant the idea into anyone's head that python could be used to create useful extensions to OOo.
You will need some modules from this thread....
Danny's Python Modules
This example looks so easy because it makes use of abstractions from my python library.
Note that the line that says....
cCashCowUrl = "file:///C:/Danny/Graphics/microsoft cash cow.bmp"
will need to be changed to point to your own bitmap of a cash cow.
I've had this stuff sitting on my hard drive since last June, and I thought I had better publish or perish.
| Code: |
from Danny.OOo.WindowLib import DBListenerWindow
from Danny.OOo.DrawLib import rgbColor
class ControlTestWindow( DBListenerWindow ):
"""This is a demonstration of how easy it is to create a modeless window with controls."""
cCashCowUrl = "file:///C:/Danny/Graphics/microsoft cash cow.bmp"
def __init__( self ):
DBListenerWindow.__init__( self, "Control Test Window" )
self.setWindowPosSize( 100, 100, 340, 400 )
self.addButton( "btnOK", -20, -10, 80, 30, "OK",
actionListenerProc = self.btnOK_clicked )
self.addButton( "btnCancel", -120, -10, 80, 30, "Cancel",
actionListenerProc = self.btnCancel_clicked )
self.addButton( "btnMeow", 20, 30, 80, 30, "Meow",
actionListenerProc = self.btnMeow_clicked )
self.addFixedText( "lblTails", 120, 50, 80, 20, "??? tails" )
self.addCheckBox( "chkTails", 120, 30, 80, 20, "With Tails",
itemListenerProc = self.chkTails_clicked )
self.addEdit( "edtXyzzy", 20, 80, 80, 20, "xyzzy" )
self.addComboBox( "cboNums", 20, 120, 80, 70, bDropdown=False )
self.addComboBoxItem( "cboNums", "Won" )
self.addComboBoxItem( "cboNums", "Too" )
self.addComboBoxItems( "cboNums", ("Free","Fore","Phive",) )
self.addComboBoxItems( "cboNums", ("Sicks","Sehvin","Ate",) )
self.addComboBox( "cboColor1", 120, 120, 80, 20 )
self.addComboBoxItems( "cboColor1", ("Red","Orange","Yellow","Green",
"Blue","Purple","Ultraviolet",) )
self.addListBox( "lstColor1", 120, 160, 80, 20, bDropdown=True )
self.addListBoxItems( "lstColor1", ("Red","Orange","Yellow","Green",
"Blue","Purple","Ultraviolet",) )
self.addListBox( "lstColor2", 240, 120, 80, 70 )
self.addListBoxItems( "lstColor2", ("Red","Orange","Yellow","Green",
"Blue","Purple","Ultraviolet",) )
self.addImageControl( "img1", 20, 220, 80, 80, nBorder=0 )
self.setImageControlImageURL( "img1", self.cCashCowUrl )
self.setControlModelProperty( "img1", "BackgroundColor", rgbColor( 255, 200, 200 ) )
self.addButton( "btnImage1", 120, 220, 80, 80 )
self.setControlModelProperty( "btnImage1", "ImageURL", self.cCashCowUrl )
def btnOK_clicked( self, oActionEvent ):
"""This is called when the OK button is clicked."""
self.windowClose()
def btnCancel_clicked( self, oActionEvent ):
"""This is called when the Cancel button is clicked."""
self.windowClose()
def btnMeow_clicked( self, oActionEvent ):
"""This is called when the Meow button is clicked."""
# whatever you've typed into the text box under the Meow button
# is copied to the fixed text box under the checkbox.
self.setFixedTextText( "lblTails", self.getEditText( "edtXyzzy" ) )
def chkTails_clicked( self, oItemEvent ):
"""This is called when the checkbox is toggled."""
if self.getCheckBoxState( "chkTails" ):
self.setFixedTextText( "lblTails", "checked" )
else:
self.setFixedTextText( "lblTails", "not checked" )
# import Danny.OOo.Test.WindowControlTest
# reload( Danny.OOo.Test.WindowControlTest ); from Danny.OOo.Test.WindowControlTest import *
|
_________________ Want to make OOo Drawings like the colored flower design to the left?
Last edited by DannyB on Sat Nov 20, 2004 1:38 pm; edited 2 times in total |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sat Nov 20, 2004 1:31 pm Post subject: |
|
|
The following example shows how easy it is to create a top level window and listen to its window events.
This creates a top level modeless window and a Writer document. When events fire on the window, such as focusGained, or keyPressed, or mousePressed, or mouseReleased, the event is written into the Writer document in real time.
I think that making the events in this example write into a writer document causes problems when the modeless window is closed. So I commented out some of the event handling routines as you can see. If you don't write the events into a Writer document, it seems fine to go ahead and uncomment all of the event handling routines.
Again, a case of publish or perish. Code nearly half a year old, etc.
| Code: |
from Danny.OOo.WindowLib import DBListenerWindow
import Danny.OOo.PrintToWriter
class EventTestWindow( DBListenerWindow ):
"""This window demonstrates that the listener methods work in a subclass."""
def __init__( self ):
DBListenerWindow.__init__( self, "Event Test Window" )
self.oPrintWriter = Danny.OOo.PrintToWriter.PrintToWriter()
# If you are going to override the following group of commented methods,
# you need to something other than write into a Writer document.
# def windowOpened( self, tEvent ):
# self.oPrintWriter.writeLn( "windowOpened" )
# def windowClosing( self, tEvent ):
# self.oPrintWriter.writeLn( "windowClosing" )
# def windowClosed( self, tEvent ):
# self.oPrintWriter.writeLn( "windowClosed" )
# def windowMinimized( self, tEvent ):
# self.oPrintWriter.writeLn( "windowMinimized" )
# def windowNormalized( self, tEvent ):
# self.oPrintWriter.writeLn( "windowNormalized" )
# def windowActivated( self, tEvent ):
# self.oPrintWriter.writeLn( "windowActivated" )
# def windowDeactivated( self, tEvent ):
# self.oPrintWriter.writeLn( "windowDeactivated" )
# def windowResized( self, tEvent ):
# self.oPrintWriter.writeLn( "windowResized" )
# def windowMoved( self, tEvent ):
# self.oPrintWriter.writeLn( "windowMoved" )
# def windowShown( self, tEvent ):
# self.oPrintWriter.writeLn( "windowShown" )
# def windowHidden( self, tEvent ):
# self.oPrintWriter.writeLn( "windowHidden" )
def focusGained( self, tEvent ):
self.oPrintWriter.writeLn( "focusGained" )
def focusLost( self, tEvent ):
self.oPrintWriter.writeLn( "focusLost" )
def keyPressed( self, tEvent ):
self.oPrintWriter.writeLn( "keyPressed",
"KeyCode:", tEvent.KeyCode,
"KeyChar:", tEvent.KeyChar,
"KeyFunc:", tEvent.KeyFunc )
def keyReleased( self, tEvent ):
self.oPrintWriter.writeLn( "keyReleased",
"KeyCode:", tEvent.KeyCode,
"KeyChar:", tEvent.KeyChar,
"KeyFunc:", tEvent.KeyFunc )
def mousePressed( self, tEvent ):
self.oPrintWriter.writeLn( "mousePressed ",
"Buttons:" + str( tEvent.Buttons ),
"X,Y:" + str( tEvent.X ) + "," + str( tEvent.Y ),
"ClickCount:" + str( tEvent.ClickCount ),
"PopupTrigger:" + str( tEvent.PopupTrigger ) )
def mouseReleased( self, tEvent ):
self.oPrintWriter.writeLn( "mouseReleased",
"Buttons:" + str( tEvent.Buttons ),
"X,Y:" + str( tEvent.X ) + "," + str( tEvent.Y ),
"ClickCount:" + str( tEvent.ClickCount ),
"PopupTrigger:" + str( tEvent.PopupTrigger ) )
def mouseEntered( self, tEvent ):
self.oPrintWriter.writeLn( "mouseEntered",
"Buttons:" + str( tEvent.Buttons ),
"X,Y:" + str( tEvent.X ) + "," + str( tEvent.Y ),
"ClickCount:" + str( tEvent.ClickCount ),
"PopupTrigger:" + str( tEvent.PopupTrigger ) )
def mouseExited( self, tEvent ):
self.oPrintWriter.writeLn( "mouseExited",
"Buttons:" + str( tEvent.Buttons ),
"X,Y:" + str( tEvent.X ) + "," + str( tEvent.Y ),
"ClickCount:" + str( tEvent.ClickCount ),
"PopupTrigger:" + str( tEvent.PopupTrigger ) )
def windowPaint( self, tEvent ):
self.oPrintWriter.writeLn( "windowPaint",
"UpdateRect:" + str( tEvent.X ) + "," + str( tEvent.Y ) +
"," + str( tEvent.Width ) + "," + str( tEvent.Height ),
"Rect:" + str( tEvent.Buttons ) )
# def disposing( self, tEvent ):
# self.oPrintWriter.writeLn( "disposing" )
def DoEventTest():
oEventTestWindow = EventTestWindow()
|
After running the above, you will get a Writer document and a top level modeless window. After maniupating the window, the Writer document contains text like....
| Code: | focusGained
mouseEntered Buttons:0 X,Y:274,307 ClickCount:0 PopupTrigger:0
mouseExited Buttons:0 X,Y:331,372 ClickCount:0 PopupTrigger:0
mouseEntered Buttons:0 X,Y:298,347 ClickCount:0 PopupTrigger:0
mousePressed Buttons:1 X,Y:193,319 ClickCount:1 PopupTrigger:0
mouseReleased Buttons:1 X,Y:192,319 ClickCount:1 PopupTrigger:0
mouseExited Buttons:0 X,Y:349,398 ClickCount:1 PopupTrigger:0
mouseEntered Buttons:0 X,Y:286,348 ClickCount:1 PopupTrigger:0
mouseExited Buttons:0 X,Y:335,383 ClickCount:1 PopupTrigger:0
keyPressed KeyCode: 512 KeyChar: <Char instance a> KeyFunc: 0
keyReleased KeyCode: 512 KeyChar: <Char instance a> KeyFunc: 0
keyPressed KeyCode: 513 KeyChar: <Char instance b> KeyFunc: 0
keyReleased KeyCode: 513 KeyChar: <Char instance b> KeyFunc: 0
keyPressed KeyCode: 514 KeyChar: <Char instance c> KeyFunc: 0
keyReleased KeyCode: 514 KeyChar: <Char instance c> KeyFunc: 0
focusLost
|
_________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
Posted: Sun Nov 21, 2004 8:47 am Post subject: |
|
|
Danny,
I see you are advanced enough to do what I plan to do in C++ in far future :
starting from a Basic DialogBox and automatically generate a class which manage the same dialog Box. I know, this is a hard work but you have already worked with all we need :
- sax (I have to try to use it in C++)
- dialogBox or windows (I am only at the begining and don't know how to write buttons callback)
At first glance, this answer seems to say : Danny you have still to work, there is still a lot to do...
But in fact I only want to show how advanced you are, and what a great work you have done. And with this occasion to put some ideas in this thread. _________________ Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
jluna General User

Joined: 18 Dec 2007 Posts: 16
|
Posted: Mon Jan 07, 2008 1:54 pm Post subject: |
|
|
DannyB,
Thanks for all the effort you've put into these libraries. I know these libraries (and these tests) were written some time ago, but I'm hoping you have some insight into why the window test doesn't work for me now (tried using OOo 2.2 and OOo 2.3). The window is created along with all of the controls as you would expect, but the listeners don't work. Nothing happens when you perform the actions. I've been modifying the window test and trying out my own things, but I can't seem to figure out what it is going wrong. I wrote a fairly detailed post here:
http://www.oooforum.org/forum/viewtopic.phtml?p=269530#269530
I'm just hoping you'll see this thread and have a chance to test out the window test. Thanks in advance. |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
jluna General User

Joined: 18 Dec 2007 Posts: 16
|
Posted: Fri Jan 11, 2008 8:22 am Post subject: |
|
|
| Thanks for the response Serge. Do you have any advice on how I might get my question answered? I've made two posts and I haven't had any luck so far. |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|