Hello,
I am new to wxPython but staedily and slowly finding my way in.
I am building my GUI with wxGlade which works quite well after getting used to
its functionality.
I let wxGlade write my code in a file called myapp_gui.py. Then I use anthother
file myapp_controls.py to subclass the GUI created with wxGlade. I set up my
application in the file myapp.py.
In my GUI I have ComboBox for selecting among a number of choices. I would like
to create the choices available for the ComboBox from an function
provide_buildings_choice_choices which creates a list of all choices instead of
manually entering all choices in wxGlade.
How can I do this?
If I add the function to a method which I insert into my subclass the selection
dialog doesn't show the choices.
I would be glad if anyone can offer some help here.
I hope I described my problem in an understandable manner.
Thanks in advance and kind regards,
Timmie
### myapp_controls.py ###
import sys
import wx
import mypapp_gui as gui
def provide_buildings_choice_choices():
mylist = [house: 1, tent: 2, tower: 3, lighthouse:4]
return mylist
class ModifiedMainFrame(gui.MainFrame):
"""
Main Window of the Application
"""
def add_choices(self):
self.buildings_choice = wx.ComboBox(self, -1,
choices=provide_buildings_choice_choices(), style=wx.CB_DROPDOWN) ### <--- here
is where I can need your help!
#self.statusbar = self.CreateStatusBar()
### END ###
### myapp.py ###
import wx
import gettext
import myapp_gui as gui
import myapp_controls as ctrl
class MyAppGui(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
#main_frame = ctrl.ModifiedFrame
main_frame = ctrl.ModifiedMainFrame(None, -1, "")
self.SetTopWindow(main_frame)
main_frame.Show()
return 1
# end of class MyAppGui
if __name__ == "__main__":
import gettext
gettext.install("MyApp") # replace with the appropriate catalog name
MyApp = MyAppGuiGui(0)
MyApp.MainLoop()
### END myapp.py ###
### myapp_gui.py ###
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3
import wx
# begin wxGlade: extracode
# end wxGlade
class MainFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MainFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
# Menu Bar
...
# Menu Bar end
...
self.buildings_choice = wx.ComboBox(self, -1, choices=[_("House"),
_("Tent")], style=wx.CB_DROPDOWN)
self.static_line_4 = wx.StaticLine(self, -1)
...
### END myapp_gui.py ###