Beispiel #1
0
    def AddPV_row(self):
        i = self.npv_rows = self.npv_rows + 1

        panel = self.pvpanel
        sizer = self.pvsizer
        pvchoice = MyChoice(panel, choices=self.pvlist, size=(150, -1))
        pvchoice.SetSelection(0)
        logs = MyChoice(panel, size=(50, -1))
        logs.SetSelection(0)
        ymin = wx.TextCtrl(panel, -1, '', size=(75, -1))
        ymax = wx.TextCtrl(panel, -1, '', size=(75, -1))
        desc = wx.TextCtrl(panel, -1, '', size=(150, -1))
        side = MyChoice(panel,
                        choices=('left', 'right'),
                        action=self.onSide,
                        size=(80, -1))
        side.SetSelection((i - 1) % 2)

        if i > 2:
            logs.Disable()
            ymin.Disable()
            ymax.Disable()
            desc.Disable()
            side.Disable()

        colval = (0, 0, 0)
        if i < len(self.default_colors):
            colval = self.default_colors[i]
        colr = csel.ColourSelect(panel, -1, '', colval)
        self.colorsels.append(colr)

        sizer.Add(pvchoice, (i, 0), (1, 1), LSTY, 3)
        sizer.Add(colr, (i, 1), (1, 1), CSTY, 3)
        sizer.Add(logs, (i, 2), (1, 1), CSTY, 3)
        sizer.Add(ymin, (i, 3), (1, 1), CSTY, 3)
        sizer.Add(ymax, (i, 4), (1, 1), CSTY, 3)
        sizer.Add(desc, (i, 5), (1, 1), CSTY, 3)
        sizer.Add(side, (i, 6), (1, 1), CSTY, 3)

        pvchoice.Bind(wx.EVT_CHOICE, Closure(self.onPVchoice, row=i))
        colr.Bind(csel.EVT_COLOURSELECT, Closure(self.onPVcolor, row=i))
        logs.Bind(wx.EVT_CHOICE, self.onPVwid)
        ymin.Bind(wx.EVT_TEXT_ENTER, self.onPVwid)
        ymax.Bind(wx.EVT_TEXT_ENTER, self.onPVwid)

        self.pvchoices.append(pvchoice)
        self.pvlabels.append(desc)
        self.pvwids.append((logs, colr, ymin, ymax, desc, side))
Beispiel #2
0
    def group_panel(self,
                    parent,
                    label='Fine Stages',
                    precision=3,
                    collapseable=False,
                    add_buttons=None,
                    group='fine'):
        """make motor group panel """
        motors = self.motorgroups[group]

        is_xy = motors[1] is not None

        if collapseable:
            cpane = CP.PyCollapsiblePane(parent, agwStyle=wx.CP_GTK_EXPANDER)
            cpane.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED,
                       Closure(self.onCollapse, panel=cpane, label=label))
            cpane.Collapse(True)
            cpane.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD, False))
            cpane.SetLabel('Show %s' % label)
            panel = cpane.GetPane()
        else:
            panel = wx.Panel(parent)

        self.tweaks[group] = NumericCombo(panel,
                                          self.tweaklist[group],
                                          precision=precision,
                                          init=3)

        slabel = wx.BoxSizer(wx.HORIZONTAL)
        slabel.Add(wx.StaticText(panel, label=" %s: " % label, size=(150, -1)),
                   1, wx.EXPAND | LEFT_BOT)
        slabel.Add(self.tweaks[group], 0, ALL_EXP | LEFT_TOP)

        smotor = wx.BoxSizer(wx.VERTICAL)
        smotor.Add(slabel, 0, ALL_EXP)

        for mnam in motors:
            if mnam is None: continue
            self.motorwids[mnam] = MotorPanel(panel, label=mnam, psize='small')
            self.motorwids[mnam].desc.SetLabel(mnam)
            smotor.Add(self.motorwids[mnam], 0, ALL_EXP | LEFT_TOP)

        if add_buttons is not None:
            for label, action in add_buttons:
                smotor.Add(add_button(panel, label, action=action))

        btnbox = self.make_button_panel(panel, full=is_xy, group=group)
        btnbox_style = CEN_BOT
        if is_xy:
            btnbox_style = CEN_TOP

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(smotor, 0, ALL_EXP | LEFT_TOP)
        sizer.Add(btnbox, 0, btnbox_style, 1)

        pack(panel, sizer)
        if collapseable:
            return cpane
        return panel
