def initUI(self):
        """
        Start the user interface.
        """

        self.statusbar = self.CreateStatusBar()

        hbox = wx.BoxSizer(wx.HORIZONTAL)

        # Add plots to panel 1
        panel = wx.Panel(self, -1)
        vbox1 = wx.BoxSizer(wx.VERTICAL)
        self.figure = Figure()
        self.canvas = FigureCanvasWxAgg(panel, -1, self.figure)
        self.toolbar = NavigationToolbar2WxAgg(self.canvas)
        self.toolbar.Realize()
        vbox1.Add(self.canvas, 1, wx.ALIGN_LEFT | wx.EXPAND)
        vbox1.Add(self.toolbar, 0, wx.ALIGN_LEFT)
        panel.SetSizer(vbox1)
        hbox.Add(panel, 1, wx.EXPAND)

        # Use some sizers to see layout options
        self.SetSizer(hbox)
        self.SetAutoLayout(1)
        hbox.Fit(self)
Esempio n. 2
0
    def init_plot0(self, parent):
        """Builds the single plot panel"""
        self.plot0_panel = wx.Panel(parent)
        self.plot0_panel_sizer = wx.BoxSizer(wx.VERTICAL)
        self.figure0 = matplotlib.figure.Figure((5, 4), 75)
        self.canvas0 = FigureCanvas(self.plot0_panel, -1, self.figure0)
        self.toolbar0 = NavigationToolbar2WxAgg(self.canvas0)

        self.axes0 = self.figure0.add_subplot(111, navigate=True)
        self.axes0.grid(True)

        plot0_lbl = wx.StaticText(self.plot0_panel, wx.ID_ANY,
                                  u"C-Scan Viewer", wx.DefaultPosition,
                                  wx.DefaultSize, 0)
        plot0_lbl.SetFont(
            wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False,
                    wx.EmptyString))

        self.plot0_panel_sizer.Add(plot0_lbl, 0, ui_defaults.sizer_flags,
                                   ui_defaults.widget_margin)
        self.plot0_panel_sizer.Add(self.canvas0, ui_defaults.ctrl_pct,
                                   ui_defaults.sizer_flags,
                                   ui_defaults.widget_margin)
        self.plot0_panel_sizer.Add(self.toolbar0, 0, ui_defaults.sizer_flags,
                                   ui_defaults.widget_margin)
        self.toolbar0.Realize()
        self.plot0_panel.SetSizer(self.plot0_panel_sizer)
Esempio n. 3
0
    def __init__(self, parent, color=None, dpi=None, **kwargs):
        from matplotlib.backends.backend_wxagg import (FigureCanvasWxAgg,
                                                       NavigationToolbar2WxAgg)
        from matplotlib.figure import Figure

        # initialize Panel
        if 'id' not in kwargs.keys():
            kwargs['id'] = wx.ID_ANY
        if 'style' not in kwargs.keys():
            kwargs['style'] = wx.NO_FULL_REPAINT_ON_RESIZE
        wx.Panel.__init__(self, parent, **kwargs)
        self.parent = parent

        # initialize matplotlib stuff
        self.figure = Figure(None, dpi)
        self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
        self.ax = self.figure.add_subplot(111)
        self.figure.subplots_adjust(hspace=0.8)
        self.toolbar = NavigationToolbar2WxAgg(self.canvas)

        vSizer = wx.BoxSizer(wx.VERTICAL)
        vSizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        vSizer.Add(self.toolbar, 0, wx.EXPAND)
        self.draw()
        self.SetAutoLayout(True)
        self.SetSizer(vSizer)
        self.Layout()
Esempio n. 4
0
    def init_plots(self, parent):
        """Builds the two plot windows"""
        self.plot_panel = wx.Panel(parent)
        self.plot_panel_sizer = wx.BoxSizer(wx.VERTICAL)
        self.figure1 = matplotlib.figure.Figure((5, 4), 75)
        self.figure2 = matplotlib.figure.Figure((5, 4), 75)
        self.canvas1 = FigureCanvas(self.plot_panel, -1, self.figure1)
        self.canvas2 = FigureCanvas(self.plot_panel, -1, self.figure2)
        self.toolbar1 = NavigationToolbar2WxAgg(self.canvas1)

        self.toolbar2 = NavigationToolbar2WxAgg(self.canvas2)

        self.axes1 = self.figure1.add_subplot(111, navigate=True)
        self.axes1.grid(True)
        self.axes2 = self.figure2.add_subplot(111, navigate=True)
        self.axes2.grid(True)
        plot1_lbl = wx.StaticText(self.plot_panel, wx.ID_ANY, u"Plot 1",
                                  wx.DefaultPosition, wx.DefaultSize, 0)
        plot1_lbl.SetFont(
            wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False,
                    wx.EmptyString))
        plot2_lbl = wx.StaticText(self.plot_panel, wx.ID_ANY, u"Plot 2",
                                  wx.DefaultPosition, wx.DefaultSize, 0)
        plot2_lbl.SetFont(
            wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False,
                    wx.EmptyString))
        self.plot_panel_sizer.Add(plot1_lbl, 0, ui_defaults.sizer_flags,
                                  ui_defaults.widget_margin)
        self.plot_panel_sizer.Add(self.canvas1, ui_defaults.ctrl_pct,
                                  ui_defaults.sizer_flags,
                                  ui_defaults.widget_margin)
        self.plot_panel_sizer.Add(self.toolbar1, 0, ui_defaults.sizer_flags,
                                  ui_defaults.widget_margin)
        self.toolbar1.Realize()
        self.plot_panel_sizer.Add(plot2_lbl, 0, ui_defaults.sizer_flags,
                                  ui_defaults.widget_margin)
        self.plot_panel_sizer.Add(self.canvas2, ui_defaults.ctrl_pct,
                                  ui_defaults.sizer_flags,
                                  ui_defaults.widget_margin)
        self.plot_panel_sizer.Add(self.toolbar2, 0, ui_defaults.sizer_flags,
                                  ui_defaults.widget_margin)
        self.toolbar2.Realize()
        self.plot_panel.SetSizer(self.plot_panel_sizer)
