I have been programming with wxWidgets for a few years using C++, but have only just started using Python and wxPython.
I am trying to write a very simple barcode reader / stock-taking app that runs on a Raspberry Pi. I am using Python 2.7 and wxPython from the Raspbian ‘Stretch’ repository.
My app has a single frame with 4 wx.TextCtrl and 12 buttons arranged as a ‘number pad’. 1 of the wx.TextCtrl is read-only and the other 3 should have numbers entered by the user by pressing the buttons on the ‘number pad’ (using a mouse or touch panel).
My approach is to capture a wx.EVT_SET_FOCUS event in each of the wx.TextCtrl and I had planned to record its Python handle/label/pointer using event.GetWindow(). Then when a number button is pressed, I would append the corresponding number to the control using something like focusCtrl.AppendText('1')
.
However, I am still a bit confused about the Python handle / unmutable object / mutable list concept. In particular, how I can record the whatever_it_is that is returned from event.GetWindow()?
This is what I have tried:
# In def __init__
self.qtyField.Bind(wx.EVT_SET_FOCUS, self.OnFocus)
# Then ...
def OnFocus(self, event):
print (“Got a focus event”)
self.focusWindow = event.GetWindow()
event.Skip()
# And ...
def OnOne(self, event): # wxGlade: MyFrame.<event_handler>
self.focusWindow.AppendText(‘1’)
event.Skip()
``
However, self.focusWindow only gets local scope (I think), so the self.focusWindow in OnOne is not the same as in OnFocus. If I want to create an object with class scope (i.e. focusWindow = wx.TextCtrl()), then it actually instantiates an extra control (as is reasonably expected).
I realise that these are basic Python questions, but I thought to ask here because of the wxPython context.
Separately, but related, I am using wxGlade to create the frame. wxGlade only has some of the events available to a control, specifically the hierarchical wx.Window events are not included. What is the best way to work with this - should I subclass the wxGlade created frame in my own file or edit the wxGlade generated “mainwindow.py”?
Finally, I miss the CodeLite working environment with code completion, debugging etc. I know this is a personal choice but any hints / tips on an IDE are much appreciated. I started with Idle, but now moved to Eric because it promised code completion - which I have failed to get working so far.
Thanks for any help!