Beispiel #3
0
    def onSave(self, name):
        if len(name) < 1:
            return

        if name in self.positions and self.viewer.v_replace:
            ret = popup(self, "Overwrite Position %s?" % name,
                        "Veriry Overwrite Position",
                        style=wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION)
            if ret != wx.ID_YES:
                return

        imgfile = '%s.jpg' % time.strftime('%b%d_%H%M%S')
        imgfile = os.path.join(self.viewer.imgdir, imgfile)
        tmp_pos = self.viewer.ctrlpanel.read_position()
        imgdata, count = None, 0
        if not os.path.exists(self.viewer.imgdir):
            os.makedirs(self.viewer.imgdir)
        while imgdata is None and count <100:
            imgdata = self.viewer.save_image(imgfile)
            if imgdata is None:
                time.sleep(0.5)
            count = count + 1

        imgdata['source'] = 'SampleStage'
        imgdata['data_format'] = 'file'
        imgdata.pop('data')
        notes = json.dumps(imgdata)
        fullpath = os.path.join(os.getcwd(), imgfile)

        self.positions[name] = {'image': fullpath,
                                'timestamp': time.strftime('%b %d %H:%M:%S'),
                                'position': tmp_pos,
                                'notes':  notes}

        if name not in self.pos_list.GetItems():
            self.pos_list.Append(name)

        self.instdb.save_position(self.instname, name, tmp_pos,
                                  notes=notes, image=fullpath)

        self.pos_list.SetStringSelection(name)
        # auto-save file
        self.viewer.autosave(positions=self.positions)

        self.viewer.write_htmllog(name, self.positions[name])

        imgfile_exists = False
        t0 = time.time()
        if not imgfile_exists and time.time()-t0 < 10:
            imgfile_exists = os.path.exists(fullpath)
            time.sleep(0.5)
        if imgfile_exists:
            self.viewer.write_message("Saved Position '%s', image in %s" %
                                      (name, imgfile))
        else:
            self.viewer.write_message("COULD NOT SAVE IMAGE FILE!!")

        wx.CallAfter(Closure(self.onSelect, event=None, name=name))
Beispiel #4
0
 def _btn(name):
     img = images[name].GetImage()
     btn = wx.BitmapButton(panel,
                           -1,
                           wx.BitmapFromImage(img),
                           style=wx.NO_BORDER)
     btn.Bind(wx.EVT_BUTTON, Closure(self.onMove,
                                     group=group,
                                     name=name))
     return btn