Esempio n. 5
0
def AddFigure(figure: matplotlib.figure.Figure):
    frame.canvas = FigureCanvasWxAgg(panel, -1, figure)
    frame.toolbar = NavigationToolbar2WxAgg(frame.canvas)

    frame.toolbar.Realize()  #Damn, I just realised!

    frame.sizer = wx.BoxSizer(wx.VERTICAL)
    frame.sizedCanvas = frame.sizer.Add(frame.canvas, 1, wx.EXPAND)
    frame.sizer.Add(frame.toolbar, 0, wx.LEFT | wx.EXPAND)
    panel.SetSizer(frame.sizer)
Esempio n. 6
0
 def __init__(self, *args, **kwargs):
     self.x_points = None
     self.y_points = None
     self._parent = kwargs.get('parent', None)
     self._figure = pyplot.figure()
     self._canvas = FigureCanvasWxAgg(self._parent, -1, self._figure)
     self._toolbar = NavigationToolbar2WxAgg(self._canvas)
     self._figure.clf()
     # self._figure.subplots_adjust(left=None, bottom=None, right=None,
     #                             top=None, wspace=None, hspace=0.3)
     self._cmap = pyplot.cm.RdYlGn_r
     self._figure.hold(True)
     self._canvas.SetSize(self._parent.GetSize())
     self._canvas.draw()
Esempio n. 7
0
 def add_2Dtoolbar(self, panel):
     """
     Adds the standard matplotlib toolbar that provides extra viewing
     features (e.g., pan and zoom).
     """
     panel.toolbar = NavigationToolbar2WxAgg(panel.canvas)
     panel.toolbar.Realize()
     tw, th = panel.toolbar.GetSizeTuple()
     fw, fh = panel.canvas.GetSizeTuple()
     panel.toolbar.SetSize(wx.Size(fw, th))
     panel.sizer.Add(panel.toolbar, 0, wx.LEFT | wx.EXPAND)
     # update the axes menu on the toolbar
     panel.toolbar.update()
     panel.SendSizeEvent()
Esempio n. 8
0
 def get_toolbar(self):
     if not self.toolbar:
         self.toolbar = NavigationToolbar2WxAgg(self.figure.canvas)
         self.toolbar.Realize()
         self.id_save = wx.NewId()
         self.id_info = wx.NewId()
         self.toolbar.AddSimpleTool(
             self.id_save, wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE),
             _("Save plot as ASCII file"), 'Activate custom contol')
         wx.EVT_TOOL(self.toolbar, self.id_save, self.on_save_dat)
         self.toolbar.AddSimpleTool(
             self.id_info, wx.ArtProvider.GetBitmap(wx.ART_INFORMATION),
             _("Details"), 'Activate custom contol')
         wx.EVT_TOOL(self.toolbar, self.id_info, self.on_plot_info)
         self.toolbar.EnableTool(self.id_save, False)
         self.toolbar.EnableTool(self.id_info, False)
     return self.toolbar
Esempio n. 9
0
    def __init__(self, *args, **kwargs):
        super(ASPanelWxMPL, self).__init__(*args)

        self.figure = kwargs.pop('figure', None)
        if not self.figure:
            self.figure = Figure(ASPanelWxMPL.DEFAULT_SIZE,
                                 ASPanelWxMPL.DEFAULT_DPI)

        self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
        self.toolbar = NavigationToolbar2WxAgg(self.canvas)
        self.toolbar.Hide()

        self.__set_size()

        self.Bind(wx.EVT_SIZE, self.on_resize)
        #self.Bind(wx.EVT_PAINT, self.on_redraw)
        self.canvas.mpl_connect('motion_notify_event', self.on_mouse_move)
Esempio n. 10
0
    def __init__(self):
        Frame.__init__(self, None, -1, "Test embedded wxFigure")

        self.fig = Figure((9,8), 75)
        self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
        self.toolbar = NavigationToolbar2WxAgg(self.canvas)
        self.toolbar.Realize()

        self.figmgr = FigureManager(self.canvas, 1, self)
        tw, th = self.toolbar.GetSizeTuple()
        fw, fh = self.canvas.GetSizeTuple()
        self.toolbar.SetSize(Size(fw, th))
        sizer = BoxSizer(VERTICAL)

        # This way of adding to sizer allows resizing
        sizer.Add(self.canvas, 1, LEFT|TOP|GROW)
        sizer.Add(self.toolbar, 0, GROW)
        self.SetSizer(sizer)
        self.Fit()

        self.plot3d()
Esempio n. 11
0
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)

        vbox = wx.BoxSizer(wx.VERTICAL)

        self.image_view = ImageView(self,
                                    ID_EXPOSURE_VIEW,
                                    size=(487, 195),
                                    style=wx.BORDER_SUNKEN)
        vbox.Add(self.image_view, 1, wx.EXPAND)

        self.figure = Figure()
        self.plot = FigureCanvas(self, wx.ID_ANY, self.figure)
        self.plot.SetSize((487, 195))
        self.plot.SetWindowStyle(wx.BORDER_SUNKEN)
        vbox.Add(self.plot, 1, wx.EXPAND)
        self.plot.Hide()

        self.toolbar = NavigationToolbar2WxAgg(self.plot)
        vbox.Add(self.toolbar, 0, wx.EXPAND)
        self.plot.Hide()

        self.SetSizerAndFit(vbox)
