[wxPython] Q: wxChoice

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Q: wxChoice

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



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Q: wxChoice

Robin Dunn
> 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.
>

It would be helpful next time if you would also specify what you expected and
what is not happening correctly.  Maybe then I could answer right away
without having to take the time to run the code.

There is nothing wrong with your use of wxChoice, but there is with the
window you place it on.  You are not doing anything to manage it's size, and
so it stays size (20,20) and so you can never see the wxChoice which is
located at (80, 50).  The wxSplitterWindow will autmatically manage the size
of it's child windows, you are using wxTextCtrls which is okay.  But then you
create a wxPanel as a child of the wxTextCtrl which doesn't expect to have
child windows and doesn't know what to do with them if it has.

If you let us know what you are trying to accomplish then somebody can help
you better, but here are some suggestions:

1. if you want the panel to fill its half of the splitter, then create it as
a child of the splitter and leave the TextCtrl out of it.

2. If you want it to show up side by side with the text ctrl then put them
both on a new panel, make that panel be the child of the splitter, and teach
the panel how to layout its children, (with sizers, layout contraints, or
brute force.)

3. If you want it to float above the rest then put the choice in a wxDialog
instead of a panel.

4. If you want to flip between several windows all within the splitter, then
add them as pages in a notebook and let the notebook be the child of the
splitter.


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

    wxMenu.Enable(ID, false)

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



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