def _init_ctrls(self, prnt):

        wx.Panel.__init__(self, parent=prnt)

        vsizer=wx.BoxSizer(wx.VERTICAL)

        ucGain = wx.StaticBoxSizer(wx.StaticBox(self, -1, u'Gain (%)'), wx.VERTICAL)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.l = wx.StaticText(self, -1, '%3.1f'%(100.0*self.cam.GetGain()/100)+'%') #ideally this should be self.cam.GetGain()/self.cam.MaxGain, where MaxGain is set to 100 for the specific camera.
        hsizer.Add(self.l, 0, wx.ALL, 2)
        self.sl = wx.Slider(self, -1, 100.0*self.cam.GetGain()/100, 0, 100, size=wx.Size(150,-1),style=wx.SL_HORIZONTAL | wx.SL_HORIZONTAL | wx.SL_AUTOTICKS )
        self.sl.SetTickFreq(10,1)
        wx.EVT_SCROLL(self,self.onSlide)
        hsizer.Add(self.sl, 1, wx.ALL|wx.EXPAND, 2)
        ucGain.Add(hsizer, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL, 0)

        self.stGainFactor = wx.StaticText(self, -1, 'Gain Factor = %3.2f' % self.cam.GetGainFactor())
        ucGain.Add(self.stGainFactor, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL, 0)

        self.stepc = wx.StaticText(self, -1, 'Electrons/Count = %3.2f' % (7.97/self.cam.GetGainFactor()))
        ucGain.Add(self.stepc, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL, 0)


        vsizer.Add(ucGain, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL, 0)

        self.SetSizer(vsizer)
Exemple #2
0
    def SetupSlider(self):
        self.widget = wx.Slider(self,
                                wx.NewId(),
                                int(self.obj_dict['value'] *
                                    self.obj_dict['divisor']),
                                int(self.obj_dict['min']),
                                int(self.obj_dict['max']),
                                style=self.obj_dict['style'],
                                size=self.button_size)

        self.sbsizer.Add(self.widget)

        sliderID = wx.NewId()
        div = self.obj_dict['divisor']
        if div == 1.: label_str = "%.0f" % (self.obj_dict['value'])
        if div == 10.: label_str = "%.1f" % (self.obj_dict['value'])
        if div == 100.: label_str = "%.2f" % (self.obj_dict['value'])
        if div == 1000.: label_str = "%.3f" % (self.obj_dict['value'])
        if div == 10000.: label_str = "%.4f" % (self.obj_dict['value'])

        self.label = wx.StaticText(self,
                                   sliderID,
                                   label_str,
                                   size=self.button_size)
        self.sbsizer.Add(self.label)

        #wx.EVT_BUTTON(self.defaultB,self.defaultBID,self.defaultCB)
        wx.EVT_SCROLL(self.widget, self.SliderCB)
Exemple #3
0
    def __init__(self, parent, start=None, end=None):
        self._start = start or datetime.datetime.combine(
            datetime.datetime.now().date(), datetime.time(0, 0, 0))
        self._end = end or self._start + datetime.timedelta(days=7)
        super(CalendarCanvas, self).__init__(parent,
                                             wx.ID_ANY,
                                             style=wx.FULL_REPAINT_ON_RESIZE)

        self._coords = dict(
        )  # Event => (startIdx, endIdx, startIdxRecursive, endIdxRecursive, yMin, yMax)
        self._maxIndex = 0
        self._minSize = (0, 0)

        # Drawing attributes
        self._precision = 1  # Minutes
        self._gridSize = 15  # Minutes
        self._eventHeight = 32.0
        self._eventWidthMin = 0.1
        self._eventWidth = 0.1
        self._margin = 5.0
        self._marginTop = 22.0
        self._outlineColorDark = wx.Colour(180, 180, 180)
        self._outlineColorLight = wx.Colour(210, 210, 210)
        self._headerSpans = []
        self._daySpans = []
        self._selection = set()
        self._mouseState = self.MS_IDLE
        self._mouseOrigin = None
        self._mouseDragPos = None
        self._todayColor = wx.Colour(0, 0, 128)

        self._hScroll = wx.ScrollBar(self, wx.ID_ANY, style=wx.SB_HORIZONTAL)
        self._vScroll = wx.ScrollBar(self, wx.ID_ANY, style=wx.SB_VERTICAL)

        self._hScroll.Hide()
        self._vScroll.Hide()

        wx.EVT_SCROLL(self._hScroll, self._OnScroll)
        wx.EVT_SCROLL(self._vScroll, self._OnScroll)

        wx.EVT_PAINT(self, self._OnPaint)
        wx.EVT_SIZE(self, self._OnResize)
        wx.EVT_LEFT_DOWN(self, self._OnLeftDown)
        wx.EVT_LEFT_UP(self, self._OnLeftUp)
        wx.EVT_RIGHT_DOWN(self, self._OnRightDown)
        wx.EVT_MOTION(self, self._OnMotion)
        self._Invalidate()
    def __init__(self, piezos, parent, joystick=None, id=-1):
        # begin wxGlade: MyFrame1.__init__
        #kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Panel.__init__(self, parent, id)

        self.piezos = piezos
        self.joystick = joystick
        #self.panel_1 = wx.Panel(self, -1)
        self.sliders = []
        self.sliderLabels = []
        #self.SetTitle("Piezo Control")
        #sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_2 = wx.BoxSizer(wx.VERTICAL)

        for p in self.piezos:
            #if sys.platform == 'darwin': #sliders are subtly broken on MacOS, requiring workaround
            sl = wx.Slider(
                self,
                -1,
                100 * p[0].GetPos(p[1]),
                100 * p[0].GetMin(p[1]),
                100 * p[0].GetMax(p[1]),
                size=wx.Size(100, -1),
                style=wx.SL_HORIZONTAL)  #|wx.SL_AUTOTICKS|wx.SL_LABELS)
            #else:
            #    sl = wx.Slider(self.panel_1, -1, 100*p[0].GetPos(p[1]), 100*p[0].GetMin(p[1]), 100*p[0].GetMax(p[1]), size=wx.Size(300,-1), style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS)
            #sl.SetSize((800,20))
            if 'units' in dir(p[0]):
                unit = p[0].units
            else:
                unit = u'\u03BCm'
            sLab = wx.StaticBox(
                self, -1, u'%s - %2.4f %s' % (p[2], p[0].GetPos(p[1]), unit))

            #            if 'minorTick' in dir(p):
            #                sl.SetTickFreq(100, p.minorTick)
            #            else:
            #                sl.SetTickFreq(100, 1)
            sz = wx.StaticBoxSizer(sLab, wx.HORIZONTAL)
            sz.Add(sl, 1, wx.ALL | wx.EXPAND, 2)
            #sz.Add(sLab, 0, wx.ALL|wx.EXPAND, 2)
            sizer_2.Add(sz, 1, wx.EXPAND, 0)

            self.sliders.append(sl)
            self.sliderLabels.append(sLab)

        if not joystick is None:
            self.cbJoystick = wx.CheckBox(self, -1, 'Enable Joystick')
            sizer_2.Add(self.cbJoystick, 0, wx.TOP | wx.BOTTOM, 2)
            self.cbJoystick.Bind(wx.EVT_CHECKBOX, self.OnJoystickEnable)

        #sizer_2.AddSpacer(1)

        wx.EVT_SCROLL(self, self.onSlide)

        #self.SetAutoLayout(1)
        self.SetSizer(sizer_2)
        sizer_2.Fit(self)
Exemple #5
0
    def SetupScrollBars(self):
        # hook the scrollbars provided by the wxDynamicSashWindow
        # to this view
        v_bar = self.dyn_sash.GetVScrollBar(self)
        h_bar = self.dyn_sash.GetHScrollBar(self)
        wx.EVT_SCROLL(v_bar,self.OnSBScroll)
        wx.EVT_SCROLL(h_bar,self.OnSBScroll)
        wx.EVT_SET_FOCUS(v_bar, self.OnSBFocus)
        wx.EVT_SET_FOCUS(h_bar, self.OnSBFocus)
##        eventManager.Register(self.OnSBScroll, wx.EVT_SCROLL, v_bar)
##        eventManager.Register(self.OnSBScroll, wx.EVT_SCROLL, h_bar)
##        eventManager.Register(self.OnSBFocus,  wx.EVT_SET_FOCUS, v_bar)
##        eventManager.Register(self.OnSBFocus,  wx.EVT_SET_FOCUS, h_bar)

        # And set the wxStyledText to use these scrollbars instead
        # of its built-in ones.
        self.SetVScrollBar(v_bar)
        self.SetHScrollBar(h_bar)
Exemple #6
0
 def __init__(self, *args, **kwds):
     wx.Slider.__init__(self, *args, **kwds)
     
     self.old_value = self.GetValue()
     self.slider_held = False
     
     wx.EVT_SCROLL(self, self.__on_generic_event)
     wx.EVT_SCROLL_THUMBTRACK(self, self.__on_track_thumb)
     wx.EVT_SCROLL_THUMBRELEASE(self, self.__on_release_thumb)
Exemple #7
0
 def _create_control(self, window, wxpos, wxthumbsize, wxrange):
     if self.orientation == 'horizontal':
         wxstyle = wx.HORIZONTAL
     else:
         wxstyle = wx.VERTICAL
     self._control = wx.ScrollBar(window.control, style=wxstyle)
     self._control.SetScrollbar(wxpos, wxthumbsize, wxrange, wxthumbsize, True)
     wx.EVT_SCROLL(self._control, self._wx_scroll_handler)
     wx.EVT_SET_FOCUS(self._control, self._yield_focus)
     wx.EVT_SCROLL_THUMBTRACK(self._control, self._thumbtrack)
     wx.EVT_SCROLL_THUMBRELEASE(self._control, self._thumbreleased)
     wx.EVT_SIZE(self._control, self._control_resized)