Esempio n. 12
0
    def __init__(self, parent, app):
        self._app = app
        self._plot_context = app._plot_context
        self.animation = None
        self.canvas_force_resize = False
        self.canvas_last_resize_s = None

        wx.Panel.__init__(self, parent, -1)

        self.canvas = FigureCanvasWxAgg(self, -1, self._plot_context.fig)
        self.toolbar = NavigationToolbar2WxAgg(
            self.canvas)  # matplotlib toolbar
        self.toolbar.Realize()

        self.canvas.Bind(wx.EVT_SIZE, self.OnSizeCanvas)

        # Now put all into a sizer which will resize the figure when the window size changes
        sizer = wx.BoxSizer(wx.VERTICAL)
        # This way of adding to sizer allows resizing
        sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        # Best to allow the toolbar to resize!
        sizer.Add(self.toolbar, 0, wx.GROW)
        self.SetSizer(sizer)
        self.Fit()
Esempio n. 13
0
    def filter_objects(self, workspace, orig_labels):
        import wx
        import matplotlib
        from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
        from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
        from cellprofiler.gui.cpfigure import renumber_labels_for_display

        assert isinstance(workspace, cpw.Workspace)
        orig_objects_name = self.object_name.value
        #
        # Get the labels matrix and make a mask of objects to keep from it
        #
        #
        # Display a UI for choosing objects
        #
        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
        dialog_box = wx.Dialog(workspace.frame,
                               -1,
                               "Choose objects to keep",
                               style=style)
        sizer = wx.BoxSizer(wx.VERTICAL)
        dialog_box.SetSizer(sizer)
        figure = matplotlib.figure.Figure()
        panel = FigureCanvasWxAgg(dialog_box, -1, figure)
        sizer.Add(panel, 1, wx.EXPAND)
        toolbar = NavigationToolbar2WxAgg(panel)
        sizer.Add(toolbar, 0, wx.EXPAND)
        mask = orig_labels != 0
        #
        # Make 3 axes
        #
        orig_axes = figure.add_subplot(2, 2, 1)
        orig_axes._adjustable = 'box-forced'
        keep_axes = figure.add_subplot(2,
                                       2,
                                       2,
                                       sharex=orig_axes,
                                       sharey=orig_axes)
        remove_axes = figure.add_subplot(2,
                                         2,
                                         4,
                                         sharex=orig_axes,
                                         sharey=orig_axes)
        for axes in (orig_axes, keep_axes, remove_axes):
            axes._adjustable = 'box-forced'

        info_axes = figure.add_subplot(2, 2, 3)
        assert isinstance(info_axes, matplotlib.axes.Axes)
        info_axes.set_axis_off()
        #
        # Add an explanation and possibly a checkbox to the info axis
        #
        ui_text = ("Keep or remove objects by clicking\n"
                   "on them with the mouse.\n"
                   'Press the "Done" button when\nediting is complete.')
        info_axes.text(0, 0, ui_text, size="small")
        wants_image_display = [self.wants_image_display.value]
        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
        #
        # Need padding on top because tool bar is wonky about its height
        #
        sizer.Add(sub_sizer, 0, wx.EXPAND | wx.TOP, 10)

        resume_id = 100
        cancel_id = 101
        keep_all_id = 102
        remove_all_id = 103
        reverse_select = 104
        #########################################
        #
        # Buttons for keep / remove / toggle
        #
        #########################################

        keep_button = wx.Button(dialog_box, keep_all_id, "Keep all")
        sub_sizer.Add(keep_button, 0, wx.ALIGN_CENTER)

        remove_button = wx.Button(dialog_box, remove_all_id, "Remove all")
        sub_sizer.Add(remove_button, 0, wx.ALIGN_CENTER)

        toggle_button = wx.Button(dialog_box, reverse_select,
                                  "Reverse selection")
        sub_sizer.Add(toggle_button, 0, wx.ALIGN_CENTER)

        ######################################
        #
        # Buttons for resume and cancel
        #
        ######################################
        button_sizer = wx.StdDialogButtonSizer()
        resume_button = wx.Button(dialog_box, resume_id, "Done")
        button_sizer.AddButton(resume_button)
        sub_sizer.Add(button_sizer, 0, wx.ALIGN_CENTER)

        def on_resume(event):
            dialog_box.EndModal(wx.OK)

        dialog_box.Bind(wx.EVT_BUTTON, on_resume, resume_button)
        button_sizer.SetAffirmativeButton(resume_button)

        cancel_button = wx.Button(dialog_box, cancel_id, "Cancel")
        button_sizer.AddButton(cancel_button)

        def on_cancel(event):
            dialog_box.EndModal(wx.CANCEL)

        dialog_box.Bind(wx.EVT_BUTTON, on_cancel, cancel_button)
        button_sizer.SetNegativeButton(cancel_button)
        button_sizer.Realize()

        ################### d i s p l a y #######
        #
        # The following is a function that we can call to refresh
        # the figure's appearance based on the mask and the original labels
        #
        ##########################################
        cm = matplotlib.cm.get_cmap(cpprefs.get_default_colormap())
        cm.set_bad((0, 0, 0))

        def display():
            if len(orig_axes.images) > 0:
                # Save zoom and scale if coming through here a second time
                x0, x1 = orig_axes.get_xlim()
                y0, y1 = orig_axes.get_ylim()
                set_lim = True
            else:
                set_lim = False
            for axes, labels, title in ((orig_axes, orig_labels,
                                         "Original: %s" % orig_objects_name),
                                        (keep_axes, orig_labels * mask,
                                         "Objects to keep"),
                                        (remove_axes, orig_labels * (~mask),
                                         "Objects to remove")):

                assert isinstance(axes, matplotlib.axes.Axes)
                labels = renumber_labels_for_display(labels)
                axes.clear()
                if np.all(labels == 0):
                    use_cm = matplotlib.cm.gray
                    is_blank = True
                else:
                    use_cm = cm
                    is_blank = False
                if wants_image_display[0]:
                    outlines = outline(labels)
                    image = workspace.image_set.get_image(
                        self.image_name.value)
                    image = image.pixel_data.astype(np.float)
                    image, _ = cpo.size_similarly(labels, image)
                    if image.ndim == 2:
                        image = np.dstack((image, image, image))
                    if not is_blank:
                        mappable = matplotlib.cm.ScalarMappable(cmap=use_cm)
                        mappable.set_clim(1, labels.max())
                        limage = mappable.to_rgba(labels)[:, :, :3]
                        image[outlines != 0, :] = limage[outlines != 0, :]
                    axes.imshow(image)

                else:
                    axes.imshow(labels, cmap=use_cm)
                axes.set_title(title,
                               fontname=cpprefs.get_title_font_name(),
                               fontsize=cpprefs.get_title_font_size())
            if set_lim:
                orig_axes.set_xlim((x0, x1))
                orig_axes.set_ylim((y0, y1))
            figure.canvas.draw()
            panel.Refresh()

        if self.wants_image_display:
            display_image_checkbox = matplotlib.widgets.CheckButtons(
                info_axes, ["Display image"], [True])
            display_image_checkbox.labels[0].set_size("small")
            r = display_image_checkbox.rectangles[0]
            rwidth = r.get_width()
            rheight = r.get_height()
            rx, ry = r.get_xy()
            new_rwidth = rwidth / 2
            new_rheight = rheight / 2
            new_rx = rx + rwidth / 2
            new_ry = ry + rheight / 4
            r.set_width(new_rwidth)
            r.set_height(new_rheight)
            r.set_xy((new_rx, new_ry))
            l1, l2 = display_image_checkbox.lines[0]
            l1.set_data((np.array((new_rx, new_rx + new_rwidth)),
                         np.array((new_ry, new_ry + new_rheight))))
            l2.set_data((np.array((new_rx, new_rx + new_rwidth)),
                         np.array((new_ry + new_rheight, new_ry))))

            def on_display_image_clicked(_):
                wants_image_display[0] = not wants_image_display[0]
                display()

            display_image_checkbox.on_clicked(on_display_image_clicked)

        def on_click(event):
            if event.inaxes not in (orig_axes, keep_axes, remove_axes):
                return
            x = int(event.xdata)
            y = int(event.ydata)
            if (x < 0 or x >= orig_labels.shape[1] or y < 0
                    or y >= orig_labels.shape[0]):
                return
            lnum = orig_labels[y, x]
            if lnum == 0:
                return
            if event.inaxes == orig_axes:
                mask[orig_labels == lnum] = ~mask[orig_labels == lnum]
            elif event.inaxes == keep_axes:
                mask[orig_labels == lnum] = False
            else:
                mask[orig_labels == lnum] = True
            display()

        figure.canvas.mpl_connect('button_press_event', on_click)

        ################################
        #
        # Functions for keep / remove/ toggle
        #
        ################################

        def on_keep(event):
            mask[:, :] = (orig_labels != 0)
            display()

        dialog_box.Bind(wx.EVT_BUTTON, on_keep, keep_button)

        def on_remove(event):
            mask[:, :] = 0
            display()

        dialog_box.Bind(wx.EVT_BUTTON, on_remove, remove_button)

        def on_toggle(event):
            mask[orig_labels != 0] = ~mask[orig_labels != 0]
            display()

        dialog_box.Bind(wx.EVT_BUTTON, on_toggle, toggle_button)

        display()
        dialog_box.Fit()
        result = dialog_box.ShowModal()
        dialog_box.Destroy()
        if result != wx.OK:
            raise RuntimeError("User cancelled EditObjectsManually")
        filtered_labels = orig_labels.copy()
        filtered_labels[~mask] = 0
        return filtered_labels
