473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems with current value of wx.SpinCtrl and EVT_SPIN

Hello,

I am new to Python/wxPython and am experiencing first problems. I have
a dialog which includes a SpinCtrl and a Slider. I want the Slider to
affect the SpinCtrl and vice versa
(http://wiki.wxpython.org/index.cgi/C...geDemos#Part1).

The code I wrote does, however, not work correctly. The event EVT_SPIN
is never handled (even though I wrote a handler), and in the handler of
EVT_SCROLL_CHANGED I do not obtain the modified value, but the value
before the control has changed.

Any feedback would be greatly appreciated.
To clarify my problem, here's the code (Python2.4, wxPython 2.6) :

import wx

class AppFrame(wx.Frame):
def OnSpinGeneral(self, event):
b = wx.MessageBox("never reached")

def OnSpin(self, event):
# I tried to use Skip so that the changing of the value would
take place before
# I invoke GetValue(), however this has no effect
event.Skip()

print self.spin.GetValue()
self.slider.SetValue(self.spin.GetValue())

def OnScrollChanged(self, event):
self.spin.SetValue(self.slider.GetValue())

def __init__(self):
wx.Frame.__init__( self,
None, -1, "",
#size=FRAME_SIZE,
style=wx.DEFAULT_FRAME_STYLE )
self.sizer = wx.BoxSizer( wx.VERTICAL )

self.spin = wx.SpinCtrl(self, min = 0, max = 50)
self.slider = wx.Slider(self, 1, 6, 0, 50)

self.sizer.Add(self.spin)
self.sizer.Add(self.slider)

self.Bind(wx.EVT_SCROLL_CHANGED, self.OnScrollChanged,
self.slider)
self.Bind(wx.EVT_SPIN_UP, self.OnSpin, self.spin)
self.Bind(wx.EVT_SPIN_DOWN, self.OnSpin, self.spin)
self.Bind(wx.EVT_SPIN, self.OnSpinGeneral, self.spin)

self.SetSizer(self.sizer)
self.SetAutoLayout(1)
self.Show(1)

app = wx.PySimpleApp()
frame = AppFrame()
app.MainLoop()

Apr 9 '06 #1
3 3695
blackno666 wrote:
I am new to Python/wxPython and am experiencing first problems. I have
a dialog which includes a SpinCtrl and a Slider. I want the Slider to
affect the SpinCtrl and vice versa
(http://wiki.wxpython.org/index.cgi/C...geDemos#Part1).

The code I wrote does, however, not work correctly. The event EVT_SPIN
is never handled (even though I wrote a handler), and in the handler of
EVT_SCROLL_CHANGED I do not obtain the modified value, but the value
before the control has changed.


Does it *appear* to work? That is, if you run it, does the slider move
if you click on one of the spinner buttons, and does the spinner value
change when you move the slider (and release the button)? Because
that's what happens for me, so I'm not sure what it is that you expected
it to do... (wxPython 2.6.1.0 on WinXP SP2)

-Peter

Apr 9 '06 #2
Yes, it "works". However buggy.

When the slider is set to 0 and the up button is pressed in the
SpinCtrl, the value in the SpinCtrl will be 1, but the slider will not
move. There's also a discrepancy between the value displayed in the
SpinCtrl and the value output by

print self.spin.GetValue().

When playing with this code I also noticed that I was not able change
the behaviour of the up and down buttons. I expected that if I modify
OnSpin in the following way:

def OnSpin(self, event):
pass

That pressing the spin buttons would have no effect. However, the value
is still increased or decreased....

Apr 9 '06 #3
Just found a solution to the problem:

when using wx.EVT_SPINCTRL instead of wx.EVT_SPIN_UP, wx.EVT_SPIN_DOWN
or wx.EVT_SPIN the program behaves correctly.

wxWidget documentation for wxSpinCtrl states that "You may also use the
wxSpinButton event macros, however the corresponding events will not be
generated under all platforms"; I ran the program on WinXP SP2.
However, the events seem to be handled (at least EVT_SPIN_UP,
wx.EVT_SPIN_DOWN). So I do not understand why handling these events
leads to a buggy behaviour.

Apr 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Buchleitner Martin | last post by:
Hi! I got another problem parsing my XML document: <document> <paragraph> <style val=listing/> <text>listing #1 text</text> </paragraph> <paragraph>
4
by: Jack | last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that builds the sql string. In the front end asp page, the checkbox code is written as follows: <i><input...
11
by: brian.newman | last post by:
I'm trying to use a layer inside a form to hide/reveal a part of the form, but my code doesn't seem to be working and I need some help debugging it. I'm not getting an error which has made it...
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
6
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
14
by: Henk | last post by:
Hi Guys, (see actual code below) I wrote a little program that is supposed to read a file (input.txt) into memory (using a stack) and then reverse the file and display it to output. It works,...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
17
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control...
1
by: PowerLifter1450 | last post by:
I've been having a very rough time installinig mySQL on Linux. I have been following the instructions form here: http://www.hostlibrary.com/installing_apache_mysql_php_on_linux Everytime I get to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.