コード例 #1
0
ファイル: pooky.py プロジェクト: sbackus/pooky
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        # This is always the same
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Disable the stop button, enabled when you click start
        self.ui.stop.setEnabled(False)

        # Open up a file dialog
        self.filename = ""

        # Create our exec thread, separate from the GUI thread
        self.execthread = ExecThread(self)

        # Connect up the outputs and such
        self.connect(self.execthread, SIGNAL("stdin(QString)"), self.setStdin)
        self.connect(self.execthread, SIGNAL("code(QString)"), self.setCode)
        self.connect(self.execthread, SIGNAL("registers(QString)"),
                     self.setRegisters)
        self.connect(self.execthread, SIGNAL("stdout(QString)"),
                     self.setStdout)

        self.connect(self.execthread, SIGNAL("donePlaying()"),
                     self.donePlaying)
        self.connect(self.execthread, SIGNAL("clearStdout()"),
                     self.clearStdout)
コード例 #2
0
ファイル: pooky.py プロジェクト: sbackus/pooky
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        # This is always the same
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)

        # Disable the stop button, enabled when you click start
        self.ui.stop.setEnabled(False)

        # Open up a file dialog
        self.filename = ""

        # Create our exec thread, separate from the GUI thread
        self.execthread = ExecThread(self)

        # Connect up the outputs and such
        self.connect(self.execthread, SIGNAL("stdin(QString)"),
                     self.setStdin)
        self.connect(self.execthread, SIGNAL("code(QString)"), self.setCode)
        self.connect(self.execthread, SIGNAL("registers(QString)"),
                     self.setRegisters)
        self.connect(self.execthread, SIGNAL("stdout(QString)"),
                     self.setStdout)

        self.connect(self.execthread, SIGNAL("donePlaying()"),
                     self.donePlaying)
        self.connect(self.execthread, SIGNAL("clearStdout()"),
                     self.clearStdout)
コード例 #3
0
ファイル: pooky.py プロジェクト: sbackus/pooky
class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        # This is always the same
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)

        # Disable the stop button, enabled when you click start
        self.ui.stop.setEnabled(False)

        # Open up a file dialog
        self.filename = ""

        # Create our exec thread, separate from the GUI thread
        self.execthread = ExecThread(self)

        # Connect up the outputs and such
        self.connect(self.execthread, SIGNAL("stdin(QString)"),
                     self.setStdin)
        self.connect(self.execthread, SIGNAL("code(QString)"), self.setCode)
        self.connect(self.execthread, SIGNAL("registers(QString)"),
                     self.setRegisters)
        self.connect(self.execthread, SIGNAL("stdout(QString)"),
                     self.setStdout)

        self.connect(self.execthread, SIGNAL("donePlaying()"),
                     self.donePlaying)
        self.connect(self.execthread, SIGNAL("clearStdout()"),
                     self.clearStdout)


    def getFile(self):
        while True:
            filename = \
                    QtGui.QFileDialog.getOpenFileName(self, "Open", ".")
            ext = filename.split(".")[-1]
            # User hits cancel
            if filename == "":
                return False
            # Bad extension
            elif ext not in ("ook", "bf"):
                print "Valid input files must end in .ook or .bf"
            # Good extension
            else:
                break

        self.filename = filename
        self.ui.filename.setText(self.filename)

        # Start the main thread if it's not running
        if not self.execthread.isRunning():
            self.execthread.start()

        return True


    def setStdin(self, string):
        self.ui.stdin.setText(string)
    def setCode(self, string):
        self.ui.code.setText(string)
    def setRegisters(self, string):
        self.ui.registers.setText(string)
    def setStdout(self, string):
        self.ui.stdout.insertPlainText(string)
    def clearStdout(self):
        self.ui.stdout.setText("")
    def donePlaying(self):
        self.ui.start.setEnabled(True)
        self.ui.stop.setEnabled(False)
        self.ui.step.setEnabled(True)


    def on_start_released(self):
        # Button states
        #print "Start triggered"
        self.ui.start.setEnabled(False)
        self.ui.stop.setEnabled(True)
        self.ui.step.setEnabled(False)

        self.emit(SIGNAL("play()"))


    def on_stop_released(self):
        #print "Stop triggered"
        # Button states
        self.ui.start.setEnabled(True)
        self.ui.stop.setEnabled(False)
        self.ui.step.setEnabled(True)

        self.emit(SIGNAL("stop()"))


    def on_step_released(self):
        #print "Step triggered"
        self.emit(SIGNAL("step()"))


    def on_actionOpen_triggered(self, checked=None):
        if checked is None:
            return
        #print "Open triggered"
        if self.getFile():
            self.clearStdout()
            self.emit(SIGNAL("opened()"))


    def on_actionExit_triggered(self):
        sys.exit(0)
コード例 #4
0
ファイル: pooky.py プロジェクト: sbackus/pooky
class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        # This is always the same
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Disable the stop button, enabled when you click start
        self.ui.stop.setEnabled(False)

        # Open up a file dialog
        self.filename = ""

        # Create our exec thread, separate from the GUI thread
        self.execthread = ExecThread(self)

        # Connect up the outputs and such
        self.connect(self.execthread, SIGNAL("stdin(QString)"), self.setStdin)
        self.connect(self.execthread, SIGNAL("code(QString)"), self.setCode)
        self.connect(self.execthread, SIGNAL("registers(QString)"),
                     self.setRegisters)
        self.connect(self.execthread, SIGNAL("stdout(QString)"),
                     self.setStdout)

        self.connect(self.execthread, SIGNAL("donePlaying()"),
                     self.donePlaying)
        self.connect(self.execthread, SIGNAL("clearStdout()"),
                     self.clearStdout)

    def getFile(self):
        while True:
            filename = \
                    QtGui.QFileDialog.getOpenFileName(self, "Open", ".")
            ext = filename.split(".")[-1]
            # User hits cancel
            if filename == "":
                return False
            # Bad extension
            elif ext not in ("ook", "bf"):
                print "Valid input files must end in .ook or .bf"
            # Good extension
            else:
                break

        self.filename = filename
        self.ui.filename.setText(self.filename)

        # Start the main thread if it's not running
        if not self.execthread.isRunning():
            self.execthread.start()

        return True

    def setStdin(self, string):
        self.ui.stdin.setText(string)

    def setCode(self, string):
        self.ui.code.setText(string)

    def setRegisters(self, string):
        self.ui.registers.setText(string)

    def setStdout(self, string):
        self.ui.stdout.insertPlainText(string)

    def clearStdout(self):
        self.ui.stdout.setText("")

    def donePlaying(self):
        self.ui.start.setEnabled(True)
        self.ui.stop.setEnabled(False)
        self.ui.step.setEnabled(True)

    def on_start_released(self):
        # Button states
        #print "Start triggered"
        self.ui.start.setEnabled(False)
        self.ui.stop.setEnabled(True)
        self.ui.step.setEnabled(False)

        self.emit(SIGNAL("play()"))

    def on_stop_released(self):
        #print "Stop triggered"
        # Button states
        self.ui.start.setEnabled(True)
        self.ui.stop.setEnabled(False)
        self.ui.step.setEnabled(True)

        self.emit(SIGNAL("stop()"))

    def on_step_released(self):
        #print "Step triggered"
        self.emit(SIGNAL("step()"))

    def on_actionOpen_triggered(self, checked=None):
        if checked is None:
            return
        #print "Open triggered"
        if self.getFile():
            self.clearStdout()
            self.emit(SIGNAL("opened()"))

    def on_actionExit_triggered(self):
        sys.exit(0)