Beispiel #1
0
 def __init__(self, *args, **kwargs):
     super(TextEditPanel, self).__init__(*args, **kwargs)
     sizer = wx.BoxSizer(wx.VERTICAL)
     self.text_ctrl = wx.TextCtrl(self, style=wx.TE_MULTILINE)
     self.check_zero = wx.CheckBox(self, label='Zero-terminated')
     self.combo_empty = wx.ComboBox(
         self,
         style=wx.CB_READONLY | wx.CB_DROPDOWN,
         value="empty string",
         choices=["empty string", "null", "zero"])
     self.tlk_id = IntCtrl(self,
                           min=0,
                           max=0xFFFFFFFF,
                           limited=False,
                           allow_long=True,
                           style=wx.ALIGN_RIGHT)  # SpinCtrl for TlkString
     sizer.Add(self.text_ctrl, 1, wx.EXPAND)
     sizer2 = wx.BoxSizer(wx.HORIZONTAL)
     sizer2.Add(self.check_zero, 0,
                wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
     sizer2.Add(self.combo_empty, 0,
                wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
     sizer2.Add(self.tlk_id, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
     sizer.Add(sizer2, 0, wx.EXPAND)
     self.SetSizer(sizer)
Beispiel #2
0
    def createControls(self):
        self.OrderType = wx.RadioBox(self.pnl,
                                     label='OrderType',
                                     pos=(80, 30),
                                     choices=["LMT", "MKT"],
                                     majorDimension=1,
                                     style=wx.RA_SPECIFY_ROWS)
        self.Action = wx.RadioBox(self.pnl,
                                  label='Action',
                                  pos=(60, 30),
                                  choices=["BUY", "SELL"],
                                  majorDimension=1,
                                  style=wx.RA_SPECIFY_ROWS)
        self.hbox1 = wx.BoxSizer(wx.VERTICAL)
        l1 = wx.StaticText(self.pnl, -1, "Symbol")
        self.hbox1.Add(l1, 1, wx.ALIGN_LEFT | wx.ALL, 5)
        self.Symbol = wx.TextCtrl(self.pnl)
        self.hbox1.Add(self.Symbol)

        self.hbox2 = wx.BoxSizer(wx.VERTICAL)
        l2 = wx.StaticText(self.pnl, -1, "Quantity")
        self.hbox2.Add(l2, 1, wx.ALIGN_LEFT | wx.ALL, 5)
        self.Quantity = IntCtrl(self.pnl)
        self.hbox2.Add(self.Quantity)

        self.hbox3 = wx.BoxSizer(wx.VERTICAL)
        l3 = wx.StaticText(self.pnl, -1, "LmtPrice")
        self.hbox3.Add(l3, 1, wx.ALIGN_LEFT | wx.ALL, 5)
        self.LmtPrice = NumCtrl(self.pnl, fractionWidth=2, min=0, max=None)
        self.hbox3.Add(self.LmtPrice)
Beispiel #3
0
 def coletarDadosDoProduto(Self, v):
     produto = wx.Dialog(Self,
                         -1,
                         title="Adicionar produto para cálculo",
                         name="Adicionar produto para cálculo")
     Self.texto_estatico_produto = wx.StaticText(produto,
                                                 label="Digite o produto:")
     Self.formula_produto = wx.TextCtrl(produto,
                                        -1,
                                        name="Digite o produto:")
     Self.Texto_estatico_preco = wx.StaticText(
         produto,
         label="Digite o preço total do produto no formato real.Centavo:")
     Self.formula_preco = wx.TextCtrl(
         produto,
         -1,
         name="Digite o preço total do produto no formato real.centavo:")
     Self.texto_estatico_quantidade = wx.StaticText(
         produto, label="Digite a quantidade do produto:")
     Self.formula_quantidade = IntCtrl(
         produto, -1, name="Digite a quantidade do protudo:")
     Self.texto_estatico_porcentagem = wx.StaticText(
         produto,
         label="Digite a porcentagem que será a base para o seu lucro:")
     Self.formula_porcentagem = IntCtrl(
         produto,
         -1,
         name="Digite a porcentagem que será a base para o seu lucro:")
     botaoCalcular = wx.Button(produto, wx.ID_OK, label="Calcular preço")
     botaoCancelar = wx.Button(produto, wx.ID_CANCEL, label="Cancelar")
     informacoesProduto = produto.ShowModal()
     if informacoesProduto == wx.ID_OK:
         Self.tratarDadosDigitadosPeloUsuario()
Beispiel #4
0
    def __init__(self, parent):
        self.main_frame = gui.main_frame.MainFrame.get_instance()
        super().__init__(parent,
                         id=wx.ID_ANY,
                         title='Edit frame',
                         style=wx.BORDER_THEME | wx.FRAME_NO_WINDOW_MENU,
                         size=(165, 40))
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.data_sizer = wx.BoxSizer()
        self.control_sizer = wx.BoxSizer()

        self.label = wx.StaticText(self,
                                   id=wx.ID_ANY,
                                   label='Установить кол-во: ')
        self.int_ctrl = IntCtrl(self,
                                id=wx.ID_ANY,
                                default_color=wx.SystemSettings.GetColour(
                                    wx.SYS_COLOUR_HIGHLIGHTTEXT))
        self.btn_submit = wx.Button(self, id=101, label='Submit')
        self.btn_cancel = wx.Button(self, id=102, label='Cancel')

        self.btn_submit.Bind(wx.EVT_BUTTON, self._action)
        self.btn_cancel.Bind(wx.EVT_BUTTON, self._action)
        self.int_ctrl.Bind(wx.EVT_KEY_DOWN, self._btn_push)

        self.data_sizer.Add(self.label)
        self.data_sizer.Add(self.int_ctrl)
        self.sizer.Add(self.data_sizer)
        self.control_sizer.Add(self.btn_submit, flag=wx.ALIGN_CENTRE)
        self.control_sizer.Add(self.btn_cancel, flag=wx.ALIGN_CENTRE)
        self.sizer.Add(self.control_sizer)
        self.SetSizer(self.sizer)
Beispiel #5
0
    def __init__(self, parent, main_window, no_tabs):
        self.parent = parent
        self.main_window = main_window
        self.no_tabs = no_tabs

        IntCtrl.__init__(self,
                         parent,
                         allow_long=True,
                         style=wx.NO_BORDER,
                         default_color=get_color(config["text_color"]))

        self.last_change_s = time.clock()

        tipmsg = _("For switching tables enter the table number or "
                   "use the mouse wheel.")
        self.SetToolTip(wx.ToolTip(tipmsg))

        # State for preventing to post GridActionTableSwitchMsg
        self.switching = False
        self.cursor_pos = 0

        self.Bind(EVT_INT, self.OnInt)
        self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
        self.Bind(wx.EVT_SET_FOCUS, self.OnFocus)
        self.main_window.Bind(self.EVT_CMD_RESIZE_GRID, self.OnResizeGrid)
        self.main_window.Bind(self.EVT_CMD_TABLE_CHANGED, self.OnTableChanged)
 def create_shift_element(self, parent, value):
     field = IntCtrl(parent,
                     value=value,
                     style=wx.TE_PROCESS_ENTER | wx.TE_RIGHT,
                     size=self.element_size)
     field.index = self.shift_vector.GetItemCount()
     self.shift_vector.Add(field, flag=wx.EXPAND | wx.RIGHT, border=5)
     self.Bind(wx.EVT_TEXT_ENTER, self.on_shift_field, field)
class NumberEntryDialog(wx.Dialog):
    def __init__(self,
                 parent,
                 message="Please enter a number.",
                 caption="Number Entry",
                 prompt="Number:",
                 value=None,
                 min=None,
                 max=None):

        super(NumberEntryDialog, self).__init__(parent, title=caption)
        kwargs = {
            'parent': self,
            'min': min,
            'max': max,
            'value': value,
            'limited': True,
            'allow_none': False,
        }
        self.intctrl = IntCtrl(
            **{k: v
               for k, v in kwargs.iteritems() if v is not None})

        sizer = wx.BoxSizer(wx.VERTICAL)
        if message:
            sizer.Add(wx.StaticText(self, label=message),
                      flag=wx.ALL,
                      border=4)
        hSizer = wx.BoxSizer(wx.HORIZONTAL)
        if prompt:
            hSizer.Add(wx.StaticText(self, label=prompt),
                       flag=wx.ALIGN_CENTER_VERTICAL)
        hSizer.Add(self.intctrl, 1, flag=wx.EXPAND)
        sizer.Add(hSizer, flag=wx.ALL | wx.EXPAND, border=4)

        btnsizer = wx.StdDialogButtonSizer()

        btn = wx.Button(self, wx.ID_OK)
        btn.SetDefault()
        btnsizer.AddButton(btn)

        btn = wx.Button(self, wx.ID_CANCEL)
        btnsizer.AddButton(btn)
        btnsizer.Realize()

        sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

        self.SetSizer(sizer)
        self.SetSize(200, 50 * (2 + int(bool(message))))
        #self.Fit()

        self.CenterOnParent()

    def SetValue(self, v):
        self.intctrl.SetValue(v)

    def GetValue(self):
        return self.intctrl.GetValue()
Beispiel #8
0
class IntegerEditPanel(wx.Panel):
    edits = Integral

    def __init__(self, *args, **kwargs):
        super(IntegerEditPanel, self).__init__(*args, **kwargs)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.intspin = wx.SpinCtrl(self,
                                   style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS)
        self.intctrl = IntCtrl(self,
                               limited=True,
                               allow_long=True,
                               style=wx.ALIGN_RIGHT)
        self.floatctrl = wx.TextCtrl(self, style=wx.ALIGN_RIGHT)
        self.floatchk = wx.CheckBox(self, label='Treat as floating-point')
        sizer.Add(self.intspin, flag=wx.ALIGN_CENTER_VERTICAL)
        sizer.Add(self.intctrl, flag=wx.ALIGN_CENTER_VERTICAL)
        sizer.Add(self.floatctrl, flag=wx.ALIGN_CENTER_VERTICAL)
        sizer.Add(self.floatchk,
                  flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
                  border=10)
        self.Bind(wx.EVT_CHECKBOX, self.OnFloatToggle, self.floatchk)
        self.SetSizer(sizer)

    def SetValue(self, value, kind):
        self.kind = kind
        self.Freeze()
        self.floatchk.Value = False
        self.floatctrl.Hide()
        if type(value).maxval > sys.maxsize:
            self.intspin.Hide()
            self.intctrl.Show()
            self.intctrl.SetBounds(type(value).minval, type(value).maxval)
            self.intctrl.SetValue(long(value))
        else:
            self.intctrl.Hide()
            self.intspin.Show()
            self.intspin.SetRange(type(value).minval, type(value).maxval)
            self.intspin.SetValue(value)
        if kind.size in (4, 8):
            self.floatchk.Show()
            self.intfmt = kind.format[False]
            self.floatfmt = FLOAT32.format[
                False] if kind.size == 4 else FLOAT64.format[False]
        else:
            self.floatchk.Hide()
        self.Layout()
        self.Thaw()

    def GetValue(self):
        if self.intspin.Shown:
            return self.kind(self.intspin.GetValue())
        elif self.intctrl.Shown:
            try:
                return self.kind(self.intctrl.GetValue())
            except ValueError, e:
                raise ValueError, "%r" % e
        else:
Beispiel #9
0
    def CreatePlotPanel(self, main_sizer):
        sizer = wx.BoxSizer(wx.VERTICAL)
        #control_sizer = wx.BoxSizer(wx.HORIZONTAL)
        control_sizer = wx.GridSizer(cols=4, vgap=10, hgap=5)
        panel = wx.Panel(self, -1)
        button_panel = wx.Panel(panel, -1)
        self.canvas = CanvasPanel(panel)

        btn_save_plot = wx.Button(button_panel, -1, "Export Image")
        btn_save_csv = wx.Button(button_panel, -1, "Export CSV")
        legend_chk = wx.CheckBox(button_panel, -1, "Legend")
        btn_edit_label = wx.Button(button_panel, -1, "Edit Labels")
        legend_pos_text = wx.StaticText(button_panel,
                                        -1,
                                        "Location: ",
                                        style=wx.ALIGN_RIGHT)
        legend_font_text = wx.StaticText(button_panel,
                                         -1,
                                         "Font Size: ",
                                         style=wx.ALIGN_RIGHT)
        legend_font_ctrl = IntCtrl(button_panel,
                                   -1,
                                   LEGEND_FONT_SIZE,
                                   min=1,
                                   max=100,
                                   allow_none=False,
                                   style=wx.TE_PROCESS_ENTER)
        self.legend_pos = wx.Choice(button_panel, -1, choices=legend_positions)
        self.legend_pos.SetSelection(0)

        btn_save_plot.Bind(wx.EVT_BUTTON, self.SavePlot)
        btn_save_csv.Bind(wx.EVT_BUTTON, self.SaveCSV)
        legend_chk.Bind(wx.EVT_CHECKBOX, self.toggleLegend)
        self.legend_pos.Bind(wx.EVT_CHOICE, self.set_legend_position)
        btn_edit_label.Bind(wx.EVT_BUTTON, self.open_label_dialog)
        legend_font_ctrl.Bind(wx.EVT_TEXT_ENTER, self.onFontChange)
        legend_font_ctrl.Bind(wx.EVT_TEXT, self.onFontChange)

        #main_sizer.Add(panel, 5, wx.EXPAND | wx.ALL)
        main_sizer.Add(panel, 4)
        sizer.Add(self.canvas, 6, wx.EXPAND)
        sizer.Add(button_panel, 1, wx.EXPAND | wx.ALL | wx.GROW)

        control_sizer.Add(legend_chk, 1)
        control_sizer.Add(btn_edit_label, 1)
        control_sizer.Add(legend_pos_text, 1, wx.ALIGN_RIGHT)
        control_sizer.Add(self.legend_pos, 1, wx.ALIGN_LEFT)
        control_sizer.Add(legend_font_text, 1)
        control_sizer.Add(legend_font_ctrl, 1)
        control_sizer.Add(btn_save_plot, 1)
        control_sizer.Add(btn_save_csv, 1)

        button_panel.SetSizer(control_sizer)
        panel.SetSizer(sizer)
    def __init__(self, parent, strategy=None):
        wx.Dialog.__init__(self, parent)

        sizer = wx.GridSizer(5, 2)

        self.strategy = strategy

        if self.strategy is None:
            self.SetTitle("Add Strategy")
        else:
            self.SetTitle("Edit Strategy")

        self._name = wx.TextCtrl(self)
        self._fnoType = wx.ComboBox(self, choices=["future", "call", "put"])
        self._buyWeek = wx.ComboBox(self, choices=['0', '1', '2', '3', '4'])
        self._buyWeek.SetValue('0')
        self._sellWeek = wx.ComboBox(self, choices=['0', '1', '2', '3', '4'])
        self._sellWeek.SetValue('0')
        self._priceTarget = IntCtrl(self, min=-20, max=20)

        sizer.Add(wx.StaticText(self, label="Name:"))
        sizer.Add(self._name)

        sizer.Add(wx.StaticText(self, label="FnO Type:"))
        sizer.Add(self._fnoType)

        sizer.Add(wx.StaticText(self, label="Buy Week:"))
        sizer.Add(self._buyWeek)

        sizer.Add(wx.StaticText(self, label="Sell Week:"))
        sizer.Add(self._sellWeek)

        sizer.Add(wx.StaticText(self, label="Price Target %:"))
        sizer.Add(self._priceTarget)

        if self.strategy is None:
            label = "Add"
        else:
            label = "Edit"

        okBtn = wx.Button(self, id=wx.ID_OK, label=label)
        okBtn.Bind(wx.EVT_BUTTON, self._onOk)
        cancelBtn = wx.Button(self, id=wx.ID_CANCEL, label="Cancel")

        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        btnSizer.Add(okBtn)
        btnSizer.Add(cancelBtn)

        sizer.Add(btnSizer)

        self.update()
        self.SetSizerAndFit(sizer)

        self.Center()
Beispiel #11
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.parent = parent

        #Attributes
        self.scoreLabel = wx.StaticText(self,
                                        label="blub",
                                        size=(self.width, -1))
        self.scoreLabel.SetBackgroundColour(wx.WHITE)
        self.add(self.scoreLabel)
        self.aiSpeedLabel = wx.StaticText(self,
                                          label="AISpeed",
                                          size=(self.width / 2, -1))
        self.add(self.aiSpeedLabel)
        self.aiSpeedCtrl = IntCtrl(self, size=(self.width / 2, -1))
        self.add(self.aiSpeedCtrl)
        self.aiSelectLabel = wx.StaticText(self,
                                           label="AI",
                                           size=(self.width / 4, -1))
        self.add(self.aiSelectLabel)
        self.aiSelectCB = wx.ComboBox(self,
                                      style=wx.CB_DROPDOWN | wx.CB_READONLY,
                                      choices=self.parent.aiList.keys(),
                                      size=(self.width / 4 * 3, -1))
        self.aiSelectCB.SetSelection(3)
        self.add(self.aiSelectCB)
        self.runCountLabel = wx.StaticText(self,
                                           label="Runs",
                                           size=(self.width / 2, -1))
        self.add(self.runCountLabel)
        self.runCountCtrl = IntCtrl(self, size=(self.width / 2, -1))
        self.add(self.runCountCtrl)
        self.runAIButton = wx.Button(self,
                                     label="Run AI",
                                     size=(self.width, -1))
        self.add(self.runAIButton)
        #         self.trainAIButton = wx.Button(self, label="Train AI", size=(self.width,-1))
        #         self.add(self.trainAIButton)
        self.stopAIButton = wx.Button(self,
                                      label="Stop AI",
                                      size=(self.width, -1))
        self.add(self.stopAIButton)
        self.restartButton = wx.Button(self,
                                       label="Restart",
                                       size=(self.width, -1))
        self.add(self.restartButton)

        #Layout
        self.__doLayout()

        #Event Handlers
        self.restartButton.Bind(wx.EVT_BUTTON, self.parent.onRestart)
        self.runAIButton.Bind(wx.EVT_BUTTON, self.parent.onRunAI)
        self.stopAIButton.Bind(wx.EVT_BUTTON, self.parent.onStopAI)
Beispiel #12
0
class SetQuantity(wx.Frame):
    def __init__(self, parent):
        self.main_frame = gui.main_frame.MainFrame.get_instance()
        super().__init__(parent,
                         id=wx.ID_ANY,
                         title='Edit frame',
                         style=wx.BORDER_THEME | wx.FRAME_NO_WINDOW_MENU,
                         size=(165, 40))
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.data_sizer = wx.BoxSizer()
        self.control_sizer = wx.BoxSizer()

        self.label = wx.StaticText(self,
                                   id=wx.ID_ANY,
                                   label='Установить кол-во: ')
        self.int_ctrl = IntCtrl(self,
                                id=wx.ID_ANY,
                                default_color=wx.SystemSettings.GetColour(
                                    wx.SYS_COLOUR_HIGHLIGHTTEXT))
        self.btn_submit = wx.Button(self, id=101, label='Submit')
        self.btn_cancel = wx.Button(self, id=102, label='Cancel')

        self.btn_submit.Bind(wx.EVT_BUTTON, self._action)
        self.btn_cancel.Bind(wx.EVT_BUTTON, self._action)
        self.int_ctrl.Bind(wx.EVT_KEY_DOWN, self._btn_push)

        self.data_sizer.Add(self.label)
        self.data_sizer.Add(self.int_ctrl)
        self.sizer.Add(self.data_sizer)
        self.control_sizer.Add(self.btn_submit, flag=wx.ALIGN_CENTRE)
        self.control_sizer.Add(self.btn_cancel, flag=wx.ALIGN_CENTRE)
        self.sizer.Add(self.control_sizer)
        self.SetSizer(self.sizer)

    def _action(self, evt):
        if evt.GetId() == 101:
            wx.PostEvent(
                self.main_frame,
                SelViewAction(action='quantity',
                              object=str(self.int_ctrl.GetValue())))
            self.Close()
        elif evt.GetId() == 102:
            self.Close()

    def _btn_push(self, evt):
        if evt.GetKeyCode() == 13:
            self.btn_submit.GetEventHandler().ProcessEvent(
                wx.PyCommandEvent(wx.EVT_BUTTON.typeId,
                                  self.btn_submit.GetId()))
        elif evt.GetKeyCode() == 27:
            self.Close()
        else:
            evt.Skip()
Beispiel #13
0
 def __init__(self, buffer=None, *args, **kwargs):
     super(JumpToPostDialog, self).__init__(title=_("Jump to Item in %s" %
                                                    buffer.display_name),
                                            *args,
                                            **kwargs)
     #First Row
     wx.StaticText(parent=self.pane,
                   label=_("Enter item number to jump to, 1 to %s:") %
                   str(len(buffer)))
     self.number = IntCtrl(parent=self.pane)
     self.number.SetValue(int(len(buffer) - buffer.index))
     self.number.SetSizerProps(expand=True)
     self.finish_setup()
    def create_df_head(self, parent):
        rb1 = wx.RadioButton(parent, 11, label="Head", style=wx.RB_GROUP)
        rb2 = wx.RadioButton(parent, 22, label="Tail")
        l1 = wx.StaticText(parent, -1, "No. of records: ")
        tc1 = IntCtrl(parent, -1, value=5, size=(40, -1), style=wx.TE_PROCESS_ENTER, min=1, max=50)
        tc1.Bind(wx.EVT_TEXT_ENTER, self.on_records_no)

        df_filter_sizer = wx.BoxSizer(wx.HORIZONTAL)
        df_filter_sizer.Add(rb1)
        df_filter_sizer.Add(rb2)
        df_filter_sizer.Add(l1)
        df_filter_sizer.Add(tc1)
        return df_filter_sizer
Beispiel #15
0
 def __init__(self, parent, no_tabs):
     self.parent = parent
     self.no_tabs = no_tabs
     
     IntCtrl.__init__(self, parent, limited=True, allow_long=True)
     
     self.SetMin(0)
     self.SetMax(no_tabs - 1)
     
     self.SetToolTip(wx.ToolTip( \
         "Enter grid table number or use mouse wheel to change tables."))
     
     self.Bind(EVT_INT, self.OnInt)
     self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
     self.parent.Bind(EVT_COMMAND_RESIZE_GRID, self.OnResizeGrid)
Beispiel #16
0
 def __init__(self):
     super(AudioOptions, self).__init__(application.frame,
                                        title='Audio Options')
     p = self.GetContentsPane()
     add_accelerator(self, 'ESCAPE', lambda event: self.Close(True))
     self.default_volume = config.system['volume']
     self.default_frequency = config.system['frequency']
     self.default_pan = config.system['pan']
     p.SetSizerType('form')
     wx.StaticText(p, label='&Output Device')
     self.device = wx.Choice(p,
                             choices=sorted(
                                 application.output.get_device_names()))
     self.device.SetStringSelection(config.system['output_device_name'])
     self.device.Bind(
         wx.EVT_CHOICE,
         lambda event: set_output_device(self.device.GetStringSelection()))
     wx.StaticText(p, label='&Volume')
     self.volume = wx.Slider(p, style=wx.VERTICAL)
     self.volume.SetValue(self.default_volume)
     self.volume.Bind(wx.EVT_SLIDER,
                      lambda event: set_volume(self.volume.GetValue()))
     wx.StaticText(p, label='&Pan')
     self.pan = wx.Slider(p, style=wx.HORIZONTAL)
     self.pan.SetValue(self.default_pan)
     self.pan.Bind(wx.EVT_SLIDER,
                   lambda event: set_pan(self.pan.GetValue()))
     wx.StaticText(p, label='&Frequency')
     self.frequency = IntCtrl(p,
                              value=self.default_frequency,
                              min=min_frequency,
                              max=max_frequency,
                              limited=True)
     self.frequency.Bind(EVT_INT, set_frequency(self.frequency.GetValue()))
     add_accelerator(
         self.frequency, 'UP', lambda event: self.update_frequency(
             min(self.frequency.GetMax(),
                 self.frequency.GetValue() + 100)))
     add_accelerator(
         self.frequency, 'DOWN', lambda event: self.update_frequency(
             max(self.frequency.GetMin(),
                 self.frequency.GetValue() - 100)))
     self.ok = wx.Button(p, label='&OK')
     self.ok.Bind(wx.EVT_BUTTON, lambda event: self.Close(True))
     self.restore = wx.Button(p, label='&Restore Defaults')
     self.restore.Bind(wx.EVT_BUTTON, self.on_restore)
     self.Show(True)
     self.Maximize(True)
Beispiel #17
0
    def __init__(self,
                 parent,
                 value,
                 message='',
                 externinfo=None,
                 size=(-1, -1),
                 enabledflag=None):
        """create an Int input control

        @type value: number or string
        @para m value: initial value
        @type externinfo: tuple or list
        @param externinfo: {"min":0, "max":100}
        @type size: tuple
        @param size: control's size
        """
        IElement.__init__(self, parent, 'int', message, externinfo, size,
                          enabledflag)

        if not isinstance(value, int):
            try:
                value = int(value)
            except ValueError:
                value = 0

        if externinfo:
            obj = wx.SpinCtrl(parent,
                              min=externinfo["min"],
                              max=externinfo["max"])
        else:
            obj = IntCtrl(parent)
        self.obj = obj
        self.setValue(value)
Beispiel #18
0
 def __init__(self, *args, **kwargs):
     super(IntegerEditPanel, self).__init__(*args, **kwargs)
     sizer = wx.BoxSizer(wx.HORIZONTAL)
     self.intspin = wx.SpinCtrl(self,
                                style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS)
     self.intctrl = IntCtrl(self,
                            limited=True,
                            allow_long=True,
                            style=wx.ALIGN_RIGHT)
     self.floatctrl = wx.TextCtrl(self, style=wx.ALIGN_RIGHT)
     self.floatchk = wx.CheckBox(self, label='Treat as floating-point')
     sizer.Add(self.intspin, flag=wx.ALIGN_CENTER_VERTICAL)
     sizer.Add(self.intctrl, flag=wx.ALIGN_CENTER_VERTICAL)
     sizer.Add(self.floatctrl, flag=wx.ALIGN_CENTER_VERTICAL)
     sizer.Add(self.floatchk,
               flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
               border=10)
     self.Bind(wx.EVT_CHECKBOX, self.OnFloatToggle, self.floatchk)
     self.SetSizer(sizer)
Beispiel #19
0
    def __init__(self, parent, no_tabs):
        self.parent = parent
        self.no_tabs = no_tabs

        IntCtrl.__init__(self, parent, limited=True, allow_long=True)

        self.SetMin(0)
        self.SetMax(no_tabs - 1)

        tipmsg = _("For switching tables enter the table number or "
                   "use the mouse wheel.")
        self.SetToolTip(wx.ToolTip(tipmsg))

        # State for preventing to post GridActionTableSwitchMsg
        self.switching = False

        self.Bind(EVT_INT, self.OnInt)
        self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
        self.parent.Bind(self.EVT_CMD_RESIZE_GRID, self.OnResizeGrid)
	def __init__(self, parent, callback):
		super(TemperatureField, self).__init__(parent)
		self.callback = callback

		self.SetBackgroundColour(wx.WHITE)

		self.text = IntCtrl(self, -1)
		self.text.SetBounds(0, 300)
		self.text.SetSize((60, 28))

		self.unit = wx.StaticBitmap(self, -1, wx.BitmapFromImage(wx.Image(
				resources.getPathForImage('print-window-temperature-unit.png'))), (0, 0))

		self.button = wx.Button(self, -1, _("Set"))
		self.button.SetSize((35, 25))
		self.Bind(wx.EVT_BUTTON, lambda e: self.callback(self.text.GetValue()), self.button)

		self.text.SetPosition((0, 0))
		self.unit.SetPosition((60, 0))
		self.button.SetPosition((90, 0))
Beispiel #21
0
            def __init__(self, parent, id, title):
                pre = wx.PreDialog()
                pre.Create(parent, id, title)
                self.this = pre.this

                sizer = wx.BoxSizer(wx.VERTICAL)
                self.input = IntCtrl(self, -1)
                self.input.SetValue(0)
                sizer.Add(self.input, 0, wx.ALL, 5)

                box = wx.BoxSizer(wx.HORIZONTAL)

                box.Add(wx.Button(self, wx.ID_OK), 0, wx.ALIGN_CENTRE | wx.ALL,
                        5),
                box.Add(wx.Button(self, wx.ID_CANCEL), 0,
                        wx.ALIGN_CENTRE | wx.ALL, 5),
                sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
                self.SetSizer(sizer)
                sizer.Fit(self)
                self.SetAutoLayout(True)
Beispiel #22
0
    def __init__(self, parent, main_window, no_tabs):
        self.parent = parent
        self.main_window = main_window
        self.no_tabs = no_tabs

        IntCtrl.__init__(self, parent, limited=True, allow_long=True)

        self.SetMin(0)
        self.SetMax(no_tabs - 1)

        tipmsg = _("For switching tables enter the table number or "
                   "use the mouse wheel.")
        self.SetToolTip(wx.ToolTip(tipmsg))

        # State for preventing to post GridActionTableSwitchMsg
        self.switching = False

        self.Bind(EVT_INT, self.OnInt)
        self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
        self.main_window.Bind(self.EVT_CMD_RESIZE_GRID, self.OnResizeGrid)
        self.main_window.Bind(self.EVT_CMD_TABLE_CHANGED, self.OnTableChanged)
Beispiel #23
0
    def __init__(self, parent, main_window, no_tabs):
        self.parent = parent
        self.main_window = main_window
        self.no_tabs = no_tabs

        IntCtrl.__init__(self, parent, allow_long=True, style=wx.NO_BORDER)

        self.last_change_s = time.clock()

        tipmsg = _("For switching tables enter the table number or " "use the mouse wheel.")
        self.SetToolTip(wx.ToolTip(tipmsg))

        # State for preventing to post GridActionTableSwitchMsg
        self.switching = False
        self.cursor_pos = 0

        self.Bind(EVT_INT, self.OnInt)
        self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
        self.Bind(wx.EVT_SET_FOCUS, self.OnFocus)
        self.main_window.Bind(self.EVT_CMD_RESIZE_GRID, self.OnResizeGrid)
        self.main_window.Bind(self.EVT_CMD_TABLE_CHANGED, self.OnTableChanged)
Beispiel #24
0
class ClusterForm(wx.Dialog):
    def __init__(self, parent, title, label):
        wx.Dialog.__init__(self, parent, 20, title, wx.DefaultPosition,
                           wx.Size(300, 140))

        vbox = wx.BoxSizer(wx.VERTICAL)

        hbox = wx.BoxSizer(wx.HORIZONTAL)

        buttonbox = wx.BoxSizer(wx.HORIZONTAL)

        fgs = wx.FlexGridSizer(3, 2, 9, 5)

        self.title_tc1 = wx.StaticText(self, label=label)

        self.tc1 = wx.TextCtrl(self, size=(150, 25))

        self.max = IntCtrl(self, size=(150, 25))

        self.max.Enable(True)

        self.max.Hide()

        fgs.AddMany([(self.title_tc1), (self.tc1, 1, wx.EXPAND)])

        fgs.AddMany([(self.title_tc1), (self.max, 1, wx.EXPAND)])

        fgs.AddGrowableRow(2, 1)
        fgs.AddGrowableCol(1, 1)

        hbox.Add(fgs, flag=wx.ALL | wx.EXPAND, border=15)
        self.b_ok = wx.Button(self, label='Ok', id=OK_DIALOG)
        self.b_cancel = wx.Button(self, label='Cancel', id=CANCEL_DIALOG)

        buttonbox.Add(self.b_ok, 1, border=15)
        buttonbox.Add(self.b_cancel, 1, border=15)

        vbox.Add(hbox, flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND)
        vbox.Add(buttonbox, flag=wx.ALIGN_CENTER)
        self.SetSizer(vbox)
    class MainWindow(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id)
            self.sizer = wx.BoxSizer()

            self.timer = TimerWidget(self, -1, title, self.myCallable)
            self.sizer.Add(self.timer)
            pidlabel = wx.StaticText(self, label='Process ID')
            self.pidvalue = IntCtrl(self,
                                    size=(60, 25),
                                    allow_none=True,
                                    value=None)
            self.sizer.Add(pidlabel)
            self.sizer.Add(self.pidvalue)

            self.testbutton = wx.Button(self, label='Test')
            self.Bind(wx.EVT_BUTTON, self.onTest, self.testbutton)
            self.sizer.Add(self.testbutton)

            self.SetSizer(self.sizer)
            self.SetAutoLayout(1)
            self.sizer.Fit(self)
            self.Show(True)

        def onTest(self, evt):
            self.myCallable()

        def myCallable(self):
            pid = self.getPID()
            print 'Killing process %s...' % (pid, )
            try:
                kill_windows(pid)
            except:
                kill_linux(pid)
            print 'Killed.'
            print 'Setting Screen position down...'
            t.setMainScreenPosition('down')
            print 'Screen down...'
            print 'Closing column valves...'
            t = tecnai.Tecnai()
            t.setColumnValvePosition('closed')
            t.setColumnValvePosition('closed')
            print 'Closed.'
            print 'Setting High Tension Off...'
            import win32com.client
            t.tecnai.Gun.HTState = win32com.client.constants.htOff
            print 'High Tension Off.'

        def getPID(self):
            pid = self.pidvalue.GetValue()
            print 'PID', type(pid)
            return pid
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id)
            self.sizer = wx.BoxSizer()

            self.timer = TimerWidget(self, -1, title, self.myCallable)
            self.sizer.Add(self.timer)
            pidlabel = wx.StaticText(self, label='Process ID')
            self.pidvalue = IntCtrl(self,
                                    size=(60, 25),
                                    allow_none=True,
                                    value=None)
            self.sizer.Add(pidlabel)
            self.sizer.Add(self.pidvalue)

            self.testbutton = wx.Button(self, label='Test')
            self.Bind(wx.EVT_BUTTON, self.onTest, self.testbutton)
            self.sizer.Add(self.testbutton)

            self.SetSizer(self.sizer)
            self.SetAutoLayout(1)
            self.sizer.Fit(self)
            self.Show(True)
Beispiel #27
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        box = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(box)

        self.dataDir = os.path.join(os.path.dirname(__file__), 'data/task')
        self.tasks = {}

        self.taskChoser = wx.ComboBox(self, style=wx.CB_READONLY)
        self.taskChoser.Bind(wx.EVT_COMBOBOX, self.OnSelect)
        box.Add(self.taskChoser)

        grid = wx.GridSizer(4, 2)
        box.Add(grid)

        self.taskName = wx.TextCtrl(self)

        self.appsInput = wx.TextCtrl(self)

        self.maxDistractionInput = IntCtrl(self, value=0, min=0)

        deleteButton = wx.Button(self, label='Delete')
        deleteButton.Bind(wx.EVT_BUTTON, self.OnDelete)
        cancelButton = wx.Button(self, label='Cancel')
        cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel)
        saveButton = wx.Button(self, label='Save')
        saveButton.Bind(wx.EVT_BUTTON, self.OnSave)

        grid.AddMany([(wx.StaticText(self, label='Name:'), 0, wx.EXPAND),
                      (self.taskName, 0, wx.EXPAND),
                      (wx.StaticText(self, label='Apps:'), 0, wx.EXPAND),
                      (self.appsInput, 0, wx.EXPAND),
                      (wx.StaticText(self,
                                     label='Max. Distraction:'), 0, wx.EXPAND),
                      (self.maxDistractionInput, 0, wx.EXPAND), (deleteButton),
                      (cancelButton), (saveButton)])

        self.refresh()
Beispiel #28
0
    def crete_edit_ctrl(self, editable, par, parent, val, validator):
        """
        Creates the edit control for a parameter
        :param editable: flag to indicate if the parameter is editable
        :param par: parameter name
        :param parent: parent of the control
        :param val: value of the parameter
        :param validator: validator of the control
        :return: a wx control object (subclass of wx.Control)?
        """
        if type(validator) == type([]):
            # There should be a list of choices
            validator = validator[:]
            ctrl = wx.Choice(parent, -1, choices=validator)
            # Since we work with strings we have to find the right
            # strings positons to initilize the choice box.
            pos = 0
            if type(val) == type(''):
                pos = validator.index(val)
            elif type(par) == type(1):
                pos = par
            ctrl.SetSelection(pos)
        elif isinstance(validator, bool):
            # Parameter is a boolean
            ctrl = wx.CheckBox(self, -1)
            ctrl.SetValue(val)
            # Create a non-editable box if needed
            # ctrl.SetEditable(editable)
        elif isinstance(validator, int):
            # Parameter is an integer
            ctrl = IntCtrl(self, -1, val)
            # Create a non-editable box if needed
            ctrl.SetEditable(editable)
            if not editable:
                ctrl.SetBackgroundColour(self.not_editable_bkg_color)

        # Otherwise it should be a validator ...
        else:
            validator = validator.Clone()
            ctrl = wx.TextCtrl(parent,
                               -1,
                               str(val),
                               validator=validator,
                               style=wx.TE_RIGHT | wx.TE_RICH)

            # Create a non-editable box if needed
            ctrl.SetEditable(editable)
            if not editable:
                ctrl.SetBackgroundColour(self.not_editable_bkg_color)
        return ctrl
Beispiel #29
0
 def parse_integer(self, node, frame, parent, sizer):
     """Create a control that accepts integers."""
     a = node.attrib
     min_value = a.get('min', None)
     if min_value is not None:
         min_value = int(min_value)
     max_value = a.get('max', None)
     if max_value is not None:
         max_value = int(max_value)
     limited = int(a.get('limited', 0))
     allow_none = int(a.get('allow_none', 0))
     allow_long = int(a.get('allow_long', 0))
     value = node.text
     if value is None:
         value = 0
     else:
         value = int(value)
     return IntCtrl(parent,
                    min=min_value,
                    max=max_value,
                    limited=limited,
                    allow_none=allow_none,
                    allow_long=allow_long,
                    value=value)
	def script_addTextButton(self, r_text, g_text, b_text, r_button, g_button, b_button, button_text, command, data):
		x_text, y_text, w_text, h_text = self._getColoredRect(r_text, g_text, b_text)
		if x_text < 0:
			return
		x_button, y_button, w_button, h_button = self._getColoredRect(r_button, g_button, b_button)
		if x_button < 0:
			return
		from wx.lib.intctrl import IntCtrl
		text = IntCtrl(self, -1)
		text.SetBounds(0, 300)
		text.SetPosition((x_text, y_text))
		text.SetSize((w_text, h_text))
		
		button = wx.Button(self, -1, _(button_text))
		button.SetPosition((x_button, y_button))
		button.SetSize((w_button, h_button))
		button.command = command
		button.data = data
		self._buttonList.append(button)
		self.Bind(wx.EVT_BUTTON, lambda e: command(data % text.GetValue()), button)
Beispiel #31
0
    def populatePanel(self, panel):
        self.mainFrame = gui.mainFrame.MainFrame.getInstance()
        self.sFit = Fit.getInstance()

        helpCursor = wx.Cursor(wx.CURSOR_QUESTION_ARROW)
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        self.stTitle = wx.StaticText(panel, wx.ID_ANY, "Market && Prices",
                                     wx.DefaultPosition, wx.DefaultSize, 0)
        self.stTitle.Wrap(-1)
        self.stTitle.SetFont(wx.Font(12, 70, 90, 90, False, wx.EmptyString))

        mainSizer.Add(self.stTitle, 0, wx.ALL, 5)

        self.m_staticline1 = wx.StaticLine(panel, wx.ID_ANY,
                                           wx.DefaultPosition, wx.DefaultSize,
                                           wx.LI_HORIZONTAL)
        mainSizer.Add(self.m_staticline1, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5)

        delayTimer = wx.BoxSizer(wx.HORIZONTAL)
        self.stMarketDelay = wx.StaticText(panel, wx.ID_ANY,
                                           "Market Search Delay (ms):",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.stMarketDelay.Wrap(-1)
        if "wxGTK" not in wx.PlatformInfo:
            self.stMarketDelay.SetCursor(helpCursor)
        self.stMarketDelay.SetToolTip(
            wx.ToolTip(
                'The delay between a keystroke and the market search. Can help reduce lag when typing fast in the market search box.'
            ))
        delayTimer.Add(self.stMarketDelay, 0,
                       wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        self.intDelay = IntCtrl(panel, max=1000, limited=True)
        delayTimer.Add(self.intDelay, 0, wx.ALL, 5)
        mainSizer.Add(delayTimer, 0, wx.EXPAND | wx.TOP | wx.RIGHT, 10)
        self.intDelay.SetValue(
            self.sFit.serviceFittingOptions["marketSearchDelay"])
        self.intDelay.Bind(wx.lib.intctrl.EVT_INT, self.onMarketDelayChange)

        self.cbMarketShortcuts = wx.CheckBox(panel, wx.ID_ANY,
                                             "Show market shortcuts",
                                             wx.DefaultPosition,
                                             wx.DefaultSize, 0)
        mainSizer.Add(self.cbMarketShortcuts, 0, wx.EXPAND | wx.TOP | wx.RIGHT,
                      10)
        self.cbMarketShortcuts.SetValue(
            self.sFit.serviceFittingOptions["showMarketShortcuts"] or False)
        self.cbMarketShortcuts.Bind(wx.EVT_CHECKBOX, self.onCBShowShortcuts)

        priceSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.stDefaultSystem = wx.StaticText(panel, wx.ID_ANY,
                                             "Default Market Prices:",
                                             wx.DefaultPosition,
                                             wx.DefaultSize, 0)
        self.stDefaultSystem.Wrap(-1)
        priceSizer.Add(self.stDefaultSystem, 0,
                       wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        if "wxGTK" not in wx.PlatformInfo:
            self.stDefaultSystem.SetCursor(helpCursor)
        self.stDefaultSystem.SetToolTip(
            wx.ToolTip(
                'The source you choose will be tried first, but subsequent sources will be used if the preferred source fails. '
                'The system you choose will also be tried first, and if no data is available, global price will be used.'
            ))
        self.chPriceSource = wx.Choice(panel,
                                       choices=sorted(Price.sources.keys()))
        self.chPriceSystem = wx.Choice(panel,
                                       choices=list(Price.systemsList.keys()))
        priceSizer.Add(self.chPriceSource, 1, wx.ALL | wx.EXPAND, 5)
        priceSizer.Add(self.chPriceSystem, 1, wx.ALL | wx.EXPAND, 5)
        mainSizer.Add(priceSizer, 0, wx.EXPAND | wx.TOP | wx.RIGHT, 10)
        self.chPriceSource.SetStringSelection(
            self.sFit.serviceFittingOptions["priceSource"])
        self.chPriceSource.Bind(wx.EVT_CHOICE, self.onPricesSourceSelection)
        self.chPriceSystem.SetStringSelection(
            self.sFit.serviceFittingOptions["priceSystem"])
        self.chPriceSystem.Bind(wx.EVT_CHOICE, self.onPriceSelection)

        self.tbTotalPriceBox = wx.StaticBoxSizer(wx.VERTICAL, panel,
                                                 "Total Price Includes")
        self.tbTotalPriceDrones = wx.CheckBox(panel, -1, "Drones",
                                              wx.DefaultPosition,
                                              wx.DefaultSize, 1)
        self.tbTotalPriceDrones.SetValue(self.priceSettings.get("drones"))
        self.tbTotalPriceDrones.Bind(wx.EVT_CHECKBOX,
                                     self.OnTotalPriceDroneChange)
        self.tbTotalPriceBox.Add(self.tbTotalPriceDrones, 0,
                                 wx.LEFT | wx.RIGHT | wx.TOP, 5)
        self.tbTotalPriceCargo = wx.CheckBox(panel, -1, "Cargo",
                                             wx.DefaultPosition,
                                             wx.DefaultSize, 1)
        self.tbTotalPriceCargo.SetValue(self.priceSettings.get("cargo"))
        self.tbTotalPriceCargo.Bind(wx.EVT_CHECKBOX,
                                    self.OnTotalPriceCargoChange)
        self.tbTotalPriceBox.Add(self.tbTotalPriceCargo, 0, wx.LEFT | wx.RIGHT,
                                 5)
        self.tbTotalPriceCharacter = wx.CheckBox(panel, -1,
                                                 "Implants && Boosters",
                                                 wx.DefaultPosition,
                                                 wx.DefaultSize, 1)
        self.tbTotalPriceCharacter.SetValue(
            self.priceSettings.get("character"))
        self.tbTotalPriceCharacter.Bind(wx.EVT_CHECKBOX,
                                        self.OnTotalPriceCharacterChange)
        self.tbTotalPriceBox.Add(self.tbTotalPriceCharacter, 0,
                                 wx.LEFT | wx.RIGHT | wx.BOTTOM, 5)
        mainSizer.Add(self.tbTotalPriceBox, 0, wx.EXPAND | wx.TOP | wx.RIGHT,
                      10)

        self.rbMarketSearch = wx.RadioBox(
            panel, -1, "Market Search && Recent Items", wx.DefaultPosition,
            wx.DefaultSize, [
                "No changes to meta buttons",
                "Enable all meta buttons for a duration of search / recents",
                "Enable all meta buttons"
            ], 1, wx.RA_SPECIFY_COLS)
        self.rbMarketSearch.SetSelection(
            self.priceSettings.get('marketMGSearchMode'))
        mainSizer.Add(self.rbMarketSearch, 0, wx.RIGHT | wx.TOP | wx.EXPAND,
                      10)
        self.rbMarketSearch.Bind(wx.EVT_RADIOBOX, self.OnMarketSearchChange)

        self.rbMarketEmpty = wx.RadioBox(
            panel, -1, "Market Group Selection", wx.DefaultPosition,
            wx.DefaultSize,
            ["No changes to meta buttons", "Enable all meta buttons"], 1,
            wx.RA_SPECIFY_COLS)
        self.rbMarketEmpty.SetSelection(
            self.priceSettings.get('marketMGMarketSelectMode'))
        mainSizer.Add(self.rbMarketEmpty, 0, wx.EXPAND | wx.TOP | wx.RIGHT, 10)
        self.rbMarketEmpty.Bind(wx.EVT_RADIOBOX,
                                self.OnMarketGroupSelectionChange)

        self.rbMarketEmpty = wx.RadioBox(
            panel, -1, "Empty Market View", wx.DefaultPosition, wx.DefaultSize,
            [
                "No changes to meta buttons",
                "Enable leftmost available meta button",
                "Enable all available meta buttons"
            ], 1, wx.RA_SPECIFY_COLS)
        self.rbMarketEmpty.SetSelection(
            self.priceSettings.get('marketMGEmptyMode'))
        mainSizer.Add(self.rbMarketEmpty, 0, wx.EXPAND | wx.TOP | wx.RIGHT, 10)
        self.rbMarketEmpty.Bind(wx.EVT_RADIOBOX, self.OnMarketEmptyChange)

        self.rbMarketJump = wx.RadioBox(
            panel, -1, "Item Market Group Jump", wx.DefaultPosition,
            wx.DefaultSize, [
                "No changes to meta buttons", "Enable item's meta button",
                "Enable item's meta button, disable others",
                "Enable all meta buttons"
            ], 1, wx.RA_SPECIFY_COLS)
        self.rbMarketJump.SetSelection(
            self.priceSettings.get('marketMGJumpMode'))
        mainSizer.Add(self.rbMarketJump, 0,
                      wx.EXPAND | wx.TOP | wx.RIGHT | wx.BOTTOM, 10)
        self.rbMarketJump.Bind(wx.EVT_RADIOBOX, self.OnMarketJumpChange)

        panel.SetSizer(mainSizer)
        panel.Layout()
Beispiel #32
0
    def run_mouse(self, background_image, image_set_number):
        """Define a grid by running the UI

        Returns a CPGridInfo object
        """
        import matplotlib
        import matplotlib.backends.backend_wxagg as backend
        import wx
        from wx.lib.intctrl import IntCtrl

        #
        # Make up a dialog box. It has the following structure:
        #
        # Dialog:
        #    top_sizer:
        #        Canvas
        #            Figure
        #               Axis
        #        control_sizer
        #            first_sizer
        #               first_row
        #               first_col
        #            second_sizer
        #               second_row
        #               second_col
        #            button_sizer
        #               Redisplay
        #               OK
        #               cancel
        #    status bar
        #
        figure = matplotlib.figure.Figure()
        frame = wx.Dialog(wx.GetApp().TopWindow,
                          title="Select grid cells, image cycle #%d:" %
                          (image_set_number))
        top_sizer = wx.BoxSizer(wx.VERTICAL)
        frame.SetSizer(top_sizer)
        canvas = backend.FigureCanvasWxAgg(frame, -1, figure)
        top_sizer.Add(canvas, 1, wx.EXPAND)
        top_sizer.Add(
            wx.StaticText(
                frame,
                -1,
                "Select the center of a grid cell with the left mouse button.\n",
            ),
            0,
            wx.EXPAND | wx.ALL,
            5,
        )
        control_sizer = wx.BoxSizer(wx.HORIZONTAL)
        top_sizer.Add(control_sizer, 0, wx.EXPAND | wx.ALL, 5)
        FIRST_CELL = "First cell"
        SECOND_CELL = "Second cell"
        cell_choice = wx.RadioBox(
            frame,
            label="Choose current cell",
            choices=[FIRST_CELL, SECOND_CELL],
            style=wx.RA_VERTICAL,
        )
        control_sizer.Add(cell_choice)
        #
        # Text boxes for the first cell's row and column
        #
        first_sizer = wx.GridBagSizer(2, 2)
        control_sizer.Add(first_sizer, 1, wx.EXPAND | wx.ALL, 5)
        first_sizer.Add(
            wx.StaticText(frame, -1, "First cell column:"),
            wx.GBPosition(0, 0),
            flag=wx.EXPAND,
        )
        first_column = IntCtrl(frame,
                               -1,
                               1,
                               min=1,
                               max=self.grid_columns.value)
        first_sizer.Add(first_column, wx.GBPosition(0, 1), flag=wx.EXPAND)
        first_sizer.Add(
            wx.StaticText(frame, -1, "First cell row:"),
            wx.GBPosition(1, 0),
            flag=wx.EXPAND,
        )
        first_row = IntCtrl(frame, -1, 1, min=1, max=self.grid_rows.value)
        first_sizer.Add(first_row, wx.GBPosition(1, 1), flag=wx.EXPAND)
        first_sizer.Add(wx.StaticText(frame, -1, "X:"), wx.GBPosition(0, 2))
        first_x = IntCtrl(frame, -1, 100, min=1)
        first_sizer.Add(first_x, wx.GBPosition(0, 3))
        first_sizer.Add(wx.StaticText(frame, -1, "Y:"), wx.GBPosition(1, 2))
        first_y = IntCtrl(frame, -1, 100, min=1)
        first_sizer.Add(first_y, wx.GBPosition(1, 3))
        #
        # Text boxes for the second cell's row and column
        #
        second_sizer = wx.GridBagSizer(2, 2)
        control_sizer.Add(second_sizer, 1, wx.EXPAND | wx.ALL, 5)
        second_sizer.Add(
            wx.StaticText(frame, -1, "Second cell column:"),
            wx.GBPosition(0, 0),
            flag=wx.EXPAND,
        )
        second_column = IntCtrl(frame,
                                -1,
                                self.grid_columns.value,
                                min=1,
                                max=self.grid_columns.value)
        second_sizer.Add(second_column, wx.GBPosition(0, 1), flag=wx.EXPAND)
        second_sizer.Add(
            wx.StaticText(frame, -1, "Second cell row:"),
            wx.GBPosition(1, 0),
            flag=wx.EXPAND,
        )
        second_row = IntCtrl(frame,
                             -1,
                             self.grid_rows.value,
                             min=1,
                             max=self.grid_rows.value)
        second_sizer.Add(second_row, wx.GBPosition(1, 1), flag=wx.EXPAND)
        second_sizer.Add(wx.StaticText(frame, -1, "X:"), wx.GBPosition(0, 2))
        second_x = IntCtrl(frame, -1, 200, min=1)
        second_sizer.Add(second_x, wx.GBPosition(0, 3))
        second_sizer.Add(wx.StaticText(frame, -1, "Y:"), wx.GBPosition(1, 2))
        second_y = IntCtrl(frame, -1, 200, min=1)
        second_sizer.Add(second_y, wx.GBPosition(1, 3))
        #
        # Buttons
        #
        button_sizer = wx.BoxSizer(wx.VERTICAL)
        control_sizer.Add(button_sizer, 0, wx.EXPAND | wx.ALL, 5)
        redisplay_button = wx.Button(frame, -1, "Redisplay")
        button_sizer.Add(redisplay_button)
        button_sizer.Add(wx.Button(frame, wx.OK, "OK"))
        button_sizer.Add(wx.Button(frame, wx.CANCEL, "Cancel"))
        #
        # Status bar
        #
        status_bar = wx.StatusBar(frame, style=0)
        top_sizer.Add(status_bar, 0, wx.EXPAND)
        status_bar.SetFieldsCount(1)
        SELECT_FIRST_CELL = "Select the center of the first cell"
        SELECT_SECOND_CELL = "Select the center of the second cell"
        status_bar.SetStatusText(SELECT_FIRST_CELL)
        status = [wx.OK]
        gridding = [None]
        if self.display_image_name == "Leave blank":
            image_shape = None
        else:
            image_shape = background_image.shape[:2]

        def redisplay(event):
            figure.clf()
            axes = figure.add_subplot(1, 1, 1)

            if (event is not None) or (gridding[0] is None):
                do_gridding(first_x.Value, first_y.Value, second_x.Value,
                            second_y.Value)
            self.display_grid(background_image, gridding[0], image_set_number,
                              axes)
            canvas.draw()

        def cancel(event):
            status[0] = wx.CANCEL
            frame.SetReturnCode(wx.CANCEL)
            frame.Close(True)

        def ok(event):
            status[0] = wx.OK
            frame.SetReturnCode(wx.OK)
            frame.Close(True)

        def on_cell_selection(event):
            if cell_choice.Selection == 0:
                status_bar.SetStatusText(SELECT_FIRST_CELL)
            else:
                status_bar.SetStatusText(SELECT_SECOND_CELL)

        def do_gridding(x1, y1, x2, y2):
            try:
                gridding[0] = self.build_grid_info(
                    int(x1),
                    int(y1),
                    int(first_row.Value),
                    int(first_column.Value),
                    int(x2),
                    int(y2),
                    int(second_row.Value),
                    int(second_column.Value),
                    image_shape,
                )
            except Exception as e:
                logger.error(e.message, exc_info=True)
                status_bar.SetStatusText(e.message)
                return False
            return True

        def button_release(event):
            if event.inaxes == figure.axes[0]:
                if cell_choice.Selection == 0:
                    new_first_x = str(int(event.xdata))
                    new_first_y = str(int(event.ydata))
                    if do_gridding(new_first_x, new_first_y, second_x.Value,
                                   second_y.Value):
                        first_x.Value = new_first_x
                        first_y.Value = new_first_y
                        cell_choice.Selection = 1
                        status_bar.SetStatusText(SELECT_SECOND_CELL)
                else:
                    new_second_x = str(int(event.xdata))
                    new_second_y = str(int(event.ydata))
                    if do_gridding(first_x.Value, first_y.Value, new_second_x,
                                   new_second_y):
                        second_x.Value = new_second_x
                        second_y.Value = new_second_y
                        cell_choice.Selection = 0
                        status_bar.SetStatusText(SELECT_FIRST_CELL)
                redisplay(None)

        redisplay(None)
        frame.Fit()
        frame.Bind(wx.EVT_BUTTON, redisplay, redisplay_button)
        frame.Bind(wx.EVT_BUTTON, cancel, id=wx.CANCEL)
        frame.Bind(wx.EVT_BUTTON, ok, id=wx.OK)
        frame.Bind(wx.EVT_RADIOBOX, on_cell_selection, cell_choice)
        canvas.mpl_connect("button_release_event", button_release)
        frame.ShowModal()
        do_gridding(first_x.Value, first_y.Value, second_x.Value,
                    second_y.Value)
        frame.Destroy()
        if status[0] != wx.OK:
            raise RuntimeError("Pipeline aborted during grid editing")
        return gridding[0]
Beispiel #33
0
class TaskManager(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        box = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(box)

        self.dataDir = os.path.join(os.path.dirname(__file__), 'data/task')
        self.tasks = {}

        self.taskChoser = wx.ComboBox(self, style=wx.CB_READONLY)
        self.taskChoser.Bind(wx.EVT_COMBOBOX, self.OnSelect)
        box.Add(self.taskChoser)

        grid = wx.GridSizer(4, 2)
        box.Add(grid)

        self.taskName = wx.TextCtrl(self)

        self.appsInput = wx.TextCtrl(self)

        self.maxDistractionInput = IntCtrl(self, value=0, min=0)

        deleteButton = wx.Button(self, label='Delete')
        deleteButton.Bind(wx.EVT_BUTTON, self.OnDelete)
        cancelButton = wx.Button(self, label='Cancel')
        cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel)
        saveButton = wx.Button(self, label='Save')
        saveButton.Bind(wx.EVT_BUTTON, self.OnSave)

        grid.AddMany([(wx.StaticText(self, label='Name:'), 0, wx.EXPAND),
                      (self.taskName, 0, wx.EXPAND),
                      (wx.StaticText(self, label='Apps:'), 0, wx.EXPAND),
                      (self.appsInput, 0, wx.EXPAND),
                      (wx.StaticText(self,
                                     label='Max. Distraction:'), 0, wx.EXPAND),
                      (self.maxDistractionInput, 0, wx.EXPAND), (deleteButton),
                      (cancelButton), (saveButton)])

        self.refresh()

    def OnDelete(self, event):
        if self.taskName.GetValue():
            dlg = wx.MessageDialog(self,
                                   "Do you really want to delete this task?",
                                   "Delete " + self.taskName.GetValue(),
                                   wx.OK | wx.CANCEL)
            result = dlg.ShowModal()
            if result == wx.ID_OK:
                filePath = os.path.join(self.dataDir, self.taskName.GetValue())
                os.remove(filePath)
                del self.tasks[self.taskName.GetValue()]
                self.refresh()

    def OnSave(self, event):
        if self.taskName.GetValue():
            filePath = os.path.join(self.dataDir, self.taskName.GetValue())
            t = Task(self.taskName.GetValue(), self.appsInput.GetValue(),
                     self.maxDistractionInput.GetValue())
            t.dump(open(filePath, 'w'))
            self.tasks[self.taskName.GetValue()] = t
            self.refresh(self.taskName.GetValue())

    def OnCancel(self, event):
        self.refresh(self.taskChoser.GetValue())

    def refresh(self, selectedTask=None):
        taskList = os.listdir(self.dataDir)
        self.taskChoser.Clear()
        for name in taskList:
            self.taskChoser.Append(name)
            if name:
                filePath = os.path.join(self.dataDir, name)
                t = Task.load(open(filePath))
                f = open(filePath, 'w')
                f.write(t.dumps())
                self.tasks[name] = t
        if selectedTask:
            self.taskChoser.SetStringSelection(selectedTask)
        else:
            self.taskChoser.SetSelection(0)
        self.OnSelect(None)

    def OnSelect(self, event):
        name = self.taskChoser.GetValue()
        if name:
            self.taskName.SetValue(name)
            t = self.tasks[name]
            self.appsInput.SetValue(t.appNames)
            self.maxDistractionInput.SetValue(t.maxDistraction)
Beispiel #34
0
    def __init__(self, *args, **kwargs):
        IntCtrl.__init__(self, *args, **kwargs)

        self.__bindings()