Exemple #8
0
    def __init__(self, parent, lasers, winid=-1):
        # begin wxGlade: MyFrame1.__init__
        #kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Panel.__init__(self, parent, winid)

        #self.cam = cam
        self.lasers = [l for l in lasers if l.IsPowerControlable()]
        self.laserNames = [l.GetName() for l in self.lasers]

        self.sliders = []
        self.labels = []
        self.sliding = False
        #self.SetTitle("Piezo Control")

        sizer_2 = wx.BoxSizer(wx.VERTICAL)

        for c in range(len(self.lasers)):
            sz = wx.BoxSizer(wx.HORIZONTAL)
            l = wx.StaticText(self, -1, self.laserNames[c])
            self.labels.append(l)
            sz.Add(l, 0, wx.ALL, 2)
            #if sys.platform == 'darwin': #sliders are subtly broken on MacOS, requiring workaround
            #sl = wx.Slider(self, -1, self.lasers[c].GetPower(), 0, 10, size=wx.Size(150,-1),style=wx.SL_HORIZONTAL)#|wx.SL_AUTOTICKS|wx.SL_LABELS)
            sl = wx.Slider(
                self,
                -1,
                self.lasers[c].GetPower(),
                0,
                100,
                size=wx.Size(150, -1),
                style=wx.SL_HORIZONTAL)  #|wx.SL_AUTOTICKS|wx.SL_LABELS)
            #else: #sane OS's
            #    sl = wx.Slider(self, -1, self.cam.laserPowers[c], 0, 1000, size=wx.Size(300,-1),style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS)

            #sl.SetSize((800,20))
            if wx.version() < '4':
                #FIXME for wx >=4
                sl.SetTickFreq(10, 1)
            #sz = wx.StaticBoxSizer(wx.StaticBox(self, -1, self.laserNames[c] + " [mW]"), wx.HORIZONTAL)

            sz.Add(sl, 1, wx.ALL | wx.EXPAND, 2)
            sizer_2.Add(sz, 1, wx.EXPAND, 0)

            self.sliders.append(sl)

        #sizer_2.AddSpacer(5)

        wx.EVT_SCROLL(self, self.onSlide)

        #self.SetAutoLayout(1)
        self.SetSizer(sizer_2)
        sizer_2.Fit(self)
Exemple #9
0
    def SetupControls(self, vbsouter):
        vbsouter.Clear(True)
        hbs = wx.BoxSizer(wx.HORIZONTAL)
        self.cropselect = ImageCropSelect(self, self.image)

        self.vbs = wx.BoxSizer(wx.VERTICAL)
        self.colourselect = wx.lib.colourselect.ColourSelect(
            self, wx.NewId(), "Background Color ...", (255, 255, 255))
        self.vbs.Add(self.colourselect, 0, wx.ALL | wx.EXPAND, 5)
        wx.lib.colourselect.EVT_COLOURSELECT(self, self.colourselect.GetId(),
                                             self.OnBackgroundColour)
        self.vbs.Add(wx.StaticText(self, -1, "Target"), 0, wx.ALL, 5)
        self.targetbox = wx.ListBox(self, -1, size=(-1, 100))
        self.vbs.Add(self.targetbox, 0, wx.EXPAND | wx.ALL, 5)
        self.vbs.Add(wx.StaticText(self, -1, "Scale"), 0, wx.ALL, 5)

        for one, (s, _) in enumerate(self.SCALES):
            if s == 1: break
        self.slider = wx.Slider(self,
                                -1,
                                one,
                                0,
                                len(self.SCALES) - 1,
                                style=wx.HORIZONTAL | wx.SL_AUTOTICKS)
        self.vbs.Add(self.slider, 0, wx.ALL | wx.EXPAND, 5)
        self.zoomlabel = wx.StaticText(self, -1, self.SCALES[one][1])
        self.vbs.Add(self.zoomlabel, 0, wx.ALL | wx.ALIGN_CENTRE_HORIZONTAL, 5)

        self.vbs.Add(wx.StaticText(self, -1, "Preview"), 0, wx.ALL, 5)
        self.imagepreview = ImagePreview(self)
        self.cropselect.SetPreviewWindow(self.imagepreview)
        self.vbs.Add(self.imagepreview, 0, wx.ALL, 5)

        hbs.Add(self.vbs, 0, wx.ALL, 5)
        hbs.Add(self.cropselect, 1, wx.ALL | wx.EXPAND, 5)

        vbsouter.Add(hbs, 1, wx.EXPAND | wx.ALL, 5)

        vbsouter.Add(wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL), 0,
                     wx.EXPAND | wx.ALL, 5)
        vbsouter.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.HELP), 0,
                     wx.ALIGN_CENTRE | wx.ALL, 5)

        wx.EVT_SCROLL(self, self.SetZoom)
        wx.EVT_LISTBOX(self, self.targetbox.GetId(), self.OnTargetSelect)
        wx.EVT_LISTBOX_DCLICK(self, self.targetbox.GetId(),
                              self.OnTargetSelect)

        self.OnOriginSelect()
def color_editor_for(editor, parent, update_handler=None):
    """ Creates a custom color editor panel for a specified editor.
    """
    # Create a panel to hold all of the buttons:
    panel = wx.Panel(parent, -1)
    sizer = wx.BoxSizer(wx.HORIZONTAL)
    panel._swatch_editor = swatch_editor = editor.factory.simple_editor(
        editor.ui, editor.object, editor.name, editor.description, panel)
    swatch_editor.prepare(panel)
    control = swatch_editor.control
    control.is_custom = True
    control.update_handler = update_handler
    control.SetSize(wx.Size(110, 72))
    sizer.Add(control, 1, wx.EXPAND | wx.RIGHT, 4)

    # Add all of the color choice buttons:
    sizer2 = wx.GridSizer(0, 12, 0, 0)

    for i in range(len(color_samples)):
        control = wx.Button(panel, -1, '', size=wx.Size(18, 18))
        control.SetBackgroundColour(color_samples[i])
        control.update_handler = update_handler
        wx.EVT_BUTTON(panel, control.GetId(),
                      swatch_editor.update_object_from_swatch)
        sizer2.Add(control)
        editor.set_tooltip(control)

    sizer.Add(sizer2)

    alpha = editor.factory.get_color(editor)[3]
    swatch_editor._slider = slider = wx.Slider(panel,
                                               -1,
                                               100 - int(alpha * 100.0),
                                               0,
                                               100,
                                               size=wx.Size(20, 40),
                                               style=wx.SL_VERTICAL
                                               | wx.SL_AUTOTICKS)
    slider.SetTickFreq(10, 1)
    slider.SetPageSize(10)
    slider.SetLineSize(1)
    wx.EVT_SCROLL(slider, swatch_editor.update_object_from_scroll)
    sizer.Add(slider, 0, wx.EXPAND | wx.LEFT, 6)

    # Set-up the layout:
    panel.SetSizerAndFit(sizer)

    # Return the panel as the result:
    return panel
Exemple #11
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory
        if not factory.low_name:
            self.low = factory.low

        if not factory.high_name:
            self.high = factory.high

        self.format = factory.format

        self.evaluate = factory.evaluate
        self.sync_value(factory.evaluate_name, 'evaluate', 'from')

        size = wx.DefaultSize
        if factory.label_width > 0:
            size = wx.Size(factory.label_width, 20)

        self.sync_value(factory.low_name, 'low', 'from')
        self.sync_value(factory.high_name, 'high', 'from')
        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        fvalue = self.value

        if not (self.low <= fvalue <= self.high):
            fvalue_text = ''
            fvalue = self.low
        else:
            try:
                fvalue_text = self.format % fvalue
            except (ValueError, TypeError) as e:
                fvalue_text = ''

        ivalue = self._convert_to_slider(fvalue)

        self._label_lo = wx.StaticText(panel,
                                       -1,
                                       '999999',
                                       size=size,
                                       style=wx.ALIGN_RIGHT
                                       | wx.ST_NO_AUTORESIZE)
        sizer.Add(self._label_lo, 0, wx.ALIGN_CENTER)
        panel.slider = slider = Slider(panel,
                                       -1,
                                       ivalue,
                                       0,
                                       10000,
                                       size=wx.Size(80, 20),
                                       style=wx.SL_HORIZONTAL
                                       | wx.SL_AUTOTICKS)
        slider.SetTickFreq(1000)
        slider.SetValue(1)
        slider.SetPageSize(1000)
        slider.SetLineSize(100)
        wx.EVT_SCROLL(slider, self.update_object_on_scroll)
        sizer.Add(slider, 1, wx.EXPAND)
        self._label_hi = wx.StaticText(panel, -1, '999999', size=size)
        sizer.Add(self._label_hi, 0, wx.ALIGN_CENTER)

        panel.text = text = wx.TextCtrl(panel,
                                        -1,
                                        fvalue_text,
                                        size=wx.Size(56, 20),
                                        style=wx.TE_PROCESS_ENTER)
        wx.EVT_TEXT_ENTER(panel, text.GetId(), self.update_object_on_enter)
        wx.EVT_KILL_FOCUS(text, self.update_object_on_enter)

        sizer.Add(text, 0, wx.LEFT | wx.EXPAND, 4)

        low_label = factory.low_label
        if factory.low_name != '':
            low_label = self.format % self.low

        high_label = factory.high_label
        if factory.high_name != '':
            high_label = self.format % self.high

        self._label_lo.SetLabel(low_label)
        self._label_hi.SetLabel(high_label)
        self.set_tooltip(slider)
        self.set_tooltip(self._label_lo)
        self.set_tooltip(self._label_hi)
        self.set_tooltip(text)

        # Set-up the layout:
        panel.SetSizerAndFit(sizer)
