示例#1
0
文件: gui.py 项目: lunacik/os
 def __init__(self):
     super(RMWindow, self).__init__()
     
     self.rm = RealMachine()
     self.row = self.rm.MAX_VMS * 16 + 1 
     self.column = 16
     self.vmWindow = None
     self.fileName = None
     
     QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Windows'))
     QtGui.QApplication.setPalette(QtGui.QApplication.style().standardPalette())
     
     self.setGeometry(0, 0, 870, 340)
     self.move(self.frameGeometry().topLeft())
     self.setWindowTitle('Real Machine')
     self.centralWidget = QtGui.QWidget(self)
     self.centralWidget.setEnabled(True)
     self.setCentralWidget(self.centralWidget)
     
     #---------------------------------------------------------------------
     self.init_table(self.row)
     self.init_load_btn()
     self.init_reset_btn()
     self.init_pPtr_label()
示例#2
0
文件: gui.py 项目: lunacik/os
class RMWindow(QtGui.QMainWindow):
    def __init__(self):
        super(RMWindow, self).__init__()
        
        self.rm = RealMachine()
        self.row = self.rm.MAX_VMS * 16 + 1 
        self.column = 16
        self.vmWindow = None
        self.fileName = None
        
        QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Windows'))
        QtGui.QApplication.setPalette(QtGui.QApplication.style().standardPalette())
        
        self.setGeometry(0, 0, 870, 340)
        self.move(self.frameGeometry().topLeft())
        self.setWindowTitle('Real Machine')
        self.centralWidget = QtGui.QWidget(self)
        self.centralWidget.setEnabled(True)
        self.setCentralWidget(self.centralWidget)
        
        #---------------------------------------------------------------------
        self.init_table(self.row)
        self.init_load_btn()
        self.init_reset_btn()
        self.init_pPtr_label()
        #---------------------------------------------------------------------
        
        
    def init_pPtr_label(self):
        self.pPtrLabel = QtGui.QLabel(self)
        self.pPtrLabel.setGeometry(QtCore.QRect(20, 320, 100, 20))
        self.pPtrLabel.setText("PPTR = " + str(hex(self.rm.PPTR)[2:].upper()))

    def load_btn_handler(self):
        self.show_file_dialog()
        if os.path.exists(self.fileName):
            self.rm.start_vm(self.fileName)
            self.fill_rm()
            self.vmWindow = VMWindow(self)
            self.connect(self.vmWindow, QtCore.SIGNAL("vm_win_close( QWidget * )"), self.vm_close_sig_handler)
            self.vmWindow.show()
            if int(self.rm.vm.PAGE / 256 + 1) >= self.rm.MAX_VMS:
                self.loadButton.setEnabled(False)
    
    def reset_btn_handler(self):
        self.rm.clear_mem()
        self.fill_rm()
    
    def fill_rm(self):
        for i in range(self.row):
            for j in range(self.column):
                item = QtGui.QTableWidgetItem(str(self.rm.memory[16 * i + j]))
                self.tableWidget.setItem(i, j, item)
                
    def init_table(self, row):
        self.tableWidget = QtGui.QTableWidget(self.centralWidget)
        self.tableWidget.setGeometry(QtCore.QRect(20, 20, 768, 297))
        self.tableWidget.setColumnCount(self.column)
        self.tableWidget.setRowCount(self.row)
        self.tableWidget.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
        list = []
        for i in range(row):
            list.append(str(hex(i)[2:]).upper())
        self.tableWidget.setHorizontalHeaderLabels(list)
        self.tableWidget.setVerticalHeaderLabels(list)
        self.tableWidget.horizontalHeader().setDefaultSectionSize(45)
        self.tableWidget.verticalHeader().setDefaultSectionSize(18)  
        
    def show_file_dialog(self):
        directory = QtCore.QDir.currentPath()
        fDialog = QtGui.QFileDialog()
        self.fileName, _ = fDialog.getOpenFileName(self, 'Open file', directory, "*.pr")
        
    def vm_close_sig_handler(self):
        self.rm.remove_vm(int(self.rm.vm.PAGE / 256))
        self.fill_rm()
        self.loadButton.setEnabled(True)

    def init_load_btn(self):
        self.loadButton = QtGui.QPushButton(self.centralWidget)
        self.loadButton.setGeometry(QtCore.QRect(800, 20, 50, 25))
        self.loadButton.setText("Load")
        self.loadButton.clicked.connect(self.load_btn_handler)
        
    def init_reset_btn(self):
        self.resetButton = QtGui.QPushButton(self.centralWidget)
        self.resetButton.setGeometry(QtCore.QRect(800, 45, 50, 25))
        self.resetButton.setText("Reset")
        self.resetButton.clicked.connect(self.reset_btn_handler)