VeVi
VeVi

Reputation: 281

wxpython + how to bind button when using different classes

I'm learning wxpython and have a question about buttons. I have a main class in my file, which calls another class where a notebook is formed, that calls another class that makes the layout for the notebook page. I'm programming together with other people, so I've to use someone elses way of programming.

My problem is that I it doesn't do a thing when clicking the "addbutton". Maybe it has something to do with the way I call the button?

"self.notebook.PageOne.addbutton.Bind(wx.EVT_BUTTON, self.on_add_to_plotlist)"

Tx

My code:

class TabPanelMicroanalysis(wx.Panel):

  def __init__(self, parent, id):

    # # general panel information
    #wx.Frame.__init__(self, parent, id)
    wx.Panel.__init__(self, parent, id)

    # list with available measurements + button to add to plot
    self.lbltempmeasurements = wx.StaticText(self, label="Available measurements:")
    self.tempmeasurements = ObjectListView(self, wx.ID_ANY,style=wx.LC_REPORT|wx.SUNKEN_BORDER)
    self.tempmeasurements.SetColumns(microanalysis_options.TempMeasColumndefs)
    self.tempmeasurements.CreateCheckStateColumn(0)
    self.addbutton = wx.Button(self, wx.ID_ANY, "Add to plot")

class NotebookMA(wx.Notebook):
  def __init__(self, parent,id):
     wx.Notebook.__init__(self, parent, id)

    # Create the first tab and add it to the notebook
     self.PageOne = TabPanelMicroanalysis(self, wx.ID_ANY)
     self.AddPage(self.PageOne, "Microanalysis name")


class Main(wx.Frame):

  #Frame that holds all other widgets
  def __init__(self, parent = None, id = -1, notify_channel = "chanMicroanalysis", ** kwargs):

    #general panel information
    wx.Frame.__init__(self, parent, wx.ID_ANY)
    self.SetTitle('Microanalysis')
    self.panel = wx.Panel(self, wx.ID_ANY)
    pub.subscribe(self.on_message, notify_channel)

    # add menubar
    self.menubar = menubar_view(self, wx.ID_ANY)

    #make notebook
    self.notebook = NotebookMA(self.panel, wx.ID_ANY)

    self._do_layout()
    pub.sendMessage("PyShark", dict(caller=self, module="microanalyse_controller", package="Controllers"))

def _do_layout(self):

    self.vsizer = wx.BoxSizer(wx.VERTICAL)
    self.vsizer.Add(self.notebook,1,wx.EXPAND)
    self.panel.SetSizer(self.vsizer)
    self.SetMenuBar(self.menubar)
    self.Maximize()
    self.Show()

def _do_bindings(self):
    #print "testje"
    self.notebook.PageOne.addbutton.Bind(wx.EVT_BUTTON, self.on_add_to_plotlist)


# EVENT handlers -------------------------------------------------------------------------------------------------------
def on_message(self, message):
    pass

 def on_add_to_plotlist(self, event):

     objectsAddPlotList = self.notebook.PageOne.tempmeasurements.GetSelectedObjects()
     pub.sendMessage(self.notify_channel,
                     Container(type="EVT_ADD_TO_PLOTLIST", origin=self.notebook.PageOne.tempmeasurements, data=objectsAddPlotList))

Upvotes: 0

Views: 421

Answers (1)

VeVi
VeVi

Reputation: 281

Okay, never mind. I forgot to place

self._do_bindings()

in my main class :s

Upvotes: 1

Related Questions