示例#1
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():
            try:
                obj = state.child_pipe_recv.recv()
            except EOFError:
                self.timer.Stop()
                self.Destroy()
                return

            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()
                #self.values_rest[obj.name] = {"text": obj.text, "fg": obj.fg, "bg": obj.bg, "row": obj.row}
            elif isinstance(obj, Text):
                '''request to add text to the console'''
                #self.text_rest.add({"text": obj.text, "fg": obj.fg, "bg": obj.bg})
                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()
            elif isinstance(obj, win_layout.WinLayout):
                win_layout.set_wx_window_layout(self, obj)
示例#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():
            try:
                obj = state.child_pipe_recv.recv()
            except EOFError:
                self.timer.Stop()
                self.Destroy()
                return

            if isinstance(obj, Value):
                # request to set a status field
                if obj.name not in self.values:
                    # create a new status field
                    statictextbox = wx.StaticText(self.panel, -1, obj.text)
                    font = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
                    statictextbox.SetFont(font)
                    # 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(statictextbox, border=5)
                    self.status[obj.row].AddSpacer(20)
                    self.values[obj.name] = statictextbox
                statictextbox = self.values[obj.name]
                statictextbox.SetForegroundColour(obj.fg)
                statictextbox.SetBackgroundColour(obj.bg)
                statictextbox.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()
            elif isinstance(obj, mp_menu.MPButton):
                if obj is not None:
                    newbtn = wx.Button(self.panel, label=obj.label)
                    newbtn.Bind(wx.EVT_BUTTON, self.on_button)
                    self.buttongridsizer.Add(newbtn, 0, wx.EXPAND)
                    self.buttons.append(obj)
            elif isinstance(obj, win_layout.WinLayout):
                win_layout.set_wx_window_layout(self, obj)