Example #1
0
 def startTestRun(self):
     """
     | Sets the window layout to a test layout.
     | Launches a thread that will instantiate a *Sequencer*
     | (see :ref:`label_Sequencer` and :ref:`label_SequencerThread`).
     | Sets a timer to periodically check the incoming queue.
     """
     
     self.consoleDict = {}
     self.stackedLayout.setCurrentIndex(1)
     
     ###   Launches the *SequencerThread*   ###
     self.sequencerThread = SequencerThread(self.guiApi)
     self.sequencerThread.start()
Example #2
0
class MtpGui(QtGui.QWidget):
    """
    | Takes care of providing a simple graphical user interface.
    """
    def __init__(self, parent=None):
        super(MtpGui, self).__init__(parent)
        
        self.inBoundQueue = Queue.Queue() #main inbound queue
        self.outBoundQueue = Queue.Queue() #main outbound queue, currently only for Dlg returns
        self.guiApi = MtpGuiApi(self.inBoundQueue,self.outBoundQueue)
        
        self.resize(705,628)
        self.move(400,100)
        
        self.setWindowTitle('Miselu Test Platform ['+sys.argv[3].split('.')[0]+']')
        
        ###   Sets a timer to poll the incoming queue   ###
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.checkQueue)
        self.timer.start(500)
        
        self.initLayout()
    
    
    def initLayout(self):
        """
        Initializes the layout of the window.
        """

        self.stackedLayout = QtGui.QStackedLayout()
        
        ###   Index 0   ###
        button = QtGui.QPushButton('Start Test')
        button.clicked.connect(self.startTestRun)
        l = QtGui.QVBoxLayout()
        l.setAlignment(QtCore.Qt.AlignTop)
        l.addWidget(button)
        w = QtGui.QWidget()
        w.setLayout(l)
        self.stackedLayout.addWidget(w)
        
        ###   Index 1 ###
        self.tabWidget = QtGui.QTabWidget() 
        self.stackedLayout.addWidget(self.tabWidget)
        
        self.setLayout(self.stackedLayout)
        
    def reInitLayout(self):
        self.stackedLayout.setCurrentIndex(0)
        self.stackedLayout.takeAt(1).widget().deleteLater()
        self.tabWidget = QtGui.QTabWidget() 
        self.stackedLayout.addWidget(self.tabWidget)

    def startTestRun(self):
        """
        | Sets the window layout to a test layout.
        | Launches a thread that will instantiate a *Sequencer*
        | (see :ref:`label_Sequencer` and :ref:`label_SequencerThread`).
        | Sets a timer to periodically check the incoming queue.
        """
        
        self.consoleDict = {}
        self.stackedLayout.setCurrentIndex(1)
        
        ###   Launches the *SequencerThread*   ###
        self.sequencerThread = SequencerThread(self.guiApi)
        self.sequencerThread.start()


    def addConsole(self,consoleID,consoleTitle):
        """
        Adds a new console to the tabWidget on the gui.
        
        Args:
        
        * consoleID (str): Unique identifier for console
        * consoleTitle (str): This is what is displayed on the tab
        
        Returns:
            None
        """
        self.consoleDict[consoleID] = consoleWidget(self.tabWidget)
        self.tabWidget.addTab(self.consoleDict[consoleID],consoleTitle)
       
       
    def consoleWrite(self,consoleID,s):
        """
        Writes (appends) into a console.
        
        Args:
        
        * consoleID (str): Unique identifier for the console
        * s (str): String to write
        
        Returns:
            None
        """
        
        
        ss = ''
        for i in range(len(s)):
            if ord(s[i])&0x80:
                c = '[ %0.2X ]' % ord(s[i])
                print c
            else:
                c = s[i]
            ss += c

        t = self.consoleDict[consoleID].consoleLabel
        t.setText((str(t.text())+str(ss))[-5000:])
        t.adjustSize()
        
        t = self.consoleDict[consoleID]
        t.scrollArea.verticalScrollBar().setValue(t.scrollArea.verticalScrollBar().maximum())

    def flushOutboundQueue(self):
        self.outBoundQueue.queue.clear()

    def checkQueue(self):
        """
        Reads and processes any and all messages in the incomming queue.
        """
        stop = False
        while not stop:
            try:
                entry = self.inBoundQueue.get_nowait()
                self.processQueueEntry(entry)
            except Queue.Empty:
                stop = True

                
    def processQueueEntry(self,entry):
        """
        Processes the entry. That is executes the command requested.
        
        Args:
        
        * entry (dict): A dictionary with the data required to process such message
            * It always should contain at least the key *command*
            * The other contents of entry depend on the command itself
        
        Returns:
            None
        """
        if entry['command']=='addConsole':
    
            self.addConsole(entry['consoleID'],entry['title'])
        
        elif entry['command']=='consoleWrite':
            if (entry['consoleID'] in self.consoleDict.keys() ):
                self.consoleWrite(entry['consoleID'],entry['text'])
      
        elif entry['command']=='pDialog':
            entry.pop('command')
            entry['queue']=self.outBoundQueue
            entry['parent'] = self
            self.dialogWindow = Window_pDialog(**entry)
            self.dialogWindow.show()
        
        elif entry['command']=='closeDialogBox':
            self.dialogWindow.close()            
        
        elif entry['command']=='reInitLayout':
            self.reInitLayout()
        
        elif entry['command']=='processEvents':
            QtGui.QApplication.processEvents()
        
        elif entry['command']=='flushOutboundQueue':
            self.flushOutboundQueue()
        
        elif entry['command']=='init':
            self.flushOutboundQueue()
            
        elif entry['command']=='webKitWindow':
            entry.pop('command')
            self.webKitWindow = Window_webKit(**entry)
            self.webKitWindow.show()
        
        elif entry['command']=='webKitWindow2':
            entry.pop('command')
            entry['queue']=self.outBoundQueue
            entry['parent'] = self
            self.webKitWindow = Window_webKit_2(**entry)
            self.webKitWindow.show()
       
       
        elif entry['command']=='webKitWindow_reload':
            self.webKitWindow.reload()
        
        
        elif entry['command']=='webKitWindow_change':
            entry.pop('command')
            self.webKitWindow.html = entry ['html']
            self.webKitWindow.urlBase = entry['urlBase']
            self.webKitWindow.reload()
        
            
        elif entry['command']=='closeWebKitWindow':
            self.webKitWindow.close()            
            
        else:
            raise Exception('Invalid command:'+entry['command'])