Beispiel #5
0
    def onSavePosition(self, event=None):
        name = event.GetString().strip()

        if self.v_replace and name in self.config['positions']:
            ret = popup(self,
                        "Overwrite Position %s?" % name,
                        "Veriry Overwrite Position",
                        style=wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)

            if ret != wx.ID_YES:
                return
        imgfile = '%s.jpg' % time.strftime('%b%d_%H%M%S')
        fname = "%s/%s" % (self.imgdir, imgfile)
        self.waiting_for_imagefile = True
        self.save_image(fname=fname)

        tmp_pos = []
        for v in self.config['stages'].values():
            tmp_pos.append(float(self.motors[v['label']].VAL))

        self.positions[name] = {
            'image': imgfile,
            'timestamp': time.strftime('%b %d %H:%M:%S'),
            'position': tmp_pos
        }

        if name not in self.pos_list.GetItems():
            self.pos_list.Append(name)

        self.pos_name.Clear()
        self.pos_list.SetStringSelection(name)
        # auto-save file
        self.config['positions'] = self.positions
        self.autosave()
        self.write_htmllog(name)
        self.write_message("Saved Position '%s', image in %s" % (name, fname))
        wx.CallAfter(Closure(self.onSelectPosition, event=None, name=name))
    def __init__(self,
                 parent,
                 image_panel=None,
                 camera_id=0,
                 center_cb=None,
                 xhair_cb=None,
                 **kws):
        super(ConfPanel_Fly2, self).__init__(parent,
                                             center_cb=center_cb,
                                             xhair_cb=xhair_cb)
        self.image_panel = image_panel
        self.camera_id = camera_id
        self.camera = self.image_panel.camera

        wids = self.wids
        sizer = self.sizer

        self.title = self.txt("PyCapture2: ", size=285)
        self.title2 = self.txt(" ", size=285)

        sizer.Add(self.title, (0, 0), (1, 3), LEFT)
        sizer.Add(self.title2, (1, 0), (1, 3), LEFT)
        next_row = self.show_position_info(row=2)

        self.__initializing = True
        i = next_row + 1
        #('Sharpness', '%', 100), ('Hue', 'deg', 100), ('Saturation', '%', 100),
        for dat in (
            ('shutter', 'ms', 50, 0, 70),
            ('gain', 'dB', 0, -2, 24),
                # ('brightness', '%', 0,  0,  6),
            ('gamma', '', 1, 0.5, 4)):

            key, units, defval, minval, maxval = dat
            wids[key] = FloatCtrl(self,
                                  value=defval,
                                  minval=minval,
                                  maxval=maxval,
                                  precision=1,
                                  action=self.onValue,
                                  act_on_losefocus=True,
                                  action_kw={'prop': key},
                                  size=(75, -1))
            label = '%s' % (key.title())
            if len(units) > 0:
                label = '%s (%s)' % (key.title(), units)
            sizer.Add(self.txt(label), (i, 0), (1, 1), LEFT)
            sizer.Add(wids[key], (i, 1), (1, 1), LEFT)

            akey = '%s_auto' % key
            wids[akey] = wx.CheckBox(self, -1, label='auto')
            wids[akey].SetValue(0)
            wids[akey].Bind(wx.EVT_CHECKBOX, Closure(self.onAuto, prop=key))
            sizer.Add(wids[akey], (i, 2), (1, 1), LEFT)
            i = i + 1

        for color in ('blue', 'red'):
            key = 'wb_%s' % color
            wids[key] = FloatCtrl(self,
                                  value=0,
                                  maxval=1024,
                                  precision=0,
                                  action=self.onValue,
                                  act_on_losefocus=True,
                                  action_kw={'prop': key},
                                  size=(75, -1))
            label = 'White Balance (%s)' % (color)
            sizer.Add(self.txt(label), (i, 0), (1, 1), LEFT)
            sizer.Add(wids[key], (i, 1), (1, 1), LEFT)

            if color == 'blue':
                akey = 'wb_auto'
                wids[akey] = wx.CheckBox(self, -1, label='auto')
                wids[akey].SetValue(0)
                wids[akey].Bind(wx.EVT_CHECKBOX, Closure(self.onAuto,
                                                         prop=key))
                sizer.Add(wids[akey], (i, 2), (1, 1), LEFT)
            i += 1

        datapush_time = "%.1f" % self.image_panel.datapush_delay
        wids['dpush_time'] = FloatCtrl(self,
                                       value=datapush_time,
                                       maxval=1e6,
                                       precision=1,
                                       minval=0,
                                       action=self.onValue,
                                       act_on_losefocus=True,
                                       action_kw={'prop': 'autosave_time'},
                                       size=(75, -1))

        label = 'AutoSave Time (sec)'
        sizer.Add(self.txt(label), (i, 0), (1, 1), LEFT)
        sizer.Add(wids['dpush_time'], (i, 1), (1, 1), LEFT)

        # wids['datapush'].SetValue(1)
        # wids['datapush'].Bind(wx.EVT_CHECKBOX, self.onEnableDataPush)
        # sizer.Add(wids['datapush'], (i+1, 0), (1, 3), LEFT)

        pack(self, sizer)
        self.__initializing = False
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.onTimer, self.timer)
        wx.CallAfter(self.onConnect)