Exemple #12
0
    def __init__(self, parent, key, val, global_config, env):
        if DEBUG: print key, val
        self.parent = parent
        self.env = env
        self.key = key
        self.val = val
        self.global_config = global_config
        self.env = env

        WIDGET_W = global_config['CONFIG_WIDGET_W']['value']
        WIDGET_H = global_config['CONFIG_WIDGET_H']['value']
        self.wsize = wx.Size(WIDGET_W, WIDGET_H)

        self.sbox = wx.StaticBox(self.parent, -1, key, style=wx.BORDER_STATIC)
        self.sbox.SetWindowStyle(wx.BORDER_NONE)

        self.sizer = wx.StaticBoxSizer(self.sbox, wx.HORIZONTAL)
        self.widget = None
        self.label = None
        self.defaultB = None
        self.showColourDialogB = None
        self.defaultBID = wx.NewId()
        self.set = 0
        self.bmp = None

        #every CfgCtrlObj has a defaultB:
        self.defaultB = wx.Button(self.parent,
                                  self.defaultBID,
                                  "Default",
                                  size=self.wsize)

        if self.val['wtype'] == 'wx.ComboBox':
            cbID = wx.NewId()
            cb = wx.ComboBox(self.parent, cbID, size=self.wsize, choices=[])
            for idx in range(len(self.val['default'])):
                cb.Append(self.val['default'][idx])
            cb.SetValue(self.val['value'])
            self.widget = cb

            #self.widget.SetValue(self.val['value'])
            self.sizer.Add(self.widget)
            wx.EVT_COMBOBOX(self.parent, cbID, self.comboCB)

            if self.val['icon']:
                #in this version, if icon, then actor.
                fname = os.path.abspath(
                    os.path.join(self.env.sitepkgdir, global_config['APPNAME'],
                                 'Actors', self.val['value'], 'icon.gif'))
                gif = wx.Image(fname, wx.BITMAP_TYPE_GIF).ConvertToBitmap()
                self.bmp = wx.StaticBitmap(
                    self.parent, -1, gif)  #,size=wx.Size(WIDGET_W,WIDGET_W)
                self.sizer.Add(self.bmp)
            else:
                self.label = wx.StaticText(self.parent,
                                           wx.NewId(),
                                           '',
                                           size=self.wsize)
                self.sizer.Add(self.label)

            wx.EVT_BUTTON(self.defaultB, self.defaultBID, self.defaultCB)

        elif self.val['wtype'] == 'wx.TextCtrl':
            self.widget = wx.TextCtrl(self.parent,
                                      wx.NewId(),
                                      style=self.val['style'],
                                      size=self.wsize)
            self.widget.SetValue(self.val['value'])
            self.widget.SetLabel(self.val['descr'])
            self.sizer.Add(self.widget)

            label_str = ''
            self.label = wx.StaticText(self.parent,
                                       wx.NewId(),
                                       label_str,
                                       size=self.wsize)
            self.sizer.Add(self.label)

            wx.EVT_BUTTON(self.defaultB, self.defaultBID, self.defaultCB)

        elif self.val['wtype'] == 'wx.ImageDialog':
            ImgBrowserID = wx.NewId()
            self.widget = ib.ImageDialog(
                self.parent,
                self.val['path'],
            )

            ibID = wx.NewId()
            self.ibB = wx.Button(self.parent,
                                 ibID,
                                 "ImageDialog",
                                 size=self.wsize)
            self.sizer.Add(self.ibB)
            wx.EVT_BUTTON(self.ibB, ibID, self.imagedialogCB)

            label_str = ''
            self.label = wx.StaticText(self.parent,
                                       wx.NewId(),
                                       label_str,
                                       size=self.wsize)
            self.label.SetLabel(self.val['value'])
            self.sizer.Add(self.label)

            wx.EVT_BUTTON(self.defaultB, self.defaultBID, self.defaultCB)

        elif self.val['wtype'] == 'wx.FileDialog':

            FileDialogID = wx.NewId()
            self.widget = wx.FileDialog(
                self.parent,
                message="Choose file",
                defaultDir=self.val['path'],
            )

            fdID = wx.NewId()
            self.fdB = wx.Button(self.parent,
                                 fdID,
                                 "ShowDialog",
                                 size=self.wsize)
            self.sizer.Add(self.fdB)
            wx.EVT_BUTTON(self.fdB, fdID, self.filedialogCB)

            label_str = ''
            self.label = wx.StaticText(self.parent,
                                       wx.NewId(),
                                       label_str,
                                       size=self.wsize)
            self.label.SetLabel(self.val['value'])
            self.sizer.Add(self.label)

            wx.EVT_BUTTON(self.defaultB, self.defaultBID, self.defaultCB)

        elif self.val['wtype'] == 'wx.CheckBox':
            CheckBoxID = wx.NewId()
            self.widget = wx.CheckBox(self.parent,
                                      CheckBoxID,
                                      "",
                                      size=self.wsize)
            self.widget.SetValue(int(self.val['value']))
            self.sizer.Add(self.widget)
            wx.EVT_CHECKBOX(self.widget, CheckBoxID, self.checkboxCB)

            label_str = ''
            self.label = wx.StaticText(self.parent,
                                       wx.NewId(),
                                       label_str,
                                       size=self.wsize)
            self.label.SetLabel( ` self.val['value'] `)
            self.sizer.Add(self.label)

            wx.EVT_BUTTON(self.defaultB, self.defaultBID, self.defaultCB)

            self.checkboxCB(None)  #to set the label after label exists

        elif self.val['wtype'] == 'wx.SpinCtrl':
            SpinCtrlID = wx.NewId()
            self.widget = wx.SpinCtrl(self.parent, SpinCtrlID, size=self.wsize)
            self.widget.SetRange(self.val['min'], self.val['max'])
            self.widget.SetValue(int(self.val['value']))
            self.sizer.Add(self.widget)
            wx.EVT_SPINCTRL(self.widget, SpinCtrlID, self.spinctrlCB)

            label_str = ''
            self.label = wx.StaticText(self.parent,
                                       wx.NewId(),
                                       label_str,
                                       size=self.wsize)
            self.label.SetLabel( ` self.val['value'] `)
            self.sizer.Add(self.label)

            wx.EVT_BUTTON(self.defaultB, self.defaultBID, self.defaultCB)

        elif self.val['wtype'] == 'wx.ColourDialog':

            self.widget = wx.ColourDialog(self.parent)
            self.widget.GetColourData().SetChooseFull(True)
            self.widget.GetColourData().SetColour(
                wx.Colour(self.val['value'][0], self.val['value'][1],
                          self.val['value'][2]))

            showColourDialogBID = wx.NewId()
            self.showColourDialogB = wx.Button(self.parent,
                                               showColourDialogBID,
                                               "ShowDialog",
                                               size=self.wsize)
            self.showColourDialogB.SetBackgroundColour(
                self.widget.GetColourData().GetColour().Get())
            self.sizer.Add(self.showColourDialogB)
            wx.EVT_BUTTON(self.showColourDialogB, showColourDialogBID,
                          self.showColourDialogCB)

            label_str = ''
            self.label = wx.StaticText(self.parent,
                                       wx.NewId(),
                                       label_str,
                                       size=self.wsize)
            self.label.SetLabel( ` self.val['value'] `)
            self.sizer.Add(self.label)

            self.defaultB.SetBackgroundColour(self.val['default'])
            wx.EVT_BUTTON(self.defaultB, self.defaultBID, self.defaultCB)

        elif self.val['wtype'] == 'wx.Slider':

            self.widget = wx.Slider(self.parent,
                                    wx.NewId(),
                                    int(self.val['value'] *
                                        self.val['divisor']),
                                    int(self.val['min']),
                                    int(self.val['max']),
                                    style=self.val['style'],
                                    size=self.wsize)

            self.sizer.Add(self.widget)

            sliderID = wx.NewId()
            div = self.val['divisor']
            if div == 1.: label_str = "%.0f" % (self.val['value'])
            if div == 10.: label_str = "%.1f" % (self.val['value'])
            if div == 100.: label_str = "%.2f" % (self.val['value'])
            if div == 1000.: label_str = "%.3f" % (self.val['value'])
            if div == 10000.: label_str = "%.4f" % (self.val['value'])

            self.label = wx.StaticText(self.parent,
                                       sliderID,
                                       label_str,
                                       size=self.wsize)
            self.sizer.Add(self.label)

            wx.EVT_BUTTON(self.defaultB, self.defaultBID, self.defaultCB)
            wx.EVT_SCROLL(self.widget, self.sliderCB)

        self.sizer.Add(self.defaultB)
        if self.val.has_key('tooltip'):
            if DEBUG: print self.val
            self.defaultB.SetToolTip(wx.ToolTip(self.val['tooltip']))
