How do I force code to wait for a option window to shut?

Dear Users,

This is my first time on this list, normally post many messages on the
VTK users forum. I've now got that bit of the program working and need
help with some GUI issues. My code is written in Python and also uses
VTK, but I haven't even got to adding the render windows to the GUI.

Tha main GUI with menu controls and status bars etc all on one class
which calls on another class which creates the user input frames were
default values may be adjusted. This user input class also refers to
another class which contains default values and lists for combo boxes
as well as text to go along side the combo boxes.

I've created it in this manner so that it is easy to change the
language of the program as one of our project partners are German, and
to be able to have another class record entered values and change the
lists and default values on the combo boxes to ease user interaction.

Right, description aside here's my problem. The main GUI calls a
function in a different class to create the menu which in turn creates
a frame and fills it with panels of checkboxes or comboboxes which are
created by other funtions in the same class. The program creates the
option window but does not wait for the window to be canceled, or
confirmed. I need to know how the window has been closed, whether by
the cross in the top corner, by the ok button, or perhaps by a cancel
button that I haven't created yet. If the widow has been closed or
canceled I want the program not to any calculations where as if it is
confirmed there are a few more functions I would like to call which
will use the values just set.

I've included a reduced section of my code bellow. All the bits that
are missing are similar to bits which are shown. The code is called by
the GUI just by creating an instance of the gather variables class.

