wxPython menu creation refactoring

A

alex

Hello everybody
I am still trying to refactor a simple GUI basing on an example
in "wxPython In Action", "Listing 5.5 A refactored example" where the
menue creation is "automatized".
I understand the problem (each second for loop in "def createMenuData
(self)"
creates a distinct menu) but I tried now for some evenings and do not
get to
any possible solution.
I am still learning Python and hope to use it as a front end for
my Fortran programs (subprocess and ctypes work very well...)
with the aim of increasing the Python part (text parsing) in the
future.
The following code shows the problem and works out of the DOS box.
Any help would be greatly apreciated.

Alex


#
#!/usr/bin/env python
#
"""Add Python docs string"""
import wx
#
#
class Frame(wx.Frame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
#
self.createPanel()
self.createMenuData()


def menuData(self):
return (("&File",
("&Open", self.OnOpen),
("&Restart", self.OnRestart),
("&Exit", self.OnExit)),
("&About",
("&About", self.OnAbout)))


def createMenuData(self):
menuBar = wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel = eachMenuData[0]
for eachLabel, eachHandler in eachMenuData[1:]:
menuBar.Append(self.createMenu(eachLabel,
eachHandler), menuLabel)
self.SetMenuBar(menuBar)


def createMenu(self, itemLabel, itemHandler):
menu = wx.Menu()
menuItem = menu.Append(wx.NewId(), itemLabel)
self.Bind(wx.EVT_MENU, itemHandler, menuItem)
return menu


def createPanel(self):
self.panel = wx.Panel(self)
self.panel.SetBackgroundColour(wx.SystemSettings_GetColour
(wx.SYS_COLOUR_3DFACE))
StatusBar = self.CreateStatusBar()

self.Centre()
self.Show(True)


def OnExit(self, event):
self.Close()

def OnOpen(self, event):
pass

def OnRestart(self, event):
pass

def OnAbout(self, event):
pass


class App(wx.App):
def OnInit(self):
frame = Frame("Gui Frame", (100, 100), (600, 450))
frame.Show()
self.SetTopWindow(frame)
return True
#
#
if __name__ == '__main__':
#
app = App()
app.MainLoop()
#
#
 
A

alex

Good evening Nick
Thank you for answer I will study your code and learn from it.
I subscribed to the wxPython users mailing list which is for my actual
questions probably the more accurate place.
But I always apreciate that when I post even a probably simple
question I always get an answer from this group.
Thank you
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top