Some GUI's libraries have spin button widget with optional feature - acceleration.
When holding down one of the buttons (up or down) - as a result an acceleration of change in the value according to how long it is depressed.
Is this feature in wx.SpinButton and what's the best way to implement it?
No, that's not a built in feature of the SpinButton. Note that the SpinButton isn't implemented cross-platform, so you might want to look at wx.SpinCtrl or FloatSpin. Anyway, to implement what you want, you could probably catch the wx.EVT_SPIN and start a wx.Timer. When the timer hits some pre-determined value, you could start updating the control yourself. I'm not sure if this would work as you would be trying to update a widget that is already being updated, but it might...
Of course, you'd also have to bind to the mouse up event to stop the timer and stop the updates. I suspect you my have to roll your own widget though...
I would ask on the wxPython mailing list. Someone there might have more ideas.
Related
I have a canvas that is covered by many...many images. Most overlap each other sometimes 10 deep. A simple example is
a1 = self.Canvas.create_rectangle(0,0,100,100,fill="red")
self.Canvas.tag_bind(a1,"<Button-1>",self.eventa1)
b1 = self.Canvas.create_rectangle(0,0,100,100,fill="green")
self.Canvas.tag_bind(b1,"<Button-1>",self.eventb1)
c1 = self.Canvas.create_rectangle(0,0,100,100,fill="blue")
self.Canvas.tag_bind(c1,"<Button-1>",self.eventc1)
The top layer shows blue. I click on it and eventc1 is called as expected.
I was wondering if there is any way when I click on position X, Y to get each event covering that point (red, green and blue layer in this case) to fire the corresponding event for that layer in order top to bottom.
Or can the blue event processing have a way to cause the next lower layer' event to automatically fire. There is no way the blue event knows what it is sitting on top of. 20 years ago, I used GTK+ in C and it allowed an event to return an indication to fire a lower level event or not.
Your code does not look at all like C I must say. Looks more like some slippery slithery language...
In GTK you can customise a widget to your hearts content. GtkDrawingArea is typically used when you want to tinker around UI side too. You can override the event handlers for mouse interaction e.g.: widget_klass->button_press_event, widget_klass->motion_notify_event widget_klass->button_release_event and widget_klass->expose_event. You can make your own signal handlers with g_signal_new and fire off which ever one (or multiple ones thereof) you want according to where the click is in each of your custom event handlers. Make sure to add gtk_widget_add_events(widget, GDK_BUTTON_PRESS_MASK|etc...) to enable these events in your classes init function.
Enforcing a strict signal handling order might be a bit more complicated. The signals have the option for G_SIGNAL_RUN_FIRST etc, and you could get 3 running a strict order this way though there's always the chance that the event loop may receive signals at two different stages. Best would be to fire off the one signal with data provided that would list the functions to call and order in which they need to be invoked.
So yes you can do that in C, though it might be tricky. I'm pretty sure all the bindings don't loose functionality so you should be able to do it in almost any language, but as for all non-c coding, when you want to delve deep, the deobfuscation places you on a slippery slope. If you know how to do it in C, skip the snakes and ladders game and write it in C. If you've got boss/team constraints, port it when done, to make people happy - I believe there is enough consistency across the GTK API bindings that it shouldn't be too much of an issue. But being forced to think in a ladedah mindset of simpleness and being expected to achieve fine detailed complex solutions is just untenable.
I am writing an app in kivy which does cpu-heavy calculations at launch. I want the app to display what it's doing at the moment along with the progress, however, since the main loop is not reached yet, it just displays empty white screen until it finishes working. Can I force kivy to update the interface?
Basically I'm looking for kivy's equivalent of Tkinter's root.update()
I could create a workaround by defining a series of functions with each calling the next one through Clock.schedule_once(nextFunction, 1), but that would be very sloppy.
Thanks in advance.
Leaving aside the question of whether you should be using threading or something instead (which possibly you should), the answer is just that you should move your cpu calculations to somewhere else. Display something simple initially (i.e. returning a simple widget from your build method), then do the calculations after that, such as by clock scheduling them.
Your calculations will still block the gui in this case. You can work around this by doing them in a thread or by manually breaking them up into small pieces that can be sequentially scheduled.
It might be possible to update the gui by manually calling something like Clock.tick(), but I'm not sure if this will work right, and even if so it won't be able to display graphics before they have been initialised.
I am in the process of writing an app that I want to make a GUI for. I've got a little bit of experience with making GUI's in wxpython already, but one thing I have not had to try yet; is minimizing an application to tray. I have been doing my research and figured out how to make the icon, but what I have gotten stuck in the mud with is minimizing the Frame to the tray. I have found no functions that I can use to hide the frame with (wx.Frame.Hide() is not the answer). Do any of you know of any way that I could accomplish this? Thanks!
You need to look at the wxPython demo's source code. Look for the part which mentions the DemoTaskBarIcon. Then you'll want to bind to wx.EVT_ICONIZE. You do end up using the frame's Hide() method within the "iconize" event handler. How else would you hide it? Then to show it again, you'll want to use the menu from your task bar icon (which is technically a system tray icon on Windows). See also:
http://bytes.com/topic/python/answers/699757-wxpython-how-minimize-taskbar
http://wxpython-users.1045709.n5.nabble.com/minimize-to-try-question-td2359957.html
Just wondering whether there is any provision/method to bind clicks on images/(or include a button) to result into some events. Also is there any kind of way to draw a StaticLine kind of thing in a RichTextCtrl in wxPython.
You can bind to a button if you like, you could use a bitmapbutton instead, or bind mouse events to your static bitmap. The wxPython demo has examples for all of these methods.
With regards to the "StaticLine kinda thing", are you trying to resize the richtextctrl on demand? You might want to look at the ExpandoTextCtrl instead, which is also demonstrated in the demo. If not, I would need some more detail than "kinda thing".. ;)
I am currently working on a (Python2.5) application which handles input from a game controller. We've designated a button as a shift button to change the mapping (inputtype,value->function) of the other buttons on the fly. The mapping also depends on the mode our application is running in. We are running into lots of hairy edge cases (e.g. how to handle press shift, press button x, release shift, release button x) and I was wondering if there are any known good structures/architectures/patterns for dealing with this kind of input?
Satemachines are a good pattern to handle complex inputs.
Here is a machine that handle the above sequence.
You can implement statemachines with switch or state pattern (see Python state-machine design )