コード例 #1
0
ファイル: wxgrapheditor.py プロジェクト: jaymonty/mavproxy
    def __init__(self, title, graphdef, callback):
        wx.Dialog.__init__(self, None, -1, title, size=(900, 400))

        self.callback = callback
        self.graphdef = graphdef

        self.panel = wx.Panel(self, -1)
        vbox = wx.BoxSizer(wx.VERTICAL)

        # name entry
        hbox_name = wx.BoxSizer(wx.HORIZONTAL)
        st_name = wx.StaticText(self.panel, -1, 'Name: ')
        self.tc_name = wx.TextCtrl(self.panel, -1, size=(400, -1))
        self.tc_name.Value = self.graphdef.name
        hbox_name.Add(st_name, 0, wx.LEFT, 10)
        hbox_name.Add(self.tc_name, 0, wx.LEFT, 35)
        vbox.Add(hbox_name, 0, wx.TOP, 10)

        # expression entry
        st = wx.StaticText(self.panel, -1, 'Expressions: ')
        vbox.Add(st, 0, wx.LEFT, 10)

        hbox_expressions = wx.BoxSizer(wx.HORIZONTAL)
        self.tc_expressions = wx.TextCtrl(self.panel,
                                          -1,
                                          style=wx.TE_MULTILINE | wx.HSCROLL,
                                          size=(800, 80))
        elist = []
        for e in self.graphdef.expressions:
            e = ' '.join(e.split())
            elist.append(e)
        self.tc_expressions.Value = '\n'.join(elist)
        vbox.Add(self.tc_expressions, 0, wx.LEFT, 15)

        # description entry
        st = wx.StaticText(self.panel, -1, 'Description: ')
        vbox.Add(st, 0, wx.LEFT, 10)
        self.tc_description = wx.TextCtrl(self.panel,
                                          -1,
                                          style=wx.TE_MULTILINE)
        vbox.Add(self.tc_description, 1,
                 wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, 15)
        self.tc_description.Value = self.graphdef.description

        # buttons
        button_save = wx.Button(self.panel, 1, 'Save')
        button_cancel = wx.Button(self.panel, 2, 'Cancel')
        button_test = wx.Button(self.panel, 3, 'Test')
        hbox_buttons = wx.BoxSizer(wx.HORIZONTAL)
        hbox_buttons.Add(button_save, 0, wx.LEFT, 10)
        hbox_buttons.Add(button_cancel, 0, wx.LEFT, 10)
        hbox_buttons.Add(button_test, 0, wx.LEFT, 10)
        vbox.Add(hbox_buttons, 0, wx.TOP, 10)
        self.Bind(wx.EVT_BUTTON, self.OnSave, id=1)
        self.Bind(wx.EVT_BUTTON, self.OnCancel, id=2)
        self.Bind(wx.EVT_BUTTON, self.OnTest, id=3)

        self.panel.SetSizer(vbox)
        self.Centre()
コード例 #2
0
 def on_timer(self, event):
     state = self.state
     if state.close_event.wait(0.001):
         self.timer.Stop()
         self.Destroy()
         return
     while state.child_pipe_recv.poll():
         obj = state.child_pipe_recv.recv()
         if isinstance(obj, Value):
             # request to set a status field
             if not obj.name in self.values:
                 # create a new status field
                 value = wx.StaticText(self.panel, -1, obj.text)
                 # possibly add more status rows
                 for i in range(len(self.status), obj.row + 1):
                     self.status.append(wx.BoxSizer(wx.HORIZONTAL))
                     self.vbox.Insert(len(self.status) - 1,
                                      self.status[i],
                                      0,
                                      flag=wx.ALIGN_LEFT | wx.TOP)
                     self.vbox.Layout()
                 self.status[obj.row].Add(value, border=5)
                 self.status[obj.row].AddSpacer(20)
                 self.values[obj.name] = value
             value = self.values[obj.name]
             value.SetForegroundColour(obj.fg)
             value.SetBackgroundColour(obj.bg)
             value.SetLabel(obj.text)
             self.panel.Layout()
         elif isinstance(obj, Text):
             '''request to add text to the console'''
             self.pending.append(obj)
             for p in self.pending:
                 # we're scrolled at the bottom
                 oldstyle = self.control.GetDefaultStyle()
                 style = wx.TextAttr()
                 style.SetTextColour(p.fg)
                 style.SetBackgroundColour(p.bg)
                 self.control.SetDefaultStyle(style)
                 self.control.AppendText(p.text)
                 self.control.SetDefaultStyle(oldstyle)
             self.pending = []
         elif isinstance(obj, mp_menu.MPMenuTop):
             if obj is not None:
                 self.SetMenuBar(None)
                 self.menu = obj
                 self.SetMenuBar(self.menu.wx_menu())
                 self.Bind(wx.EVT_MENU, self.on_menu)
             self.Refresh()
             self.Update()