Esempio n. 14
0
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((1000, 800))

        # Menu Bar
        self.frame_menubar = wx.MenuBar()
        wxglade_tmp_menu = wx.Menu()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, u"设置", u"选项设置")
        self.Bind(wx.EVT_MENU, self.hello, id=item.GetId())
        self.frame_menubar.Append(wxglade_tmp_menu, u"文件")
        wxglade_tmp_menu = wx.Menu()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, u"关于", u"关于本软件")
        self.Bind(wx.EVT_MENU, self.about, id=item.GetId())
        self.frame_menubar.Append(wxglade_tmp_menu, u"帮助")
        self.SetMenuBar(self.frame_menubar)
        # Menu Bar end
        self.frame_statusbar = self.CreateStatusBar(1)

        # Tool Bar
        self.frame_toolbar = wx.ToolBar(self, -1)
        self.SetToolBar(self.frame_toolbar)
        self.frame_toolbar.AddTool(
            1001, "Home",
            wx.Bitmap("C:\\Users\\Admin\\Desktop\\home.png",
                      wx.BITMAP_TYPE_ANY), wx.NullBitmap, wx.ITEM_NORMAL,
            "Home", "")
        self.frame_toolbar.AddTool(
            1002, "Back",
            wx.Bitmap("C:\\Users\\Admin\\Desktop\\home.png",
                      wx.BITMAP_TYPE_ANY), wx.NullBitmap, wx.ITEM_NORMAL,
            "Back", "")
        self.frame_toolbar.AddTool(
            1003, "Forward",
            wx.Bitmap("C:\\Users\\Admin\\Desktop\\home.png",
                      wx.BITMAP_TYPE_ANY), wx.NullBitmap, wx.ITEM_NORMAL,
            "Forward", "")
        self.frame_toolbar.AddTool(
            1004, "Move",
            wx.Bitmap("C:\\Users\\Admin\\Desktop\\home.png",
                      wx.BITMAP_TYPE_ANY), wx.NullBitmap, wx.ITEM_NORMAL,
            "Move", "")
        self.frame_toolbar.AddTool(
            1005, "Zoom",
            wx.Bitmap("C:\\Users\\Admin\\Desktop\\home.png",
                      wx.BITMAP_TYPE_ANY), wx.NullBitmap, wx.ITEM_NORMAL,
            "Zoom", "")
        # Tool Bar end
        self.window_1 = wx.SplitterWindow(self, wx.ID_ANY)
        self.window_1_pane_1 = wx.ScrolledWindow(self.window_1,
                                                 wx.ID_ANY,
                                                 style=wx.TAB_TRAVERSAL)
        self.tree_ctrl_1 = wx.TreeCtrl(self.window_1_pane_1, wx.ID_ANY)
        self.CreateTreeCtrl(tree=self.tree_ctrl_1)
        self.window_1_pane_2 = wx.Panel(self.window_1, wx.ID_ANY)
        self.notebook_1 = wx.Notebook(self.window_1_pane_2, wx.ID_ANY)
        self.notebook_1_pane_2 = wx.Panel(self.notebook_1, wx.ID_ANY)
        self.button_1 = wx.Button(self.notebook_1_pane_2, wx.ID_ANY, u"绘图")
        self.window_2 = matplotlib_canvas.MatplotlibCanvas(
            self.notebook_1_pane_2, wx.ID_ANY)
        self.notebook_1_pane_3 = wx.Panel(self.notebook_1, wx.ID_ANY)
        self.window_3 = wx.SplitterWindow(self.notebook_1_pane_3, wx.ID_ANY)
        self.window_3_pane_1 = wx.ScrolledWindow(self.window_3,
                                                 wx.ID_ANY,
                                                 style=wx.TAB_TRAVERSAL)
        self.choice_1 = wx.Choice(self.window_3_pane_1, wx.ID_ANY, choices=[])
        self.client = pymongo.MongoClient(host='192.168.2.232', port=27017)
        # 密码认证
        self.client.admin.authenticate('nego', '123456abcd.')
        db_names = self.get_db_names()
        self.choice_1.AppendItems(db_names)
        self.choice_2 = wx.Choice(self.window_3_pane_1, wx.ID_ANY, choices=[])
        self.text_ctrl_1 = wx.TextCtrl(self.window_3_pane_1, wx.ID_ANY, "")
        self.text_ctrl_2 = wx.TextCtrl(self.window_3_pane_1, wx.ID_ANY, "")
        self.text_ctrl_3 = wx.TextCtrl(self.window_3_pane_1, wx.ID_ANY, "")
        self.text_ctrl_4 = wx.TextCtrl(self.window_3_pane_1, wx.ID_ANY, "")
        self.button_2 = wx.Button(self.window_3_pane_1, wx.ID_ANY, u"查询")
        self.list_box_1 = wx.ListBox(self.window_3_pane_1,
                                     wx.ID_ANY,
                                     choices=[])
        self.list_box_2 = wx.ListBox(self.window_3_pane_1,
                                     wx.ID_ANY,
                                     choices=[])
        self.radio_box_1 = wx.RadioBox(self.window_3_pane_1,
                                       wx.ID_ANY,
                                       u"类型",
                                       choices=[u"时域", u"频域"],
                                       majorDimension=1,
                                       style=wx.RA_SPECIFY_ROWS)
        self.button_3 = wx.Button(self.window_3_pane_1, wx.ID_ANY, u"绘图")
        self.window_3_pane_2 = wx.Panel(self.window_3, wx.ID_ANY)
        self.window_4 = matplotlib_canvas.MatplotlibCanvas(
            self.window_3_pane_2, wx.ID_ANY)
        self.toolbar = NavigationToolbar2WxAgg(self.window_4)
        self.toolbar.Hide()

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_TOOL, self.toolbar_home, id=1001)
        self.Bind(wx.EVT_TOOL, self.toolbar_back, id=1002)
        self.Bind(wx.EVT_TOOL, self.toolbar_forward, id=1003)
        self.Bind(wx.EVT_TOOL, self.toolbar_pan, id=1004)
        self.Bind(wx.EVT_TOOL, self.toolbar_zoom, id=1005)
        self.Bind(wx.EVT_TREE_SEL_CHANGING, self.ontree_ctrl_1,
                  self.tree_ctrl_1)
        self.Bind(wx.EVT_BUTTON, self.onbutton_1, self.button_1)
        self.Bind(wx.EVT_CHOICE, self.onchoice_1, self.choice_1)
        self.Bind(wx.EVT_BUTTON, self.onbutton_2, self.button_2)
        self.Bind(wx.EVT_BUTTON, self.onbutton_3, self.button_3)
