A problem using the slider control (posible duplicate email)
"Sommer, Chuck" <[email protected]> Mon, 20 Apr 2009 10:56:21 -0400
| Newsgroups | gmane.comp.python.pythoncard |
|---|---|
| Message-ID | <[email protected]> |
I have created a Python-Card application that uses a Spinner and a Slider to control the same value. When I update the Spinner, I want the Slider updated, and when I update the Slider I want the spinner updated.
My first attempt to synchronize these 2 objects resulted in something that when I worked the slider, the slider never released the mouse and I had to kill the application. I modified the slider to send a "command" and I now have a working program.
In the broken version I used the event
def on_gainPotSlider2_mouseUp(self,event):
In the working version I use the command
def on_sliderAction_command(self,event):
This example, on startup prior to any PythonCard code executing,
uses the console input to decide which version of the program to run.
So gang, what did I do wrong the first time?
Thanks Chuck
Chuck Sommer
Insight Technology Inc.
[email protected]
Tel: 603-551-6283
Cell: 603-234-2306
Warning: This Document may contain technical data that is subject to the control of the international traffic in arms regulations and/or the export administration regulations
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Pythoncard-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pythoncard-users
spinner_slider.rsrc.py
(application/octet-stream, 736 B)
{'application':{'type':'Application',
'name':'Template',
'backgrounds': [
{'type':'Background',
'name':'bgTemplate',
'title':'Standard Template with no menus',
'size':(400, 300),
'components': [
{'type':'Slider',
'name':'gainPotSlider2',
'position':(17, 43),
'command':u'sliderAction',
'labels':False,
'layout':'horizontal',
'max':255,
'min':0,
'tickFrequency':0,
'ticks':False,
'value':0,
},
{'type':'Spinner',
'name':'gainPotSpinner1',
'position':(10, 10),
'max':255,
'min':0,
'value':0,
},
] # end components
} # end background
] # end backgrounds
} }
spinner_slider.py
(application/octet-stream, 2.3 KB)
#!/usr/bin/python
"""
__version__ = "$Revision: 1.3 $"
__date__ = "$Date: 2004/04/14 02:38:47 $"
"""
from PythonCard import model
class MyBackground(model.Background):
def on_initialize(self, event):
# if you have any initialization
# including sizer setup, do it here
self.potVal = 80
self.components.gainPotSpinner1.value = self.potVal
self.components.gainPotSlider2.value = self.potVal
pass
# when the text in the spinner is updated,
# update the value of self.potVal and
# update the slider and redraw it
def on_gainPotSpinner1_textUpdate(self, event):
self.potVal = self.components.gainPotSpinner1.value
self.components.gainPotSlider2.value = self.potVal
self.components.gainPotSlider2.redraw()
class MyBackground_mouseUp(MyBackground):
'''Example that uses the mouseUp event on gainPotSlider2
to update self.Val and the gainPotSpinner1'''
# when the mouse is released in the spinner is released,
# update the value of self.potVal and
# update the spinner and redraw it
def on_gainPotSlider2_mouseUp(self,event):
self.potVal = self.components.gainPotSlider2.value
self.components.gainPotSpinner1.value = self.potVal
self.components.gainPotSpinner1.redraw()
class MyBackground_sliderAction_command(MyBackground):
'''Example that uses the command ("sliderAction") of gainPotSlider2
to update self.Val and the gainPotSpinner1'''
# when the slider has an action (command)
# update the value of self.potVal and
# update the spinner and redraw it
def on_sliderAction_command(self,event):
self.potVal = self.components.gainPotSlider2.value
self.components.gainPotSpinner1.value = self.potVal
self.components.gainPotSpinner1.redraw()
if __name__ == '__main__':
myInputString = raw_input('''
1 = broken example (all others = working example) ? ''')
if((len(myInputString) > 0) and (myInputString[0] == '1')):
print "executing the broken example"
app = model.Application(MyBackground_mouseUp)
else:
print "executing the fixed example"
app = model.Application(MyBackground_sliderAction_command)
app.MainLoop()