Exemple #13
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory
        if not factory.low_name:
            self.low = factory.low
            self.min = self.low

        if not factory.high_name:
            self.high = factory.high
            self.max = self.high

        self.max = factory.max
        self.min = factory.min

        self.format = factory.format

        self.evaluate = factory.evaluate
        self.sync_value(factory.evaluate_name, "evaluate", "from")

        self.sync_value(factory.low_name, "low", "both")
        self.sync_value(factory.high_name, "high", "both")

        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.FlexGridSizer(2, 3, 0, 0)

        # low text box
        self._label_lo = wx.TextCtrl(
            panel,
            -1,
            self.format % self.low,
            size=wx.Size(56, 20),
            style=wx.TE_PROCESS_ENTER,
        )
        sizer.Add(self._label_lo, 0, wx.ALIGN_CENTER)
        wx.EVT_TEXT_ENTER(
            panel, self._label_lo.GetId(), self.update_low_on_enter
        )
        wx.EVT_KILL_FOCUS(self._label_lo, self.update_low_on_enter)

        # low slider
        self.control.lslider = Slider(
            panel,
            -1,
            0,
            0,
            10000,
            size=wx.Size(100, 20),
            style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS,
        )
        self.control.lslider.SetValue(self._convert_to_slider(self.low))
        self.control.lslider.SetTickFreq(1000, 1)
        self.control.lslider.SetPageSize(1000)
        self.control.lslider.SetLineSize(100)
        wx.EVT_SCROLL(self.control.lslider, self.update_object_on_scroll)
        sizer.Add(self.control.lslider, 1, wx.EXPAND)
        sizer.AddStretchSpacer(0)

        # high slider
        sizer.AddStretchSpacer(0)
        self.control.rslider = Slider(
            panel,
            -1,
            self._convert_to_slider(self.high),
            0,
            10000,
            size=wx.Size(100, 20),
            style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS,
        )
        self.control.rslider.SetTickFreq(1000, 1)
        self.control.rslider.SetPageSize(1000)
        self.control.rslider.SetLineSize(100)
        wx.EVT_SCROLL(self.control.rslider, self.update_object_on_scroll)
        sizer.Add(self.control.rslider, 1, wx.EXPAND)

        # high text box
        self._label_hi = wx.TextCtrl(
            panel,
            -1,
            self.format % self.high,
            size=wx.Size(56, 20),
            style=wx.TE_PROCESS_ENTER,
        )
        sizer.Add(self._label_hi, 0, wx.ALIGN_CENTER)
        wx.EVT_TEXT_ENTER(
            panel, self._label_hi.GetId(), self.update_high_on_enter
        )
        wx.EVT_KILL_FOCUS(self._label_hi, self.update_high_on_enter)

        self.set_tooltip(self.control.lslider)
        self.set_tooltip(self.control.rslider)
        self.set_tooltip(self._label_lo)
        self.set_tooltip(self._label_hi)

        # Set-up the layout:
        panel.SetSizerAndFit(sizer)
Exemple #14
0
    def __init__(self, parent, id):

        # initializations
        self.low_norm_mass = ''  # mass for given height if BMI=20
        self.upp_norm_mass = ''  # mass for given height if BMI=25
        self.focus = 0  # set to avoid error on 'Reset'

        wx.Panel.__init__(self,
                          parent=parent,
                          id=id,
                          pos=wx.DefaultPosition,
                          size=wx.DefaultSize,
                          style=wx.SIMPLE_BORDER | wx.TAB_TRAVERSAL)
        #------------------------------
        #sizer with heading label
        #------------------------------
        label = wx.StaticText(self,
                              -1,
                              _("Current height/mass"),
                              wx.DefaultPosition,
                              wx.DefaultSize,
                              style=wx.ALIGN_CENTRE)
        label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
        label.SetForegroundColour(wx.Colour(0, 0, 131))
        szr_upper_heading = wx.BoxSizer(wx.HORIZONTAL)
        szr_upper_heading.Add(label, 1, 0)
        #------------------------------
        #sizer holding the height stuff
        #------------------------------
        label = wx.StaticText(self, -1, _("Height (cm)"), size=(1, 20))
        label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))
        label.SetForegroundColour(wx.Colour(0, 0, 131))

        self.txtheight = wx.TextCtrl(self, -1, "", size=(100, 20))
        self.txtheight.SetFont(
            wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))

        wx.EVT_TEXT(self, self.txtheight.GetId(), self.EvtText_height)
        wx.EVT_SET_FOCUS(self.txtheight, self.OnSetFocus_height)
        wx.EVT_CHAR(self.txtheight, self.EvtChar_height)

        szr_height = wx.BoxSizer(wx.HORIZONTAL)
        szr_height.Add((10, 1), 0, 0)
        szr_height.Add(label, 1, wx.ALIGN_CENTRE_VERTICAL, 0)
        szr_height.Add(self.txtheight, 1, wx.ALIGN_CENTRE_VERTICAL | wx.EXPAND,
                       0)
        #------------------------------
        #sizer holding the mass stuff -- some people incorrectly call this stuff "weight"
        #------------------------------
        label = wx.StaticText(self, -1, _("Mass (kg)"), size=(20, 20))
        label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))
        label.SetForegroundColour(wx.Colour(0, 0, 131))

        self.txtmass = wx.TextCtrl(self, -1, "", size=(100, 20))
        self.txtmass.SetFont(
            wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))

        wx.EVT_TEXT(self, self.txtmass.GetId(), self.EvtText_mass)
        wx.EVT_SET_FOCUS(self.txtmass, self.OnSetFocus_mass)
        wx.EVT_CHAR(self.txtmass, self.EvtChar_mass)

        szr_mass = wx.BoxSizer(wx.HORIZONTAL)
        szr_mass.Add((10, 1), 0, 0)
        szr_mass.Add(label, 1, wx.ALIGN_CENTRE_VERTICAL, 0)
        szr_mass.Add(self.txtmass, 1, wx.ALIGN_CENTRE_VERTICAL | wx.EXPAND, 0)
        szr_mass.Add((5, 5), 1, 0)
        #-----------------)-------------
        #sizer holding the BMI stuff
        #------------------------------
        label = wx.StaticText(self, -1, _("BMI"), size=(100, 20))
        label.SetFont(wx.Font(13, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))
        label.SetForegroundColour(wx.Colour(0, 0, 131))

        self.txtbmi = wx.TextCtrl(self,
                                  -1,
                                  "",
                                  size=(100, 20),
                                  style=wx.TE_READONLY)
        self.txtbmi.Enable(False)
        self.txtbmi.SetFont(
            wx.Font(13, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))

        szr_bmi = wx.BoxSizer(wx.HORIZONTAL)
        szr_bmi.Add((10, 1), 0, 0)
        szr_bmi.Add(label, 1, wx.ALIGN_CENTRE_VERTICAL | 0, 0)
        szr_bmi.Add(self.txtbmi, 1, wx.ALIGN_CENTRE_VERTICAL | wx.EXPAND, 0)
        szr_bmi.Add((5, 5), 1, 0)
        #--------------------------------------------------
        #the color ellipses to show where on scale of mass
        #--------------------------------------------------
        bmi_colour_scale = BMI_Colour_Scale(self)
        bmi_colour_scale.Enable(False)
        szr_col_scale = wx.BoxSizer(wx.HORIZONTAL)
        szr_col_scale.Add(bmi_colour_scale, 1, wx.EXPAND)
        #-----------------------------------------------------
        #put a slider control under the bmi colour range scale
        #-----------------------------------------------------
        self.slider = wx.Slider(
            self, -1, 15, 15, 34, wx.Point(30, 60), wx.Size(324, -1),
            wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
        self.slider.SetTickFreq(1, 1)
        wx.EVT_SCROLL(self.slider, self.SLIDER_EVT)
        wx.EVT_CHAR(self.slider, self.EvtChar_slider)

        szr_slider = wx.BoxSizer(wx.HORIZONTAL)
        szr_slider.Add(self.slider, 1, wx.EXPAND)
        #---------------------------------------------------------------------
        #Add the adjusted values heading, underlined, autoexpand to fill width
        #FIXME: find underline constant
        #---------------------------------------------------------------------
        label = wx.StaticText(self,
                              -1,
                              _("Adjusted Values"),
                              wx.DefaultPosition,
                              wx.DefaultSize,
                              style=wx.ALIGN_CENTRE)  #add underline
        label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
        label.SetForegroundColour(wx.Colour(0, 0, 131))

        szr_lower_heading = wx.BoxSizer(wx.HORIZONTAL)
        szr_lower_heading.Add(label, 1, wx.EXPAND)
        #-----------------------
        #Put in the goal mass
        #----------------------
        label = wx.StaticText(self, -1, _("Goal mass"), size=(30, 20))
        label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))
        label.SetForegroundColour(wx.Colour(0, 0, 131))

        self.txtgoal = wx.TextCtrl(self, -1, "", size=(100, 20))
        self.txtgoal.SetFont(
            wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))

        wx.EVT_TEXT(self, self.txtgoal.GetId(), self.EvtText_goal)
        wx.EVT_SET_FOCUS(self.txtgoal, self.OnSetFocus_goal)
        wx.EVT_CHAR(self.txtgoal, self.EvtChar_goal)

        szr_goal_mass = wx.BoxSizer(wx.HORIZONTAL)
        szr_goal_mass.Add((10, 1), 0, 0)
        szr_goal_mass.Add(label, 1, wx.ALIGN_CENTRE_VERTICAL, 0)
        szr_goal_mass.Add(self.txtgoal, 1,
                          wx.ALIGN_CENTRE_VERTICAL | wx.EXPAND, 0)
        #-----------------------------
        #and the amount to loose in Kg
        #-----------------------------
        label = wx.StaticText(self, -1, _("kg to lose"), size=(30, 20))
        label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))
        label.SetForegroundColour(wx.Colour(0, 0, 131))

        self.txtloss = wx.TextCtrl(self, -1, "", size=(100, 20))
        self.txtloss.SetFont(
            wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, False, ''))

        wx.EVT_TEXT(self, self.txtloss.GetId(), self.EvtText_loss)
        wx.EVT_SET_FOCUS(self.txtloss, self.OnSetFocus_loss)
        wx.EVT_CHAR(self.txtloss, self.EvtChar_loss)

        szr_to_loose = wx.BoxSizer(wx.HORIZONTAL)
        szr_to_loose.Add((10, 1), 0, 0)
        szr_to_loose.Add(label, 1, wx.ALIGN_CENTRE_VERTICAL, 0)
        szr_to_loose.Add(self.txtloss, 1, wx.ALIGN_CENTRE_VERTICAL | wx.EXPAND,
                         0)
        #-----------------------------------------------------------------
        #finally add all the horizontal sizers from top down to main sizer
        #-----------------------------------------------------------------
        szr_main = wx.BoxSizer(wx.VERTICAL)
        szr_main.Add((1, 5), 0, 0)
        szr_main.Add(szr_upper_heading, 0, wx.EXPAND)
        szr_main.Add((1, 5), 0, 0)
        szr_main.Add(szr_height, 0, 0)
        szr_main.Add((1, 5), 0, 0)
        szr_main.Add(szr_mass, 0, 0)
        szr_main.Add((1, 5), 0, 0)
        szr_main.Add(szr_bmi, 0, 0)
        szr_main.Add((1, 20), 0, 0)
        szr_main.Add(szr_col_scale, 0, 0)
        szr_main.Add(szr_slider, 0, 0)
        szr_main.Add(szr_lower_heading, 0, wx.EXPAND)
        szr_main.Add((1, 5), 0, 0)
        szr_main.Add(szr_goal_mass, 0, 0)
        szr_main.Add((1, 5), 0, 0)
        szr_main.Add(szr_to_loose, 0, 0)
        szr_main.Add((1, 20), 0, 0)
        #---------------------------------------
        #set, fit and layout sizer so it appears
        #---------------------------------------
        self.SetSizer(szr_main)
        szr_main.Fit(self)
        self.SetAutoLayout(True)
        self.Show(True)