Esempio n. 15
0
    def __init__(self,parent,title):
        ''' init method for main frame '''
        self.temp_output = [] # To hold count rates at each timestep
        self.t0 = 0 # time when run is started
        self.t1 = 0 # time when save happens
        
        wx.Frame.__init__(self,parent,title=title)
        
        self.HRMTime = HRMTimeAPI()
        
        ########### Init Params ###########
        self.recordinglength = 1000 # ms
        self.ncounts = 1000000
        self.dtmax = 40000 # ps # max correlation time between herald and signal
        self.dntags = 2 # number of time tags to consider for calculating the cross correlation
        self.plotbinfactor = 1 # number of time bins to combine for plot
        self.DataCollectFlag = False # Dont collect data at program start
        self.dirname = ''
        self.cumulativeflag = True #rsm
        
        ########### Right Panel ############
        self.rightpanel = wx.Panel(self,style=wx.BORDER)
        
        self.combobox = wx.ComboBox(self.rightpanel,choices=['Cross Correlation','Heralded Cross Correlation','Auto Correlation C0','Auto Correlation C1','Auto Correlation C2'],style=wx.CB_DROPDOWN)
        self.combobox.SetValue('Cross Correlation')
        self.Bind(wx.EVT_COMBOBOX, self.OnComboSelect, self.combobox)
        
        self.cumulativetickboxtextlabel = wx.StaticText(self.rightpanel,label='Cumulative mode?')
        self.cumulativetickbox = wx.CheckBox(self.rightpanel)
        self.cumulativetickbox.SetValue(True) #rsm
        self.tickboxsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.tickboxsizer.Add(self.cumulativetickboxtextlabel,1,wx.EXPAND)
        self.tickboxsizer.Add(self.cumulativetickbox,0,wx.EXPAND)
        
        self.rightpaneltextctrls = []
        self.rightpaneltextlabels = []
        self.rightpaneltextctrls.append(wx.TextCtrl(self.rightpanel,value=str(self.recordinglength)))
        self.rightpaneltextlabels.append(wx.StaticText(self.rightpanel,label='Max recording time (s)'))
        self.rightpaneltextctrls.append(wx.TextCtrl(self.rightpanel,value=str(self.ncounts)))
        self.rightpaneltextlabels.append(wx.StaticText(self.rightpanel,label='Max number of counts'))        
        self.rightpaneltextctrls.append(wx.TextCtrl(self.rightpanel,value=str(self.dtmax)))
        self.rightpaneltextlabels.append(wx.StaticText(self.rightpanel,label='Max correlation time (ps)'))        
        self.rightpaneltextctrls.append(wx.TextCtrl(self.rightpanel,value=str(self.plotbinfactor)))
        self.rightpaneltextlabels.append(wx.StaticText(self.rightpanel,label='Plot binning factor'))    
        self.rightpaneltextctrls.append(wx.TextCtrl(self.rightpanel,value=str(self.dntags)))
        self.rightpaneltextlabels.append(wx.StaticText(self.rightpanel,label='# of tags per trigger'))
        
        self.applybutton = wx.Button(self.rightpanel, wx.ID_ANY, 'Apply')
        self.Bind(wx.EVT_BUTTON, self.OnApply, self.applybutton)
        
        # Create sizer
        self.rightpanelsizer = wx.BoxSizer(wx.VERTICAL)
        self.rightpanelsizer.Add(wx.StaticText(self.rightpanel,label='Settings',style=wx.ALIGN_CENTRE_HORIZONTAL),0,wx.EXPAND|wx.ALL,border=10)
        self.rightpanelsizer.Add(self.combobox,0,wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM,border=10)
        self.rightpanelsizer.Add(self.tickboxsizer,0,wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM,border=10)
        for i in range(len(self.rightpaneltextctrls)):
            self.rightpanelsizer.Add(self.rightpaneltextlabels[i],0,wx.EXPAND|wx.LEFT|wx.RIGHT,border=10)
            self.rightpanelsizer.Add(self.rightpaneltextctrls[i],0,wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM,border=10)
        self.rightpanelsizer.Add(self.applybutton,0,wx.EXPAND|wx.LEFT|wx.RIGHT,border=10)
        
        # Layout sizer
        self.rightpanel.SetSizerAndFit(self.rightpanelsizer)

        ########## Create Left Panel ##########
        self.leftpanel = wx.Panel(self)
        
        ########### Plot Panel ############
        self.plotpanel = wx.Panel(self.leftpanel)
        self.fig = plt.figure(figsize=(8,4.944),facecolor='white')

        self.canvas = FigureCanvasWxAgg(self.plotpanel, wx.ID_ANY, self.fig)
        self.navtoolbar = NavigationToolbar2WxAgg(self.canvas)

        # Create sizer
        self.plotsizer = wx.BoxSizer(wx.VERTICAL)
        self.plotsizer.Add(self.canvas, 1, wx.LEFT|wx.RIGHT|wx.GROW,border=0)
        self.plotsizer.Add(self.navtoolbar, 0, wx.LEFT|wx.RIGHT|wx.EXPAND,border=0)

        # Layout sizer
        self.plotpanel.SetSizerAndFit(self.plotsizer)
        
        ########### Top Button Panel ###########
        self.topbuttonpanel = wx.Panel(self.leftpanel)
        self.topbuttons = []
        self.topbuttons.append(wx.Button(self.topbuttonpanel, wx.ID_ANY, 'Run Once'))
        self.Bind(wx.EVT_BUTTON, self.OnRunOnce, self.topbuttons[-1])
        self.topbuttons.append(wx.Button(self.topbuttonpanel, wx.ID_ANY, 'Run Continuous'))
        self.Bind(wx.EVT_BUTTON, self.OnRunContinuous, self.topbuttons[-1])
        self.topbuttons.append(wx.Button(self.topbuttonpanel, wx.ID_ANY, 'Stop'))
        self.Bind(wx.EVT_BUTTON, self.OnStop, self.topbuttons[-1])
        self.topbuttons.append(wx.Button(self.topbuttonpanel, wx.ID_ANY, 'Save Correlation Data'))
        self.Bind(wx.EVT_BUTTON, self.OnSaveCorrelation, self.topbuttons[-1])
        
        # Create sizer
        self.topbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
        for i,button in enumerate(self.topbuttons):
            self.topbuttonsizer.Add(button, 1, wx.EXPAND)

        # Layout sizer
        self.topbuttonpanel.SetSizerAndFit(self.topbuttonsizer)
        
        ######### Left panel sizer ##########
        self.leftsizer = wx.BoxSizer(wx.VERTICAL)
        self.leftsizer.Add(self.topbuttonpanel,0,wx.EXPAND)
        self.leftsizer.Add(self.plotpanel,1,wx.EXPAND)
        self.SetSizerAndFit(self.leftsizer)
        
        ######### Top level sizer #############
        self.topsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.topsizer.Add(self.leftpanel, 1, wx.EXPAND)
        self.topsizer.Add(self.rightpanel, 0, wx.EXPAND)
        self.SetSizerAndFit(self.topsizer)
        
        self.ax = self.fig.add_subplot(111)
        self.ax.set_xlabel('Delay (ns)')
        self.ax.set_ylabel('Unnormalised Cross Correlation')
        self.ax.autoscale(tight=True)
        self.canvas.draw()
        
        self.Show()
