Exemplo n.º 1
0
    def create_main_panel(self):
        self.panel = tk.Panel(self)
        self.dpi = 100
        self.fig = Figure((5., 5.), dpi=self.dpi)
        self.canvas = FigCanvas(self.panel, -1, self.fig)

        self.axes = self.fig.add_subplot(111)

        self.drawbutton = tk.Button(self.panel, -1, "Plot")
        self.Bind(tk.EVT_BUTTON, self.on_draw_button, self.drawbutton)

        self.logx = tk.CheckBox(self.panel, -1, "log X", style=tk.ALIGN_RIGHT)
        self.Bind(tk.EVT_CHECKBOX, self.on_logx, self.logx)

        self.logy = tk.CheckBox(self.panel, -1, "log Y", style=tk.ALIGN_RIGHT)
        self.Bind(tk.EVT_CHECKBOX, self.on_logy, self.logy)

        self.grid = tk.CheckBox(self.panel, -1, "grid", style=tk.ALIGN_RIGHT)
        self.Bind(tk.EVT_CHECKBOX, self.on_grid, self.grid)

        modelList = [d.name for d in self.dataObjList]

        # create list of population models. Set all "on" by default
        self.modelCheckList = tk.CheckListBox(self.panel,
                                              -1,
                                              choices=modelList,
                                              style=tk.ALIGN_RIGHT)
        self.modelCheckList.SetChecked(range(len(modelList)))

        # Create the navigation toolbar, tied to the canvas
        #
        self.toolbar = NavigationToolbar(self.canvas)

        #
        # Layout with box sizers
        #

        self.vbox = tk.BoxSizer(wx.VERTICAL)
        self.v_buttonbox_1 = tk.BoxSizer(wx.VERTICAL)
        self.v_buttonbox_2 = tk.BoxSizer(wx.VERTICAL)
        self.hpltbox = tk.BoxSizer(
            wx.HORIZONTAL)  # for plot and plot selection
        self.htoolbox = tk.BoxSizer(
            wx.HORIZONTAL)  # for drawing and log toggles

        # fill the top box first, radio buttons in a vbox,
        # next to the canvas
        self.radioBoxX = tk.RadioBox(self.panel,
                                     1,
                                     'X Axis',
                                     choices=self.dataObjList[0].textlabels,
                                     majorDimension=1,
                                     style=tk.RA_SPECIFY_COLS)

        self.radioBoxY = tk.RadioBox(self.panel,
                                     2,
                                     'Y Axis',
                                     choices=self.dataObjList[0].textlabels,
                                     majorDimension=1,
                                     style=tk.RA_SPECIFY_COLS)

        self.xIndex = 0
        self.yIndex = 0

        # event for radio box with ID 1
        tk.EVT_RADIOBOX(self.panel, 1, self.onXRadioClick)
        # event for radiobox with ID 2
        tk.EVT_RADIOBOX(self.panel, 2, self.onYRadioClick)

        # top horizontal panel - canvas and radio boxes
        self.hpltbox.Add(self.radioBoxX)
        self.hpltbox.Add(self.radioBoxY)
        self.hpltbox.Add(self.canvas, 1, tk.LEFT | wx.TOP | wx.GROW)
        self.hpltbox.Add(self.modelCheckList, 0, border=3)

        # add the matplotlib toolbar
        self.vbox.Add(self.hpltbox)
        self.vbox.Add(self.toolbar, 0, tk.EXPAND)
        self.vbox.AddSpacer(10)

        # bottom horizontal panel - check buttons and plot button
        flags = tk.ALIGN_LEFT | wx.ALL | wx.ALIGN_CENTER_VERTICAL
        self.htoolbox.Add(self.drawbutton, 0, border=3, flag=flags)
        self.htoolbox.Add(self.logx, 0, border=3, flag=flags)
        self.htoolbox.Add(self.logy, 0, border=3, flag=flags)
        self.htoolbox.AddSpacer(20)
        self.htoolbox.Add(self.grid, 0, border=3, flag=flags)

        self.vbox.Add(self.htoolbox, 0, flag=tk.ALIGN_LEFT | wx.TOP)

        self.panel.SetSizer(self.vbox)
        self.vbox.Fit(self)