Example #1
0
    def update(self, message):
        """
        Trigerred by FacemovieThread.
        Uses the Observer pattern to inform the user about the progress of the current job.
        """
        if len(message) == 3:
            # notifications
            ##self.console_logger.debug(message)
            self.my_logger.debug(message)

            if message[0] == "PROGRESS":  # progress bar
                # big steps performed
                wx.MutexGuiEnter()  # to avoid thread problems
                self.progressgauge.SetValue(self.gaugerange *
                                            float(message[2]))
                self.statusbar.SetStatusText(message[1], 0)
                wx.MutexGuiLeave()

                if float(message[2]) >= 1.0:  # 100% of process
                    self.my_logger.debug("Reached end of facemovie process")
                    ##self.console_logger.debug("Reached end of facemovie process")
                    self.process_running = False

            elif message[0] == "STATUS":  # status label
                if message[1] == "Error":
                    wx.MutexGuiEnter()  # to avoid thread problems
                    self.statusbar.SetStatusText("Error detected", 0)
                    self.progressgauge.SetValue(0)
                    wx.MutexGuiLeave()
                    self.process_running = False

                wx.MutexGuiEnter()  # to avoid thread problems
                self.statusbar.SetStatusText(message[1], 1)
                wx.MutexGuiLeave()
            elif message[0] == "FILEADD":
                item = wx.ListItem()
                item.SetText(message[1])
                wx.MutexGuiEnter()  # to avoid thread problems
                self.filelist.InsertItem(item)
                wx.MutexGuiLeave()
            elif message[0] == "FILEDONE":
                for i in range(self.filelist.GetItemCount()):
                    if message[1] == self.filelist.GetItemText(i):
                        if message[2] == 1:
                            color = "green"
                        else:
                            color = "red"
                        wx.MutexGuiEnter()  # to avoid thread problems
                        self.filelist.SetItemTextColour(i, color)
                        wx.MutexGuiLeave()

        elif len(message) > 1:  # system commands shall be ignored
            #self.console_logger.debug("Unrecognized command")
            self.my_logger.debug("Unrecognized command")
            #self.console_logger.debug(message)
            self.my_logger.debug(message)
Example #2
0
 def run(self):
     try:
         self.message = " " + self.username + " : " + self.message + '\n'
         self.connection.send(self.message)
         wx.MutexGuiEnter()
         Publisher().sendMessage("PrintMsg", self.message)
         wx.MutexGuiLeave()
         
     except Exception, e:
         wx.MutexGuiEnter()
         Publisher().sendMessage("PrintMsg", str(e))
         wx.MutexGuiLeave()
Example #3
0
    def asyncWrite(self, text):
        '''
        Write given text to buffer in an asynchroneous way.
        It is used from another thread to be able to acces the GUI.
        @param text: Text to append
        @type text: string
        '''
        try:
            wx.MutexGuiEnter()

            #be sure not to be interrutpted before the MutexGuiLeave!
            self.write(text)

        except KeyboardInterrupt:
            wx.MutexGuiLeave()
            raise KeyboardInterrupt
        wx.MutexGuiLeave()
Example #4
0
 def asyncWrite(self, text):
     '''
     Write given text to buffer in an asynchroneous way.
     It is used from another thread to be able to acces the GUI.
     @param text: Text to append
     @type text: string
     '''
     try:
         #print >>sys.__stdout__,'entering'
         wx.MutexGuiEnter()
         #print >>sys.__stdout__,'locking the GUI'
             
         #be sure not to be interrutpted before the MutexGuiLeave!
         self.write(text)
             
         #print >>sys.__stdout__,'done'
             
     except KeyboardInterrupt:
         #print >>sys.__stdout__,'got keyboard interrupt'
         wx.MutexGuiLeave()
         #print >>sys.__stdout__,'interrupt unlock the GUI'
         raise KeyboardInterrupt
     wx.MutexGuiLeave()
Example #5
0
    def __listen_for_commands(self):

        #this loop gets broken when self.exit() gets called since the
        #connection will get closed causing the recv() call to raise an
        #EOF exception and exit the thread
        while True:
            try:
                cmd = self.__connection.recv()

            except EOFError:
                return

            #try:
            try:
                wx.MutexGuiEnter()
                self.__execute_command(cmd)
            except:
                remote_ex = _RemoteException(*sys.exc_info())
                self.__connection.send(remote_ex)
                continue
            finally:
                wx.MutexGuiLeave()

            self.__connection.send(CMD_RECV_ACKNOWLEDGEMENT)