Esempio n. 16
0
import os
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg, NavigationToolbar2WxAgg
from matplotlib.backends.backend_wx import _load_bitmap
import matplotlib as mpl

app = wx.PySimpleApp()
f = wx.Frame(None)
fig = mpl.figure.Figure()
p = FigureCanvasWxAgg(f, -1, fig)

toolbar = NavigationToolbar2WxAgg(p)
toolbar.Hide()

#toolbar constants
TBFLAGS = (wx.TB_HORIZONTAL | wx.TB_TEXT)
tsize = (24, 24)
tb = f.CreateToolBar(TBFLAGS)

_NTB2_HOME = wx.NewId()
_NTB2_BACK = wx.NewId()
_NTB2_FORWARD = wx.NewId()
_NTB2_PAN = wx.NewId()
_NTB2_ZOOM = wx.NewId()
_NTB2_SAVE = wx.NewId()
_NTB2_SUBPLOT = wx.NewId()

tb.AddSimpleTool(_NTB2_HOME, _load_bitmap('home.png'), 'Home',
                 'Reset original view')
tb.AddSimpleTool(_NTB2_BACK, _load_bitmap('back.png'), 'Back',
                 'Back navigation view')
Esempio n. 17
0
 def add_toolbar(self):
     self.toolbar = NavigationToolbar2WxAgg(self.canvas)
     self.toolbar.Realize()
     self.sizer90.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
     self.toolbar.Update()
