GUI in Python using wxGlade

diffuser78 at gmail.com diffuser78 at gmail.com
Thu Jun 15 17:43:36 CEST 2006


I am pasting my code. I created a small little GUI without any
functionality as of yet. I wanted to ask few questions on that.

[code]
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# generated by wxGlade 0.4cvs on Thu Jun 15 10:51:12 2006

import wx

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.panel_1 = wx.Panel(self, -1)

        # Menu Bar
        self.frame_1_menubar = wx.MenuBar()
        self.SetMenuBar(self.frame_1_menubar)
        self.File = wx.Menu()
        self.CreateNewConfigFile = wx.MenuItem(self.File, wx.NewId(),
_("Create New Config File"), "", wx.ITEM_NORMAL)
        self.File.AppendItem(self.CreateNewConfigFile)
        self.OpenConfigFile = wx.MenuItem(self.File, wx.NewId(),
_("Open Config File"), "", wx.ITEM_NORMAL)
        self.File.AppendItem(self.OpenConfigFile)
        self.EditConfigFile = wx.MenuItem(self.File, wx.NewId(),
_("Edit Config File"), "", wx.ITEM_NORMAL)
        self.File.AppendItem(self.EditConfigFile)
        self.Close = wx.MenuItem(self.File, wx.NewId(), _("Close"), "",
wx.ITEM_NORMAL)
        self.File.AppendItem(self.Close)
        self.Exit = wx.MenuItem(self.File, wx.NewId(), _("Exit"), "",
wx.ITEM_NORMAL)
        self.File.AppendItem(self.Exit)
        self.frame_1_menubar.Append(self.File, _("File"))
        self.Action = wx.Menu()
        self.AddComputer = wx.MenuItem(self.Action, wx.NewId(), _("Add
Computer"), "", wx.ITEM_NORMAL)
        self.Action.AppendItem(self.AddComputer)
        self.Shutdown = wx.MenuItem(self.Action, wx.NewId(),
_("Shutdown..."), "", wx.ITEM_NORMAL)
        self.Action.AppendItem(self.Shutdown)
        self.ShutdownAll = wx.MenuItem(self.Action, wx.NewId(),
_("Shutdown All"), "", wx.ITEM_NORMAL)
        self.Action.AppendItem(self.ShutdownAll)
        self.frame_1_menubar.Append(self.Action, _("Action"))
        self.Help = wx.Menu()
        self.Tutorial = wx.MenuItem(self.Help, wx.NewId(),
_("Tutorial"), "", wx.ITEM_NORMAL)
        self.Help.AppendItem(self.Tutorial)
        self.AboutUs = wx.MenuItem(self.Help, wx.NewId(), _("About
us"), "", wx.ITEM_NORMAL)
        self.Help.AppendItem(self.AboutUs)
        self.frame_1_menubar.Append(self.Help, _("Help"))
        # Menu Bar end
        self.frame_1_statusbar = self.CreateStatusBar(1, 0)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle(_("Test"))
        self.SetSize((600, 450))
        self.frame_1_statusbar.SetStatusWidths([-1])
        # statusbar fields
        frame_1_statusbar_fields = [_("Test Application")]
        for i in range(len(frame_1_statusbar_fields)):

self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i)
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
        self.SetAutoLayout(True)
        self.SetSizer(sizer_1)
        self.Layout()
        # end wxGlade

# end of class MyFrame


class MyApp(wx.App):
    def OnInit(self):
        wx.InitAllImageHandlers()
        frame_1 = MyFrame(None, -1, "")
        self.SetTopWindow(frame_1)
        frame_1.Show()
        return 1

# end of class MyApp

if __name__ == "__main__":
    import gettext
    gettext.install("app") # replace with the appropriate catalog name

    app = MyApp(0)
    app.MainLoop()
[/code]

If I click on any of the items of the File Menu, say I click on "Open
config File", I want a new windows to come up.

My questions is when I create a new Frame/Windows in wxGlade, will it
be wxFrame or wxMDI Frame......which one should I choose and why ?

I am not completely aware of all the small tools that wxGlade gives and
how to place them.


Any kind of help is greatly appreciated.

Thanks



> Without having time to go into a full, the way to proceed with Glade
> (unless I am mistaken) is to design each window independently of the
> others, and to use a button press in one window to create an instance of
> another type of window.




More information about the Python-list mailing list