Example #6
0
    def _openFile(self, read, use_gauge=False, read_buf=CHUNK_SIZE):
        def addTreeItem(parent, event_list, caption, data, absolute_tic,
                        child_list):
            SetItemText = event_list.SetItemText
            SetItemImage = event_list.SetItemImage
            tree_item = event_list.AppendItem(parent, caption)
            SetItemText(tree_item, tic_to_time(absolute_tic), 0)
            for column, caption in enumerate(data, 2):
                SetItemText(tree_item, caption, column)
            if child_list:
                SetItemImage(tree_item,
                             self._folderClosed,
                             which=wx.TreeItemIcon_Normal)
                SetItemImage(tree_item,
                             self._folderOpened,
                             which=wx.TreeItemIcon_Expanded)
            else:
                SetItemImage(tree_item,
                             self._file,
                             which=wx.TreeItemIcon_Normal)
            for (child_caption, child_data, child_absolute_tic,
                 grand_child_list) in child_list:
                addTreeItem(tree_item, event_list, child_caption, child_data,
                            child_absolute_tic, grand_child_list)

        tree_list = deque()

        def flushTreeList():
            pop = tree_list.popleft
            while True:
                try:
                    args, kw = pop()
                except IndexError:
                    break
                addTreeItem(args[0].GetRootItem(), *args, **kw)

        def addBaseTreeItem(*args, **kw):
            need_reschedule = not tree_list
            tree_list.append((args, kw))
            if need_reschedule:
                maybeCallAfter(flushTreeList)

        def captureEvent(tic, event_type, data):
            if event_type == MESSAGE_RAW:
                addBaseTreeItem(self.capture_list, data, (), tic, ())
            elif event_type == MESSAGE_RESET:
                addBaseTreeItem(self.bus_list,
                                'Reset (%s)' % (short_tic_to_time(data), ), (),
                                tic, ())
            else:
                raise NotImplementedError(event_type)

        captureEvent.stop = lambda: None
        captureEvent.push = captureEvent

        def busEvent(tic, event_type, data):
            assert event_type == MESSAGE_TRANSACTION, event_type
            assert len(data) == 1, data
            addBaseTreeItem(self.bus_list,
                            'SOF %i' % (decode(data[0])['frame'], ), (), tic,
                            ())

        busEvent.stop = lambda: None
        busEvent.push = busEvent

        def newHub(address):
            maybeCallAfter(self._newHub, address)
            return HubEventListManager(self, address, None, addBaseTreeItem)

        error_push = EndpointEventListManager(None,
                                              None,
                                              None,
                                              addBaseTreeItem,
                                              event_list=self.error_list).push

        def newPipe(address, endpoint):
            maybeCallAfter(self._newEndpoint, address, endpoint)
            result = EndpointEventListManager(self, address, endpoint,
                                              addBaseTreeItem)
            if endpoint == 0:
                result = Endpoint0TransferAggregator(result, error_push)
            return result

        update_delta = self.load_gauge.GetRange() / 100
        read_length = last_update = 0
        stream = ReorderedStream(
            Packetiser(
                TransactionAggregator(
                    PipeAggregator(
                        busEvent,
                        error_push,
                        newHub,
                        newPipe,
                    ),
                    error_push,
                ),
                captureEvent,
            ))
        parse = stream.push
        if use_gauge:
            gauge = self.load_gauge
            SetGaugeValue = gauge.SetValue
        while True:
            data = read(read_buf)
            if not data:
                break
            if use_gauge:
                read_length += len(data)
                if read_length > last_update + update_delta:
                    sys.stdout.write('.')
                    sys.stdout.flush()
                    last_update = read_length
                    # Side effect: causes a gui refresh, flushing "CallAfter" queue.
                    wx.MutexGuiEnter()
                    try:
                        SetGaugeValue(read_length)
                    finally:
                        wx.MutexGuiLeave()
            try:
                parse(data)
            except ParsingDone:
                break
        maybeCallAfter(flushTreeList)
        stream.stop()
        if use_gauge:
            maybeCallAfter(gauge.Show, False)
Example #7
0
 def MainThreadMutexGuiLeave(self):
     wx.MutexGuiLeave()
Example #8
0
 def run(self):
     while 1:
         data = self.connection.recv(1024)
         wx.MutexGuiEnter()
         Publisher().sendMessage("PrintMsg", data)
         wx.MutexGuiLeave()