Esempio n. 18
0
    def __init__(self, *args, **kw):
        wx.Panel.__init__(self, *args, **kw)

        # Fig
        self.fig = Figure(
            figsize=(1, 1),
            dpi=75,
            facecolor='white',
            edgecolor='white',
        )
        # Canvas
        self.canvas = FigureCanvas(self, -1, self.fig)
        self.fig.set_canvas(self.canvas)

        # Axes
        self.axes = self.fig.add_axes(Subplot(self.fig, 111))
        self.axes.set_autoscale_on(False)
        self.theta_axes = self.axes.twinx()
        self.theta_axes.set_autoscale_on(False)

        # Show toolbar or not?
        self.toolbar = NavigationToolbar2WxAgg(self.canvas)
        self.toolbar.Show(True)

        # Create a figure manager to manage things
        self.figmgr = FigureManager(self.canvas, 1, self)

        # Panel layout
        self.profile_selector_label = wx.StaticText(self, label="Sample")
        self.profile_selector = wx.Choice(self)
        self.profile_selector.Hide()
        self.profile_selector_label.Hide()
        self.Bind(wx.EVT_CHOICE, self.OnProfileSelect)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas,
                       1,
                       border=2,
                       flag=wx.LEFT | wx.TOP | wx.GROW)
        self.tbsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.tbsizer.Add(self.toolbar, 0, wx.ALIGN_CENTER_VERTICAL)
        self.tbsizer.AddSpacer(20)
        self.tbsizer.Add(self.profile_selector_label, 0,
                         wx.ALIGN_CENTER_VERTICAL)
        self.tbsizer.AddSpacer(5)
        self.tbsizer.Add(self.profile_selector, 0, wx.ALIGN_CENTER_VERTICAL)
        self.sizer.Add(self.tbsizer)

        self.SetSizer(self.sizer)
        self.sizer.Fit(self)

        # Status bar
        frame = self.GetTopLevelParent()
        self.statusbar = frame.GetStatusBar()
        if self.statusbar is None:
            self.statusbar = frame.CreateStatusBar()
        status_update = lambda msg: self.statusbar.SetStatusText(msg)

        # Set the profile interactor
        self.profile = ProfileInteractor(self.axes,
                                         self.theta_axes,
                                         status_update=status_update)

        # Add context menu and keyboard support to canvas
        self.canvas.Bind(wx.EVT_RIGHT_DOWN, self.OnContextMenu)
        #self.canvas.Bind(wx.EVT_LEFT_DOWN, lambda evt: self.canvas.SetFocus())

        self.model = None
        self._need_interactors = self._need_redraw = False
        self.Bind(wx.EVT_SHOW, self.OnShow)