Exemple #15
0
    def __init__(self, parent, tabToShow=0, lab=False):
        """ Initialize the Program Options Dialog Box """
        self.parent = parent
        self.lab = lab
        dlgWidth = 600
        # The Configuration Options dialog needs to be a different on different platforms, and
        # if we're showing the LAB version's initial configuration, we need a bit more room.
        if 'wxMSW' in wx.PlatformInfo:
            if self.lab:
                dlgHeight = 445
            else:
                dlgHeight = 445
        else:
            if self.lab:
                dlgHeight = 395
            else:
                dlgHeight = 345
        # Define the Dialog Box
        wx.Dialog.__init__(self,
                           parent,
                           -1,
                           _("Transana Settings"),
                           wx.DefaultPosition,
                           wx.Size(dlgWidth, dlgHeight),
                           style=wx.CAPTION | wx.SYSTEM_MENU | wx.THICK_FRAME)

        # To look right, the Mac needs the Small Window Variant.
        if "__WXMAC__" in wx.PlatformInfo:
            self.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)

        # Create the form's main VERTICAL Sizer
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        # Define a wxNotebook for the Tab structure
        notebook = wx.Notebook(self, -1, size=self.GetSizeTuple())
        # Add the notebook to the main sizer
        mainSizer.Add(notebook, 1, wx.EXPAND | wx.ALL, 3)

        # Define the Directories Tab that goes in the wxNotebook
        panelDirectories = wx.Panel(notebook,
                                    -1,
                                    size=notebook.GetSizeTuple(),
                                    name='OptionsSettings.DirectoriesPanel')

        # Define the main VERTICAL sizer for the Notebook Page
        panelDirSizer = wx.BoxSizer(wx.VERTICAL)

        # The LAB version initial configuration dialog gets some introductory text that can be skipped otherwise.
        if lab:
            # Add the LAB Version configuration instructions Label to the Directories Tab
            instText = _(
                "Transana needs to know where you store your data.  Please identify the location where you store your \nsource media files, where you want Transana to save your waveform data, and where you want your \ndatabase files stored.  "
            ) + '\n\n'
            instText += _(
                "None of this should be on the lab computer, where others may be able to access your confidential data, \nor where data may be deleted over night."
            )
            lblLabInst = wx.StaticText(panelDirectories,
                                       -1,
                                       instText,
                                       style=wx.ST_NO_AUTORESIZE)
            # Add the label to the Panel Sizer
            panelDirSizer.Add(lblLabInst, 0, wx.LEFT | wx.RIGHT | wx.TOP, 10)

        # Add the Media Library Directory Label to the Directories Tab
        lblVideoDirectory = wx.StaticText(panelDirectories,
                                          -1,
                                          _("Media Library Directory"),
                                          style=wx.ST_NO_AUTORESIZE)
        # Add the label to the Panel Sizer
        panelDirSizer.Add(lblVideoDirectory, 0, wx.LEFT | wx.RIGHT | wx.TOP,
                          10)
        # Add a spacer
        panelDirSizer.Add((0, 3))

        # Create a Row Sizer
        r1Sizer = wx.BoxSizer(wx.HORIZONTAL)
        # Add the Media Library Directory TextCtrl to the Directories Tab
        # If the Media path is not empty, we should normalize the path specification
        if TransanaGlobal.configData.videoPath == '':
            videoPath = TransanaGlobal.configData.videoPath
        else:
            videoPath = os.path.normpath(TransanaGlobal.configData.videoPath)
        self.videoDirectory = wx.TextCtrl(panelDirectories, -1, videoPath)
        # Add the element to the Row Sizer
        r1Sizer.Add(self.videoDirectory, 6, wx.EXPAND | wx.RIGHT, 10)

        # Add the Media Library Directory Browse Button to the Directories Tab
        self.btnVideoBrowse = wx.Button(panelDirectories, -1, _("Browse"))
        # Add the element to the Row Sizer
        r1Sizer.Add(self.btnVideoBrowse, 0)
        wx.EVT_BUTTON(self, self.btnVideoBrowse.GetId(), self.OnBrowse)

        # Add the Row Sizer to the Panel Sizer
        panelDirSizer.Add(r1Sizer, 0,
                          wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)

        # Add the Waveform Directory Label to the Directories Tab
        lblWaveformDirectory = wx.StaticText(panelDirectories,
                                             -1,
                                             _("Waveform Directory"),
                                             style=wx.ST_NO_AUTORESIZE)
        # Add the label to the Panel Sizer
        panelDirSizer.Add(lblWaveformDirectory, 0, wx.LEFT | wx.RIGHT, 10)
        # Add a spacer
        panelDirSizer.Add((0, 3))

        # Create a Row Sizer
        r2Sizer = wx.BoxSizer(wx.HORIZONTAL)
        # Add the Waveform Directory TextCtrl to the Directories Tab
        # If the visualization path is not empty, we should normalize the path specification
        if TransanaGlobal.configData.visualizationPath == '':
            visualizationPath = TransanaGlobal.configData.visualizationPath
        else:
            visualizationPath = os.path.normpath(
                TransanaGlobal.configData.visualizationPath)
        self.waveformDirectory = wx.TextCtrl(panelDirectories, -1,
                                             visualizationPath)
        # Add the element to the Row Sizer
        r2Sizer.Add(self.waveformDirectory, 6, wx.EXPAND | wx.RIGHT, 10)

        # Add the Waveform Directory Browse Button to the Directories Tab
        self.btnWaveformBrowse = wx.Button(panelDirectories, -1, _("Browse"))
        # Add the element to the Row Sizer
        r2Sizer.Add(self.btnWaveformBrowse, 0)
        wx.EVT_BUTTON(self, self.btnWaveformBrowse.GetId(), self.OnBrowse)

        # Add the Row Sizer to the Panel Sizer
        panelDirSizer.Add(r2Sizer, 0,
                          wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)

        # Add the Database Directory Label to the Directories Tab
        lblDatabaseDirectory = wx.StaticText(panelDirectories,
                                             -1,
                                             _("Database Directory"),
                                             style=wx.ST_NO_AUTORESIZE)
        # Add the element to the Panel Sizer
        panelDirSizer.Add(lblDatabaseDirectory, 0, wx.LEFT | wx.RIGHT, 10)
        # Add a spacer
        panelDirSizer.Add((0, 3))

        # Create a Row Sizer
        r3Sizer = wx.BoxSizer(wx.HORIZONTAL)
        # Add the Database Directory TextCtrl to the Directories Tab
        # If the database path is not empty, we should normalize the path specification
        if TransanaGlobal.configData.databaseDir == '':
            databaseDir = TransanaGlobal.configData.databaseDir
        else:
            databaseDir = os.path.normpath(
                TransanaGlobal.configData.databaseDir)
        self.oldDatabaseDir = databaseDir
        self.databaseDirectory = wx.TextCtrl(panelDirectories, -1, databaseDir)
        # Add the element to the Row Sizer
        r3Sizer.Add(self.databaseDirectory, 6, wx.EXPAND | wx.RIGHT, 10)

        # Add the Database Directory Browse Button to the Directories Tab
        self.btnDatabaseBrowse = wx.Button(panelDirectories, -1, _("Browse"))
        # Add the element to the Row Sizer
        r3Sizer.Add(self.btnDatabaseBrowse, 0)
        wx.EVT_BUTTON(self, self.btnDatabaseBrowse.GetId(), self.OnBrowse)

        # Add the Row Sizer to the Panel Sizer
        panelDirSizer.Add(r3Sizer, 0,
                          wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)

        # The Database Directory should not be visible for the Multi-user version of the program.
        # Let's just hide it so that the program doesn't crash for being unable to populate the control.
        if not TransanaConstants.singleUserVersion:
            lblDatabaseDirectory.Show(False)
            self.databaseDirectory.Show(False)
            self.btnDatabaseBrowse.Show(False)

        # Tell the Directories Panel to lay out now and do AutoLayout
        panelDirectories.SetSizer(panelDirSizer)
        panelDirectories.SetAutoLayout(True)
        panelDirectories.Layout()

        # If we're not doing the LAB version's initial configuration screen, we allow for a lot more configuration data
        if not self.lab:
            # Add the Transcriber Panel to the Notebook
            panelTranscriber = wx.Panel(
                notebook,
                -1,
                size=notebook.GetSizeTuple(),
                name='OptionsSettings.TranscriberPanel')

            # Define the main VERTICAL sizer for the Notebook Page
            panelTranSizer = wx.BoxSizer(wx.VERTICAL)

            # Add the Media Setback Label to the Transcriber Settings Tab
            lblTranscriptionSetback = wx.StaticText(
                panelTranscriber,
                -1,
                _("Transcription Setback:  (Auto-rewind interval for Ctrl-S)"),
                style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Panel Sizer
            panelTranSizer.Add(lblTranscriptionSetback, 0, wx.LEFT | wx.TOP,
                               10)
            # Add a spacer
            panelTranSizer.Add((0, 3))

            # Add the Media Setback Slider to the Transcriber Settings Tab
            self.transcriptionSetback = wx.Slider(
                panelTranscriber,
                -1,
                TransanaGlobal.configData.transcriptionSetback,
                0,
                5,
                style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS)
            # Add the element to the Panel Sizer
            panelTranSizer.Add(self.transcriptionSetback, 0,
                               wx.EXPAND | wx.LEFT | wx.RIGHT, 10)

            # Create a Row Sizer
            setbackSizer = wx.BoxSizer(wx.HORIZONTAL)
            # Add a spacer so the numbers are positioned correctly
            setbackSizer.Add((11, 0))
            # Add the Media Setback "0" Value Label to the Transcriber Settings Tab
            lblTranscriptionSetbackMin = wx.StaticText(
                panelTranscriber, -1, "0", style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            setbackSizer.Add(lblTranscriptionSetbackMin, 0)
            # Add a spacer
            setbackSizer.Add((1, 0), 1, wx.EXPAND)

            # Add the Media Setback "1" Value Label to the Transcriber Settings Tab
            lblTranscriptionSetback1 = wx.StaticText(panelTranscriber,
                                                     -1,
                                                     "1",
                                                     style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            setbackSizer.Add(lblTranscriptionSetback1, 0)
            # Add a spacer
            setbackSizer.Add((1, 0), 1, wx.EXPAND)

            # Add the Media Setback "2" Value Label to the Transcriber Settings Tab
            lblTranscriptionSetback2 = wx.StaticText(panelTranscriber,
                                                     -1,
                                                     "2",
                                                     style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            setbackSizer.Add(lblTranscriptionSetback2, 0)
            # Add a spacer
            setbackSizer.Add((1, 0), 1, wx.EXPAND)

            # Add the Media Setback "3" Value Label to the Transcriber Settings Tab
            lblTranscriptionSetback3 = wx.StaticText(panelTranscriber,
                                                     -1,
                                                     "3",
                                                     style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            setbackSizer.Add(lblTranscriptionSetback3, 0)
            # Add a spacer
            setbackSizer.Add((1, 0), 1, wx.EXPAND)

            # Add the Media Setback "4" Value Label to the Transcriber Settings Tab
            lblTranscriptionSetback4 = wx.StaticText(panelTranscriber,
                                                     -1,
                                                     "4",
                                                     style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            setbackSizer.Add(lblTranscriptionSetback4, 0)
            # Add a spacer
            setbackSizer.Add((1, 0), 1, wx.EXPAND)

            # Add the Media Setback "5" Value Label to the Transcriber Settings Tab
            lblTranscriptionSetbackMax = wx.StaticText(
                panelTranscriber, -1, "5", style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            setbackSizer.Add(lblTranscriptionSetbackMax, 0)
            # Add a spacer so the values are positioned correctly
            setbackSizer.Add((9, 0))

            # Add the Row Sizer to the Panel Sizer
            panelTranSizer.Add(setbackSizer, 0, wx.EXPAND | wx.LEFT | wx.RIGHT,
                               10)

            # On Windows, we can use a number of different media players.  There are trade-offs.
            #   wx.media.MEDIABACKEND_DIRECTSHOW allows speed adjustment, but not WMV or WMA formats (at least on XP).
            #   wx.media.MEDIABACKEND_WMP10 allows WMV and WMA formats, but speed adjustment is broken.
            # Let's allow the user to select which back end to use!
            if ('wxMSW' in wx.PlatformInfo):
                # Add the Media Player Option Label to the Transcriber Settings Tab
                lblMediaPlayer = wx.StaticText(panelTranscriber,
                                               -1,
                                               _("Media Player Selection"),
                                               style=wx.ST_NO_AUTORESIZE)
                # Add the element to the Panel Sizer
                panelTranSizer.Add(lblMediaPlayer, 0, wx.LEFT | wx.TOP, 10)
                # Add a spacer
                panelTranSizer.Add((0, 3))

                # Add the Media Player Option to the Transcriber Settings Tab
                self.chMediaPlayer = wx.Choice(
                    panelTranscriber,
                    -1,
                    choices=[
                        _('Windows Media Player back end'),
                        _('DirectShow back end')
                    ])
                self.chMediaPlayer.SetSelection(
                    TransanaGlobal.configData.mediaPlayer)
                # Add the element to the Panel Sizer
                panelTranSizer.Add(self.chMediaPlayer, 0,
                                   wx.EXPAND | wx.LEFT | wx.RIGHT, 10)

            # Create a Row Sizer
            lblSpeedSizer = wx.BoxSizer(wx.HORIZONTAL)
            # Add the Media Speed Slider Label to the Transcriber Settings Tab
            lblVideoSpeed = wx.StaticText(panelTranscriber,
                                          -1,
                                          _("Media Playback Speed"),
                                          style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            lblSpeedSizer.Add(lblVideoSpeed, 0)
            # Add a spacer
            lblSpeedSizer.Add((1, 0), 1, wx.EXPAND)

            # Screen elements get a bit out of order here!  We put the CURRENT VALUE of the slider above the slider.
            # We'll use the order of adding things to sizers to get around the logic problems this presents.

            # Add the Media Speed Slider to the Transcriber Settings Tab
            self.videoSpeed = wx.Slider(panelTranscriber,
                                        -1,
                                        TransanaGlobal.configData.videoSpeed,
                                        1,
                                        20,
                                        style=wx.SL_HORIZONTAL
                                        | wx.SL_AUTOTICKS)

            # Add the Media Speed Slider Current Setting Label to the Transcriber Settings Tab
            self.lblVideoSpeedSetting = wx.StaticText(
                panelTranscriber, -1,
                "%1.1f" % (float(self.videoSpeed.GetValue()) / 10))
            # Add the element to the Row Sizer
            lblSpeedSizer.Add(self.lblVideoSpeedSetting, 0, wx.ALIGN_RIGHT)

            # Add the LABEL Row Sizer to the Panel Sizer
            panelTranSizer.Add(lblSpeedSizer, 0,
                               wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
            # Add a spacer
            panelTranSizer.Add((0, 3))
            # Add the ELEMENT (Control) to the Panel Sizer
            panelTranSizer.Add(self.videoSpeed, 0,
                               wx.EXPAND | wx.LEFT | wx.RIGHT, 10)

            # Define the Scroll Event for the Slider to keep the Current Setting Label updated
            wx.EVT_SCROLL(self, self.OnScroll)

            # Create a Row Sizer
            speedSizer = wx.BoxSizer(wx.HORIZONTAL)
            # Add a spacer so the values are positioned correctly
            speedSizer.Add((6, 0))
            # Add the Media Speed Slider Minimum Speed Label to the Transcriber Settings Tab
            lblVideoSpeedMin = wx.StaticText(panelTranscriber,
                                             -1,
                                             "0.1",
                                             style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            speedSizer.Add(lblVideoSpeedMin, 0)
            # Add a spacer
            speedSizer.Add((1, 0), 8, wx.EXPAND)

            # Add the Media Speed Slider Normal Speed Label to the Transcriber Settings Tab
            lblVideoSpeed1 = wx.StaticText(panelTranscriber,
                                           -1,
                                           "1.0",
                                           style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            speedSizer.Add(lblVideoSpeed1, 0)
            # Add a spacer
            speedSizer.Add((1, 0), 9, wx.EXPAND)

            # Add the Media Speed Slider Maximum Speed Label to the Transcriber Settings Tab
            lblVideoSpeedMax = wx.StaticText(panelTranscriber,
                                             -1,
                                             "2.0",
                                             style=wx.ST_NO_AUTORESIZE)
            # Add the element to the Row Sizer
            speedSizer.Add(lblVideoSpeedMax, 0)
            # Add a spacer so the values are positioned properly
            speedSizer.Add((4, 0))

            # Add the Row Sizer to the Panel Sizer
            panelTranSizer.Add(speedSizer, 0, wx.EXPAND | wx.LEFT | wx.RIGHT,
                               10)

            # Create a Row Sizer
            fontSizer = wx.BoxSizer(wx.HORIZONTAL)

            # STC needs the Tab Size setting.  RTC does not support it.
            if not TransanaConstants.USESRTC:
                # Create an Element Sizer
                v1 = wx.BoxSizer(wx.VERTICAL)

                # Add Tab Size
                lblTabSize = wx.StaticText(panelTranscriber, -1, _("Tab Size"))
                # Add the element to the element Sizer
                v1.Add(lblTabSize, 0, wx.BOTTOM, 3)

                # Tab Size Box
                self.tabSize = wx.Choice(panelTranscriber,
                                         -1,
                                         choices=[
                                             '0', '2', '4', '6', '8', '10',
                                             '12', '14', '16', '18', '20'
                                         ])
                # Add the element to the element Sizer
                v1.Add(self.tabSize, 0, wx.EXPAND | wx.RIGHT, 10)

                # Add the element Sizer to the Row Sizer
                fontSizer.Add(v1, 1, wx.EXPAND)

                # Set the value to the default value provided by the Configuration Data
                self.tabSize.SetStringSelection(
                    TransanaGlobal.configData.tabSize)

            # Create an Element Sizer
            v2 = wx.BoxSizer(wx.VERTICAL)
            # Add Default Transcript Font
            lblDefaultFont = wx.StaticText(panelTranscriber, -1,
                                           _("Default Font"))
            # Add the label to the element Sizer
            v2.Add(lblDefaultFont, 0, wx.BOTTOM, 3)

            # We need to figure out what options we have for the default font.
            # First, let's get a list of all available fonts.
            fontEnum = wx.FontEnumerator()
            fontEnum.EnumerateFacenames()
            fontList = fontEnum.GetFacenames()

            # Now let's set up a list of the fonts we'd like.
            defaultFontList = [
                'Arial', 'Comic Sans MS', 'Courier', 'Courier New', 'Futura',
                'Geneva', 'Helvetica', 'Times', 'Times New Roman', 'Verdana'
            ]
            # Initialize the actual font list to nothing.
            choicelist = []
            # Now iterate through the list of fonts we'd like...
            for font in defaultFontList:
                # ... and see if each font is available ...
                if font in fontList:
                    # ... and if so, add it to the list.
                    choicelist.append(font)

            # If the list is empty, let's at least put one real value in it.
            if len(choicelist) == 0:
                font = wx.Font(TransanaGlobal.configData.defaultFontSize,
                               wx.DEFAULT, wx.NORMAL, wx.NORMAL)
                choicelist.append(font.GetFaceName())

            # As of wxPython 2.9.5.0, Mac doesn't support wx.CB_SORT and gives an ugly message about it!
            if 'wxMac' in wx.PlatformInfo:
                style = wx.CB_DROPDOWN
                choicelist.sort()
            else:
                style = wx.CB_DROPDOWN | wx.CB_SORT
            # Default Font Combo Box
            self.defaultFont = wx.ComboBox(panelTranscriber,
                                           -1,
                                           choices=choicelist,
                                           style=style)
            # Add the element to the element Sizer
            v2.Add(self.defaultFont, 0, wx.EXPAND | wx.RIGHT, 10)

            # Set the value to the default value provided by the Configuration Data
            self.defaultFont.SetValue(
                TransanaGlobal.configData.defaultFontFace)

            # Add the element Sizer to the Row Sizer
            fontSizer.Add(v2, 3, wx.EXPAND)

            # Create an Element Sizer
            v3 = wx.BoxSizer(wx.VERTICAL)
            # Add Default Transcript Font Size
            lblDefaultFontSize = wx.StaticText(panelTranscriber, -1,
                                               _("Default Font Size"))
            # Add the label to the element Sizer
            v3.Add(lblDefaultFontSize, 0, wx.BOTTOM, 3)

            # Set up the list of choices
            choicelist = ['8', '10', '11', '12', '14', '16', '20']

            # Default Font Combo Box
            self.defaultFontSize = wx.ComboBox(panelTranscriber,
                                               -1,
                                               choices=choicelist,
                                               style=wx.CB_DROPDOWN)
            # Add the element to the element Sizer
            v3.Add(self.defaultFontSize, 0, wx.EXPAND)

            # Set the value to the default value provided by the Configuration Data
            self.defaultFontSize.SetValue(
                str(TransanaGlobal.configData.defaultFontSize))

            # Add the element sizer to the Row Sizer
            fontSizer.Add(v3, 2, wx.EXPAND)

            # Add the Row Sizer to the Panel Sizer
            panelTranSizer.Add(fontSizer, 0,
                               wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)

            # Create a Row Sizer
            fontSizer2 = wx.BoxSizer(wx.HORIZONTAL)

            # Create an Element Sizer
            v4 = wx.BoxSizer(wx.VERTICAL)
            # Add Special Transcript Font
            lblSpecialFont = wx.StaticText(panelTranscriber, -1,
                                           _("Special Symbol Font"))
            # Add the label to the element Sizer
            v4.Add(lblSpecialFont, 0, wx.BOTTOM, 3)

            # Now let's set up a list of the fonts we'd like.
            defaultFontList = [
                'Arial', 'Comic Sans MS', 'Courier', 'Courier New', 'Futura',
                'Geneva', 'Helvetica', 'Times', 'Times New Roman', 'Verdana'
            ]
            # Initialize the actual font list to nothing.
            choicelist = []
            # Now iterate through the list of fonts we'd like...
            for font in defaultFontList:
                # ... and see if each font is available ...
                if font in fontList:
                    # ... and if so, add it to the list.
                    choicelist.append(font)

            # If the list is empty, let's at least put one real value in it.
            if len(choicelist) == 0:
                font = wx.Font(TransanaGlobal.configData.defaultFontSize,
                               wx.DEFAULT, wx.NORMAL, wx.NORMAL)
                choicelist.append(font.GetFaceName())

            # As of wxPython 2.9.5.0, Mac doesn't support wx.CB_SORT and gives an ugly message about it!
            if 'wxMac' in wx.PlatformInfo:
                style = wx.CB_DROPDOWN
                choicelist.sort()
            else:
                style = wx.CB_DROPDOWN | wx.CB_SORT
            # Special Font Combo Box
            self.specialFont = wx.ComboBox(panelTranscriber,
                                           -1,
                                           choices=choicelist,
                                           style=style)
            # Add the element to the element Sizer
            v4.Add(self.specialFont, 0, wx.EXPAND | wx.RIGHT, 10)

            # Set the value to the default value provided by the Configuration Data
            self.specialFont.SetValue(
                TransanaGlobal.configData.specialFontFace)

            # Add the element Sizer to the Row Sizer
            fontSizer2.Add(v4, 3, wx.EXPAND)

            # Create an Element Sizer
            v5 = wx.BoxSizer(wx.VERTICAL)
            # Add Special Transcript Font Size
            lblspecialFontSize = wx.StaticText(panelTranscriber, -1,
                                               _("Special Symbol Font Size"))
            # Add the label to the element Sizer
            v5.Add(lblspecialFontSize, 0, wx.BOTTOM, 3)

            # Set up the list of choices
            choicelist = [
                '8', '10', '11', '12', '14', '16', '18', '20', '22', '24'
            ]

            # Special Font Size Combo Box
            self.specialFontSize = wx.ComboBox(panelTranscriber,
                                               -1,
                                               choices=choicelist,
                                               style=wx.CB_DROPDOWN)
            # Add the element to the element Sizer
            v5.Add(self.specialFontSize, 0, wx.EXPAND)

            # Set the value to the special value provided by the Configuration Data
            self.specialFontSize.SetValue(
                str(TransanaGlobal.configData.specialFontSize))

            # Add the element sizer to the Row Sizer
            fontSizer2.Add(v5, 2, wx.EXPAND)

            # Add the Row Sizer to the Panel Sizer
            panelTranSizer.Add(fontSizer2, 0,
                               wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)

            # Create a Row Sizer
            checkboxSizer = wx.BoxSizer(wx.HORIZONTAL)

            # STC needs the Word Wrap setting.  RTC does not support it.
            if not TransanaConstants.USESRTC:
                # Word Wrap checkbox  NOT SUPPORTED BY RICH TEXT CTRL!!
                self.cbWordWrap = wx.CheckBox(panelTranscriber,
                                              -1,
                                              _("Word Wrap") + "  ",
                                              style=wx.ALIGN_RIGHT)
                # Add the element to the Row Sizer
                checkboxSizer.Add(self.cbWordWrap, 0)
                # Set the value to the configured value for Word Wrap
                self.cbWordWrap.SetValue(
                    (TransanaGlobal.configData.wordWrap == stc.STC_WRAP_WORD))
                # Add a spacer to the sizer
                checkboxSizer.Add((10, 0))

            # Auto Save checkbox
            self.cbAutoSave = wx.CheckBox(panelTranscriber,
                                          -1,
                                          _("Auto Save (10 min)") + "  ",
                                          style=wx.ALIGN_RIGHT)
            # Add the element to the Row Sizer
            checkboxSizer.Add(self.cbAutoSave, 0)
            # Set the value to the configured value for Word Wrap
            self.cbAutoSave.SetValue((TransanaGlobal.configData.autoSave))

            # Add a spacer
            checkboxSizer.Add((20, 1))

            # Max Transcript Image Width checkbox
            self.cbMaxTranscriptImageWidth = wx.CheckBox(
                panelTranscriber,
                -1,
                _("Limit Image Width in Transcripts") + "  ",
                style=wx.ALIGN_RIGHT)
            # Add the element to the Row Sizer
            checkboxSizer.Add(self.cbMaxTranscriptImageWidth, 0)
            # Set the value to the configured value for Word Wrap
            self.cbMaxTranscriptImageWidth.SetValue(
                (TransanaGlobal.configData.maxTranscriptImageWidth))

            # Add the row sizer to the panel sizer
            panelTranSizer.Add(checkboxSizer, 0, wx.LEFT | wx.RIGHT | wx.TOP,
                               10)

            # Tell the Transcriber Panel to lay out now and do AutoLayout
            panelTranscriber.SetSizer(panelTranSizer)
            panelTranscriber.SetAutoLayout(True)
            panelTranscriber.Layout()

        # The Message Server Tab should only appear for the Multi-user version of the program.
        if not TransanaConstants.singleUserVersion:

            # Add the Message Server Tab to the Notebook
            self.panelMessageServer = MessageServerPanel(
                notebook, name='OptionsSettings.MessageServerPanel')

        # Add the three Panels as Tabs in the Notebook
        notebook.AddPage(panelDirectories, _("Directories"), True)
        # If we're not in the Lab version initial configuration screen ...
        if not self.lab:
            # ... add the Transcriber Settings tab.
            notebook.AddPage(panelTranscriber, _("Transcriber Settings"),
                             False)
        # If we're in the Multi-user version ...
        if not TransanaConstants.singleUserVersion:
            # ... then add the Message Server tab.
            notebook.AddPage(self.panelMessageServer, _("MU Message Server"),
                             False)

        # the tabToShow parameter is the NUMBER of the tab which should be shown initially.
        #   0 = Directories tab
        #   1 = Transcriber Settings tab
        #   2 = Message Server tab, if MU
        if tabToShow != notebook.GetSelection():
            notebook.SetSelection(tabToShow)
        # If the Directories Tab is showing ...
        if notebook.GetSelection() == 0:
            # ... the Media directory should receive initial focus
            self.videoDirectory.SetFocus()
        # If the Transcriber Settings tab is showing ...
        elif notebook.GetSelection() == 1:
            # ... the Transcription Setback slider should receive focus
            self.transcriptionSetback.SetFocus()
        # If the Message Server tab is showing ...
        elif notebook.GetSelection() == 2:
            # ... the Message Server field should recieve initial focus
            self.panelMessageServer.messageServer.SetFocus()

        # Create a Row Sizer for the buttons
        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        # Add a spacer
        btnSizer.Add((1, 0), 1, wx.EXPAND)
        # Define the buttons on the bottom of the form
        # Define the "OK" Button
        btnOK = wx.Button(self, -1, _('OK'))
        # Add the Button to the Row Sizer
        btnSizer.Add(btnOK, 0, wx.RIGHT, 10)

        # Define the Cancel Button
        btnCancel = wx.Button(self, -1, _('Cancel'))
        # Add the Button to the Row Sizer
        btnSizer.Add(btnCancel, 0, wx.RIGHT, 10)

        # Define the Help Button
        btnHelp = wx.Button(self, -1, _('Help'))
        # Add the Button to the Row Sizer
        btnSizer.Add(btnHelp, 0)

        # Add the Row Sizer to the main form sizer
        mainSizer.Add(btnSizer, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
                      3)

        # Attach events to the Buttons
        wx.EVT_BUTTON(self, btnOK.GetId(), self.OnOK)
        wx.EVT_BUTTON(self, btnCancel.GetId(), self.OnCancel)
        wx.EVT_BUTTON(self, btnHelp.GetId(), self.OnHelp)

        # Bind the notebook page change event
        notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChange)

        # Lay out the Window, and tell it to Auto Layout
        self.SetSizer(mainSizer)
        self.SetAutoLayout(True)
        self.Layout()
        TransanaGlobal.CenterOnPrimary(self)

        # Get the form's current size
        (width, height) = self.GetSize()
        # Set the current size as the minimum size
        self.SetSizeHints(width, height)

        # Make OK the Default Button
        self.SetDefaultItem(btnOK)
        # Show the newly created Window as a modal dialog
        self.ShowModal()
Exemple #16
0
class SimpleSliderEditor(BaseRangeEditor):
    """ Simple style of range editor that displays a slider and a text field.

    The user can set a value either by moving the slider or by typing a value
    in the text field.
    """

    #---------------------------------------------------------------------------
    #  Trait definitions:
    #---------------------------------------------------------------------------

    # Low value for the slider range
    low = Any

    # High value for the slider range
    high = Any

    # Formatting string used to format value and labels
    format = Str

    # Flag indicating that the UI is in the process of being updated
    ui_changing = Bool(False)

    #---------------------------------------------------------------------------
    #  Finishes initializing the editor by creating the underlying toolkit
    #  widget:
    #---------------------------------------------------------------------------

    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory
        if not factory.low_name:
            self.low = factory.low

        if not factory.high_name:
            self.high = factory.high

        self.format = factory.format

        self.evaluate = factory.evaluate
        self.sync_value(factory.evaluate_name, 'evaluate', 'from')

        size = wx.DefaultSize
        if factory.label_width > 0:
            size = wx.Size(factory.label_width, 20)

        self.sync_value(factory.low_name, 'low', 'from')
        self.sync_value(factory.high_name, 'high', 'from')
        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        fvalue = self.value

        if not (self.low <= fvalue <= self.high):
            fvalue_text = ''
            fvalue = self.low
        else:
            try:
                fvalue_text = self.format % fvalue
            except (ValueError, TypeError), e:
                fvalue_text = ''

        ivalue = self._convert_to_slider(fvalue)

        self._label_lo = wx.StaticText(panel,
                                       -1,
                                       '999999',
                                       size=size,
                                       style=wx.ALIGN_RIGHT
                                       | wx.ST_NO_AUTORESIZE)
        sizer.Add(self._label_lo, 0, wx.ALIGN_CENTER)
        panel.slider = slider = Slider(panel,
                                       -1,
                                       ivalue,
                                       0,
                                       10000,
                                       size=wx.Size(80, 20),
                                       style=wx.SL_HORIZONTAL
                                       | wx.SL_AUTOTICKS)
        slider.SetTickFreq(1000, 1)
        slider.SetPageSize(1000)
        slider.SetLineSize(100)
        wx.EVT_SCROLL(slider, self.update_object_on_scroll)
        sizer.Add(slider, 1, wx.EXPAND)
        self._label_hi = wx.StaticText(panel, -1, '999999', size=size)
        sizer.Add(self._label_hi, 0, wx.ALIGN_CENTER)

        panel.text = text = wx.TextCtrl(panel,
                                        -1,
                                        fvalue_text,
                                        size=wx.Size(56, 20),
                                        style=wx.TE_PROCESS_ENTER)
        wx.EVT_TEXT_ENTER(panel, text.GetId(), self.update_object_on_enter)
        wx.EVT_KILL_FOCUS(text, self.update_object_on_enter)

        sizer.Add(text, 0, wx.LEFT | wx.EXPAND, 4)

        low_label = factory.low_label
        if factory.low_name != '':
            low_label = self.format % self.low

        high_label = factory.high_label
        if factory.high_name != '':
            high_label = self.format % self.high

        self._label_lo.SetLabel(low_label)
        self._label_hi.SetLabel(high_label)
        self.set_tooltip(slider)
        self.set_tooltip(self._label_lo)
        self.set_tooltip(self._label_hi)
        self.set_tooltip(text)

        # Set-up the layout:
        panel.SetSizerAndFit(sizer)
Exemple #17
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory

        # Initialize using the factory range defaults:
        self.low = factory.low
        self.high = factory.high
        self.evaluate = factory.evaluate

        # Hook up the traits to listen to the object.
        self.sync_value(factory.low_name, 'low', 'from')
        self.sync_value(factory.high_name, 'high', 'from')
        self.sync_value(factory.evaluate_name, 'evaluate', 'from')

        self.init_range()
        low = self.cur_low
        high = self.cur_high

        self._set_format()
        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        fvalue = self.value
        try:
            fvalue_text = self._format % fvalue
            1 / (low <= fvalue <= high)
        except:
            fvalue_text = ''
            fvalue = low

        if high > low:
            ivalue = int((float(fvalue - low) / (high - low)) * 10000)
        else:
            ivalue = low

        # Lower limit label:
        label_lo = wx.StaticText(panel, -1, '999999')
        panel.label_lo = label_lo
        sizer.Add(label_lo, 2, wx.ALIGN_CENTER)

        # Lower limit button:
        bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_BACK, size=(15, 15))
        button_lo = wx.BitmapButton(panel,
                                    -1,
                                    bitmap=bmp,
                                    size=(-1, 20),
                                    style=wx.BU_EXACTFIT | wx.NO_BORDER)
        panel.button_lo = button_lo
        button_lo.Bind(wx.EVT_BUTTON, self.reduce_range, button_lo)
        sizer.Add(button_lo, 1, wx.ALIGN_CENTER)

        # Slider:
        panel.slider = slider = Slider(panel,
                                       -1,
                                       ivalue,
                                       0,
                                       10000,
                                       size=wx.Size(80, 20),
                                       style=wx.SL_HORIZONTAL
                                       | wx.SL_AUTOTICKS)
        slider.SetTickFreq(1000)
        slider.SetValue(1)
        slider.SetPageSize(1000)
        slider.SetLineSize(100)
        wx.EVT_SCROLL(slider, self.update_object_on_scroll)
        sizer.Add(slider, 6, wx.EXPAND)

        # Upper limit button:
        bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, size=(15, 15))
        button_hi = wx.BitmapButton(panel,
                                    -1,
                                    bitmap=bmp,
                                    size=(-1, 20),
                                    style=wx.BU_EXACTFIT | wx.NO_BORDER)
        panel.button_hi = button_hi
        button_hi.Bind(wx.EVT_BUTTON, self.increase_range, button_hi)
        sizer.Add(button_hi, 1, wx.ALIGN_CENTER)

        # Upper limit label:
        label_hi = wx.StaticText(panel, -1, '999999')
        panel.label_hi = label_hi
        sizer.Add(label_hi, 2, wx.ALIGN_CENTER)

        # Text entry:
        panel.text = text = wx.TextCtrl(panel,
                                        -1,
                                        fvalue_text,
                                        size=wx.Size(56, 20),
                                        style=wx.TE_PROCESS_ENTER)
        wx.EVT_TEXT_ENTER(panel, text.GetId(), self.update_object_on_enter)
        wx.EVT_KILL_FOCUS(text, self.update_object_on_enter)

        sizer.Add(text, 0, wx.LEFT | wx.EXPAND, 4)

        # Set-up the layout:
        panel.SetSizerAndFit(sizer)
        label_lo.SetLabel(str(low))
        label_hi.SetLabel(str(high))
        self.set_tooltip(slider)
        self.set_tooltip(label_lo)
        self.set_tooltip(label_hi)
        self.set_tooltip(text)

        # Update the ranges and button just in case.
        self.update_range_ui()