class GatherVariables:
    def __init__(self, mainwindow):
        self.values = DefaultValues()
        self.mainwindow = mainwindow
        
        self.cells = self.values.cells
        self.extents = self.values.extents
        self.type = self.values.type
        self.segment = self.values.segment
        self.dzlyr = self.values.dzlyr
        self.RegularBlockVariables()

    def RegularBlockVariables(self):
        wxFrame.__init__(self.mainwindow, NULL, -1, 'parent',
wxDefaultPosition, (500, 300))

        self.frame = wxFrame(self.mainwindow, -1, "Sizer & input test")

        axispanel = wxPanel(self.frame, -1, size=(100,100),
style=wxSUNKEN_BORDER)

        panel1 = self.NumCellsPanel(axispanel)
        panel2 = self.LowValuePanel(axispanel)
        panel3 = self.ExtentPanel(axispanel)
        panel4 = self.LayerPanel(self.frame)
        panel5 = self.OkPanel(self.frame)

        axispanelsizer = wxBoxSizer(wxHORIZONTAL)
        axispanelsizer.Add( panel1, 1, wxALL, 0 )
        axispanelsizer.Add( panel2, 1, wxALL, 0 )
        axispanelsizer.Add( panel3, 1, wxALL, 0 )

        axispanel.SetAutoLayout(1)
        axispanel.SetSizer(axispanelsizer)
        axispanelsizer.Fit(axispanel)
        axispanelsizer.SetSizeHints(axispanel)
        
        assemblysizer = wxBoxSizer(wxVERTICAL)

        assemblysizer.Add( axispanel, 1, wxGROW, 20 )
        assemblysizer.Add( panel4, 0, wxGROW, 20 )
        assemblysizer.Add( panel5, 0, wxGROW, 20 )

        self.frame.SetAutoLayout(1)
        self.frame.SetSizer(assemblysizer)
        assemblysizer.Fit(self.frame)
        assemblysizer.SetSizeHints(self.frame)

        self.frame.Show(1)

    def NumCellsPanel(self, parent):
        ID_NCELLSX = wxNewId()
        ID_NCELLSY = wxNewId()
        ID_NCELLSZ = wxNewId()

        panel = wxPanel(parent, -1, size=(100,100), style=wxSUNKEN_BORDER)
        
        sizer = wxGridSizer(cols = 2)
        
        wxtext0 = wxStaticText(panel, -1, self.values.text0)
        wxtext1 = wxStaticText(panel, -1, self.values.text1)
        wxtext2 = wxStaticText(panel, -1, self.values.text2)

        ncellsxinp = wxComboBox(panel, ID_NCELLSX, '%.0f' %
self.values.cells[0], wxPoint(80, 50), wxSize(95, -1),
self.values.ncellsxlst, wxCB_DROPDOWN)
        ncellsyinp = wxComboBox(panel, ID_NCELLSY, '%.0f' %
self.values.cells[1], wxPoint(80, 50), wxSize(95, -1),
self.values.ncellsylst, wxCB_DROPDOWN)
        ncellszinp = wxComboBox(panel, ID_NCELLSZ, '%.0f' %
self.values.cells[2], wxPoint(80, 50), wxSize(95, -1),
self.values.ncellszlst, wxCB_DROPDOWN)

        sizer.Add( wxtext0, 1, wxALL, 10 )
        sizer.Add( ncellsxinp, 1, wxALL, 10 )
        sizer.Add( wxtext1, 1, wxALL, 10 )
        sizer.Add( ncellsyinp, 1, wxALL, 10 )
        sizer.Add( wxtext2, 1, wxALL, 10 )
        sizer.Add( ncellszinp, 1, wxALL, 10 )

        EVT_COMBOBOX(self.mainwindow, ID_NCELLSX, self.EvtComboBox0)
        EVT_TEXT_ENTER(self.mainwindow, ID_NCELLSX, self.EvtComboBox0)
        EVT_COMBOBOX(self.mainwindow, ID_NCELLSY, self.EvtComboBox1)
        EVT_TEXT_ENTER(self.mainwindow, ID_NCELLSY, self.EvtComboBox1)
        EVT_COMBOBOX(self.mainwindow, ID_NCELLSZ, self.EvtComboBox2)
        EVT_TEXT_ENTER(self.mainwindow, ID_NCELLSZ, self.EvtComboBox2)

        panel.SetAutoLayout(1)
        panel.SetSizer(sizer)
        sizer.Fit(panel)
        sizer.SetSizeHints(panel)

        return panel

    def OkPanel(self, parent):
        ID_OK = wxNewId()
        
        panel = wxPanel(parent, -1, size=(100,100), style=wxSUNKEN_BORDER)

        sizer = wxGridSizer(cols = 1)

        okbutton = wxButton(panel, ID_OK, 'Ok')

        sizer.Add( okbutton, -1, wxALIGN_CENTRE, 10 )

        EVT_BUTTON(self.mainwindow, ID_OK, self.EvtTextOk)

        panel.SetAutoLayout(1)
        panel.SetSizer(sizer)
        sizer.Fit(panel)
        sizer.SetSizeHints(panel)

        return panel

    def EvtComboBox0(self, event):
        self.values.cells[0] = float(event.GetString())
   
    def EvtTextOk(self, event):
        self.frame.Destroy()

Thank you very much for any help or advice you can offer! As of
February 2004 I'm new to programming (as may be very apparent!) and
the GUI creation is the part I'm least familiar with.

Yours Faithfully,

Wesley Brooks

Hi Wesley,

Wesley Brooks wrote:

Dear Users,

This is my first time on this list, normally post many messages on the
VTK users forum. I've now got that bit of the program working and need
help with some GUI issues. My code is written in Python and also uses
VTK, but I haven't even got to adding the render windows to the GUI.

Tha main GUI with menu controls and status bars etc all on one class
which calls on another class which creates the user input frames were
default values may be adjusted. This user input class also refers to
another class which contains default values and lists for combo boxes
as well as text to go along side the combo boxes.

I've created it in this manner so that it is easy to change the
language of the program as one of our project partners are German, and
to be able to have another class record entered values and change the
lists and default values on the combo boxes to ease user interaction.

You might want to look into I18n to handle multiple languages.
http://wiki.wxpython.org/index.cgi/RecipesI18n