Esempio n. 19
0
    def __init__(self, data, fits, labels, styles, parent, id, title):
        """a gui for exploring data stored in dictionary 'data'. 
        data = a dictionary of x,y arrays to plot where the keys are tuples (of equal length)"""
        ## initialise parent class
        wx.Frame.__init__(self, parent, id, title, size=(380, 230))
        ## Q1. Are data keys strings or tuples
        strkeys = sum([
            1 for i in data if type(i) in (type(''), type(0), type(float()))
        ])  #count number of string keys (or int or float)
        tplkeys = sum([1 for i in data if type(i) in (type(()), type([]))
                       ])  #count number of tuple or list keys
        assert min(
            strkeys,
            tplkeys) == 0  #check that there isn't a mixture of key types
        if strkeys == len(
                data
        ):  #just another check that all keys are strings in this case.
            tmp = {}
            for key, value in data.items():
                tmp[key,
                    ] = value  #turn strings keys into single length tuples
            data = tmp
            del (tmp)
            self.cols = cols = 1
        elif tplkeys == len(data):
            self.cols = cols = len(data.keys()[0])
            assert len([
                False for i in data.keys() if len(i) != cols
            ]) == 0  #check that all keys have the same number of columns
        #
        self.data = data  #data dictionary. Keys are either strings or tuples.
        #
        if fits != None: self.fits = fits  #often will = None
        else: self.fits = {}
        ##Q2. Are there any labels given
        if labels != None:
            assert len(labels) == 3  #check that there are 3 items in labels
            if type(labels[2]) not in (type(()), type([])):
                assert cols == 1
            else:
                assert len(
                    labels[2]
                ) == cols  # check that the columnhdrs entry is the same length as the data dictionary key tuples.
        else:
            labels = ['', '', ['A', 'B', 'C', 'D', 'E', 'F', 'G'][:cols]]
        #
        if styles != None: self.styles = styles  #often will = None
        else: self.styles = {}
        #
        self.Plots1 = {}
        self.FPlots1 = {}  # Fit plots
        self.showlegend = False
        self.stop_refresh_hack = False

        #### Set up panels
        splitter = wx.SplitterWindow(self, -1)
        leftpanel = wx.Panel(splitter, -1)
        rightpanel = wx.Panel(splitter, -1)

        #### Set up Objects
        self.plotchooser = plotchooser(rightpanel,
                                       cols)  #setup Plotchooser widget
        self.plotchooser.refreshColumns(labels[2])  #update column headers
        self.plotchooser.refreshEntries(
            data.keys())  #update entries and clear checkboxes
        #
        self.selectall = wx.Button(rightpanel, -1, "Select All")
        self.Bind(wx.EVT_BUTTON, self.plotall, self.selectall)
        #
        self.fig = Figure()
        self.canvas = FigureCanvas(leftpanel, -1, self.fig)
        self.ax1 = self.fig.add_subplot(111)  #plot
        self.ax1.set_xlabel(labels[0])
        self.ax1.set_ylabel(labels[1])
        self.fig.subplots_adjust(left=0.1, bottom=0.07, right=0.95, top=0.95)
        self.toolbar = NavigationToolbar2WxAgg(self.canvas)
        self.bsavedata = wx.Button(leftpanel, -1, "Save Data")
        self.Bind(wx.EVT_BUTTON, self.savedata, self.bsavedata)
        self.legendch = wx.CheckBox(leftpanel, -1, "Show Legend")
        self.Bind(wx.EVT_CHECKBOX, self.evt_legendch, self.legendch)
        self.cursorPos = wx.StaticText(leftpanel,
                                       -1,
                                       "x=0.000000 \ny=0.000000  ",
                                       style=wx.ALIGN_LEFT)
        self.canvas.mpl_connect('motion_notify_event', self.UpdateStatusBar)
        #
        self.canvas.mpl_connect('key_press_event', self.press)
        #### Do layout
        vbox1 = wx.BoxSizer(wx.VERTICAL)
        vbox1.Add(self.canvas, 15, wx.EXPAND)
        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        hbox2.Add(self.toolbar, 1, wx.LEFT | wx.EXPAND)
        hbox2.Add(self.bsavedata, 0, wx.ALL, border=6)
        hbox2.Add(self.legendch, 0, wx.ALL, border=6)
        hbox2.Add(self.cursorPos,
                  0,
                  wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT,
                  border=6)
        vbox1.Add(hbox2, 1, wx.EXPAND)
        leftpanel.SetSizer(vbox1)
        vbox2 = wx.BoxSizer(wx.VERTICAL)
        vbox2.Add(self.plotchooser, 2, wx.EXPAND)
        vbox2.Add(self.selectall, 0, wx.ALL, border=6)
        rightpanel.SetSizer(vbox2)
        splitter.SplitVertically(leftpanel, rightpanel, -150)
        splitter.SetMinimumPaneSize(50)
        splitter.SetSashGravity(0.5)
        topsizer = wx.BoxSizer(wx.HORIZONTAL)
        topsizer.Add(splitter, 1, wx.EXPAND)
        self.SetSizer(topsizer)
        topsizer.Fit(self)

        #### final initialisation
        self.toolbar.update()
        #self.Centre()
        self.Show(True)