Beispiel #7
0
    def create_menus(self):
        "Create the menubar"
        mbar = wx.MenuBar()
        fmenu = wx.Menu()
        pmenu = wx.Menu()
        omenu = wx.Menu()
        add_menu(self,
                 fmenu,
                 label="&Read Config",
                 text="Read Configuration",
                 action=self.onReadConfig)

        add_menu(self,
                 fmenu,
                 label="&Save Config",
                 text="Save Configuration",
                 action=self.onSaveConfig)

        add_menu(self,
                 fmenu,
                 label="Show Projections\tCtrl+G",
                 text="Start Projection Plots",
                 action=self.onStartProjections)

        add_menu(self,
                 fmenu,
                 label="Print Blurriness\tCtrl+B",
                 text="print blurriness",
                 action=self.onReportBlurry)

        add_menu(self,
                 fmenu,
                 label="Stop Projection\tCtrl+C",
                 text="Stop Projection Plots",
                 action=self.onStopProjections)

        add_menu(self,
                 fmenu,
                 label="Select &Working Directory\tCtrl+W",
                 text="change Working Folder",
                 action=self.onChangeWorkdir)

        if self.cam_type.startswith('area'):
            add_menu(self,
                     fmenu,
                     label="Change AreaDetector",
                     text="Change Camera to different AreaDetector",
                     action=self.onChangeCamera)

        fmenu.AppendSeparator()
        add_menu(self,
                 fmenu,
                 label="E&xit\tCtrl+x",
                 text="Quit Program",
                 action=self.onClose)

        add_menu(self,
                 pmenu,
                 label="Export Positions",
                 text="Export Positions",
                 action=self.onExportPositions)
        add_menu(self,
                 pmenu,
                 label="Import Positions",
                 text="Import Positions",
                 action=self.onImportPositions)
        add_menu(self,
                 pmenu,
                 label="Erase Many Positions\tCtrl+E",
                 text="Select Multiple Positions to Erase",
                 action=self.onEraseMany)

        add_menu(self,
                 omenu,
                 label="Image Overlays",
                 text="Setup Image Overlays",
                 action=self.onConfigOverlays)

        vmove = wx.NewId()
        verase = wx.NewId()
        vreplace = wx.NewId()
        cenfine = wx.NewId()
        self.menu_opts = {
            vmove: 'v_move',
            verase: 'v_erase',
            vreplace: 'v_replace',
            cenfine: 'center_with_fine_stages'
        }

        mitem = omenu.Append(vmove, "Verify Go To ",
                             "Prompt to Verify Moving with 'Go To'",
                             wx.ITEM_CHECK)
        mitem.Check()
        self.Bind(wx.EVT_MENU, self.onMenuOption, mitem)

        mitem = omenu.Append(verase, "Verify Erase",
                             "Prompt to Verify Erasing Positions",
                             wx.ITEM_CHECK)
        mitem.Check()
        self.Bind(wx.EVT_MENU, self.onMenuOption, mitem)

        mitem = omenu.Append(vreplace, "Verify Overwrite",
                             "Prompt to Verify Overwriting Positions",
                             wx.ITEM_CHECK)
        mitem.Check()
        self.Bind(wx.EVT_MENU, self.onMenuOption, mitem)

        mitem = omenu.Append(cenfine, "Center With Fine Stages",
                             "Bring to Center will move the Fine Stages",
                             wx.ITEM_CHECK)
        mitem.Check(0)
        self.Bind(wx.EVT_MENU, self.onMenuOption, mitem)

        omenu.AppendSeparator()

        # print( 'Create Menus ',      self.ctrlpanel.subpanels)
        # for key, val in self.config['stages'].items():
        #     print( key, val)

        for name, panel in self.ctrlpanel.subpanels.items():
            show = 0
            label = 'Enable %s' % name
            mid = wx.NewId()
            self.menu_opts[mid] = label
            for mname, data in self.config['stages'].items():
                if data['group'] == name:
                    show = show + data['show']
            mitem = omenu.Append(mid, label, label, wx.ITEM_CHECK)
            if show > 0:
                mitem.Check()
            self.Bind(wx.EVT_MENU,
                      Closure(self.onShowHide, name=name, panel=panel), mitem)

        mbar.Append(fmenu, '&File')
        mbar.Append(omenu, '&Options')
        mbar.Append(pmenu, 'Positions')

        if len(self.config['scandb'].get('offline', '')):
            cmenu = wx.Menu()
            # add_menu(self, cmenu, label="Calibrate Microscope",
            #          text="Calibrate to Offline Microscope",
            #          action = self.pospanel.onMicroscopeCalibrate)
            add_menu(self,
                     cmenu,
                     label="Copy Positions from Offline Microscope",
                     text="Copy Positions from Offline Microscope",
                     action=self.pospanel.onMicroscopeTransfer)

            mbar.Append(cmenu, 'Offline Microscope')

        self.SetMenuBar(mbar)
