[wxPython] Help on choice dialog/Python

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Help on choice dialog/Python

Eric Freese
HELP!!!!!

I've already sent too much time trying to get a choice dialog to work and
will hope that the experts on this list will be able to tell me what is
wrong in the attached script.  I'm sure it is something simple that I am
missing.  I am using wxPython 2.1.13 on Win NT4 and Win 98.

Also, how do I grey out menu items which are not active?

Any suggestions will be appreciated.  Thanks in advance.

Please reply to [hidden email].

Eric Freese

===============================================================

import sys, os
from wxPython.wx import *

class MyFrame(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, -1, title,
                         wxDefaultPosition, wxSize(700, 550))
        self.otherWin = None
        EVT_IDLE(self, self.OnIdle)

        self.Centre(wxBOTH)
        self.CreateStatusBar(1, wxST_SIZEGRIP)
        self.splitter = wxSplitterWindow(self, -1)
        self.splitterSelection = wxSplitterWindow(self.splitter, -1)
        self.splitterDisplay = wxSplitterWindow(self.splitter, -1)

        # Prevent TreeCtrl from displaying all items after destruction
        self.dying = false

        self.mainmenu = wxMenuBar()

        # Make a Find menu
        menu = wxMenu()
        mID = NewId()
        menu.Append(mID, '&Choice', 'Test choice')
        EVT_MENU(self, mID, self.OnTestChoice)
        mID = NewId()
        menu.Append(mID, 'E&xit', 'Get the heck outta here!')
        EVT_MENU(self, mID, self.OnFileExit)
        self.mainmenu.Append(menu, '&Test')
        self.SetMenuBar(self.mainmenu)

        # Set up a TextCtrl on the Display page
        # This will be an HTML page at some point
        self.dispPage = wxTextCtrl(self.splitterDisplay, -1, '',
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY)

        # Set up a log on the right page
        self.log = wxTextCtrl(self.splitterDisplay, -1, '',
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
        (w, self.charHeight) = self.log.GetTextExtent('X')
        #self.WriteText('wxPython Demo Log:\n')

        # add the windows to the splitter and split it.
        self.splitter.SetMinimumPaneSize(20)
        self.splitter.SplitHorizontally(self.splitterSelection,
self.splitterDisplay)
        self.splitter.SetSashPosition(50)

        self.splitterDisplay.SplitHorizontally(self.dispPage, self.log)
        self.splitterDisplay.SetSashPosition(350)
        self.splitterDisplay.SetMinimumPaneSize(20)

    #---------------------------------------------
    def WriteText(self, text):
        self.log.WriteText(text)
        w, h = self.log.GetClientSizeTuple()
        numLines = h/self.charHeight
        x, y = self.log.PositionToXY(self.log.GetLastPosition())
        self.log.ShowPosition(self.log.XYToPosition(x, y-numLines+1))

    def write(self, txt):
        self.WriteText(txt)

    #---------------------------------------------
    def EvtChoice(self, event):
        self.log.WriteText('EvtChoice: %s\n' % event.GetString())

    #---------------------------------------------
    def OnFileExit(self, event):
        self.Close()

    #---------------------------------------------
    def OnItemExpanded(self, event):
        item = event.GetItem()
        self.log.WriteText("OnItemExpanded: %s\n" %
self.tree.GetItemText(item))

    #---------------------------------------------
    def OnCloseWindow(self, event):
        self.dying = true
        self.Destroy()

    #---------------------------------------------
    def OnIdle(self, event):
        if self.otherWin:
            self.otherWin.Raise()
            self.otherWin = None

    #---------------------------------------------
    def OnItemCollapsed(self, event):
        item = event.GetItem()
        self.log.WriteText("OnItemCollapsed: %s\n" %
self.tree.GetItemText(item))

    #---------------------------------------------
    def OnSelChanged(self, event):
        item = event.GetItem()
        self.log.WriteText("OnSelChanged: %s\n" %
self.tree.GetItemText(item))

    #---------------------------------------------
    def SetOverview(self, name, text):
        self.ovr.Clear()
        self.ovr.WriteText(text)
        self.ovr.SetInsertionPoint(0)
        self.ovr.ShowPosition(0)

#---------------------------------------------
    def OnTestChoice(self, event):
        tc = TestChoice(self.dispPage, self.log)
        return tc

#---------------------------------------------------------------------------
class TestChoice(wxPanel):
    def __init__(self, parent, log):
        self.log = log
        global choiceList
        wxPanel.__init__(self, parent, -1)
        wxStaticText(self, -1, "Select one:", wxPoint(15, 50), wxSize(75,
20))
        wxChoice(self, 40, wxPoint(80, 50), wxSize(95, 20), choiceList)
        EVT_CHOICE(self, 40, self.EvtChoice)

    def EvtChoice(self, event):
        frame.log.WriteText('EvtChoice: %s\n' % event.GetString())

#---------------------------------------------------------------------------
class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(None, -1, "test choice")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

#---------------------------------------------------------------------------

global choiceList

choiceList = ['None', 'All']

app = MyApp(0)
app.MainLoop()



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users