Right, description aside here's my problem. The main GUI calls a
function in a different class to create the menu which in turn creates
a frame and fills it with panels of checkboxes or comboboxes which are
created by other funtions in the same class. The program creates the
option window but does not wait for the window to be canceled, or
confirmed. I need to know how the window has been closed, whether by
the cross in the top corner, by the ok button, or perhaps by a cancel
button that I haven't created yet. If the widow has been closed or
canceled I want the program not to any calculations where as if it is
confirmed there are a few more functions I would like to call which
will use the values just set.

What about using a dialog type window to get your options and then do something along these lines:

            try:
                dlg =wx.MessageDialog(self, dlgText, dlgName,
                wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
                       if dlg.ShowModal() == wx.ID_YES:
                    self.mainFrame.ds.rollback()
                else:
                    return
            finally:
                dlg.Destroy()

Here I use a predefined MessageDialog, but obviously the same would work with a Dialog you defined. In my case if the user clicks the Yes button I rollback the database changes, otherwise I just return. BTW, this MessageDialog is called within my Dialog when user tries to close it without saving data, so not exactly what you do but hopefully still helpful.

See you
Werner

···

I've included a reduced section of my code bellow. All the bits that
are missing are similar to bits which are shown. The code is called by
the GUI just by creating an instance of the gather variables class.

class GatherVariables:
   def __init__(self, mainwindow):
       self.values = DefaultValues()
       self.mainwindow = mainwindow
              self.cells = self.values.cells
       self.extents = self.values.extents
       self.type = self.values.type
       self.segment = self.values.segment
       self.dzlyr = self.values.dzlyr
       self.RegularBlockVariables()

         def RegularBlockVariables(self):
       wxFrame.__init__(self.mainwindow, NULL, -1, 'parent',
wxDefaultPosition, (500, 300))

       self.frame = wxFrame(self.mainwindow, -1, "Sizer & input test")

       axispanel = wxPanel(self.frame, -1, size=(100,100),
style=wxSUNKEN_BORDER)

       panel1 = self.NumCellsPanel(axispanel)
       panel2 = self.LowValuePanel(axispanel)
       panel3 = self.ExtentPanel(axispanel)
       panel4 = self.LayerPanel(self.frame)
       panel5 = self.OkPanel(self.frame)

       axispanelsizer = wxBoxSizer(wxHORIZONTAL)
       axispanelsizer.Add( panel1, 1, wxALL, 0 )
       axispanelsizer.Add( panel2, 1, wxALL, 0 )
       axispanelsizer.Add( panel3, 1, wxALL, 0 )

       axispanel.SetAutoLayout(1)
       axispanel.SetSizer(axispanelsizer)
       axispanelsizer.Fit(axispanel)
       axispanelsizer.SetSizeHints(axispanel)
              assemblysizer = wxBoxSizer(wxVERTICAL)

       assemblysizer.Add( axispanel, 1, wxGROW, 20 )
       assemblysizer.Add( panel4, 0, wxGROW, 20 )
       assemblysizer.Add( panel5, 0, wxGROW, 20 )

       self.frame.SetAutoLayout(1)
       self.frame.SetSizer(assemblysizer)
       assemblysizer.Fit(self.frame)
       assemblysizer.SetSizeHints(self.frame)

       self.frame.Show(1)

   def NumCellsPanel(self, parent):
       ID_NCELLSX = wxNewId()
       ID_NCELLSY = wxNewId()
       ID_NCELLSZ = wxNewId()

       panel = wxPanel(parent, -1, size=(100,100), style=wxSUNKEN_BORDER)
              sizer = wxGridSizer(cols = 2)
              wxtext0 = wxStaticText(panel, -1, self.values.text0)
       wxtext1 = wxStaticText(panel, -1, self.values.text1)
       wxtext2 = wxStaticText(panel, -1, self.values.text2)

       ncellsxinp = wxComboBox(panel, ID_NCELLSX, '%.0f' %
self.values.cells[0], wxPoint(80, 50), wxSize(95, -1),
self.values.ncellsxlst, wxCB_DROPDOWN)
       ncellsyinp = wxComboBox(panel, ID_NCELLSY, '%.0f' %
self.values.cells[1], wxPoint(80, 50), wxSize(95, -1),
self.values.ncellsylst, wxCB_DROPDOWN)
       ncellszinp = wxComboBox(panel, ID_NCELLSZ, '%.0f' %
self.values.cells[2], wxPoint(80, 50), wxSize(95, -1),
self.values.ncellszlst, wxCB_DROPDOWN)

       sizer.Add( wxtext0, 1, wxALL, 10 )
       sizer.Add( ncellsxinp, 1, wxALL, 10 )
       sizer.Add( wxtext1, 1, wxALL, 10 )
       sizer.Add( ncellsyinp, 1, wxALL, 10 )
       sizer.Add( wxtext2, 1, wxALL, 10 )
       sizer.Add( ncellszinp, 1, wxALL, 10 )

       EVT_COMBOBOX(self.mainwindow, ID_NCELLSX, self.EvtComboBox0)
       EVT_TEXT_ENTER(self.mainwindow, ID_NCELLSX, self.EvtComboBox0)
       EVT_COMBOBOX(self.mainwindow, ID_NCELLSY, self.EvtComboBox1)
       EVT_TEXT_ENTER(self.mainwindow, ID_NCELLSY, self.EvtComboBox1)
       EVT_COMBOBOX(self.mainwindow, ID_NCELLSZ, self.EvtComboBox2)
       EVT_TEXT_ENTER(self.mainwindow, ID_NCELLSZ, self.EvtComboBox2)

       panel.SetAutoLayout(1)
       panel.SetSizer(sizer)
       sizer.Fit(panel)
       sizer.SetSizeHints(panel)

       return panel

   def OkPanel(self, parent):
       ID_OK = wxNewId()
              panel = wxPanel(parent, -1, size=(100,100), style=wxSUNKEN_BORDER)

       sizer = wxGridSizer(cols = 1)

       okbutton = wxButton(panel, ID_OK, 'Ok')

       sizer.Add( okbutton, -1, wxALIGN_CENTRE, 10 )

       EVT_BUTTON(self.mainwindow, ID_OK, self.EvtTextOk)

       panel.SetAutoLayout(1)
       panel.SetSizer(sizer)
       sizer.Fit(panel)
       sizer.SetSizeHints(panel)

       return panel

   def EvtComboBox0(self, event):
       self.values.cells[0] = float(event.GetString())
     def EvtTextOk(self, event):
       self.frame.Destroy()

Thank you very much for any help or advice you can offer! As of
February 2004 I'm new to programming (as may be very apparent!) and
the GUI creation is the part I'm least familiar with.

Yours Faithfully,

Wesley Brooks

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Werner,

Cheers for your help, I hadn't come across a few of the things in your example.

I've got it working now by using the ShowModal() rather than Show(1)
and creating an event that is carried out when wxID_CANCEL is called
that records the event. I'm also now using the wxDialog rather than a
frame.

Another problem that I had was that the text events (EVT_TEXT_ENTER)
weren't being processed unless the wxTE_PROCESS_ENTER flag was in the
style.

Wesley Brooks

···

On Apr 7, 2005 11:09 AM, Werner F. Bruhin <werner.bruhin@free.fr> wrote:

Hi Wesley,

Wesley Brooks wrote:

>Dear Users,
>
>This is my first time on this list, normally post many messages on the
>VTK users forum. I've now got that bit of the program working and need
>help with some GUI issues. My code is written in Python and also uses
>VTK, but I haven't even got to adding the render windows to the GUI.
>
>Tha main GUI with menu controls and status bars etc all on one class
>which calls on another class which creates the user input frames were
>default values may be adjusted. This user input class also refers to
>another class which contains default values and lists for combo boxes
>as well as text to go along side the combo boxes.
>
>I've created it in this manner so that it is easy to change the
>language of the program as one of our project partners are German, and
>to be able to have another class record entered values and change the
>lists and default values on the combo boxes to ease user interaction.
>
>
You might want to look into I18n to handle multiple languages.
http://wiki.wxpython.org/index.cgi/RecipesI18n

>Right, description aside here's my problem. The main GUI calls a
>function in a different class to create the menu which in turn creates
>a frame and fills it with panels of checkboxes or comboboxes which are
>created by other funtions in the same class. The program creates the
>option window but does not wait for the window to be canceled, or
>confirmed. I need to know how the window has been closed, whether by
>the cross in the top corner, by the ok button, or perhaps by a cancel
>button that I haven't created yet. If the widow has been closed or
>canceled I want the program not to any calculations where as if it is
>confirmed there are a few more functions I would like to call which
>will use the values just set.
>
>
What about using a dialog type window to get your options and then do
something along these lines:

            try:
                dlg =wx.MessageDialog(self, dlgText, dlgName,
                wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)

                if dlg.ShowModal() == wx.ID_YES:
                    self.mainFrame.ds.rollback()
                else:
                    return
            finally:
                dlg.Destroy()

Here I use a predefined MessageDialog, but obviously the same would work
with a Dialog you defined. In my case if the user clicks the Yes button
I rollback the database changes, otherwise I just return. BTW, this
MessageDialog is called within my Dialog when user tries to close it
without saving data, so not exactly what you do but hopefully still helpful.

See you
Werner

>I've included a reduced section of my code bellow. All the bits that
>are missing are similar to bits which are shown. The code is called by
>the GUI just by creating an instance of the gather variables class.
>
>class GatherVariables:
> def __init__(self, mainwindow):
> self.values = DefaultValues()
> self.mainwindow = mainwindow
>
> self.cells = self.values.cells
> self.extents = self.values.extents
> self.type = self.values.type
> self.segment = self.values.segment
> self.dzlyr = self.values.dzlyr
> self.RegularBlockVariables()
>
>
> def RegularBlockVariables(self):
> wxFrame.__init__(self.mainwindow, NULL, -1, 'parent',
>wxDefaultPosition, (500, 300))
>
> self.frame = wxFrame(self.mainwindow, -1, "Sizer & input test")
>
> axispanel = wxPanel(self.frame, -1, size=(100,100),
>style=wxSUNKEN_BORDER)
>
> panel1 = self.NumCellsPanel(axispanel)
> panel2 = self.LowValuePanel(axispanel)
> panel3 = self.ExtentPanel(axispanel)
> panel4 = self.LayerPanel(self.frame)
> panel5 = self.OkPanel(self.frame)
>
> axispanelsizer = wxBoxSizer(wxHORIZONTAL)
> axispanelsizer.Add( panel1, 1, wxALL, 0 )
> axispanelsizer.Add( panel2, 1, wxALL, 0 )
> axispanelsizer.Add( panel3, 1, wxALL, 0 )
>
> axispanel.SetAutoLayout(1)
> axispanel.SetSizer(axispanelsizer)
> axispanelsizer.Fit(axispanel)
> axispanelsizer.SetSizeHints(axispanel)
>
> assemblysizer = wxBoxSizer(wxVERTICAL)
>
> assemblysizer.Add( axispanel, 1, wxGROW, 20 )
> assemblysizer.Add( panel4, 0, wxGROW, 20 )
> assemblysizer.Add( panel5, 0, wxGROW, 20 )
>
> self.frame.SetAutoLayout(1)
> self.frame.SetSizer(assemblysizer)
> assemblysizer.Fit(self.frame)
> assemblysizer.SetSizeHints(self.frame)
>
> self.frame.Show(1)
>
> def NumCellsPanel(self, parent):
> ID_NCELLSX = wxNewId()
> ID_NCELLSY = wxNewId()
> ID_NCELLSZ = wxNewId()
>
> panel = wxPanel(parent, -1, size=(100,100), style=wxSUNKEN_BORDER)
>
> sizer = wxGridSizer(cols = 2)
>
> wxtext0 = wxStaticText(panel, -1, self.values.text0)
> wxtext1 = wxStaticText(panel, -1, self.values.text1)
> wxtext2 = wxStaticText(panel, -1, self.values.text2)
>
> ncellsxinp = wxComboBox(panel, ID_NCELLSX, '%.0f' %
>self.values.cells[0], wxPoint(80, 50), wxSize(95, -1),
>self.values.ncellsxlst, wxCB_DROPDOWN)
> ncellsyinp = wxComboBox(panel, ID_NCELLSY, '%.0f' %
>self.values.cells[1], wxPoint(80, 50), wxSize(95, -1),
>self.values.ncellsylst, wxCB_DROPDOWN)
> ncellszinp = wxComboBox(panel, ID_NCELLSZ, '%.0f' %
>self.values.cells[2], wxPoint(80, 50), wxSize(95, -1),
>self.values.ncellszlst, wxCB_DROPDOWN)
>
> sizer.Add( wxtext0, 1, wxALL, 10 )
> sizer.Add( ncellsxinp, 1, wxALL, 10 )
> sizer.Add( wxtext1, 1, wxALL, 10 )
> sizer.Add( ncellsyinp, 1, wxALL, 10 )
> sizer.Add( wxtext2, 1, wxALL, 10 )
> sizer.Add( ncellszinp, 1, wxALL, 10 )
>
> EVT_COMBOBOX(self.mainwindow, ID_NCELLSX, self.EvtComboBox0)
> EVT_TEXT_ENTER(self.mainwindow, ID_NCELLSX, self.EvtComboBox0)
> EVT_COMBOBOX(self.mainwindow, ID_NCELLSY, self.EvtComboBox1)
> EVT_TEXT_ENTER(self.mainwindow, ID_NCELLSY, self.EvtComboBox1)
> EVT_COMBOBOX(self.mainwindow, ID_NCELLSZ, self.EvtComboBox2)
> EVT_TEXT_ENTER(self.mainwindow, ID_NCELLSZ, self.EvtComboBox2)
>
> panel.SetAutoLayout(1)
> panel.SetSizer(sizer)
> sizer.Fit(panel)
> sizer.SetSizeHints(panel)
>
> return panel
>
> def OkPanel(self, parent):
> ID_OK = wxNewId()
>
> panel = wxPanel(parent, -1, size=(100,100), style=wxSUNKEN_BORDER)
>
> sizer = wxGridSizer(cols = 1)
>
> okbutton = wxButton(panel, ID_OK, 'Ok')
>
> sizer.Add( okbutton, -1, wxALIGN_CENTRE, 10 )
>
> EVT_BUTTON(self.mainwindow, ID_OK, self.EvtTextOk)
>
> panel.SetAutoLayout(1)
> panel.SetSizer(sizer)
> sizer.Fit(panel)
> sizer.SetSizeHints(panel)
>
> return panel
>
> def EvtComboBox0(self, event):
> self.values.cells[0] = float(event.GetString())
>
> def EvtTextOk(self, event):
> self.frame.Destroy()
>
>Thank you very much for any help or advice you can offer! As of
>February 2004 I'm new to programming (as may be very apparent!) and
>the GUI creation is the part I'm least familiar with.
>
>Yours Faithfully,
>
>Wesley Brooks
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
>For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

I have bound an event in an editor window for dropping files:

  self.Bind(wx.EVT_DROP_FILES, self.OnDropFiles)

This works fine. I would like to pass the event up to the frame which is
an ancestor of the editor so that the frame can update its status bar. But I
cannot get the event to propagate. Can this be done?

This is Windows (I think the only place where the drop files is presently
implemented).

Thanks

Peter

Hello Peter,

I have bound an event in an editor window for dropping files:

self.Bind(wx.EVT_DROP_FILES, self.OnDropFiles)

This works fine. I would like to pass the event up to the frame which is
an ancestor of the editor so that the frame can update its status bar.

But

I cannot get the event to propagate. Can this be done?

Couldn't you do something like:

def OnDropFiles(self, event):
    # Receiving the event
    # Do something here

    self.parent.DoSomethingElse(**kwds)

where self.parent is the Frame reference that you could store in the __init__
method of the editor, or something similar.

Does it make any sense?

Andrea.

Hello Peter,

I have bound an event in an editor window for dropping files:

self.Bind(wx.EVT_DROP_FILES, self.OnDropFiles)

This works fine. I would like to pass the event up to the frame which is
an ancestor of the editor so that the frame can update its status bar.

But

I
cannot get the event to propagate. Can this be done?

Sorry, I have formulated my answer really badly. Suppose that you have your
editor's __init__ function as:

# I suppose you are using STC as Editor

import wx.stc as stc

class MyEditor(stc.StyledTextCtrl):
    def __init__(self, parent, ID):
    
        stc.StyledTextCtrl.__init__(self, parent, ID)

        # if you have the frame as a parent of the editor:
        self.parent = parent

Then, in the event handler:

    def OnDropFiles(self, event):
        # Receiving the event
        # Do something here

        self.parent.ModifyTheToolbar(**kwds)

With the arguments you want to pass to the ModifyTheToolbar() method of
the frame. If you don't have the frame as a parent, you could do something
like:

import wx.stc as stc

class MyEditor(stc.StyledTextCtrl):
    def __init__(self, parent, ID, FrameParent):
    
        stc.StyledTextCtrl.__init__(self, parent, ID)

        # if you have the frame as a parent of the editor:
        self.parent = FrameParent

In the MyEditor class you pass in the __init__ function a reference of the
Frame. Next, in the Frame class you could have a method like:

    def ModifyMyToolbar(self, **kwds):
        do something with your toolbar

HTH.

Andrea.

andrea_gavana@tin.it wrote:

Hello Peter,

I have bound an event in an editor window for dropping files:

self.Bind(wx.EVT_DROP_FILES, self.OnDropFiles)

This works fine. I would like to pass the event up to the frame which is
an ancestor of the editor so that the frame can update its status bar.

But

I cannot get the event to propagate. Can this be done?

Couldn't you do something like:

def OnDropFiles(self, event):
    # Receiving the event
    # Do something here

    self.parent.DoSomethingElse(**kwds)

where self.parent is the Frame reference that you could store in the __init__
method of the editor, or something similar.

Another common approach is to just resend the event:

  parent = self.GetParent()
  parent.GetEventHandler().ProcessEvent(event)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks for these answers. I did not make it clear that there were a lot of
intermediate windows between the editor and the frame with the status bar. I
wanted to bubble an event upward without caring about the the intermediate
windows and witrhout passing the frame down. Maybe this is not a desirabvle
aim ... anyway what I have done is bind an event handler in in the frame:

  self.Bind(wx.EVT_MENU, self.updateStatusBars, id=1944)

There is no menu item with this id. But in the OnDropFiles(self,evt)
function with catches the drop files event I have added:

    evt = wx.CommandEvent(wx.wxEVT_COMMAND_MENU_SELECTED)
            evt.SetId(1944)
            evt.SetEventObject(self)
            self.GetEventHandler().ProcessEvent(evt)

which is adapted from some code from Robin that I found on this list. The
menu event is a command event so bubbles up OK and is caught by the frame. I
don't know what the SetEventObject is meant to do but it was in Robin's
original. I thought of trying to create my own custome event but baulked at
this because I did not really know what to do. In particular which modules
need to know about the custom event class I might create. Mostly I am
learning wxPython so the answers were much appreciated. I hope the book
comes soon :slight_smile:

Thanks

Peter

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: 08 April 2005 23:22
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Propagating an File Drop Event

andrea_gavana@tin.it wrote:
> Hello Peter,
>
>
>>I have bound an event in an editor window for dropping files:
>>
>> self.Bind(wx.EVT_DROP_FILES, self.OnDropFiles)
>>
>>This works fine. I would like to pass the event up to the frame which is
>>an ancestor of the editor so that the frame can update its status bar.
>
> But
>
>>I cannot get the event to propagate. Can this be done?
>
>
> Couldn't you do something like:
>
> def OnDropFiles(self, event):
> # Receiving the event
> # Do something here
>
> self.parent.DoSomethingElse(**kwds)
>
> where self.parent is the Frame reference that you could store in the
__init__
> method of the editor, or something similar.
>

Another common approach is to just resend the event:

  parent = self.GetParent()
  parent.GetEventHandler().ProcessEvent(event)

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Peter Mott wrote:

Thanks for these answers. I did not make it clear that there were a lot of
intermediate windows between the editor and the frame with the status bar. I
wanted to bubble an event upward without caring about the the intermediate
windows and witrhout passing the frame down.

You can get the top-level window containing self using wx.GetTopLevelWindow(self).

Maybe this is not a desirabvle
aim ... anyway what I have done is bind an event handler in in the frame:

  self.Bind(wx.EVT_MENU, self.updateStatusBars, id=1944)

There is no menu item with this id. But in the OnDropFiles(self,evt)
function with catches the drop files event I have added:

    evt = wx.CommandEvent(wx.wxEVT_COMMAND_MENU_SELECTED)
            evt.SetId(1944)
            evt.SetEventObject(self)
            self.GetEventHandler().ProcessEvent(evt)

which is adapted from some code from Robin that I found on this list. The
menu event is a command event so bubbles up OK and is caught by the frame. I
don't know what the SetEventObject is meant to do but it was in Robin's
original.

I guess you don't you need to pass the filename(s) that were dropped?

I thought of trying to create my own custome event but baulked at
this because I did not really know what to do. In particular which modules
need to know about the custom event class I might create.

The code that sends the event kneeds to know the event class since it needs to create it. The receiving end only needs to know enough to bind the event, so either the event type or the EVT_* binder object.

Mostly I am
learning wxPython so the answers were much appreciated. I hope the book
comes soon :slight_smile:

The manuscript is more-or-less done, and it is in the review process right now.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

The menu event is a command event so bubbles up OK and is caught by the
frame.

I guess you don't you need to pass the filename(s) that were dropped?

If I had a custom event it would pass the filename. As it was the filename
is an instance variable of the editor class and the top-level window can
reference the editor(s). However wx.GetTopLevelWindow(self) seems to be the
right way to go for this particular problem.

Peter

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: 11 April 2005 19:59
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Propagating an File Drop Event

Peter Mott wrote:
>
> Thanks for these answers. I did not make it clear that there were a lot
of
> intermediate windows between the editor and the frame with the status
bar. I
> wanted to bubble an event upward without caring about the the
intermediate
> windows and witrhout passing the frame down.

You can get the top-level window containing self using
wx.GetTopLevelWindow(self).

> Maybe this is not a desirabvle
> aim ... anyway what I have done is bind an event handler in in the
frame:
>
> self.Bind(wx.EVT_MENU, self.updateStatusBars, id=1944)
>
> There is no menu item with this id. But in the OnDropFiles(self,evt)
> function with catches the drop files event I have added:
>
> evt = wx.CommandEvent(wx.wxEVT_COMMAND_MENU_SELECTED)
> evt.SetId(1944)
> evt.SetEventObject(self)
> self.GetEventHandler().ProcessEvent(evt)
>
> which is adapted from some code from Robin that I found on this list.
The
> menu event is a command event so bubbles up OK and is caught by the
frame. I
> don't know what the SetEventObject is meant to do but it was in Robin's
> original.

I guess you don't you need to pass the filename(s) that were dropped?

> I thought of trying to create my own custome event but baulked at
> this because I did not really know what to do. In particular which
modules
> need to know about the custom event class I might create.

The code that sends the event kneeds to know the event class since it
needs to create it. The receiving end only needs to know enough to bind
the event, so either the event type or the EVT_* binder object.

> Mostly I am
> learning wxPython so the answers were much appreciated. I hope the book
> comes soon :slight_smile:

The manuscript is more-or-less done, and it is in the review process
right now.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org