コード例 #3
0
 def _add_input(self, setting, ctrl, ctrl2=None, value=None):
     tab_name = setting.tab
     label = setting.label
     tab = self.panel(tab_name)
     box = wx.BoxSizer(wx.HORIZONTAL)
     labelctrl = wx.StaticText(tab, -1, label)
     box.Add(labelctrl, 0, wx.ALIGN_CENTRE | wx.ALL, 5)
     box.Add(ctrl, 1, wx.ALIGN_CENTRE | wx.ALL, 5)
     if ctrl2 is not None:
         box.Add(ctrl2, 0, wx.ALIGN_CENTRE | wx.ALL, 5)
     self.sizer(tab_name).Add(box, 0,
                              wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
                              5)
     self.controls[label] = ctrl
     if value is not None:
         ctrl.Value = value
     else:
         ctrl.Value = str(setting.value)
     self.control_map[ctrl.GetId()] = label
     self.setting_map[label] = setting
コード例 #4
0
ファイル: __init__.py プロジェクト: saifullah3396/JdeRobot
    def __init__(
        self,
        option_parser,  #The OptionParser object
        parent=None,
        ID=0,
        title='Optparse Dialog',
        pos=wx.DefaultPosition,
        size=wx.DefaultSize,
        style=wx.DEFAULT_DIALOG_STYLE,
        name='OptparseDialog',
    ):

        provider = wx.SimpleHelpProvider()
        wx.HelpProvider_Set(provider)

        pre = wx.PreDialog()
        pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
        pre.Create(parent, ID, title, pos, size, style)

        self.PostCreate(pre)

        sizer = wx.BoxSizer(wx.VERTICAL)

        self.option_controls = {}

        top_label_text = '%s %s' % (option_parser.get_prog_name(),
                                    option_parser.get_version())
        label = wx.StaticText(self, -1, top_label_text)
        sizer.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        self.browse_option_map = {}

        # Add controls for all the options
        for option in option_parser.option_list:
            if option.dest is None:
                continue

            if option.help is None:
                option.help = u''

            box = wx.BoxSizer(wx.HORIZONTAL)
            if 'store' == option.action:
                label = wx.StaticText(self, -1, option.dest)
                label.SetHelpText(option.help)
                box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

                if 'choice' == option.type:
                    if optparse.NO_DEFAULT == option.default:
                        option.default = option.choices[0]
                    ctrl = wx.ComboBox(self,
                                       -1,
                                       choices=option.choices,
                                       value=option.default,
                                       style=wx.CB_DROPDOWN | wx.CB_READONLY
                                       | wx.CB_SORT)
                else:
                    if 'MULTILINE' in option.help:
                        ctrl = wx.TextCtrl(self,
                                           -1,
                                           "",
                                           size=(300, 100),
                                           style=wx.TE_MULTILINE
                                           | wx.TE_PROCESS_ENTER)
                    else:
                        ctrl = wx.TextCtrl(self, -1, "", size=(300, -1))

                    if ( option.default != optparse.NO_DEFAULT ) and \
                       ( option.default is not None ):
                        ctrl.Value = unicode(option.default)

                box.Add(ctrl, 1, wx.ALIGN_CENTRE | wx.ALL, 5)

                if option.type in ['file', 'directory']:
                    browse = wx.Button(self, label='...')
                    browse.SetHelpText('Click to open %s browser' %
                                       (option.type))
                    self.browse_option_map[browse.GetId()] = option, ctrl
                    wx.EVT_BUTTON(self, browse.GetId(), self.OnSelectPath)
                    box.Add(browse, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

            elif option.action in ('store_true', 'store_false'):
                ctrl = wx.CheckBox(self, -1, option.dest, size=(300, -1))
                box.Add(ctrl, 0, wx.ALIGN_CENTRE | wx.ALL, 5)
            else:
                raise NotImplementedError('Unknown option action: %s' %
                                          repr(option.action))

            ctrl.SetHelpText(option.help)
            sizer.Add(box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

            self.option_controls[option] = ctrl

        # Add a text control for entering args
        box = wx.BoxSizer(wx.HORIZONTAL)
        label = wx.StaticText(self, -1, 'args')
        label.SetHelpText('This is the place to enter the args')

        self.args_ctrl = wx.TextCtrl(self,
                                     -1,
                                     '',
                                     size=(-1, 100),
                                     style=wx.TE_MULTILINE
                                     | wx.TE_PROCESS_ENTER)
        self.args_ctrl.SetHelpText(
            '''Args can either be separated by a space or a newline
Args the contain spaces must be entered like so: "arg with sapce"
''')
        box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5)
        box.Add(self.args_ctrl, 1, wx.ALIGN_CENTRE | wx.ALL, 5)

        sizer.Add(box, 0,
                  wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5)

        line = wx.StaticLine(self, -1, size=(20, -1), style=wx.LI_HORIZONTAL)
        sizer.Add(line, 0,
                  wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5)

        btnsizer = wx.StdDialogButtonSizer()

        if wx.Platform != "__WXMSW__":
            btn = wx.ContextHelpButton(self)
            btnsizer.AddButton(btn)

        btn = wx.Button(self, wx.ID_OK)
        btn.SetHelpText("The OK button completes the dialog")
        btn.SetDefault()
        btnsizer.AddButton(btn)

        btn = wx.Button(self, wx.ID_CANCEL)
        btn.SetHelpText("The Cancel button cancels the dialog. (Cool, huh?)")
        btnsizer.AddButton(btn)
        btnsizer.Realize()

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

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