Beispiel #8
0
    def __init__(self,
                 parent,
                 image_panel=None,
                 camera_id=0,
                 center_cb=None,
                 xhair_cb=None,
                 **kws):
        super(ConfPanel_PySpin, self).__init__(parent,
                                               center_cb=center_cb,
                                               xhair_cb=xhair_cb,
                                               **kws)
        self.image_panel = image_panel
        self.camera_id = camera_id
        self.camera = self.image_panel.camera
        wids = self.wids
        sizer = self.sizer
        with_color_conv = False

        self.title = self.txt("PySpinnaker: ", size=285)
        self.title2 = self.txt(" ", size=285)
        self.title3 = self.txt(" ", size=285)
        btn_start = add_button(self,
                               "Restart Camera",
                               action=self.onRestart,
                               size=(250, -1))
        next_row = self.show_position_info(row=0)

        sizer.Add(self.title, (next_row, 0), (1, 3), LEFT)
        sizer.Add(self.title2, (next_row + 1, 0), (1, 3), LEFT)
        sizer.Add(self.title3, (next_row + 2, 0), (1, 3), LEFT)
        self.__initializing = True
        i = next_row + 3

        for dat in (('exposure', 'ms', 50, 0.03, MAX_EXPOSURE_TIME),
                    ('gain', 'dB', 5, 0, 40)):
            # ('gamma', '',       1, 0.5, 4)):

            key, units, defval, minval, maxval = dat
            wids[key] = FloatCtrl(self,
                                  value=defval,
                                  minval=minval,
                                  maxval=maxval,
                                  precision=2,
                                  action=self.onValue,
                                  act_on_losefocus=True,
                                  action_kw={'prop': key},
                                  size=(75, -1))
            label = '%s' % (key.title())
            if len(units) > 0:
                label = '%s (%s)' % (key.title(), units)
            sizer.Add(self.txt(label), (i, 0), (1, 1), LEFT)
            sizer.Add(wids[key], (i, 1), (1, 1), LEFT)

            if key != 'gamma':
                akey = '%s_auto' % key
                wids[akey] = wx.CheckBox(self, -1, label='auto')
                wids[akey].SetValue(0)
                wids[akey].Bind(wx.EVT_CHECKBOX, Closure(self.onAuto,
                                                         prop=key))
                sizer.Add(wids[akey], (i, 2), (1, 1), LEFT)
            i = i + 1

        for color in ('blue', 'red'):
            key = 'wb_%s' % color
            wids[key] = FloatCtrl(self,
                                  value=0,
                                  minval=0.3,
                                  maxval=4,
                                  precision=3,
                                  action=self.onValue,
                                  act_on_losefocus=True,
                                  action_kw={'prop': key},
                                  size=(75, -1))
            wids[key].Disable()
            label = 'White Balance (%s)' % (color)
            sizer.Add(self.txt(label), (i, 0), (1, 1), LEFT)
            sizer.Add(wids[key], (i, 1), (1, 1), LEFT)
            if color == 'blue':
                akey = 'wb_auto'
                wids[akey] = wx.CheckBox(self, -1, label='auto')
                wids[akey].SetValue(0)
                wids[akey].Bind(wx.EVT_CHECKBOX, Closure(self.onAuto,
                                                         prop=key))
                sizer.Add(wids[akey], (i, 2), (1, 1), LEFT)
            i += 1

        datapush_time = "%.1f" % self.image_panel.datapush_delay
        wids['dpush_time'] = FloatCtrl(self,
                                       value=datapush_time,
                                       maxval=1e6,
                                       precision=1,
                                       minval=0,
                                       action=self.onValue,
                                       act_on_losefocus=True,
                                       action_kw={'prop': 'autosave_time'},
                                       size=(75, -1))

        label = 'AutoSave Time (sec)'
        sizer.Add(self.txt(label), (i, 0), (1, 1), LEFT)
        sizer.Add(wids['dpush_time'], (i, 1), (1, 1), LEFT)
        i = i + 1
        sizer.Add(btn_start, (i, 0), (1, 2), LEFT)

        if with_color_conv:
            conv_choices = ('DEFAULT', 'NO_COLOR_PROCESSING',
                            'NEAREST_NEIGHBOR', 'EDGE_SENSING', 'HQ_LINEAR',
                            'RIGOROUS', 'IPP', 'DIRECTIONAL_FILTER',
                            'WEIGHTED_DIRECTIONAL_FILTER')
            wids['color_conv'] = wx.Choice(self,
                                           -1,
                                           choices=conv_choices,
                                           size=(150, -1))
            wids['color_conv'].Bind(wx.EVT_CHOICE, self.onColorConv)
            i += 1
            sizer.Add(self.txt('Conversion: '), (i, 0), (1, 1), LEFT)
            sizer.Add(wids['color_conv'], (i, 1), (1, 1), LEFT)

        # wids['datapush'].SetValue(1)
        # wids['datapush'].Bind(wx.EVT_CHECKBOX, self.onEnableDataPush)
        # sizer.Add(wids['datapush'], (i+1, 0), (1, 3), LEFT)

        pack(self, sizer)
        self.__initializing = False
        self.read_props_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.onTimer, self.read_props_timer)
        wx.CallAfter(self.onConnect)
Beispiel #9
0
 def arrow(self, panel, group, name):
     "bitmap button"
     bitmap = Bitmap(icons[name].GetImage())
     b = wx.BitmapButton(panel, -1, bitmap, style=wx.NO_BORDER)
     b.Bind(wx.EVT_BUTTON, Closure(self.onMove, group=group, name=name))
     return b