Beispiel #1
0
class CurrencyConv(QtWidgets.QMainWindow):
    def __init__(self):
        super(CurrencyConv, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.init_UI()

    def init_UI(self):
        self.setWindowTitle('Currency Converter')
        self.setWindowIcon(QIcon('icon.png'))

        self.ui.input_currency.setPlaceholderText('From currency: ')
        self.ui.input_amount.setPlaceholderText('I got: ')
        self.ui.output_currency.setPlaceholderText('To currency: ')
        self.ui.output_amount.setPlaceholderText('I\'ll get: ')
        self.ui.pushButton.clicked.connect(self.converter)

    def converter(self):
        c = CurrencyConverter()
        input_currency = self.ui.input_currency.text()
        output_currency = self.ui.output_currency.text()
        input_amount = int(self.ui.input_amount.text())
        
        output_amount = round(c.convert(input_amount, '%s' % (input_currency), '%s' % (output_currency)), 2)

        self.ui.output_amount.setText(str(output_amount))
Beispiel #2
0
    def __init__(self):

        # Controller Thread Variable (z.B. um den Thread zu beenden)
        self.con_Thread_var = True

        # Client
        self.client = None

        # Connected Thread Variable
        self.connected = False

        # initialise controller
        self.controller1 = Controller()

        # Data to be packed and processed
        self.direction = 0
        self.leghight = 0
        self.velocity = 0

        # Create window
        super(MyWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Connect button
        self.ui.connectButton.clicked.connect(self.connect)

        # Threads
        self.con_thread = Thread(target=self.conReact, args=())
        self.con_thread.start()
        self.data_thread = Thread(target=self.dataReact, args=())
        self.data_thread.start()
        self.send_thread = Thread(target=self.sendReact, args=())
Beispiel #3
0
 def __init__(self):
     super(ApplicationWindow, self).__init__()
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     ######## create html file #######
     file = open("graph.html", "w")
     file.close()
     ############Preprocessing #################
     self.dataset1 = pd.read_csv('covid_19_clean_complete.csv')
     self.dataset2 = pd.read_csv('COVID19_line_list_data.csv')
     self.dataset1 = self.dataset1.iloc[:1000, :]
     # replacing Mainland china with just China
     self.dataset1['Country/Region'] = self.dataset1[
         'Country/Region'].replace('Mainland China', 'China')
     # Replace missing values with a number
     self.dataset1["Province/State"].fillna("Not Found", inplace=True)
     self.dataset2["gender"].fillna("Not Found", inplace=True)
     ########Connections ############
     list_buttons = [
         self.ui.comboBox, self.ui.comboBox, self.ui.comboBox,
         self.ui.comboBoxMap, self.ui.comboBox_lengthBar,
         self.ui.comboBox_SortBars, self.ui.comboBox_lengthBar
     ]
     list_fns = [
         self.visual_options, self.sorted_comboBox, self.map_control,
         self.map_control, self.comboBoxBar_control, self.sorted_comboBox,
         self.sorted_comboBox
     ]
     for i in range(len(list_buttons)):
         list_buttons[i].currentIndexChanged.connect(list_fns[i])
Beispiel #4
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowTitle('Code-to-Html')
        self.setWindowIcon(QIcon('pic/icon.png'))

        # StyleSheet
        self.setStyleSheet('''
        QMainWindow{background-color:
        qlineargradient(spread:
        pad, x1:0, y1:0.5, x2:1, y2:0.5,
        stop:0 rgb(255, 255, 255),
        stop:1 rgb(150, 150, 150));}
        ''')

        # Highlight class
        self.highlight = Highlight()

        # ComboBox
        all_langs = self.highlight.return_all_languages()
        all_styles = self.highlight.return_all_styles()
        self.ui.comboBox.addItems(all_langs)
        self.ui.comboBox_2.addItems(all_styles)

        # Button
        self.ui.pushButton.clicked.connect(self.convertEvent)
Beispiel #5
0
	def __init__ (self, rpc, rpcworker, params, parent = None):
		QtGui.QMainWindow.__init__ (self, parent)

		self.rpc = rpc
		self.rpcworker = rpcworker
		self.rpcworker.lostconnection.connect (self.lostconnection)
		self.params = params

		self.ui = Ui_MainWindow()
		self.ui.setupUi (self)
		self.setWindowFlags (QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowMinimizeButtonHint)

		self.setWindowTitle (self.tr ("Cartoon Encoding and Uploading Platform"))
		self.setWindowIcon (QtGui.QIcon (':/images/icon.png'))

		self.createActions()
		self.createplayer()
		self.createmerger()
		self.createUIdetails()
		self.creategobject()

		self.transcoding = list()
		self.translisting = TransTaskProcessing
		self.mergelist = list()
		self.checkers = list()
		self.splitchoose = SplitNotChosen
		self.playerfile = None

		self.leftclicked = False
    def btn_functionality(self):
        self.MainWindow = QMainWindow()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self.MainWindow)

        self.ui.pushButton_Run.clicked.connect(self.get_comboBox_info)
        self.ui.pushButton_GoToFolder.clicked.connect(self.go_to_folder)
    def __init__(self):
        super(myWindow, self).__init__()
        self.myCommand = " "
        self.setWindowIcon(QtGui.QIcon('two.ico'))
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.firstFit_bar.triggered.connect(self.firstFitbar_recognize)  # firstFit模式触发
        self.ui.bestFit_bar.triggered.connect(self.bestFitbar_recognize)  # bestFit模式触发
        self.ui.text_btn.clicked.connect(self.text_changed)  # 文本框输入确认按钮连接文本处理函数
        self.ui.textbox.returnPressed.connect(self.text_changed)  # 文本框输入响应enter键
        self.ui.clear_btn.clicked.connect(self.clear)  # Reset按钮连接重置内存空间函数

        for i in range(0, 64):
            self.ui.btnGroup[i].clicked.connect(
                partial(self.addNode, 10*(i+1)))
        self.isbestFit = False  # 标志是否选择bestFit识别
        self.workNumber = 0  # 作业个数
        self.nodeList = []  # 结点链表
        # 初始化,将640k视为一个空结点
        self.nodeList.insert(0, {'number': -1,  # 非作业结点
                                 'start': 0,  # 开始为0
                                 'length': 640,  # 长度为640
                                 'isnull': True})  # 空闲
        # 加入一个非作业btn
        self.nodeList[0]['btn'] = self.addButton(self.nodeList[0])
Beispiel #8
0
    def btn_functionality(self):
        self.MainWindow = QMainWindow()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self.MainWindow)

        self.ui.pushButton_Run.clicked.connect(self.get_comboBox_info)
        self.ui.pushButton_Clear.clicked.connect(self.clear_texteditbox)
        self.ui.pushButton_Save.clicked.connect(self.file_save)
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.Q1 = Image_Processing()
        self.Q2 = Image_Smoothing()
        self.Q3 = Edge_Detection()

        self.ui.setupUi(self)
        self.show()
Beispiel #10
0
    def __init__(self, parent=None):
        # os.chdir(mainpath);
        super(MainWindow, self).__init__(parent)
        # self.status = self.statusBar()
        # self.status.showMessage("This is StatusBar",5000)
        # self.setWindowTitle("PyQt MianWindow")
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        #print "self=",self
        #print "self.dir=",dir(self)
        #cls=getattr(WebConfig,"%s_Cfg"%product)

        #根据WebConfig模块里面的类名*_Cfg 更新下拉表单的数据
        pi = 0
        for item in dir(WebConfig):
            rm = re.search("_Cfg", item)
            if rm is not None and item != "WEB_Cfg":
                self.ui.dut_type.setItemText(
                    pi, _translate("MainWindow",
                                   item.split("_")[0], None))
                self.ui.cmp_type.setItemText(
                    pi, _translate("MainWindow",
                                   item.split("_")[0], None))
                pi = pi + 1

        #将sys.stdout的write函数重写为Redirect的write函数,Redirect重定向到testlog框
        #需重点理解

        self.stdout = Redirect(self.ui.testlog)
        sys.stdout = self.stdout

        #初始化树
        self.init_tree()

        #加载配置文件
        self.configfile = os.path.join(mainpath, "config.ini")
        self.selectfile = os.path.join(mainpath, "selected.ini")
        self.load_config()

        #设置UI界面连接
        self.ui.btn_save.clicked.connect(self.save_config)
        self.ui.btn_auto.clicked.connect(self.get_auto)
        self.ui.btn_tcl.clicked.connect(self.get_tcl)
        self.ui.btn_python.clicked.connect(self.get_python)
        self.ui.btn_run.clicked.connect(self.run_test)
        self.ui.btn_log.clicked.connect(self.set_log)
        self.ui.btn_stop.clicked.connect(self.run_stop)
        self.ui.rep_btn.clicked.connect(self.make_test_report)

        self.init_login()
        #print "product_cmp=%s"%self.product_cmp
        #print "login="******""
Beispiel #11
0
 def __init__(self):
     QMainWindow.__init__(self)
     Ui_MainWindow.__init__(self)
     self.setupUi(self)
     self.setWindowTitle("人臉特徵點小工具")
     self.btn_load_pic.clicked.connect(self.load_image_to_pic_view_1)
     self.btn_load_landmarks.clicked.connect(self.load_landmarks_by_file)
     self.btn_export_landmarks.clicked.connect(self.save_landmarks_by_file)
     self.btn_delete_last_point.clicked.connect(self.delete_last_point)
     self.set_default()
Beispiel #12
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Icon
        byte_data = b64decode(icon)
        image_data = BytesIO(byte_data)
        image = Image.open(image_data)
        image = image.convert('RGBA')
        qImage = ImageQt.ImageQt(image)
        image = QPixmap.fromImage(qImage)
        self.setWindowIcon(QIcon(image))

        # Hide Window Title
        self.setFixedSize(self.width(), self.height())
        self.setWindowFlag(Qt.FramelessWindowHint)
        self.setWindowOpacity(0.9)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setCursor(Qt.CrossCursor)
        self.screenWidth = QDesktopWidget().screenGeometry().width()
        self.screenHeight = QDesktopWidget().screenGeometry().height()

        # LCD
        self.ui.lcdNumber.setDigitCount(8)
        self.ui.lcdNumber.display('00:00:00')

        # Button
        self.start = True
        self.sec = 0
        self.timer = QTimer()
        self.timer.timeout.connect(self.LCDEvent)
        self.ui.pushButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
        self.ui.pushButton.clicked.connect(self.timeGo)
        self.ui.pushButton_2.setIcon(self.style().standardIcon(QStyle.SP_MediaStop))
        self.ui.pushButton_2.clicked.connect(self.initTime)
        self.ui.pushButton_3.setIcon(self.style().standardIcon(QStyle.SP_DialogCancelButton))
        self.ui.pushButton_3.clicked.connect(self.exitEvent)

        # Shortcut
        self.startShortcut = QShortcut(QKeySequence("Ctrl+s"), self)
        self.startShortcut.activated.connect(self.timeGo)

        self.leftMove = QShortcut(QKeySequence("Ctrl+left"), self)
        self.rightMove = QShortcut(QKeySequence("Ctrl+right"), self)
        self.upMove = QShortcut(QKeySequence("Ctrl+up"), self)
        self.downMove = QShortcut(QKeySequence("Ctrl+down"), self)

        self.leftMove.activated.connect(lambda: self.shortcutMoveEvent('left'))
        self.rightMove.activated.connect(lambda: self.shortcutMoveEvent('right'))
        self.upMove.activated.connect(lambda: self.shortcutMoveEvent('up'))
        self.downMove.activated.connect(lambda: self.shortcutMoveEvent('down'))

        self.exit = QShortcut(QKeySequence("Ctrl+D"), self)
        self.exit.activated.connect(self.exitEvent)
	def __init__(self, samp_T_us, cpi_samps, savefile, emulate=False):
		"""
		PURPOSE: creates a new Speed_Gun
		ARGS: 
			samp_T_us (float): sampling period in microseconds
			cpi_samps (int): number of samples in one cpi
			emulate (bool): if True loads pre-recorded data, if False runs for 
				real
			savefile (str): the file to save to
		RETURNS: new instance of a Speed_Gun
		NOTES:
		"""
		#Save arguments
		self.samp_T_us = samp_T_us
		self.fs = 1e6 / samp_T_us
		self.cpi_samps = cpi_samps
		self.emulate = emulate
		self.savefile = savefile

		#Setup app
		self.app = QtWidgets.QApplication(sys.argv)
		self.main_win = QtWidgets.QMainWindow()
		self.ui = Ui_MainWindow()
		self.ui.setupUi(self.main_win)

		#Initialize UI values
		self.init_ui_values()

		#Connect buttons
		self.ui.run_button.clicked.connect(self.run_button_clicked)
		self.ui.stop_button.clicked.connect(self.stop_button_clicked)
		self.ui.vel_radbutton.toggled.connect(self.rad_button_toggled)
		self.ui.raw_sig_radbutton.toggled.connect(self.rad_button_toggled)

		#Setup queues
		self.record_q = queue.Queue()
		self.res_q = queue.Queue()
		self.save_q = queue.Queue()

		#Setup other modules
		#Setup recorder.replayer
		if emulate:
			self.recorder = Replayer("C:\\Users\\rga0230\\Documents\\School\\EE-137\\EE-137-Doppler-Radar\\data\\car.mat", [self.record_q, self.save_q], ts_us=samp_T_us, chunk_size=cpi_samps)
		else:
			self.recorder = Chunked_Arduino_ADC(samp_T_us, cpi_samps, [self.record_q, self.save_q])
		#Setup processor
		self.proc = Processor(samp_T_us, cpi_samps, self.record_q, self.res_q)
		#Setup saver
		self.saver = Chunk_Saver(savefile, samp_T_us, cpi_samps, self.save_q)

		#Setup variables for our update thread
		self.update_thread = threading.Thread(target = self.update_thread_run)
		self.update_keep_going = threading.Event()
		self.update_keep_going.set()
Beispiel #14
0
 def __init__(self, parent=None):
     super(MainWindow, self).__init__(parent)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.ui.Reg_Button.clicked.connect(self.registration)
     self.ui.Book_issuance_pushButton.clicked.connect(self.book_issuance)
     self.ui.Add_books_Button.clicked.connect(self.add_book)
     self.ui.Recovery_book_pushButton.clicked.connect(self.book_return)
     self.funcs = funcs.add()
     self.dialog = DIALOG(self.ui.UDC_label)
     self.ui.UDC_pushButton.clicked.connect(self.UDC_B)
     self.update_table()
Beispiel #15
0
 def __init__(self):
     QMainWindow.__init__(self)
     Ui_MainWindow.__init__(self)
     super().__init__()
     self.dirname = os.path.dirname(os.path.abspath(__file__))
     self.core = Engine()
     self.settings=QSettings(os.path.join(self.dirname,"setting.ini"),QSettings.IniFormat)
     self.setupUi(self)
     self.initAction()
     self.show()
     self.projectFile = None
     if sys.argv.__len__() > 1:
         self.loadProjectFile(sys.argv[-1])
Beispiel #16
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowTitle('Code-to-Html')
        self.setWindowIcon(QIcon('pic/icon.png'))

        # StyleSheet
        self.setStyleSheet('''
        QMainWindow{background-color:
        qlineargradient(spread:
        pad, x1:0, y1:0.5, x2:1, y2:0.5,
        stop:0 rgb(255, 255, 255),
        stop:1 rgb(150, 150, 150));}
        ''')

        # Highlight class
        self.highlight = Highlight()

        # ComboBox
        all_langs = self.highlight.return_all_languages()
        all_styles = self.highlight.return_all_styles()
        self.ui.comboBox.addItems(all_langs)
        self.ui.comboBox_2.addItems(all_styles)

        # Button
        self.ui.pushButton.clicked.connect(self.convertEvent)

    # Convert the input code to html text
    def convertEvent(self):
        code = self.ui.plainTextEdit.toPlainText()
        code = self.highlightEvent(code)
        self.ui.textBrowser.setHtml(
            re.findall("(.*)<textarea readonly id=", code, re.DOTALL)[0])
        self.ui.plainTextEdit_2.setPlainText(code)
        self.ui.plainTextEdit_2.selectAll()
        self.ui.plainTextEdit_2.copy()

        # Fresh
        self.ui.plainTextEdit_2.repaint()
        self.ui.textBrowser.repaint()

    # Using highlight class to highlight the code
    def highlightEvent(self, code):
        lexer = self.ui.comboBox.currentText()
        style = self.ui.comboBox_2.currentText()
        results = self.highlight.highlightEvent(code, style, lexer,
                                                self.ui.checkBox.isChecked())

        return results
Beispiel #17
0
 def __init__(self, parent=None):
     QtWidgets.QWidget.__init__(self, parent)
     global fs, data , gainArray
     self.flag = 2
     self.UI=Ui_MainWindow()
     self.UI.setupUi(self)
     self.UI.Popupwindow.triggered.connect(self.newwindowfunc)
     self.UI.Hanning.triggered.connect(self.Hanningfunc)
     self.UI.Rect.triggered.connect(self.Rectfunc)
     self.UI.Hamming.triggered.connect(self.Hammingfunc)
     self.UI.OpenAction.triggered.connect(self.OpenFile)
     self.UI.playAction.triggered.connect(self.Play)
     self.UI.stopAction.triggered.connect(self.stop)
     self.UI.save.triggered.connect(self.savefunc)
     self.loopslider()
Beispiel #18
0
     def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        
        self.le = QLineEdit()
        self.le.setObjectName("host")
        self.le.setText("Host")

        self.pb = QPushButton()
        self.pb.setObjectName("connect")
        self.pb.setText("Connect")
        
        self.connect(self.ui.pushButton1_0, SIGNAL("clicked()"),self.button_display_orginal_model)
        self.connect(self.ui.pushButton1_1, SIGNAL("clicked()"),self.button_edit_orginal_model)
        self.connect(self.ui.pushButton1_2, SIGNAL("clicked()"),self.button_view_orginal_model)
        self.connect(self.ui.pushButton2_0, SIGNAL("clicked()"),self.button_generate_species)
        self.connect(self.ui.pushButton2_1, SIGNAL("clicked()"),self.button_edit_species)
        self.connect(self.ui.pushButton2_2, SIGNAL("clicked()"),self.button_view_species)
        self.connect(self.ui.pushButton3_0, SIGNAL("clicked()"),self.button_generate_atomic_refinment)
        self.connect(self.ui.pushButton3_1, SIGNAL("clicked()"),self.button_edit_atomic_refinment)
        self.connect(self.ui.pushButton3_2, SIGNAL("clicked()"),self.button_view_atomic_refinment)
        self.connect(self.ui.pushButton4_0, SIGNAL("clicked()"),self.button_generate_complex_refinment)
        self.connect(self.ui.pushButton4_1, SIGNAL("clicked()"),self.button_edit_complex_refinment)
        self.connect(self.ui.pushButton4_2, SIGNAL("clicked()"),self.button_view_complex_refinment)
        self.connect(self.ui.pushButton5_0, SIGNAL("clicked()"),self.button_generate_refined_model)
        self.connect(self.ui.pushButton5_1, SIGNAL("clicked()"),self.button_display_refined_model)
        self.connect(self.ui.pushButton5_2, SIGNAL("clicked()"),self.button_view_refined_model)
Beispiel #19
0
    def __init__(self, root):
        Ui_MainWindow.__init__(root)
        self.root = root
        self.setupUi(root)
        # vars
        self.current_filename = None
        #
        self.associate_actions()

        #infos
        self.type_collector_errors = []
        self.type_builder_errors = []
        self.type_checker_errors = []
        self.type_inferer_errors = []
        self.context = None
        self.scope = None
        self.ast = None
Beispiel #20
0
 def __init__(self, parent=None):
     global logDir, logDirPath
     super(MyMain, self).__init__(parent)
     self.setObjectName('MainWindow')
     self.Success = False
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.initPath()
     self.ui.logPathEdit.setText(logDir)
     self.ui.chooseLocation.clicked.connect(self.choose)
     self.ui.startButton.clicked.connect(self.start_download)
     self.ui.pause_button.clicked.connect(self.pause_download)
     self.ui.stopButton.clicked.connect(self.stop_download)
     self.ui.pushButton.clicked.connect(self.setting)
     self.ui.chooseBT.clicked.connect(self.logPath)
     self.ui.log_button.clicked.connect(self.showLog)
     self.multidownload = MultiThreadDownload(self.show_download_info)
     self.multidownload.download_info_signal.connect(
         self.show_download_info)
    def __init__(self, **kwargs):
        super(Pmeter, self).__init__()
        # -- setup the UI --
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.ui.P_IN = myQLabel('In. Pwr')
        self.ui.P_IN.setObjectName("P_IN")
        self.ui.P_IN.setAlignment(Qt.AlignCenter)
        self.ui.pin_frame.addWidget(self.ui.P_IN)

        self.ui.P_OUT = myQLabel('Outp. Pwr')
        self.ui.P_OUT.setObjectName("P_OUT")
        self.ui.P_OUT.setAlignment(Qt.AlignCenter)
        self.ui.pout_frame.addWidget(self.ui.P_OUT)

        self.SetupDict()
        self.GetConnectedRessources()

        self.but_connect['in'].clicked.connect(lambda: self.Connect('in'))
        self.but_connect['out'].clicked.connect(lambda: self.Connect('out'))
Beispiel #22
0
    def __init__(self):
        # Init the objects.
        QtWidgets.QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        InceptionV3.__init__(self)
        BCNN.__init__(self)

        # Set up the UI.
        self.setupUi(self)

        # member variables.
        self.imagepath = ''
        self.classname = ''
        self.classID = -1
        self.prdclassname = ''
        self.totalCount = 0
        self.rightCount = 0
        self.wrongCount = 0
        self.accuracy = 0.0

        # Init our customized UI & add functions to it.
        self.initUI()
Beispiel #23
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.initialArrowIcon()
        self.setFixedSize(self.size())

        # Add pLabel & delete old QLabel
        self.label_image_original = dLabel(self.ui.centralwidget, self)
        self.label_image_original.setGeometry(
            QRect(self.ui.label_image_original.pos(),
                  self.ui.label_image_original.size()))

        del self.ui.label_image_original

        # Button
        self.ui.pushButton_upload.clicked.connect(self.openFileEvent)
        self.ui.pushButton_exit.clicked.connect(self.exitEvent)
        self.ui.pushButton_save.clicked.connect(self.saveEvent)

        # Slider
        self.ui.horizontalSlider_R.setDisabled(True)
        self.ui.horizontalSlider_G.setDisabled(True)
        self.ui.horizontalSlider_B.setDisabled(True)

        self.ui.horizontalSlider_R.setMaximum(255)
        self.ui.horizontalSlider_G.setMaximum(255)
        self.ui.horizontalSlider_B.setMaximum(255)
        self.ui.horizontalSlider_R.valueChanged.connect(
            lambda: self.color_value('R'))
        self.ui.horizontalSlider_G.valueChanged.connect(
            lambda: self.color_value('G'))
        self.ui.horizontalSlider_B.valueChanged.connect(
            lambda: self.color_value('B'))

        # LineEdit
        self.ui.lineEdit_R.textChanged.connect(self.color_change)
        self.ui.lineEdit_G.textChanged.connect(self.color_change)
        self.ui.lineEdit_B.textChanged.connect(self.color_change)
Beispiel #24
0
 def __init__(self, initialPeer, ttl=2, maxKnownPeers=5, initialPeerPort=1234, parent=None):
     QtGui.QWidget.__init__(self, parent)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     initialPeerHostName, initialPeerPort = initialPeer.split(':')
     self.peerHandler = P2PMessageHandler(maxKnownPeers, initialPeerPort, initialPeerHostName)
     t = threading.Thread(target=self.peerHandler.listenForConnections, args=[])
     t.start()
     self.peerHandler.buildPeerList(initialPeerHostName, int(initialPeerPort), ttl)
     self.updatePeers()
     QtCore.QObject.connect(self.ui.btn_download, QtCore.SIGNAL('clicked()'), self.onDownloadClicked)
     QtCore.QObject.connect(self.ui.btn_addFile, QtCore.SIGNAL('clicked()'), self.onAddFileClicked)
     QtCore.QObject.connect(self.ui.btn_Search, QtCore.SIGNAL('clicked()'), self.onSearchClicked)
     QtCore.QObject.connect(self.ui.btn_refresh, QtCore.SIGNAL('clicked()'), self.onRefreshClicked)
Beispiel #25
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.MoveToScreenCenter()

        #-stable---------------------------------------------------------------------------
        self.currentDIR = os.path.dirname(os.path.realpath(__file__))

        self.db = QSqlDatabase.addDatabase("QSQLITE")
        self.db.setDatabaseName(os.path.join(self.currentDIR, "data.db"))
        if self.db.open():
            print "Open data.db successfully"
        else:
            print "Could not open data.db"
        self.CX = sqlite3.connect("data.db")
        self.CU = self.CX.cursor()

        self.tree1 = self.ui.treeWidget
        self.tree1.setColumnCount(3)
        self.tree1.setHeaderLabels(['Code','Name','IsProduct'])
        self.tree2 = self.ui.treeWidget_2
        self.tree2.setColumnCount(2)
        self.tree2.setHeaderLabels(['Code', 'Ratio', 'Product'])
        #----------------------------------------------------------------------------

        self.update_memory()
        self.update_tree()


        QtCore.QObject.connect(self.ui.pushButton_2, QtCore.SIGNAL("clicked()"), self.deleteMaterial)
        QtCore.QObject.connect(self.ui.pushButton_4, QtCore.SIGNAL("clicked()"), self.deleteRelation)
        QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.addMaterial)
        QtCore.QObject.connect(self.ui.pushButton_3, QtCore.SIGNAL("clicked()"), self.addRelation)

        QtCore.QObject.connect(self.ui.pushButton_5, QtCore.SIGNAL("clicked()"), self.singleQuery)
        QtCore.QObject.connect(self.ui.pushButton_6, QtCore.SIGNAL("clicked()"), self.multiQuery)
        QtCore.QObject.connect(self.ui.pushButton_7, QtCore.SIGNAL("clicked()"), self.singleReverseQuery)
        QtCore.QObject.connect(self.ui.pushButton_8, QtCore.SIGNAL("clicked()"), self.multiReverseQuery)
        QtCore.QObject.connect(self.ui.pushButton_9, QtCore.SIGNAL("clicked()"), self.endReverseQuery)
Beispiel #26
0
 def __init__(self):
     super(MainWindow, self).__init__()
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
Beispiel #27
0
class MainWindow (QtGui.QMainWindow):

	def __init__ (self, rpc, rpcworker, params, parent = None):
		QtGui.QMainWindow.__init__ (self, parent)

		self.rpc = rpc
		self.rpcworker = rpcworker
		self.rpcworker.lostconnection.connect (self.lostconnection)
		self.params = params

		self.ui = Ui_MainWindow()
		self.ui.setupUi (self)
		self.setWindowFlags (QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowMinimizeButtonHint)

		self.setWindowTitle (self.tr ("Cartoon Encoding and Uploading Platform"))
		self.setWindowIcon (QtGui.QIcon (':/images/icon.png'))

		self.createActions()
		self.createplayer()
		self.createmerger()
		self.createUIdetails()
		self.creategobject()

		self.transcoding = list()
		self.translisting = TransTaskProcessing
		self.mergelist = list()
		self.checkers = list()
		self.splitchoose = SplitNotChosen
		self.playerfile = None

		self.leftclicked = False

	def createActions (self):
		self.restact = QtGui.QAction (self.tr ("&Restore"), self, triggered = self.showNormal)
		self.minact = QtGui.QAction (self.tr ("Mi&nimize"), self, triggered = self.showMinimized)
		self.maxact = QtGui.QAction (self.tr ("Ma&ximize"), self, triggered = self.showMaximized)
		self.quitact = QtGui.QAction (self.tr ("&Quit"), self, triggered = QtGui.qApp.quit)

		self.trayicon = QtGui.QSystemTrayIcon (QtGui.QIcon (':/images/icon.png'))

		self.trayiconmenu = QtGui.QMenu (self)
		self.trayiconmenu.addAction (self.minact)
		self.trayiconmenu.addAction (self.maxact)
		self.trayiconmenu.addAction (self.restact)
		self.trayiconmenu.addSeparator()
		self.trayiconmenu.addAction (self.quitact)

		self.trayiconmenu.setStyleSheet ("QMenu {background-color: rgba(255, 255, 255, 255); border: 1px solid black;} QMenu::item {background-color: transparent;} QMenu::item:selected {background-color: rgba(0, 100, 255, 128);}")

		self.trayicon.setToolTip (self.tr ("Minimize to system tray. Right click this icon and choose Quit to close."))
		self.trayicon.setContextMenu (self.trayiconmenu)

		self.trayicon.show()

		self.trayicon.activated.connect (self.trayiconactivated)

	def createUIdetails (self):

		self.ui.transview.setModel (self.transfermodel (self))
		self.ui.transview.setRootIsDecorated (False)
		self.ui.transview.setAlternatingRowColors (True)
		self.ui.transview.setItemDelegate (TransferDelegate (self))
		self.ui.transview.setContextMenuPolicy (QtCore.Qt.CustomContextMenu)

		self.ui.mergeview.setModel (self.mergemodel (self))
		self.ui.mergeview.setRootIsDecorated (False)
		self.ui.mergeview.setAlternatingRowColors (True)
		self.ui.mergeview.setItemDelegate (MergeDelegate (self))

		self.ui.stackedWidget.setCurrentIndex (0)

		self.ui.lineeditstarttime.installEventFilter (self)
		self.ui.lineeditendtime.installEventFilter (self)
		self.ui.lineeditleadertitle.installEventFilter (self)

		self.params.setdefault ('LastPlayerPath', '')
		self.params.setdefault ('LastSplitTime', '')
		self.params.setdefault ('LastSplitFile', '')
		self.params.setdefault ('LastSplitPath', '')
		self.params.setdefault ('LastMergePath', '')
		self.params.setdefault ('LastMergeSrcPath', '')
		self.params.setdefault ('LastTransferPath', '')
		self.params.setdefault ('LastTransferSrcPath', '')
		self.params.setdefault ('NumEdited', 0)
		self.params.setdefault ('NumTransferred', 0)

		self.ui.labelvideoedit.setText (self.tr ("Video Edit: %d") % (self.params['NumEdited']))
		self.ui.labelvideoconvert.setText (self.tr ("Video Transfer: %d") % (self.params['NumTransferred']))

		self.ui.labellastrecordtime.setText (self.params['LastSplitTime'])
		self.ui.labellastsavefile.setText (self.params['LastSplitFile'])
		self.ui.lineeditsaveblank.setText (self.params['LastMergePath'])

		self.ui.buttoncancelbrowse.hide()

		self.ui.labelfilmtitle.setAlignment (QtCore.Qt.AlignHCenter)

	def creategobject (self):
		gobject.threads_init()
		self.mainloop = gobject.MainLoop()
		self.context = self.mainloop.get_context()

		self.p = self.context.pending
		self.t = self.context.iteration
		self.e = QtGui.qApp.processEvents

		self.contexttimer = QtCore.QTimer (QtGui.QApplication.instance())
		self.contexttimer.timeout.connect (self.contexthandler)
		self.contexttimer.start (10)

	@QtCore.Slot()
	def contexthandler (self): # optimized or not?
		p = self.p
		t = self.t
		e = self.e
		for i in xrange (100):
			if p():
				t()
			else:
				break

		e()

	@QtCore.Slot()
	def lostconnection (self):
		msg = CommonError (self.tr ("Lost connection to server. Exiting..."))
		msg.exec_()
		QtGui.qApp.quit()

	@QtCore.Slot (QtCore.QPoint)
	def on_transview_customContextMenuRequested (self, point):
		row = self.ui.transview.currentIndex().row()
		if row >= len (self.transcoding) or row < 0:
			return

		menu = QtGui.QMenu (self)
		menu.addAction (QtGui.QAction (self.tr ("Start"), self, triggered = self.singletransbegin))
		menu.addAction (QtGui.QAction (self.tr ("Pause"), self, triggered = self.singletranspause))
		menu.addAction (QtGui.QAction (self.tr ("Delete"), self, triggered = self.on_buttontransdelete_clicked))
		menu.exec_ (QtGui.QCursor.pos())

	@QtCore.Slot (unicode)
	def newmerged (self, path):
		self.params['NumEdited'] += 1
		self.ui.labelvideoedit.setText (self.tr ("Video Edit: %d") % (self.params['NumEdited']))
		self.params['LastMergePath'] = path
		self.ui.lineeditsaveblank.setText (path)

		self.rpcworker.newmergedsignal.emit (self.params)

	@QtCore.Slot (unicode, unicode, unicode)
	def newsplitted (self, time, filename, path):
		self.params['NumEdited'] += 1
		self.ui.labelvideoedit.setText (self.tr ("Video Edit: %d") % (self.params['NumEdited']))
		self.params['LastSplitTime'] = time
		self.ui.labellastrecordtime.setText (time)
		self.params['LastSplitFile'] = filename
		self.ui.labellastsavefile.setText (filename)
		self.params['LastSplitPath'] = path

		self.rpcworker.newsplittedsignal.emit (self.params)

	@QtCore.Slot (unicode)
	def newtransferred (self, path, srcpath):
		self.params['NumTransferred'] += 1
		self.ui.labelvideoconvert.setText (self.tr ("Video Transfer: %d") % (self.params['NumTransferred']))
		self.params['LastTransferPath'] = path
		self.params['LastTransferSrcPath'] = srcpath

		self.rpcworker.newtransferredsignal.emit (self.params)

	@QtCore.Slot (int)
	def trayiconactivated (self, event):
		if event == QtGui.QSystemTrayIcon.Trigger:
			if self.isHidden():
				self.ui.buttonmaximize.setIcon (QtGui.QIcon (':/images/maximize.png'))
				self.showNormal()
			else:
				self.ui.buttonmaximize.setIcon (QtGui.QIcon (':/images/maximize.png'))
				self.hide()

	@QtCore.Slot()
	def on_buttonminimize_clicked (self):
		self.showMinimized()

	@QtCore.Slot()
	def on_buttonmaximize_clicked (self):
		if self.isMaximized():
			self.ui.buttonmaximize.setIcon (QtGui.QIcon (':/images/maximize.png'))
			self.showNormal()
		else:
			self.ui.buttonmaximize.setIcon (QtGui.QIcon (':/images/restore.png'))
			self.showMaximized()

	@QtCore.Slot()
	def on_buttonclose_clicked (self):
		self.ui.buttonmaximize.setIcon (QtGui.QIcon (':/images/maximize.png'))
		self.hide()
		self.trayicon.showMessage (self.tr ("Cartoon Encoding and Uploading Platform"),
				self.tr ("Minimize to system tray. Right click this icon and choose Quit to close."),
				QtGui.QSystemTrayIcon.Information, 10000)

	def transfermodel (self, parent):
		model = QtGui.QStandardItemModel (0, 4, parent)
		model.setHorizontalHeaderLabels ([self.tr ("Cartoon Name"), self.tr ("Transfer Progress"), self.tr ("Status"), self.tr ("Output Path")])
		return model

	def mergemodel (self, parent):
		model = QtGui.QStandardItemModel (0, 4, parent)
		model.setHorizontalHeaderLabels ([self.tr ("File Name"), self.tr ("Duration"), self.tr ("Resolution"), self.tr ("Status")])
		return model

	def createplayer (self):

		winid = self.ui.frame_2.winId()
		pythonapi.PyCObject_AsVoidPtr.restype = c_void_p
		pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]
		self.windowId = pythonapi.PyCObject_AsVoidPtr (winid)

		self.ui.frame_2.mouseMoveEvent = self.mouseMoveEvent
		self.ui.frame_2.mousePressEvent = self.mousePressEvent
		self.ui.frame_2.mouseReleaseEvent = self.frameMouseRelease

		self.player = Player (self.windowId, self.ui.sliderseek.minimum(), self.ui.sliderseek.maximum(), self.ui.slidervolume.minimum(), self.ui.slidervolume.maximum())

		self.ui.buttonplayerplay.clicked.connect (self.player.playclickedsignal)
		self.ui.buttonplayerstop.clicked.connect (self.player.stopclickedsignal)
		self.ui.buttonplayerbackward.clicked.connect (self.player.backwardclickedsignal)
		self.ui.buttonplayerforward.clicked.connect (self.player.forwardclickedsignal)
		self.ui.buttonvolume.clicked.connect (self.player.muteornotsignal)
		self.ui.sliderseek.valueChanged.connect (self.player.sliderseekvaluesignal)
		self.ui.slidervolume.valueChanged.connect (self.player.slidervolumevaluesignal)

		self.player.updatelabelduration.connect (self.updatelabelduration)
		self.player.updatesliderseek.connect (self.updatesliderseek)
		self.player.updateslidervolume.connect (self.updateslidervolume)
		self.player.updatelineedit.connect (self.updatelineedit)
		self.player.setbuttonplay.connect (self.playersetbuttonplay)
		self.player.setbuttonpause.connect (self.playersetbuttonpause)

		self.player.startworker()

	@QtCore.Slot()
	def on_buttonloadfile_clicked (self):

		if os.path.isdir (self.params['LastPlayerPath']):
			lastpath = self.params['LastPlayerPath']
		else:
			lastpath = QtGui.QDesktopServices.storageLocation (QtGui.QDesktopServices.MoviesLocation)

		self.playerfile = QtGui.QFileDialog.getOpenFileName (self, self.tr ("Open"), lastpath)[0]
		if self.playerfile:
			checker = MediaFileChecker (self.playerfile, len (self.checkers))
			checker.discoveredsignal.connect (self.mediafilediscovered)
			checker.finished.connect (checker.deleteLater)
			self.checkers.append ({"worker": checker, "operation": "Player", "params": self.playerfile})
			checker.startworker()

			self.params['LastPlayerPath'] = QtCore.QDir.toNativeSeparators (QtCore.QFileInfo (self.playerfile).absolutePath())
			self.rpcworker.renewparamssignal.emit (self.params)

	@QtCore.Slot (unicode)
	def updatelabelduration (self, text):
		self.ui.labelduration.setText (text)

	@QtCore.Slot (int)
	def updatesliderseek (self, value):
		self.ui.sliderseek.blockSignals (True)
		self.ui.sliderseek.setValue (value)
		self.ui.sliderseek.blockSignals (False)

	@QtCore.Slot (unicode)
	def updatelineedit (self, text):
		if self.splitchoose == SplitNotChosen:
			return
		elif self.splitchoose == SplitAdjustStart:
			self.ui.lineeditstarttime.setText (text)
		elif self.splitchoose == SplitAdjustStop:
			self.ui.lineeditendtime.setText (text)

	@QtCore.Slot (int)
	def updateslidervolume (self, value):
		self.ui.slidervolume.blockSignals (True)
		self.ui.slidervolume.setValue (value)
		self.ui.slidervolume.blockSignals (False)

		self.on_slidervolume_valueChanged (value)

	@QtCore.Slot (int)
	def on_slidervolume_valueChanged (self, value):

		volmax = self.ui.slidervolume.maximum()
		volmin = self.ui.slidervolume.minimum()

		if value == 0:
			self.ui.buttonvolume.setIcon (QtGui.QIcon (':/images/mute.png'))
		elif value < (volmin + (volmax - volmin) / 3):
			self.ui.buttonvolume.setIcon (QtGui.QIcon (':/images/volume.png'))
		elif value < (volmin + (volmax - volmin) * 2 / 3):
			self.ui.buttonvolume.setIcon (QtGui.QIcon (':/images/weakvolume.png'))
		else:
			self.ui.buttonvolume.setIcon (QtGui.QIcon (':/images/strongvolume.png'))

	@QtCore.Slot()
	def playersetbuttonplay (self):
		self.ui.buttonplayerplay.setIcon (QtGui.QIcon (':/images/play.png'))

	@QtCore.Slot()
	def playersetbuttonpause (self):
		self.ui.buttonplayerplay.setIcon (QtGui.QIcon (':/images/pause2.png'))

	@QtCore.Slot()
	def on_buttoncancelbrowse_clicked (self):
		self.player.setloopsignal.emit (0, 0)

		self.ui.buttoncancelbrowse.hide()
		self.ui.buttonpreview.show()

		self.ui.lineeditstarttime.setEnabled (True)
		self.ui.lineeditendtime.setEnabled (True)
		
	@QtCore.Slot()
	def on_buttonpreview_clicked (self):

		self.splitchoose = SplitNotChosen
		self.ui.lineeditstarttime.setEnabled (False)
		self.ui.lineeditendtime.setEnabled (False)

		starttime = str2time (self.ui.lineeditstarttime.text())
		stoptime = str2time (self.ui.lineeditendtime.text())
		if starttime < 0 or stoptime <= starttime:
			msg = CommonError (self.tr ("Start time or stop time invalid."))
			msg.exec_()
			self.ui.buttoncancelbrowse.clicked.emit()
			return

		self.player.setloopsignal.emit (self.ui.lineeditstarttime.text(), self.ui.lineeditendtime.text())

		self.ui.buttonpreview.hide()
		self.ui.buttoncancelbrowse.show()

	def createmerger (self):

		self.merger = VideoMerger (self)

		self.merger.removerowsignal.connect (self.removemergerow)
		self.merger.updatemodel.connect (self.updatemergemodel)
		self.merger.finished.connect (self.unblockmergeelements)
		self.merger.finished.connect (self.flushmergelist)
		self.merger.filenamedecided.connect (self.updatefilename)

		self.merger.startnewmerge.connect (self.newmerged)

	@QtCore.Slot()
	def on_buttonplus_clicked (self):

		if os.path.isdir (self.params['LastMergeSrcPath']):
			lastpath = self.params['LastMergeSrcPath']
		else:
			lastpath = QtGui.QDesktopServices.storageLocation (QtGui.QDesktopServices.MoviesLocation)

		files = QtGui.QFileDialog.getOpenFileNames (self, self.tr ("Open"), lastpath)[0]
		if len (files) == 0:
			return

		self.params['LastMergeSrcPath'] = QtCore.QDir.toNativeSeparators (QtCore.QFileInfo (files[0]).absolutePath())
		self.rpcworker.renewparamssignal.emit (self.params)

		model = self.ui.mergeview.model()

		while len (files) > 0:
			newfile = QtCore.QFileInfo (files.pop (0))

			row = model.rowCount()
			model.insertRow (row)

			model.setData (model.index (row, 0), newfile.fileName())
			model.setData (model.index (row, 3), (0, self.tr ("Not Started")))

			rownum = 1
			for i in xrange (row):
				if self.mergelist[i] == MergeTaskReadyToProcess or self.mergelist[i] == MergeTaskVerifying:
					rownum += 1
			self.ui.labelmerge.setText (self.tr ("There are %d video clips to be merged.") % rownum)

			checker = MediaFileChecker (QtCore.QDir.toNativeSeparators (newfile.absoluteFilePath()), len (self.checkers))
			checker.discoveredsignal.connect (self.mediafilediscovered)
			checker.finished.connect (checker.deleteLater)
			self.merger.appendtasksignal.emit (QtCore.QDir.toNativeSeparators (newfile.absoluteFilePath()))
			self.checkers.append ({"worker": checker, "operation": "Merge", "params": row})
			self.mergelist.append (MergeTaskVerifying)
			checker.startworker()

	@QtCore.Slot()
	def on_buttonup_clicked (self):
		prevrow = row = self.ui.mergeview.currentIndex().row()
		model = self.ui.mergeview.model()

		if not self.mergelist[row] == MergeTaskReadyToProcess:
			return

		while prevrow > 0:
			prevrow -= 1
			if self.mergelist[prevrow] == MergeTaskReadyToProcess:
				break

		if prevrow < 0 or prevrow == row:
			return
		
		model.insertRow (prevrow, model.takeRow (row))
		self.mergelist[row], self.mergelist[prevrow] = self.mergelist[prevrow], self.mergelist[row]
		self.merger.switchrowsignal.emit (row, prevrow)
		self.ui.mergeview.setCurrentIndex (model.index (prevrow, 0))

	@QtCore.Slot()
	def on_buttondown_clicked (self):
		nextrow = row = self.ui.mergeview.currentIndex().row()
		model = self.ui.mergeview.model()

		if not self.mergelist[row] == MergeTaskReadyToProcess:
			return

		while nextrow < model.rowCount() - 1:
			nextrow += 1
			if self.mergelist[nextrow] == MergeTaskReadyToProcess:
				break

		if nextrow >= model.rowCount() or nextrow == row:
			return

		model.insertRow (nextrow, model.takeRow (row))
		self.mergelist[row], self.mergelist[nextrow] = self.mergelist[nextrow], self.mergelist[row]
		self.merger.switchrowsignal.emit (row, nextrow)
		self.ui.mergeview.setCurrentIndex (model.index (nextrow, 0))

	@QtCore.Slot()
	def on_buttondelete_clicked (self):
		row = self.ui.mergeview.currentIndex().row()
		self.merger.removerowsignal.emit (row)

	@QtCore.Slot()
	def on_buttonstart_clicked (self):
		filename = self.ui.lineeditfilenameblank.text()
		path = self.ui.lineeditsaveblank.text()

		if filename == "":
			msg = CommonError (self.tr ("Please input output filename"))
			msg.exec_()
			return
		elif len (filename) > 255:
			msg = CommonError (self.tr ("Filename too long."))
			msg.exec_()
			return
		
		if path == "":
			msg = CommonError (self.tr ("Please input output path"))
			msg.exec_()
			return

		self.merger.startsignal.emit (filename, path)
		self.blockmergeelements()

	@QtCore.Slot()
	def on_buttoncancel_clicked (self):
		self.merger.cancelsignal.emit()
		self.unblockmergeelements()

	@QtCore.Slot()
	def on_buttonexamine_clicked (self):
		exam = MergeExam (self.ui.lineeditfilenameblank.text(), self.ui.lineeditsaveblank.text())
		exam.move (self.pos() + self.rect().center() - exam.rect().center())
		exam.exec_()

	def blockmergeelements (self):
		self.ui.mergeview.setEnabled (False)
		self.ui.buttonstart.setEnabled (False)
		self.ui.buttonplus.setEnabled (False)
		self.ui.buttonup.setEnabled (False)
		self.ui.buttondown.setEnabled (False)
		self.ui.buttondelete.setEnabled (False)
		self.ui.lineeditfilenameblank.setEnabled (False)
		self.ui.lineeditsaveblank.setEnabled (False)
		self.ui.buttonbrowse.setEnabled (False)
		self.ui.buttonexamine.setEnabled (False)

	@QtCore.Slot()
	def unblockmergeelements (self):
		self.ui.mergeview.setEnabled (True)
		self.ui.buttonstart.setEnabled (True)
		self.ui.buttonplus.setEnabled (True)
		self.ui.buttonup.setEnabled (True)
		self.ui.buttondown.setEnabled (True)
		self.ui.buttondelete.setEnabled (True)
		self.ui.lineeditfilenameblank.setEnabled (True)
		self.ui.lineeditsaveblank.setEnabled (True)
		self.ui.buttonbrowse.setEnabled (True)
		self.ui.buttonexamine.setEnabled (True)

	@QtCore.Slot()
	def flushmergelist (self):
		for row in xrange (self.ui.mergeview.model().rowCount()):
			self.merger.removerowsignal.emit (row)

	@QtCore.Slot (unicode)
	def updatefilename (self, filename):
		self.ui.lineeditfilenameblank.setText (filename)

	@QtCore.Slot (int)
	def removemergerow (self, row):
		self.mergelist[row] = MergeTaskDeleted
		self.ui.mergeview.setRowHidden (row, QtCore.QModelIndex(), True)

		rownum = 0
		for i in xrange (self.ui.mergeview.model().rowCount()):
			if self.mergelist[i] == MergeTaskReadyToProcess or self.mergelist[i] == MergeTaskVerifying:
				rownum += 1
		self.ui.labelmerge.setText (self.tr ("There are %d video clips to be merged.") % rownum)

	@QtCore.Slot (int, int)
	def updatemergemodel (self, row, value):
		model = self.ui.mergeview.model()
		rownum = model.rowCount()

		if row >= rownum:
			for i in xrange (rownum):
				model.setData (model.index (i, 3), (100, self.tr ("Finished")))
			return

		if value is not None:
			if model.data (model.index (row, 3))[0] < value:
				if value < 100:
					model.setData (model.index (row, 3), (value, self.tr ("Processing...")))
				else:
					model.setData (model.index (row, 3), (100, self.tr ("Finished")))

			for i in xrange (row):
				model.setData (model.index (i, 3), (100, self.tr ("Finished")))

	@QtCore.Slot (unicode)
	def on_lineeditleadertitle_textChanged (self, text):
		self.ui.checkboxleadertitle.setChecked (True)

	@QtCore.Slot()
	def on_buttonsave_clicked (self):
		if not self.playerfile:
			return

		self.splitchoose = SplitNotChosen

		starttime = str2time (self.ui.lineeditstarttime.text())
		stoptime = str2time (self.ui.lineeditendtime.text())
		duration = stoptime - starttime
		if starttime < 0 or duration <= 0:
			msg = CommonError (self.tr ("Start time or stop time invalid."))
			msg.exec_()
			return

		if self.ui.checkboxleadertitle.isChecked():
			title = self.ui.lineeditleadertitle.text()
			if len (title) > 63:
				msg = CommonError (self.tr ("Movie title too long."))
				msg.exec_()
				return
		else:
			title = None

		timestring = "%s -- %s" % (time2str (starttime), time2str (stoptime))

		ss = SaveSplit (self.params['LastSplitPath'])
		ss.move (self.pos() + self.rect().center() - ss.rect().center())
		if not ss.exec_() == QtGui.QDialog.Accepted:
			return

		outputfile = os.path.join (ss.splitpath, ss.splitfile)

		self.splitter = VideoSplitter (self.playerfile, outputfile, starttime, duration, title, ss.totranscode, self.player.params, self)
		self.splitter.addtranscode.connect (self.addtranscode)
		self.splitter.startnewsplit.connect (self.newsplitted)
		self.splitter.startworker (timestring)

		self.splitprog = SplitProg()
		self.splitprog.move (self.pos() + self.rect().center() - self.splitprog.rect().center())
		self.splitter.updatemodel.connect (self.splitprog.setprogressbar)
		self.splitter.finished.connect (self.splitprog.accept)

		if not self.splitprog.exec_() == QtGui.QDialog.Accepted:
			self.splitter.finished.emit()

	@QtCore.Slot (int, tuple)
	def updatetransmodel (self, row, value):
		model = self.ui.transview.model()
		rownum = model.rowCount()

		if row >= rownum:
			return

		if value[0] is not None:
			if model.data (model.index (row, 1)) < value[0]:
				model.setData (model.index (row, 1), value[0])

			if value[0] >= 100:
				self.transcoding [row] ["status"] = TransTaskFinished
				model.setData (model.index (row, 2), self.tr ("Finished"))

				if self.translisting == TransTaskProcessing:
					self.ui.transview.setRowHidden (row, QtCore.QModelIndex(), True)
				else:
					self.ui.transview.setRowHidden (row, QtCore.QModelIndex(), False)

		if value[1] is not None:
			model.setData (model.index (row, 2), value[1])

	def closeEvent (self, event):
		if self.trayicon.isVisible():
			self.hide()
			event.ignore()

	@QtCore.Slot()
	def on_buttontransnew_clicked (self):

		model = self.ui.transview.model()

		nc = NewConvert (self.params['LastTransferPath'], self.params['LastTransferSrcPath'])
		if nc.exec_() == QtGui.QDialog.Accepted:

			files = nc.files
			newpath = nc.transferpath

			self.params['LastTransferPath'] = newpath
			self.rpcworker.renewparamssignal.emit (self.params)

			while len (files) > 0:
				newfile = QtCore.QFileInfo (files.pop (0))
				row = model.rowCount()
				model.insertRow (row)

				model.setData (model.index (row, 0), newfile.fileName())
				model.setData (model.index (row, 1), 0)
				model.setData (model.index (row, 2), self.tr ("Verifying File Parameters..."))
				model.setData (model.index (row, 3), newpath)

				checker = MediaFileChecker (QtCore.QDir.toNativeSeparators (newfile.absoluteFilePath()), len (self.checkers))
				checker.discoveredsignal.connect (self.mediafilediscovered)
				checker.finished.connect (checker.deleteLater)
				self.checkers.append ({"worker": checker, "operation": "Transcode",
					"params": (QtCore.QDir.toNativeSeparators (newfile.absoluteFilePath()), newpath, row, self)})
				self.transcoding.append ({"worker": None, "status": TransTaskVerifying})
				checker.startworker()

	@QtCore.Slot (unicode)
	def addtranscode (self, filename):
		model = self.ui.transview.model()
		newfile = QtCore.QFileInfo (filename)
		row = model.rowCount()
		model.insertRow (row)
		path = QtCore.QDir.toNativeSeparators (newfile.absolutePath())

		model.setData (model.index (row, 0), newfile.fileName())
		model.setData (model.index (row, 1), 0)
		model.setData (model.index (row, 2), self.tr ("Transcoding..."))
		model.setData (model.index (row, 3), path)

		transcode = Transcoder (QtCore.QDir.toNativeSeparators (newfile.absoluteFilePath()), path, row, self)

		transcode.playsignal.connect (transcode.play)
		transcode.pausesignal.connect (transcode.pause)
		transcode.removesignal.connect (transcode.remove)
		transcode.updatemodel.connect (self.updatetransmodel)
		transcode.finished.connect (transcode.deleteLater)
		transcode.startnewtransfer.connect (self.newtransferred)

		transcode.startworker()
		self.transcoding.append ({"worker": transcode, "status": TransTaskProcessing})

	@QtCore.Slot()
	def on_buttontransbegin_clicked (self):
		for i in xrange (self.ui.transview.model().rowCount()):
			if self.transcoding [i] ["status"] == TransTaskProcessing:
				self.transcoding [i] ["worker"].playsignal.emit()

	@QtCore.Slot()
	def singletransbegin (self):
		row = self.ui.transview.currentIndex().row()
		if row >= len (self.transcoding):
			return
		if self.transcoding [row] ["status"] == TransTaskProcessing:
			self.transcoding [row] ["worker"].playsignal.emit()

	@QtCore.Slot()
	def on_buttontranspause_clicked (self):
		for i in xrange (self.ui.transview.model().rowCount()):
			if self.transcoding [i] ["status"] == TransTaskProcessing:
				self.transcoding [i] ["worker"].pausesignal.emit()

	@QtCore.Slot()
	def singletranspause (self):
		row = self.ui.transview.currentIndex().row()
		if row >= len (self.transcoding):
			return
		if self.transcoding [row] ["status"] == TransTaskProcessing:
			self.transcoding [row] ["worker"].pausesignal.emit()

	@QtCore.Slot()
	def on_buttontransdelete_clicked (self):
		row = self.ui.transview.currentIndex().row()
		if self.transcoding [row] ["status"] == TransTaskProcessing:
			self.transcoding [row] ["worker"].removesignal.emit()
		self.transcoding [row] ["status"] = TransTaskDeleted
		self.ui.transview.setRowHidden (row, QtCore.QModelIndex(), True)

	@QtCore.Slot()
	def on_listWidget_itemClicked (self):
		self.translisting = self.ui.listWidget.currentRow() == 0 and TransTaskProcessing or TransTaskFinished

		for row in xrange (self.ui.transview.model().rowCount()):
			if self.transcoding [row] ["status"] == self.translisting:
				self.ui.transview.setRowHidden (row, QtCore.QModelIndex(), False)
			else:
				self.ui.transview.setRowHidden (row, QtCore.QModelIndex(), True)

	@QtCore.Slot()
	def on_buttonbrowse_clicked (self):
		self.ui.lineeditsaveblank.setText (QtGui.QFileDialog.getExistingDirectory (self, self.tr ("Select output directory")))

	@QtCore.Slot()
	def on_MovieEdit_clicked (self):
		self.ui.stackedWidget.setCurrentIndex (0)

	@QtCore.Slot()
	def on_FormatConvert_clicked (self):
		self.ui.stackedWidget.setCurrentIndex (1)

	@QtCore.Slot()
	def on_buttonvideomerge_clicked (self):
		self.ui.stackedWidget_2.setCurrentIndex (1)

	@QtCore.Slot()
	def on_buttonvideointerceptpage_clicked (self):
		self.ui.stackedWidget_2.setCurrentIndex (0)

	@QtCore.Slot (int, bool, dict)
	def mediafilediscovered (self, row, verified, params):

		if row >= len (self.checkers):
			return

		checker = self.checkers[row]

		if not verified:
			le = LoadError()
			le.move (self.pos() + self.rect().center() - le.rect().center())
			le.exec_()
#			le.show()

		if checker["operation"] == "Merge":

			mergerow = checker["params"]
			model = self.ui.mergeview.model()

			if not verified:
				model.setData (model.index (mergerow, 1), "%s" % (self.tr ("Video Source Criteria Not Met")))
				model.setData (model.index (mergerow, 2), "")
				self.removemergerow (mergerow)

				rownum = 0
				for i in xrange (model.rowCount()):
					if self.mergelist[i] == MergeTaskReadyToProcess or self.mergelist[i] == MergeTaskVerifying:
						rownum += 1
				self.ui.labelmerge.setText (self.tr ("There are %d video clips to be merged.") % rownum)

			else:
				model.setData (model.index (mergerow, 1), "%s" % (time2str (params.get ("length"))))
				model.setData (model.index (mergerow, 2), "%d X %d" % (params.get ("videowidth"), params.get ("videoheight")))
				self.mergelist[mergerow] = MergeTaskReadyToProcess

			self.merger.verifiedtasksignal.emit (mergerow, params, verified)

		elif checker["operation"] == "Player":

			if verified:
				self.player.params = params
				self.player.playurisignal.emit (checker["params"])
				self.ui.labelfilmtitle.setText (QtCore.QFileInfo (checker["params"]).fileName())

		elif checker["operation"] == "Transcode":

			transrow = checker["params"][2]

			if not verified:
				self.transcoding [transrow]["status"] = TransTaskDeleted
				self.ui.transview.setRowHidden (transrow, QtCore.QModelIndex(), True)
				return

			transcode = Transcoder (*checker["params"])

			transcode.playsignal.connect (transcode.play)
			transcode.pausesignal.connect (transcode.pause)
			transcode.removesignal.connect (transcode.remove)
			transcode.updatemodel.connect (self.updatetransmodel)
			transcode.finished.connect (transcode.deleteLater)
			transcode.startnewtransfer.connect (self.newtransferred)

			transcode.startworker()
			self.transcoding [transrow]["worker"] = transcode
			self.transcoding [transrow]["status"] = TransTaskProcessing

		del checker

	def eventFilter (self, obj, event):
		if event.type() == QtCore.QEvent.FocusIn:
			if obj == self.ui.lineeditstarttime:
				self.splitchoose = SplitAdjustStart
			elif obj == self.ui.lineeditendtime:
				self.splitchoose = SplitAdjustStop
			elif obj == self.ui.lineeditleadertitle:
				self.splitchoose = SplitNotChosen

		elif event.type() == QtCore.QEvent.KeyPress:
			if event.key() == QtCore.Qt.Key_Enter or event.key() == QtCore.Qt.Key_Return:
				if obj == self.ui.lineeditstarttime:
					self.player.seekstarttimesignal.emit (self.ui.lineeditstarttime.text())
				elif obj == self.ui.lineeditleadertitle:
					self.ui.buttonsave.clicked.emit()

		return QtGui.QWidget.eventFilter (self, obj, event)

	def mouseMoveEvent (self, event):
		super (MainWindow, self).mouseMoveEvent (event)

		if self.leftclicked == True:

			if self.isMaximized():
				self.ui.buttonmaximize.setIcon (QtGui.QIcon (':/images/maximize.png'))

				origsize = self.rect().size()
				self.showNormal()
				newsize = self.rect().size()

				xfactor = float (newsize.width()) / origsize.width()
				yfactor = float (newsize.height()) / origsize.height()

				self.startdragging.setX (self.startdragging.x() * xfactor)
				self.startdragging.setY (self.startdragging.y() * yfactor)

			self.move (event.globalPos() - self.startdragging)

	def mousePressEvent (self, event):
		super (MainWindow, self).mousePressEvent (event)
		if event.button() == QtCore.Qt.LeftButton:
			self.leftclicked = True
			self.startdragging = event.globalPos() - self.pos()
			self.clickedpos = event.globalPos()

	def mouseReleaseEvent (self, event):
		super (MainWindow, self).mouseReleaseEvent (event)
		self.leftclicked = False

	def mouseDoubleClickEvent (self, event):
		super (MainWindow, self).mouseDoubleClickEvent (event)
		self.ui.buttonmaximize.clicked.emit()

	def frameMouseRelease (self, event):
		super (MainWindow, self).mouseReleaseEvent (event)
		if event.button() == QtCore.Qt.LeftButton and event.globalPos() == self.clickedpos:
			self.leftclicked = False
			self.ui.buttonplayerplay.clicked.emit()

	def resizeEvent (self, event):
		pixmap = QtGui.QPixmap (self.size())

		if not self.isMaximized():
			painter = QtGui.QPainter()
			painter.begin (pixmap)
			painter.fillRect (pixmap.rect(), QtCore.Qt.white)
			painter.setBrush (QtCore.Qt.black)
			painter.drawRoundRect (pixmap.rect(), 3, 3)
			painter.end()

		self.setMask (pixmap.createMaskFromColor (QtCore.Qt.white))
Beispiel #28
0
    success(ui)

# 开始计算


def allin(ui):
    try:
        success(ui)
    except:
        error(ui)


# ———————————————————————————————————调用区——————————————————————————————

if __name__ == "__main__":
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()

    # 公称截面面积数据表
    data = pd.read_excel("./data/test.xlsx", index_col=0)
    # 进行实例化
    calculator = Calculator(data)

    ui.pushButtoncalculate.clicked.connect(partial(allin, ui))
    ui.pushButtonreturn.clicked.connect(partial(return0, ui))

    sys.exit(app.exec_())
Beispiel #29
0
class first(QtGui.QMainWindow):

    #update map [database -> memory]
    def update_memory(self):
        self.CU.execute("select * from material")
        self.MATERIAL = self.CU.fetchall()
        self.MATERIAL_id_code = {}
        self.MATERIAL_code_id = {}
        self.PRODUCT = []
        for i in self.MATERIAL:
            self.MATERIAL_id_code[i[0]] = str(i[1])
            self.MATERIAL_code_id[str(i[1])] = i[0]
            if i[3]==True:
                self.PRODUCT.append(i[1])
        self.CU.execute("select * from relation")
        self.RELATION = self.CU.fetchall()

    #update treeWdigets
    def update_tree(self):
        self.ui.treeWidget.clear()
        self.ui.treeWidget_2.clear()
        self.tree1Item = []
        self.tree2Item = {}
        for i in self.MATERIAL:
            self.tree1Item.append(QTreeWidgetItem(self.tree1))
            self.tree1Item[-1].setText(0, str(i[1]))
            self.tree1Item[-1].setText(1, str(i[2]))
            if i[3]==1:
                self.tree1Item[-1].setText(2, 'True')
        for i in self.RELATION:
            fatherID = i[1]
            fatherCode = self.MATERIAL_id_code[fatherID]
            sonID = i[2]
            sonCode = self.MATERIAL_id_code[sonID]
            ratio = i[3]

            if fatherID not in self.tree2Item:
                self.tree2Item[fatherID] = QTreeWidgetItem(self.tree2)
                self.tree2Item[fatherID].setText(0, fatherCode)
                if some_functions.return_Table_Column_Value('material', 'id', str(some_functions.code_to_id(fatherCode)))[0][3]==True:
                    self.tree2Item[fatherID].setText(2, fatherCode)
            key = (fatherID, sonID)
            if key not in self.tree2Item:
                self.tree2Item[key] = QTreeWidgetItem(self.tree2Item[fatherID])
                self.tree2Item[key].setText(0, sonCode)
                self.tree2Item[key].setText(1, str(ratio))

    def MoveToScreenCenter(self):
        screen = QDesktopWidget().screenGeometry()
        mysize = self.geometry()
        hpos = ( screen.width() - mysize.width() ) / 2
        vpos = ( screen.height() - mysize.height() ) / 2
        self.move(hpos, vpos)

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.MoveToScreenCenter()

        #-stable---------------------------------------------------------------------------
        self.currentDIR = os.path.dirname(os.path.realpath(__file__))

        self.db = QSqlDatabase.addDatabase("QSQLITE")
        self.db.setDatabaseName(os.path.join(self.currentDIR, "data.db"))
        if self.db.open():
            print "Open data.db successfully"
        else:
            print "Could not open data.db"
        self.CX = sqlite3.connect("data.db")
        self.CU = self.CX.cursor()

        self.tree1 = self.ui.treeWidget
        self.tree1.setColumnCount(3)
        self.tree1.setHeaderLabels(['Code','Name','IsProduct'])
        self.tree2 = self.ui.treeWidget_2
        self.tree2.setColumnCount(2)
        self.tree2.setHeaderLabels(['Code', 'Ratio', 'Product'])
        #----------------------------------------------------------------------------

        self.update_memory()
        self.update_tree()


        QtCore.QObject.connect(self.ui.pushButton_2, QtCore.SIGNAL("clicked()"), self.deleteMaterial)
        QtCore.QObject.connect(self.ui.pushButton_4, QtCore.SIGNAL("clicked()"), self.deleteRelation)
        QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.addMaterial)
        QtCore.QObject.connect(self.ui.pushButton_3, QtCore.SIGNAL("clicked()"), self.addRelation)

        QtCore.QObject.connect(self.ui.pushButton_5, QtCore.SIGNAL("clicked()"), self.singleQuery)
        QtCore.QObject.connect(self.ui.pushButton_6, QtCore.SIGNAL("clicked()"), self.multiQuery)
        QtCore.QObject.connect(self.ui.pushButton_7, QtCore.SIGNAL("clicked()"), self.singleReverseQuery)
        QtCore.QObject.connect(self.ui.pushButton_8, QtCore.SIGNAL("clicked()"), self.multiReverseQuery)
        QtCore.QObject.connect(self.ui.pushButton_9, QtCore.SIGNAL("clicked()"), self.endReverseQuery)


    def singleQuery(self):
        code = str(self.ui.lineEdit.text())
        self.CU.execute("select * from material where code = '"+code+"'")
        ans = self.CU.fetchmany(1)
        if len(ans) > 0:
            single_query.SingleQuery().go(code, self.MATERIAL, self.RELATION, self.PRODUCT, \
                                          self.MATERIAL_id_code, self.MATERIAL_code_id)
            QMessageBox.warning(self, "single query", 'EXCEL generated successfully')
        else:
            QMessageBox.warning(self, "single query", 'Please select an existed material code!')


    def multiQuery(self):
        code = str(self.ui.lineEdit.text())
        self.CU.execute("select * from material where code = '"+code+"'")
        ans = self.CU.fetchmany(1)
        if len(ans) > 0:
            multi_query.MultiQuery().go(code, self.MATERIAL, self.RELATION, self.PRODUCT, \
                                        self.MATERIAL_id_code, self.MATERIAL_code_id)
            QMessageBox.warning(self, "multi query", 'EXCEL generated successfully')
        else:
            QMessageBox.warning(self, "multi query", 'Please select an existed material code!')


    def singleReverseQuery(self):
        code = str(self.ui.lineEdit.text())
        self.CU.execute("select * from material where code = '"+code+"'")
        ans = self.CU.fetchmany(1)
        if len(ans) > 0:
            single_reverse_query.SingleReverseQuery().go(code, self.MATERIAL, self.RELATION, self.PRODUCT, \
                                                         self.MATERIAL_id_code, self.MATERIAL_code_id)
            QMessageBox.warning(self, "single reverse query", 'EXCEL generated successfully')
        else:
            QMessageBox.warning(self, "single reverse query", 'Please select an existed material code!')


    def multiReverseQuery(self):
        code = str(self.ui.lineEdit.text())
        self.CU.execute("select * from material where code = '"+code+"'")
        ans = self.CU.fetchmany(1)
        if len(ans) > 0:
            multi_reverse_query.MultiReverseQuery().go(code, self.MATERIAL, self.RELATION, self.PRODUCT, \
                                                       self.MATERIAL_id_code, self.MATERIAL_code_id)
            QMessageBox.warning(self, "multi reverse query", 'EXCEL generated successfully')
        else:
            QMessageBox.warning(self, "multi reverse query", 'Please select an existed material code!')


    def endReverseQuery(self):
        code = str(self.ui.lineEdit.text())
        self.CU.execute("select * from material where code = '"+code+"'")
        ans = self.CU.fetchmany(1)
        if len(ans) > 0:
            end_reverse_query.EndReverseQuery().go(code, self.MATERIAL, self.RELATION, self.PRODUCT, \
                                                   self.MATERIAL_id_code, self.MATERIAL_code_id)
            QMessageBox.warning(self, "end reverse query", 'EXCEL generated successfully')
        else:
            QMessageBox.warning(self, "end reverse query", 'Please select an existed material code!')


    def addMaterial(self):
        add1 = second()
        add1.exec_()

    def addRelation(self):
        add2 = third()
        add2.exec_()

    def deleteMaterial(self):
        selections = self.tree1.selectedItems()
        if len(selections) > 0:
            Code = str(selections[0].text(0))
            reply = QMessageBox.question(self, "TABLE material", "Are you sure to delete?", QMessageBox.Yes|QMessageBox.No)
            if reply==QMessageBox.Yes:
                self.CU.execute("select * from relation where father = "+str(self.MATERIAL_code_id[Code])+\
                                " or son = "+str(self.MATERIAL_code_id[Code]))
                ans = self.CU.fetchmany(1)
                if len(ans) > 0:
                    QMessageBox.warning(self, "ERROR", 'Please first clean TABLE relation!')
                else:
                    self.CU.execute("delete from material where code = '"+Code+"'")
                    self.CX.commit()
                    self.update_memory()
                    self.update_tree()


    def deleteRelation(self):
        selections = self.tree2.selectedItems()
        if len(selections) > 0:
            ratio = str(selections[0].text(1))
            if ratio != '':
                reply = QMessageBox.question(self, "TABLE relation", "Are you sure to delete?", QMessageBox.Yes|QMessageBox.No)
                if reply==QMessageBox.Yes:
                    parent = selections[0].parent()
                    fatherID = self.MATERIAL_code_id[str(parent.text(0))]
                    sonID = self.MATERIAL_code_id[str(selections[0].text(0))]
                    self.CU.execute("delete from relation where father = '"+str(fatherID)+"' and son = '"+str(sonID)+"'")
                    self.CX.commit()
                    self.update_memory()
                    self.update_tree()
            else:
                QMessageBox.warning(self, "ERROR", 'Please delete its children!')
Beispiel #30
0
class main(QtGui.QMainWindow):
     
     def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        
        self.le = QLineEdit()
        self.le.setObjectName("host")
        self.le.setText("Host")

        self.pb = QPushButton()
        self.pb.setObjectName("connect")
        self.pb.setText("Connect")
        
        self.connect(self.ui.pushButton1_0, SIGNAL("clicked()"),self.button_display_orginal_model)
        self.connect(self.ui.pushButton1_1, SIGNAL("clicked()"),self.button_edit_orginal_model)
        self.connect(self.ui.pushButton1_2, SIGNAL("clicked()"),self.button_view_orginal_model)
        self.connect(self.ui.pushButton2_0, SIGNAL("clicked()"),self.button_generate_species)
        self.connect(self.ui.pushButton2_1, SIGNAL("clicked()"),self.button_edit_species)
        self.connect(self.ui.pushButton2_2, SIGNAL("clicked()"),self.button_view_species)
        self.connect(self.ui.pushButton3_0, SIGNAL("clicked()"),self.button_generate_atomic_refinment)
        self.connect(self.ui.pushButton3_1, SIGNAL("clicked()"),self.button_edit_atomic_refinment)
        self.connect(self.ui.pushButton3_2, SIGNAL("clicked()"),self.button_view_atomic_refinment)
        self.connect(self.ui.pushButton4_0, SIGNAL("clicked()"),self.button_generate_complex_refinment)
        self.connect(self.ui.pushButton4_1, SIGNAL("clicked()"),self.button_edit_complex_refinment)
        self.connect(self.ui.pushButton4_2, SIGNAL("clicked()"),self.button_view_complex_refinment)
        self.connect(self.ui.pushButton5_0, SIGNAL("clicked()"),self.button_generate_refined_model)
        self.connect(self.ui.pushButton5_1, SIGNAL("clicked()"),self.button_display_refined_model)
        self.connect(self.ui.pushButton5_2, SIGNAL("clicked()"),self.button_view_refined_model)
        
     def button_display_orginal_model(self):
          
          orginal_filename = self.ui.lineEdit_1.text()
          
          try:
               f = open(orginal_filename, "r")
               
               self.ui.textEdit_original_model.clear()
               
               b = print_chemical_reaction(orginal_filename)
               for i in range (0,len(b)):
                    self.ui.textEdit_original_model.append(b[i])
               
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
          
          
          
          
     def button_edit_orginal_model(self):
          orginal_filename = self.ui.lineEdit_1.text()
          try:
               f = open(orginal_filename, "r")
                     
               if os.name == "darwin":#Mac
                    sp.Popen(["open", orginal_filename]) 
               elif  os.name=='posix': #linux
                    sp.Popen(["gedit", orginal_filename])
               elif  os.name=="nt":     #win
                    sp.Popen( ["write", orginal_filename])
          
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
                        
                   
     def button_view_orginal_model(self):
          orginal_filename = self.ui.lineEdit_1.text()
          try:
               f = open(orginal_filename, "r")
               if os.name == "darwin":#Mac
                    sp.Popen(["open", orginal_filename]) 
               elif  os.name=='posix': #linux
                    sp.Popen(["firefox", orginal_filename])
               elif  os.name=="nt":     #win
                    sp.Popen(["explorer", orginal_filename])
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
               
         
          
  #****************************************************************************************************             
                    
     def button_generate_species(self):
          orginal_filename = self.ui.lineEdit_1.text()
          try:
               f = open(orginal_filename, "r")
               dict_species=extract_species(orginal_filename)
               species_filename= self.ui.lineEdit_2.text()
               f = open(species_filename, "w")
               write_species(dict_species,species_filename)
               
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
         
          
     def button_edit_species(self):
          species_filename= self.ui.lineEdit_2.text()
          try:
               f = open(species_filename, "r")
               if os.name == "darwin":#Mac
                    sp.Popen(["open", species_filename]) 
               elif  os.name=='posix': #linux
                    sp.Popen(["gedit", species_filename])
               elif  os.name=="nt":     #win
                    sp.Popen(["write", species_filename])
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
          
     def button_view_species(self):
          species_filename= self.ui.lineEdit_2.text()
          
          try:
               f = open(species_filename, "r")
               if os.name == "darwin":#Mac
                    sp.Popen(["open", species_filename]) 
               elif  os.name=='posix': #linux
                    sp.Popen(["firefox", species_filename])
               elif  os.name=="nt":     #win
                    sp.Popen(["explorer", species_filename])
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
               
          
               
 #************************************************************************************************         
               
     def button_generate_atomic_refinment(self):
          species_filename= self.ui.lineEdit_2.text()
          try:
               f = open(species_filename, "r")
               atomic_refinment_filename= self.ui.lineEdit_3.text()
               f = open(atomic_refinment_filename, "w")
               write_atomic_refinement(species_filename,atomic_refinment_filename)
               
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
          

     def button_edit_atomic_refinment(self):
          atomic_refinment_filename= self.ui.lineEdit_3.text()
          try:
               f = open(atomic_refinment_filename, "r")
               if os.name == "darwin":#Mac
                    sp.Popen(["open", atomic_refinment_filename]) 
               elif  os.name=='posix': #linux
                    sp.Popen(["gedit", atomic_refinment_filename])
               elif  os.name=="nt":     #win
                    sp.Popen(["write",  atomic_refinment_filename])
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
          
               
          
         
          
     def button_view_atomic_refinment(self):
          atomic_refinment_filename= self.ui.lineEdit_3.text()
          try:
               f = open(atomic_refinment_filename, "r")
               if os.name == "darwin":#Mac
                    sp.Popen(["open", atomic_refinment_filename]) 
               elif  os.name=='posix': #linux
                    sp.Popen(["firefox", atomic_refinment_filename])
               elif  os.name=="nt":     #win
                    sp.Popen(["explorer",  atomic_refinment_filename])
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
          
          
 #**********************************************************************************************
               

     def button_generate_complex_refinment(self):
          species_filename= self.ui.lineEdit_2.text()
          try:
               atomic_refinment_filename= self.ui.lineEdit_3.text()
               dict_complex_refinement_generated = generate_complex_refinement(species_filename,atomic_refinment_filename)
               complex_refinment_filename= self.ui.lineEdit_4.text()
               write_complex_refinement(dict_complex_refinement_generated,complex_refinment_filename)
               
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
          

     def button_edit_complex_refinment(self):
          complex_refinment_filename= self.ui.lineEdit_4.text()
          try:
               f = open(complex_refinment_filename, "r")
               if os.name == "darwin":#Mac
                    sp.Popen(["open", complex_refinment_filename]) 
               elif  os.name=='posix': #linux
                    sp.Popen(["gedit", complex_refinment_filename])
               elif  os.name=="nt":     #win
                    sp.Popen(["write",  complex_refinment_filename])
                 
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
          
          
          
     def button_view_complex_refinment(self):
          complex_refinment_filename= self.ui.lineEdit_4.text()
          try:
               f = open(complex_refinment_filename, "r")
               if os.name == "darwin":#Mac
                    sp.Popen(["open", complex_refinment_filename]) 
               elif  os.name=='posix': #linux
                    sp.Popen(["firefox", complex_refinment_filename])
               elif  os.name=="nt":     #win
                    sp.Popen(["explorer",  complex_refinment_filename])
                
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
          
#*******************************************************************************************************************************         

     def button_generate_refined_model(self):
          try:
               orginal_model_filename = self.ui.lineEdit_1.text()
               species_filename= self.ui.lineEdit_2.text()
               dict_species_with_atomic=read_species(species_filename)
               atomic_refinment_filename= self.ui.lineEdit_3.text()
               dict_atomic_refinement = read_atomic_refinement(atomic_refinment_filename)
               complex_refinment_filename= self.ui.lineEdit_4.text()
               dict_complex_refinement_read = read_complex_refinement(complex_refinment_filename)
               reactions = read_reactions(orginal_model_filename)
               reaction_dic = generate_reactions(reactions, dict_complex_refinement_read)
               refined_model_filename = self.ui.lineEdit_5.text()
               write_reaction(dict_species_with_atomic,dict_atomic_refinement,dict_complex_refinement_read,reaction_dic,refined_model_filename)

          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
         
          
     def button_display_refined_model(self):
          refined_model_filename = self.ui.lineEdit_5.text()
          
          try:
               f = open(refined_model_filename, "r")
               self.ui.textEdit_refined_model.clear()
               b = print_chemical_reaction(refined_model_filename)
               for i in range (0,len(b)):
                    self.ui.textEdit_refined_model.append(b[i])
               
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
              
          
     def button_view_refined_model(self):
          refined_model_filename= self.ui.lineEdit_5.text()
          try:
               f = open(refined_model_filename, "r")
               if os.name == "darwin":#Mac
                    sp.Popen(["open",refined_model_filename ]) 
               elif  os.name=='posix': #linux
                    sp.Popen(["firefox", refined_model_filename])
               elif  os.name=="nt":     #win
                    sp.Popen(["explorer",  refined_model_filename])
                   
          except IOError as e:
               root = tk.Tk()
               root.withdraw()
               messagebox.showerror(title="Error",message=e.strerror + ": '" + e.filename + "'")
Beispiel #31
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Button
        self.ui.pushButton00.clicked.connect(lambda: self.buttonEvent(0, 0))
        self.ui.pushButton00.clicked.connect(lambda: self.buttonEvent(0, 0))
        self.ui.pushButton01.clicked.connect(lambda: self.buttonEvent(0, 1))
        self.ui.pushButton02.clicked.connect(lambda: self.buttonEvent(0, 2))
        self.ui.pushButton03.clicked.connect(lambda: self.buttonEvent(0, 3))
        self.ui.pushButton04.clicked.connect(lambda: self.buttonEvent(0, 4))
        self.ui.pushButton05.clicked.connect(lambda: self.buttonEvent(0, 5))
        self.ui.pushButton06.clicked.connect(lambda: self.buttonEvent(0, 6))
        self.ui.pushButton07.clicked.connect(lambda: self.buttonEvent(0, 7))
        self.ui.pushButton08.clicked.connect(lambda: self.buttonEvent(0, 8))
        self.ui.pushButton10.clicked.connect(lambda: self.buttonEvent(1, 0))
        self.ui.pushButton11.clicked.connect(lambda: self.buttonEvent(1, 1))
        self.ui.pushButton12.clicked.connect(lambda: self.buttonEvent(1, 2))
        self.ui.pushButton13.clicked.connect(lambda: self.buttonEvent(1, 3))
        self.ui.pushButton14.clicked.connect(lambda: self.buttonEvent(1, 4))
        self.ui.pushButton15.clicked.connect(lambda: self.buttonEvent(1, 5))
        self.ui.pushButton16.clicked.connect(lambda: self.buttonEvent(1, 6))
        self.ui.pushButton17.clicked.connect(lambda: self.buttonEvent(1, 7))
        self.ui.pushButton18.clicked.connect(lambda: self.buttonEvent(1, 8))
        self.ui.pushButton20.clicked.connect(lambda: self.buttonEvent(2, 0))
        self.ui.pushButton21.clicked.connect(lambda: self.buttonEvent(2, 1))
        self.ui.pushButton22.clicked.connect(lambda: self.buttonEvent(2, 2))
        self.ui.pushButton23.clicked.connect(lambda: self.buttonEvent(2, 3))
        self.ui.pushButton24.clicked.connect(lambda: self.buttonEvent(2, 4))
        self.ui.pushButton25.clicked.connect(lambda: self.buttonEvent(2, 5))
        self.ui.pushButton26.clicked.connect(lambda: self.buttonEvent(2, 6))
        self.ui.pushButton27.clicked.connect(lambda: self.buttonEvent(2, 7))
        self.ui.pushButton28.clicked.connect(lambda: self.buttonEvent(2, 8))
        self.ui.pushButton30.clicked.connect(lambda: self.buttonEvent(3, 0))
        self.ui.pushButton31.clicked.connect(lambda: self.buttonEvent(3, 1))
        self.ui.pushButton32.clicked.connect(lambda: self.buttonEvent(3, 2))
        self.ui.pushButton33.clicked.connect(lambda: self.buttonEvent(3, 3))
        self.ui.pushButton34.clicked.connect(lambda: self.buttonEvent(3, 4))
        self.ui.pushButton35.clicked.connect(lambda: self.buttonEvent(3, 5))
        self.ui.pushButton36.clicked.connect(lambda: self.buttonEvent(3, 6))
        self.ui.pushButton37.clicked.connect(lambda: self.buttonEvent(3, 7))
        self.ui.pushButton38.clicked.connect(lambda: self.buttonEvent(3, 8))
        self.ui.pushButton40.clicked.connect(lambda: self.buttonEvent(4, 0))
        self.ui.pushButton41.clicked.connect(lambda: self.buttonEvent(4, 1))
        self.ui.pushButton42.clicked.connect(lambda: self.buttonEvent(4, 2))
        self.ui.pushButton43.clicked.connect(lambda: self.buttonEvent(4, 3))
        self.ui.pushButton44.clicked.connect(lambda: self.buttonEvent(4, 4))
        self.ui.pushButton45.clicked.connect(lambda: self.buttonEvent(4, 5))
        self.ui.pushButton46.clicked.connect(lambda: self.buttonEvent(4, 6))
        self.ui.pushButton47.clicked.connect(lambda: self.buttonEvent(4, 7))
        self.ui.pushButton48.clicked.connect(lambda: self.buttonEvent(4, 8))
        self.ui.pushButton50.clicked.connect(lambda: self.buttonEvent(5, 0))
        self.ui.pushButton51.clicked.connect(lambda: self.buttonEvent(5, 1))
        self.ui.pushButton52.clicked.connect(lambda: self.buttonEvent(5, 2))
        self.ui.pushButton53.clicked.connect(lambda: self.buttonEvent(5, 3))
        self.ui.pushButton54.clicked.connect(lambda: self.buttonEvent(5, 4))
        self.ui.pushButton55.clicked.connect(lambda: self.buttonEvent(5, 5))
        self.ui.pushButton56.clicked.connect(lambda: self.buttonEvent(5, 6))
        self.ui.pushButton57.clicked.connect(lambda: self.buttonEvent(5, 7))
        self.ui.pushButton58.clicked.connect(lambda: self.buttonEvent(5, 8))
        self.ui.pushButton60.clicked.connect(lambda: self.buttonEvent(6, 0))
        self.ui.pushButton61.clicked.connect(lambda: self.buttonEvent(6, 1))
        self.ui.pushButton62.clicked.connect(lambda: self.buttonEvent(6, 2))
        self.ui.pushButton63.clicked.connect(lambda: self.buttonEvent(6, 3))
        self.ui.pushButton64.clicked.connect(lambda: self.buttonEvent(6, 4))
        self.ui.pushButton65.clicked.connect(lambda: self.buttonEvent(6, 5))
        self.ui.pushButton66.clicked.connect(lambda: self.buttonEvent(6, 6))
        self.ui.pushButton67.clicked.connect(lambda: self.buttonEvent(6, 7))
        self.ui.pushButton68.clicked.connect(lambda: self.buttonEvent(6, 8))
        self.ui.pushButton70.clicked.connect(lambda: self.buttonEvent(7, 0))
        self.ui.pushButton71.clicked.connect(lambda: self.buttonEvent(7, 1))
        self.ui.pushButton72.clicked.connect(lambda: self.buttonEvent(7, 2))
        self.ui.pushButton73.clicked.connect(lambda: self.buttonEvent(7, 3))
        self.ui.pushButton74.clicked.connect(lambda: self.buttonEvent(7, 4))
        self.ui.pushButton75.clicked.connect(lambda: self.buttonEvent(7, 5))
        self.ui.pushButton76.clicked.connect(lambda: self.buttonEvent(7, 6))
        self.ui.pushButton77.clicked.connect(lambda: self.buttonEvent(7, 7))
        self.ui.pushButton78.clicked.connect(lambda: self.buttonEvent(7, 8))
        self.ui.pushButton80.clicked.connect(lambda: self.buttonEvent(8, 0))
        self.ui.pushButton81.clicked.connect(lambda: self.buttonEvent(8, 1))
        self.ui.pushButton82.clicked.connect(lambda: self.buttonEvent(8, 2))
        self.ui.pushButton83.clicked.connect(lambda: self.buttonEvent(8, 3))
        self.ui.pushButton84.clicked.connect(lambda: self.buttonEvent(8, 4))
        self.ui.pushButton85.clicked.connect(lambda: self.buttonEvent(8, 5))
        self.ui.pushButton86.clicked.connect(lambda: self.buttonEvent(8, 6))
        self.ui.pushButton87.clicked.connect(lambda: self.buttonEvent(8, 7))
        self.ui.pushButton88.clicked.connect(lambda: self.buttonEvent(8, 8))

        # Button color
        self.colorPosition = (-1, -1)

        # Go button
        self.ui.GoButton.clicked.connect(self.GoButtonEvent)
class myWindow(QtWidgets.QMainWindow):

    def __init__(self):
        super(myWindow, self).__init__()
        self.myCommand = " "
        self.setWindowIcon(QtGui.QIcon('two.ico'))
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.firstFit_bar.triggered.connect(self.firstFitbar_recognize)  # firstFit模式触发
        self.ui.bestFit_bar.triggered.connect(self.bestFitbar_recognize)  # bestFit模式触发
        self.ui.text_btn.clicked.connect(self.text_changed)  # 文本框输入确认按钮连接文本处理函数
        self.ui.textbox.returnPressed.connect(self.text_changed)  # 文本框输入响应enter键
        self.ui.clear_btn.clicked.connect(self.clear)  # Reset按钮连接重置内存空间函数

        for i in range(0, 64):
            self.ui.btnGroup[i].clicked.connect(
                partial(self.addNode, 10*(i+1)))
        self.isbestFit = False  # 标志是否选择bestFit识别
        self.workNumber = 0  # 作业个数
        self.nodeList = []  # 结点链表
        # 初始化,将640k视为一个空结点
        self.nodeList.insert(0, {'number': -1,  # 非作业结点
                                 'start': 0,  # 开始为0
                                 'length': 640,  # 长度为640
                                 'isnull': True})  # 空闲
        # 加入一个非作业btn
        self.nodeList[0]['btn'] = self.addButton(self.nodeList[0])

    # firstFit从未选状态转变为已选状态时会触发firstFitbar_recognize函数
    def firstFitbar_recognize(self):
        self.clear()  # 重置内存空间
        self.ui.firstFit_bar.setChecked(True)
        self.ui.bestFit_bar.setChecked(False)
        self.ui.firstFit_action.setText(" √  First fit  ")
        font = QtGui.QFont()
        font.setFamily("Calibri")
        font.setPointSize(10)
        self.ui.firstFit_action.setFont(font)
        self.ui.firstFit_action.setStyleSheet(
            "QLabel { color: rgb(255,255,255);  /*字体颜色*/ \
                background-color:rgb(51,105,30);\
                }"
            "QLabel:hover{  background-color:rgb(51,105,30);/*选中的样式*/ \
                }"
        )
        self.ui.bestFit_action.setText("     Best fit  ")
        font = QtGui.QFont()
        font.setFamily("Calibri")
        font.setPointSize(10)
        self.ui.bestFit_action.setFont(font)
        self.ui.bestFit_action.setStyleSheet(
            "QLabel { color: rgb(225,225,225);  /*字体颜色*/ \
                background-color:rgb(124,179,66);\
                }"
            "QLabel:hover{ background-color:rgb(51,105,30);/*选中的样式*/ \
                            }"
        )
        self.isbestFit = False

    # bestFit从未选状态转变为已选状态时会触发bestFitbar_recognize函数
    def bestFitbar_recognize(self):
        self.clear()  # 重置内存空间
        self.ui.bestFit_bar.setChecked(True)
        self.ui.firstFit_bar.setChecked(False)
        self.ui.firstFit_action.setText("     First fit  ")
        font = QtGui.QFont()
        font.setFamily("Calibri")
        font.setPointSize(10)
        self.ui.firstFit_action.setFont(font)
        self.ui.firstFit_action.setStyleSheet(
            "QLabel { color: rgb(225,225,225);  /*字体颜色*/ \
                background-color:rgb(124,179,66);\
                }"
            "QLabel:hover{ background-color:rgb(51,105,30);/*选中的样式*/ \
                            }"
        )
        self.ui.bestFit_action.setText(" √  Best fit  ")
        font = QtGui.QFont()
        font.setFamily("Calibri")
        font.setPointSize(10)
        self.ui.bestFit_action.setFont(font)
        self.ui.bestFit_action.setStyleSheet(
            "QLabel { color: rgb(255,255,255);  /*字体颜色*/ \
                background-color:rgb(51,105,30);\
                }"
            "QLabel:hover{  background-color:rgb(51,105,30);/*选中的样式*/ \
                }"
        )
        self.isbestFit = True

    # 重置内存空间函数
    def clear(self):
        self.workNumber = 0  # 作业个数置0
        self.nodeList.insert(0, {'number': -1,  # 非作业结点
                                 'start': 0,  # 开始0
                                 'length': 640,  # 长度640
                                 'isnull': True})  # 空闲
        # 加入一个非作业btn
        self.nodeList[0]['btn'] = self.addButton(self.nodeList[0])
        size = len(self.nodeList)
        for i in range(1, size):
            self.nodeList.pop()

    # 寻找首次适应算法添加结点的位置
    def findFirstNode(self, length):
        self.targetNumber = -1
        for i in range(0, len(self.nodeList)):
            # 如果结点i为空闲
            if self.nodeList[i]['isnull'] and self.nodeList[i]['length'] >= length:
                self.targetNumber = i
                return self.targetNumber
        return -1

    # 寻找最佳适应算法添加结点的位置
    def findBestNode(self, length):
        self.min = 650
        self.targetNumber = -1
        for i in range(0, len(self.nodeList)):
            # 如果结点i为空闲
            if self.nodeList[i]['isnull'] and (self.min > self.nodeList[i]['length'] >= length):
                self.min = self.nodeList[i]['length']
                self.targetNumber = i
        return self.targetNumber

    # 添加结点
    def addNode(self, length):
        if self.isbestFit:
            i = self.findBestNode(length)
        else:
            i = self.findFirstNode(length)
        if i >= 0:
            self.workNumber += 1  # 作业数量+1
            if self.nodeList[i]['length'] > length:
                # 在该结点后插入新的作业结点
                self.nodeList.insert(i+1, {'number': self.workNumber,  # 作业workNumber
                                           'start': self.nodeList[i]['start'],  # 开始为结点i的开始
                                           'length': length,  # 长度
                                           'isnull': False})  # 不空闲
                # 加入一个作业btn
                self.nodeList[i+1]['btn'] = self.addButton(self.nodeList[i+1])
                self.nodeList[i+1]['btn'].clicked.connect(
                    partial(self.deleteNode, self.nodeList[i+1]['number']))
                # 将剩下的部分置为空白结点
                self.nodeList.insert(i+2, {'number': -1,  # 非作业结点
                                           'start': self.nodeList[i+1]['start']+length,  # 开始为i+1的开始+length
                                           'length': self.nodeList[i]['length']-length,  # 长度为结点i的长度-length
                                           'isnull': True})  # 空闲
                # 加入一个非作业btn
                self.nodeList[i+2]['btn'] = self.addButton(self.nodeList[i+2])
                # 删除结点i
                del self.nodeList[i]
            # 空闲结点i的长度等于所需长度
            elif self.nodeList[i]['length'] == length:
                # 在该结点后插入新的作业结点
                self.nodeList.insert(i + 1, {'number': self.workNumber,  # 作业workNumber
                                             'start': self.nodeList[i]['start'],  # 开始为结点i的开始
                                             'length': length,  # 长度
                                             'isnull': False})  # 不空闲
                # 插入一个作业btn
                self.nodeList[i + 1]['btn'] = self.addButton(self.nodeList[i+1])
                self.nodeList[i + 1]['btn'].clicked.connect(
                    partial(self.deleteNode, self.nodeList[i + 1]['number']))
                # 删除结点i
                del self.nodeList[i]

    # 删除作业结点
    def deleteNode(self, workNumber):
        self.current = -1
        # 寻找目标删除结点
        for i in range(0, len(self.nodeList)):
            if self.nodeList[i]['number'] == workNumber:
                self.current = i
                break
        # 找到目标删除结点
        if self.current != -1:
            # 前后都无空闲结点
            if (self.current == 0 or bool(1-self.nodeList[self.current - 1]['isnull'])) \
                    and (self.current == len(self.nodeList) - 1 or bool(1-self.nodeList[self.current + 1]['isnull'])):
                self.nodeList.insert(self.current + 1, {'number': -1,  # 非作业结点
                                                        # 开始为self.current结点的开始
                                                        'start': self.nodeList[self.current]['start'],
                                                        # 长度为结点self.current长度
                                                        'length': self.nodeList[self.current]['length'],
                                                        'isnull': True})  # 空闲
                # 加入一个非作业btn
                self.nodeList[self.current + 1]['btn'] = self.addButton(self.nodeList[self.current+1])
                del self.nodeList[self.current]
            else:
                # 结点非头结点且其前一个结点是空闲结点
                if self.current-1 >= 0 and self.nodeList[self.current-1]['isnull']:
                    # 将两部分合为一个空白结点
                    self.nodeList.insert(self.current + 1, {'number': -1,  # 非作业结点
                                                             # 开始为self.current-1结点的开始
                                                             'start': self.nodeList[self.current - 1]['start'],
                                                             # 长度为结点self.current-1的长度+结点self.current的长度
                                                             'length': self.nodeList[self.current-1]['length']
                                                                       + self.nodeList[self.current]['length'],
                                                             'isnull': True})  # 空闲
                    # 加入一个非作业btn
                    self.nodeList[self.current + 1]['btn'] = self.addButton(self.nodeList[self.current+1])
                    # 删除原来两结点
                    del self.nodeList[self.current-1]
                    # 删除current
                    del self.nodeList[self.current-1]
                    self.current -= 1
                # 结点非尾结点且其后一个结点为空白结点
                if self.current < len(self.nodeList)-1 and self.nodeList[self.current+1]['isnull']:
                    # 将两部分合为一个空白结点
                    self.nodeList.insert(self.current + 2, {'number': -1,  # 非作业结点
                                                            # 开始为self.current结点的开始
                                                           'start': self.nodeList[self.current]['start'],
                                                           # 长度为结点self.current的长度+结点self.current+1的长度
                                                           'length': self.nodeList[self.current]['length']
                                                                     + self.nodeList[self.current + 1]['length'],
                                                           'isnull': True})  # 空闲
                    # 加入一个非作业btn
                    self.nodeList[self.current + 2]['btn'] = self.addButton(self.nodeList[self.current+2])
                    # 删除原来两结点
                    del self.nodeList[self.current]
                    # 删除current+1
                    del self.nodeList[self.current]

    # 加入作业
    def addButton(self, node=[]):
        if node['isnull']:  # 空闲结点按钮
            btn = QtWidgets.QPushButton(str(node['length'])+'k', self)
            btn.setFont(QtGui.QFont('Microsoft YaHei', node['length']/42 + 5))
            btn.setGeometry(380, 30+node['start'], 100, node['length'])
            btn.setStyleSheet(
                "QPushButton{color:rgb(150,150,150)}"
                "QPushButton{background-color:rgb(240,240,240)}"
                "QPushButton{border: 1.5px solid rgb(66,66,66);}"
            )
            btn.setVisible(True)
        else:       # 作业结点按钮
            btn = QtWidgets.QPushButton('P'+str(node['number'])+':\n'+str(node['length'])+'k', self)
            btn.setFont(QtGui.QFont('Microsoft YaHei', node['length'] / 42 + 5))
            btn.setGeometry(380, 30 + node['start'], 100, node['length'])
            btn.setStyleSheet(
                "QPushButton{color:rgb(1,0,0)}"
                "QPushButton{background-color:rgb(124,179,66)}"
                "QPushButton:hover{background-color:rgb(210,210,210)}"
                "QPushButton:pressed{background-color:rgb(200,200,200)}"
                "QPushButton{border: 1.5px solid rgb(66,66,66);}"
            )
            btn.setVisible(True)
        return btn

    #文本处理函数
    def text_changed(self):
        if self.ui.textbox.text() == '':
            self.content = 0
        else:
            self.content = 0
            if ('.' not in self.ui.textbox.text()):
                self.content = int(self.ui.textbox.text())
                #self.content = int("".join(list(filter(str.isdigit, self.ui.textbox.text()))))
            else:
                self.content = float(self.ui.textbox.text())
        print(self.content)
        self.ui.textbox.setText('')
        if self.content <= 640:
            self.addNode(self.content)
Beispiel #33
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.initialArrowIcon()
        self.setFixedSize(self.size())

        # Add pLabel & delete old QLabel
        self.label_image_original = dLabel(self.ui.centralwidget, self)
        self.label_image_original.setGeometry(
            QRect(self.ui.label_image_original.pos(),
                  self.ui.label_image_original.size()))

        del self.ui.label_image_original

        # Button
        self.ui.pushButton_upload.clicked.connect(self.openFileEvent)
        self.ui.pushButton_exit.clicked.connect(self.exitEvent)
        self.ui.pushButton_save.clicked.connect(self.saveEvent)

        # Slider
        self.ui.horizontalSlider_R.setDisabled(True)
        self.ui.horizontalSlider_G.setDisabled(True)
        self.ui.horizontalSlider_B.setDisabled(True)

        self.ui.horizontalSlider_R.setMaximum(255)
        self.ui.horizontalSlider_G.setMaximum(255)
        self.ui.horizontalSlider_B.setMaximum(255)
        self.ui.horizontalSlider_R.valueChanged.connect(
            lambda: self.color_value('R'))
        self.ui.horizontalSlider_G.valueChanged.connect(
            lambda: self.color_value('G'))
        self.ui.horizontalSlider_B.valueChanged.connect(
            lambda: self.color_value('B'))

        # LineEdit
        self.ui.lineEdit_R.textChanged.connect(self.color_change)
        self.ui.lineEdit_G.textChanged.connect(self.color_change)
        self.ui.lineEdit_B.textChanged.connect(self.color_change)

    def changeOutputColor(self):
        image = ImageQt.fromqpixmap(self.ui.label_image_output.pixmap())
        image = image.resize((self.ui.label_image_output.size().width(),
                              self.ui.label_image_output.size().height()))
        image_data = list(image.getdata())

        newRGBA = (self.newR, self.newG, self.newB, self.rgba[3])
        for index in self.changePos:
            image_data[index] = newRGBA

        image.putdata(image_data)

        if image.mode == "RGB":
            r, g, b = image.split()
            image = Image.merge("RGB", (b, g, r))
        elif image.mode == "RGBA":
            r, g, b, a = image.split()
            image = Image.merge("RGBA", (b, g, r, a))
        elif image.mode == "L":
            image = image.convert("RGBA")

        image2 = image.convert("RGBA")
        data = image2.tobytes("raw", "RGBA")
        qim = QImage(data, image.size[0], image.size[1], QImage.Format_ARGB32)
        pixmap = QPixmap.fromImage(qim)

        self.ui.label_image_output.setPixmap(QPixmap(pixmap))

    def get(self, pos):
        index = pos.y() * self.label_image_original.size().width() + pos.x()
        image = ImageQt.fromqpixmap(self.label_image_original.pixmap())
        image = image.resize((self.label_image_original.size().width(),
                              self.label_image_original.size().height()))
        image_data = image.getdata()

        self.rgba = image_data[index]
        if len(self.rgba) == 3:
            r, g, b = self.rgba
        elif len(image_data[index]) == 4:
            r, g, b, a = self.rgba

        self.changePos = []

        index = 0
        for item in image_data:
            if item == self.rgba:
                self.changePos.append(index)

            index += 1

        print(len(self.changePos))
        print(self.changePos)
        self.ui.label_color_original.setStyleSheet(
            'background-color: rgb({},{},{});'.format(r, g, b))
        self.ui.horizontalSlider_R.setDisabled(False)
        self.ui.horizontalSlider_G.setDisabled(False)
        self.ui.horizontalSlider_B.setDisabled(False)

    def color_change(self):
        self.newR = int(self.ui.lineEdit_R.text())
        self.newG = int(self.ui.lineEdit_G.text())
        self.newB = int(self.ui.lineEdit_B.text())
        self.ui.label_color_output.setStyleSheet(
            'background-color: rgb({}, {}, {});'.format(
                self.newR, self.newG, self.newB))
        self.changeOutputColor()

    def color_value(self, color):
        if color == 'R':
            self.ui.lineEdit_R.setText(str(self.ui.horizontalSlider_R.value()))
        elif color == 'G':
            self.ui.lineEdit_G.setText(str(self.ui.horizontalSlider_G.value()))
        elif color == 'B':
            self.ui.lineEdit_B.setText(str(self.ui.horizontalSlider_B.value()))

    def openFileEvent(self):
        file_name, _ = QFileDialog.getOpenFileName(self, "Open Image",
                                                   QDir.homePath())

        if file_name.split('.')[-1] in ['png', 'jpg', 'jpeg']:
            image = Image.open(file_name)
            image = image.resize((self.ui.label_image_output.size().width(),
                                  self.ui.label_image_output.size().height()))

            if image.mode == "RGB":
                r, g, b = image.split()
                image = Image.merge("RGB", (b, g, r))
            elif image.mode == "RGBA":
                r, g, b, a = image.split()
                image = Image.merge("RGBA", (b, g, r, a))
            elif image.mode == "L":
                image = image.convert("RGBA")

            image2 = image.convert("RGBA")
            data = image2.tobytes("raw", "RGBA")
            qim = QImage(data, image.size[0], image.size[1],
                         QImage.Format_ARGB32)
            pixmap = QPixmap.fromImage(qim)

            self.label_image_original.setPixmap(QPixmap(pixmap))
            self.ui.label_image_output.setPixmap(QPixmap(pixmap))
            self.label_image_original.switch = 1

    def initialArrowIcon(self):
        # Load byte data
        byte_data = base64.b64decode(arrow)
        image_data = BytesIO(byte_data)
        image = Image.open(image_data)
        image = image.convert('RGBA')

        # PIL to QPixmap
        qImage = ImageQt.ImageQt(image)
        image = QPixmap.fromImage(qImage)

        self.ui.label_arrow.setPixmap(QPixmap(image))
        self.ui.label_arrow.setScaledContents(True)

    def saveEvent(self):
        image = ImageQt.fromqpixmap(self.ui.label_image_output.pixmap())
        image.save('test.png')

    def exitEvent(self):
        exit()
Beispiel #34
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.Reg_Button.clicked.connect(self.registration)
        self.ui.Book_issuance_pushButton.clicked.connect(self.book_issuance)
        self.ui.Add_books_Button.clicked.connect(self.add_book)
        self.ui.Recovery_book_pushButton.clicked.connect(self.book_return)
        self.funcs = funcs.add()
        self.dialog = DIALOG(self.ui.UDC_label)
        self.ui.UDC_pushButton.clicked.connect(self.UDC_B)
        self.update_table()

    def UDC_B(self):
        self.dialog.show()

    def update_table(self):
        a = self.funcs.update_tadle()
        rows = len(a)
        self.ui.Info_tableWidget.setColumnCount(7)
        self.ui.Info_tableWidget.setRowCount(rows)
        self.ui.Info_tableWidget.setHorizontalHeaderLabels(
            ['articul', 'UDC', 'Name', 'Title', 'Date', 'Count', 'Count on hands'])
        header = self.ui.Info_tableWidget.horizontalHeader()
        header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
        header.setSectionResizeMode(1, QHeaderView.ResizeToContents)
        header.setSectionResizeMode(2, QHeaderView.ResizeToContents)
        header.setSectionResizeMode(3, QHeaderView.ResizeToContents)
        header.setSectionResizeMode(4, QHeaderView.ResizeToContents)
        header.setSectionResizeMode(5, QHeaderView.ResizeToContents)
        header.setSectionResizeMode(6, QHeaderView.ResizeToContents)
        for i in range(len(a)):
            for j in range(len(a[i])):
                self.ui.Info_tableWidget.setItem(i, j, \
                QTableWidgetItem(str(a[i][j])))

        lst_count = self.funcs.getCount()
        counts = 0
        for elem in lst_count:
            counts += elem
        self.ui.all_books.setText(str(counts))

        lst_countHands = self.funcs.getCountHands()
        counts = 0
        for elem in lst_countHands:
            counts += elem
        self.ui.news_room.setText(str(counts))


    def registration(self):
        try:
            articul = int(self.ui.articul_lineEdit.text())
            UDC = self.ui.UDC_label.text()
            name = self.ui.Name_lineEdit.text()
            title = self.ui.Title_lineEdit.text()
            date = int(self.ui.Date_lineEdit.text())
            count = int(self.ui.Count_lineEdit.text())

            a = self.funcs.getAllBD()
            boolean = False
            for i in range(len(a)):
                if a[i][2] == title or a[i][0] == articul:
                    boolean = True
                    break
            if articul and UDC and name and title and date and count:
                if not boolean:
                    self.funcs.insert_new(articul, UDC, name, title, date, count, count)

                    self.ui.articul_lineEdit.clear()
                    self.ui.UDC_label.clear()
                    self.ui.Name_lineEdit.clear()
                    self.ui.Title_lineEdit.clear()
                    self.ui.Date_lineEdit.clear()
                    self.ui.Count_lineEdit.clear()
                else:
                    QMessageBox.about(
                        self, 'Ошибка', 'В базе данных была найдена книга с таким же названием или артикулем.')

            else:
                QMessageBox.about(
                    self, 'Ошибка', 'Не все данные были введены.')

            count_all = self.funcs.getCount()


            self.update_table()

        except Exception as e:
            QMessageBox.about(
                self, 'Ошибка', 'Введите верные значения!')



    def add_book(self):
        UDC, ok = QInputDialog.getText(self, 'Выбор Артикуля', 'Введите артикуль книги')
        if ok and UDC:
            count, ok = QInputDialog.getText(self, 'Кол-во книг', \
            'Введите кол-во книг для добавления книг в базу')
            if ok and count:
                try:
                    req = self.funcs.getCount_all_All(int(UDC))
                    count_db = int(req[0]) + int(count)
                    count_all_db = int(req[1]) + int(count)
                    self.funcs.UPDATE_counts(count_db, count_all_db, int(UDC))
                except IndexError:
                    QMessageBox.about(
                    self, 'Ошибка', 'Введите правильное значение артикуля!')
                except ValueError:
                    QMessageBox.about(
                    self, 'Ошибка', 'Введите целое значение кл-во книг для добавления!')
        self.update_table()


    def book_issuance(self):
        UDC, ok = QInputDialog.getText(self, 'Выбор Артикуль', 'Введите артикуль книги')
        if ok and UDC:
            try:
                req = self.funcs.book_issuance_SELECT(int(UDC))
                count = req[0]
                if count > 0:
                    count_on_hands = req[1] + 1
                    count -= 1
                    self.funcs.book_issuance_UPDATE(count, count_on_hands, int(UDC))

                    UDC = 'Книга "' + str(req[2]) + '" автора "' + str(req[3]) + \
                    '" успешно выдана читателю!' + '\n' + str(count) \
                    + ' книг осталось.\n' + str(count_on_hands) + \
                    ' книг(и) у читателя(ей) на руках.'

                    self.update_table()
                    QMessageBox.about(self, 'Артикуль', UDC)
                else:
                    QMessageBox.about(self, 'ERROR', "Нет книг для выдачи, \
                    ожидайте возврата книг другими читателями!")
            except IndexError:
                QMessageBox.about(
                    self, 'Ошибка', 'Введите правильное значение Артикуля.')



    def book_return(self):
        UDC, ok = QInputDialog.getText(self, 'Выбор Артикуль', 'Введите Артикуль книги')
        if ok and UDC:
            try:
                req = self.funcs.get_book_return(int(UDC))
                count_on_hands = req[0]
                if count_on_hands > 0:
                    count = req[1] + 1
                    count_on_hands -= 1
                    self.funcs.UPDATE_book_return(count, count_on_hands, int(UDC))
                    UDC = 'Книга "' + str(req[2]) + '" автора "' + str(req[3]) + \
                    '" успешно принята!' + '\n' + str(count) \
                    + ' книг осталось.\n' + str(count_on_hands) + \
                    ' книг(и) у читателя(ей) на руках.'
                    self.update_table()
                    QMessageBox.about(self, 'Артикуль', UDC)
                else:
                    QMessageBox.about(self, 'Артикуль',
                     "Никто из читателей не взял данную книгу!")
            except IndexError:
                QMessageBox.about(self, 'Ошибка',\
                 'Введите правильное значение Артикуль.')
Beispiel #35
0
class FileSharerGUI(QMainWindow, Ui_MainWindow):
    
    def __init__(self, initialPeer, ttl=2, maxKnownPeers=5, initialPeerPort=1234, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        initialPeerHostName, initialPeerPort = initialPeer.split(':')
        self.peerHandler = P2PMessageHandler(maxKnownPeers, initialPeerPort, initialPeerHostName)
        t = threading.Thread(target=self.peerHandler.listenForConnections, args=[])
        t.start()
        self.peerHandler.buildPeerList(initialPeerHostName, int(initialPeerPort), ttl)
        self.updatePeers()
        QtCore.QObject.connect(self.ui.btn_download, QtCore.SIGNAL('clicked()'), self.onDownloadClicked)
        QtCore.QObject.connect(self.ui.btn_addFile, QtCore.SIGNAL('clicked()'), self.onAddFileClicked)
        QtCore.QObject.connect(self.ui.btn_Search, QtCore.SIGNAL('clicked()'), self.onSearchClicked)
        QtCore.QObject.connect(self.ui.btn_refresh, QtCore.SIGNAL('clicked()'), self.onRefreshClicked)
    
    def updatePeers(self):
        for peerId in self.peerHandler.getPeerIds():
            self.ui.listView_files.addItem(peerId)
    
    def updateFilesList(self):
        for file in self.peerHandler.files:
            fileHost = self.peerHandler.files[file]
            if not fileHost:
                fileHost = ('localhost')
            self.listView_files.addItem("%s:%s:1234" % (file, fileHost))
            self.ui.listView_files.repaint()
    
    def onDownloadClicked(self):
        selections = self.ui.listView_files.selectedItems()
        if selections:
            for s in selections:
                if(len(s.text().split(':')) > 2):
                    fileName, hostName, port = s.text().split(':')
                    response = self.peerHandler.connectAndSend(hostName, port, GETFILE, fileName)
                    if len(response) and response[0][0] == REPLY:
                        fileDescriptor = open(fileName, 'w')
                        fileDescriptor.write(response[0][1])
                        fileDescriptor.close()
                        self.peerHandler.files[fileName] = None
        else:
            self.popupErrorMessage('Please select a file before proceeding.')            
            
    def onAddFileClicked(self):
        fileName = self.ui.tb_Search.text()
        if fileName:
            fileName = fileName.lstrip().rstrip()
            self.peerHandler.files[fileName] = None
            print('File added for sharing')
        else:
            self.popupErrorMessage('Please enter a filename before adding.')
        self.ui.tb_addFile.setText(None)
            
    def onSearchClicked(self):
        searchText = self.ui.tb_Search.text()
        if searchText:
            for peerId in self.peerHandler.getPeerIds():
                self.peerHandler.sendMessageToPeer(peerId, SEARCH, '%s %s 4' % (self.peerHandler.hostId, searchText))
        else:
            self.popupErrorMessage('Please enter some search text.')
    
    def popupErrorMessage(self, errorString):
        messageBox = QMessageBox()
        messageBox.setWindowTitle('Error!!!')
        messageBox.setText(errorString)
        messageBox.exec_()
    
    def onRefreshClicked(self):
        self.updatePeers();
        self.updateFilesList()
Beispiel #36
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Button
        self.ui.pushButton00.clicked.connect(lambda: self.buttonEvent(0, 0))
        self.ui.pushButton00.clicked.connect(lambda: self.buttonEvent(0, 0))
        self.ui.pushButton01.clicked.connect(lambda: self.buttonEvent(0, 1))
        self.ui.pushButton02.clicked.connect(lambda: self.buttonEvent(0, 2))
        self.ui.pushButton03.clicked.connect(lambda: self.buttonEvent(0, 3))
        self.ui.pushButton04.clicked.connect(lambda: self.buttonEvent(0, 4))
        self.ui.pushButton05.clicked.connect(lambda: self.buttonEvent(0, 5))
        self.ui.pushButton06.clicked.connect(lambda: self.buttonEvent(0, 6))
        self.ui.pushButton07.clicked.connect(lambda: self.buttonEvent(0, 7))
        self.ui.pushButton08.clicked.connect(lambda: self.buttonEvent(0, 8))
        self.ui.pushButton10.clicked.connect(lambda: self.buttonEvent(1, 0))
        self.ui.pushButton11.clicked.connect(lambda: self.buttonEvent(1, 1))
        self.ui.pushButton12.clicked.connect(lambda: self.buttonEvent(1, 2))
        self.ui.pushButton13.clicked.connect(lambda: self.buttonEvent(1, 3))
        self.ui.pushButton14.clicked.connect(lambda: self.buttonEvent(1, 4))
        self.ui.pushButton15.clicked.connect(lambda: self.buttonEvent(1, 5))
        self.ui.pushButton16.clicked.connect(lambda: self.buttonEvent(1, 6))
        self.ui.pushButton17.clicked.connect(lambda: self.buttonEvent(1, 7))
        self.ui.pushButton18.clicked.connect(lambda: self.buttonEvent(1, 8))
        self.ui.pushButton20.clicked.connect(lambda: self.buttonEvent(2, 0))
        self.ui.pushButton21.clicked.connect(lambda: self.buttonEvent(2, 1))
        self.ui.pushButton22.clicked.connect(lambda: self.buttonEvent(2, 2))
        self.ui.pushButton23.clicked.connect(lambda: self.buttonEvent(2, 3))
        self.ui.pushButton24.clicked.connect(lambda: self.buttonEvent(2, 4))
        self.ui.pushButton25.clicked.connect(lambda: self.buttonEvent(2, 5))
        self.ui.pushButton26.clicked.connect(lambda: self.buttonEvent(2, 6))
        self.ui.pushButton27.clicked.connect(lambda: self.buttonEvent(2, 7))
        self.ui.pushButton28.clicked.connect(lambda: self.buttonEvent(2, 8))
        self.ui.pushButton30.clicked.connect(lambda: self.buttonEvent(3, 0))
        self.ui.pushButton31.clicked.connect(lambda: self.buttonEvent(3, 1))
        self.ui.pushButton32.clicked.connect(lambda: self.buttonEvent(3, 2))
        self.ui.pushButton33.clicked.connect(lambda: self.buttonEvent(3, 3))
        self.ui.pushButton34.clicked.connect(lambda: self.buttonEvent(3, 4))
        self.ui.pushButton35.clicked.connect(lambda: self.buttonEvent(3, 5))
        self.ui.pushButton36.clicked.connect(lambda: self.buttonEvent(3, 6))
        self.ui.pushButton37.clicked.connect(lambda: self.buttonEvent(3, 7))
        self.ui.pushButton38.clicked.connect(lambda: self.buttonEvent(3, 8))
        self.ui.pushButton40.clicked.connect(lambda: self.buttonEvent(4, 0))
        self.ui.pushButton41.clicked.connect(lambda: self.buttonEvent(4, 1))
        self.ui.pushButton42.clicked.connect(lambda: self.buttonEvent(4, 2))
        self.ui.pushButton43.clicked.connect(lambda: self.buttonEvent(4, 3))
        self.ui.pushButton44.clicked.connect(lambda: self.buttonEvent(4, 4))
        self.ui.pushButton45.clicked.connect(lambda: self.buttonEvent(4, 5))
        self.ui.pushButton46.clicked.connect(lambda: self.buttonEvent(4, 6))
        self.ui.pushButton47.clicked.connect(lambda: self.buttonEvent(4, 7))
        self.ui.pushButton48.clicked.connect(lambda: self.buttonEvent(4, 8))
        self.ui.pushButton50.clicked.connect(lambda: self.buttonEvent(5, 0))
        self.ui.pushButton51.clicked.connect(lambda: self.buttonEvent(5, 1))
        self.ui.pushButton52.clicked.connect(lambda: self.buttonEvent(5, 2))
        self.ui.pushButton53.clicked.connect(lambda: self.buttonEvent(5, 3))
        self.ui.pushButton54.clicked.connect(lambda: self.buttonEvent(5, 4))
        self.ui.pushButton55.clicked.connect(lambda: self.buttonEvent(5, 5))
        self.ui.pushButton56.clicked.connect(lambda: self.buttonEvent(5, 6))
        self.ui.pushButton57.clicked.connect(lambda: self.buttonEvent(5, 7))
        self.ui.pushButton58.clicked.connect(lambda: self.buttonEvent(5, 8))
        self.ui.pushButton60.clicked.connect(lambda: self.buttonEvent(6, 0))
        self.ui.pushButton61.clicked.connect(lambda: self.buttonEvent(6, 1))
        self.ui.pushButton62.clicked.connect(lambda: self.buttonEvent(6, 2))
        self.ui.pushButton63.clicked.connect(lambda: self.buttonEvent(6, 3))
        self.ui.pushButton64.clicked.connect(lambda: self.buttonEvent(6, 4))
        self.ui.pushButton65.clicked.connect(lambda: self.buttonEvent(6, 5))
        self.ui.pushButton66.clicked.connect(lambda: self.buttonEvent(6, 6))
        self.ui.pushButton67.clicked.connect(lambda: self.buttonEvent(6, 7))
        self.ui.pushButton68.clicked.connect(lambda: self.buttonEvent(6, 8))
        self.ui.pushButton70.clicked.connect(lambda: self.buttonEvent(7, 0))
        self.ui.pushButton71.clicked.connect(lambda: self.buttonEvent(7, 1))
        self.ui.pushButton72.clicked.connect(lambda: self.buttonEvent(7, 2))
        self.ui.pushButton73.clicked.connect(lambda: self.buttonEvent(7, 3))
        self.ui.pushButton74.clicked.connect(lambda: self.buttonEvent(7, 4))
        self.ui.pushButton75.clicked.connect(lambda: self.buttonEvent(7, 5))
        self.ui.pushButton76.clicked.connect(lambda: self.buttonEvent(7, 6))
        self.ui.pushButton77.clicked.connect(lambda: self.buttonEvent(7, 7))
        self.ui.pushButton78.clicked.connect(lambda: self.buttonEvent(7, 8))
        self.ui.pushButton80.clicked.connect(lambda: self.buttonEvent(8, 0))
        self.ui.pushButton81.clicked.connect(lambda: self.buttonEvent(8, 1))
        self.ui.pushButton82.clicked.connect(lambda: self.buttonEvent(8, 2))
        self.ui.pushButton83.clicked.connect(lambda: self.buttonEvent(8, 3))
        self.ui.pushButton84.clicked.connect(lambda: self.buttonEvent(8, 4))
        self.ui.pushButton85.clicked.connect(lambda: self.buttonEvent(8, 5))
        self.ui.pushButton86.clicked.connect(lambda: self.buttonEvent(8, 6))
        self.ui.pushButton87.clicked.connect(lambda: self.buttonEvent(8, 7))
        self.ui.pushButton88.clicked.connect(lambda: self.buttonEvent(8, 8))

        # Button color
        self.colorPosition = (-1, -1)

        # Go button
        self.ui.GoButton.clicked.connect(self.GoButtonEvent)

    def buttonEvent(self, i, j):
        if self.colorPosition != (-1, -1):
            self.removeButtonColor(self.colorPosition[0],
                                   self.colorPosition[1])

        if (i, j) == (0, 0):
            self.ui.pushButton00.setStyleSheet(
                'background-color: rgb(220, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (0, 1):
            self.ui.pushButton01.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (0, 2):
            self.ui.pushButton02.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (0, 3):
            self.ui.pushButton03.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (0, 4):
            self.ui.pushButton04.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (0, 5):
            self.ui.pushButton05.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (0, 6):
            self.ui.pushButton06.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (0, 7):
            self.ui.pushButton07.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (0, 8):
            self.ui.pushButton08.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (1, 0):
            self.ui.pushButton10.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (1, 1):
            self.ui.pushButton11.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (1, 2):
            self.ui.pushButton12.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (1, 3):
            self.ui.pushButton13.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (1, 4):
            self.ui.pushButton14.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (1, 5):
            self.ui.pushButton15.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (1, 6):
            self.ui.pushButton16.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (1, 7):
            self.ui.pushButton17.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (1, 8):
            self.ui.pushButton18.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (2, 0):
            self.ui.pushButton20.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (2, 1):
            self.ui.pushButton21.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (2, 2):
            self.ui.pushButton22.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (2, 3):
            self.ui.pushButton23.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (2, 4):
            self.ui.pushButton24.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (2, 5):
            self.ui.pushButton25.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (2, 6):
            self.ui.pushButton26.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (2, 7):
            self.ui.pushButton27.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (2, 8):
            self.ui.pushButton28.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (3, 0):
            self.ui.pushButton30.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (3, 1):
            self.ui.pushButton31.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (3, 2):
            self.ui.pushButton32.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (3, 3):
            self.ui.pushButton33.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (3, 4):
            self.ui.pushButton34.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (3, 5):
            self.ui.pushButton35.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (3, 6):
            self.ui.pushButton36.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (3, 7):
            self.ui.pushButton37.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (3, 8):
            self.ui.pushButton38.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (4, 0):
            self.ui.pushButton40.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (4, 1):
            self.ui.pushButton41.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (4, 2):
            self.ui.pushButton42.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (4, 3):
            self.ui.pushButton43.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (4, 4):
            self.ui.pushButton44.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (4, 5):
            self.ui.pushButton45.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (4, 6):
            self.ui.pushButton46.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (4, 7):
            self.ui.pushButton47.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (4, 8):
            self.ui.pushButton48.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (5, 0):
            self.ui.pushButton50.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (5, 1):
            self.ui.pushButton51.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (5, 2):
            self.ui.pushButton52.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (5, 3):
            self.ui.pushButton53.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (5, 4):
            self.ui.pushButton54.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (5, 5):
            self.ui.pushButton55.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (5, 6):
            self.ui.pushButton56.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (5, 7):
            self.ui.pushButton57.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (5, 8):
            self.ui.pushButton58.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (6, 0):
            self.ui.pushButton60.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (6, 1):
            self.ui.pushButton61.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (6, 2):
            self.ui.pushButton62.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (6, 3):
            self.ui.pushButton63.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (6, 4):
            self.ui.pushButton64.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (6, 5):
            self.ui.pushButton65.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (6, 6):
            self.ui.pushButton66.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (6, 7):
            self.ui.pushButton67.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (6, 8):
            self.ui.pushButton68.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (7, 0):
            self.ui.pushButton70.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (7, 1):
            self.ui.pushButton71.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (7, 2):
            self.ui.pushButton72.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (7, 3):
            self.ui.pushButton73.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (7, 4):
            self.ui.pushButton74.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (7, 5):
            self.ui.pushButton75.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (7, 6):
            self.ui.pushButton76.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (7, 7):
            self.ui.pushButton77.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (7, 8):
            self.ui.pushButton78.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (8, 0):
            self.ui.pushButton80.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (8, 1):
            self.ui.pushButton81.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (8, 2):
            self.ui.pushButton82.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (8, 3):
            self.ui.pushButton83.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (8, 4):
            self.ui.pushButton84.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (8, 5):
            self.ui.pushButton85.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (8, 6):
            self.ui.pushButton86.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (8, 7):
            self.ui.pushButton87.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)
        elif (i, j) == (8, 8):
            self.ui.pushButton88.setStyleSheet(
                'background-color: rgb(200, 0, 0);')
            self.colorPosition = (i, j)

    def removeButtonColor(self, i, j):
        if i == 0 and j == 0:
            self.ui.pushButton00.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 0 and j == 1:
            self.ui.pushButton01.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 0 and j == 2:
            self.ui.pushButton02.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 0 and j == 3:
            self.ui.pushButton03.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 0 and j == 4:
            self.ui.pushButton04.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 0 and j == 5:
            self.ui.pushButton05.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 0 and j == 6:
            self.ui.pushButton06.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 0 and j == 7:
            self.ui.pushButton07.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 0 and j == 8:
            self.ui.pushButton08.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 1 and j == 0:
            self.ui.pushButton10.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 1 and j == 1:
            self.ui.pushButton11.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 1 and j == 2:
            self.ui.pushButton12.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 1 and j == 3:
            self.ui.pushButton13.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 1 and j == 4:
            self.ui.pushButton14.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 1 and j == 5:
            self.ui.pushButton15.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 1 and j == 6:
            self.ui.pushButton16.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 1 and j == 7:
            self.ui.pushButton17.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 1 and j == 8:
            self.ui.pushButton18.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 2 and j == 0:
            self.ui.pushButton20.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 2 and j == 1:
            self.ui.pushButton21.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 2 and j == 2:
            self.ui.pushButton22.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 2 and j == 3:
            self.ui.pushButton23.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 2 and j == 4:
            self.ui.pushButton24.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 2 and j == 5:
            self.ui.pushButton25.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 2 and j == 6:
            self.ui.pushButton26.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 2 and j == 7:
            self.ui.pushButton27.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 2 and j == 8:
            self.ui.pushButton28.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 3 and j == 0:
            self.ui.pushButton30.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 3 and j == 1:
            self.ui.pushButton31.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 3 and j == 2:
            self.ui.pushButton32.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 3 and j == 3:
            self.ui.pushButton33.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 3 and j == 4:
            self.ui.pushButton34.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 3 and j == 5:
            self.ui.pushButton35.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 3 and j == 6:
            self.ui.pushButton36.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 3 and j == 7:
            self.ui.pushButton37.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 3 and j == 8:
            self.ui.pushButton38.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 4 and j == 0:
            self.ui.pushButton40.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 4 and j == 1:
            self.ui.pushButton41.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 4 and j == 2:
            self.ui.pushButton42.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 4 and j == 3:
            self.ui.pushButton43.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 4 and j == 4:
            self.ui.pushButton44.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 4 and j == 5:
            self.ui.pushButton45.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 4 and j == 6:
            self.ui.pushButton46.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 4 and j == 7:
            self.ui.pushButton47.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 4 and j == 8:
            self.ui.pushButton48.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 5 and j == 0:
            self.ui.pushButton50.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 5 and j == 1:
            self.ui.pushButton51.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 5 and j == 2:
            self.ui.pushButton52.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 5 and j == 3:
            self.ui.pushButton53.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 5 and j == 4:
            self.ui.pushButton54.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 5 and j == 5:
            self.ui.pushButton55.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 5 and j == 6:
            self.ui.pushButton56.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 5 and j == 7:
            self.ui.pushButton57.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 5 and j == 8:
            self.ui.pushButton58.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 6 and j == 0:
            self.ui.pushButton60.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 6 and j == 1:
            self.ui.pushButton61.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 6 and j == 2:
            self.ui.pushButton62.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 6 and j == 3:
            self.ui.pushButton63.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 6 and j == 4:
            self.ui.pushButton64.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 6 and j == 5:
            self.ui.pushButton65.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 6 and j == 6:
            self.ui.pushButton66.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 6 and j == 7:
            self.ui.pushButton67.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 6 and j == 8:
            self.ui.pushButton68.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 7 and j == 0:
            self.ui.pushButton70.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 7 and j == 1:
            self.ui.pushButton71.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 7 and j == 2:
            self.ui.pushButton72.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 7 and j == 3:
            self.ui.pushButton73.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 7 and j == 4:
            self.ui.pushButton74.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 7 and j == 5:
            self.ui.pushButton75.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 7 and j == 6:
            self.ui.pushButton76.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 7 and j == 7:
            self.ui.pushButton77.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 7 and j == 8:
            self.ui.pushButton78.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 8 and j == 0:
            self.ui.pushButton80.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 8 and j == 1:
            self.ui.pushButton81.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 8 and j == 2:
            self.ui.pushButton82.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 8 and j == 3:
            self.ui.pushButton83.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 8 and j == 4:
            self.ui.pushButton84.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 8 and j == 5:
            self.ui.pushButton85.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 8 and j == 6:
            self.ui.pushButton86.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 8 and j == 7:
            self.ui.pushButton87.setStyleSheet(
                'background-color: rgb(200, 200, 200);')
        elif i == 8 and j == 8:
            self.ui.pushButton88.setStyleSheet(
                'background-color: rgb(200, 200, 200);')

    def keyPressEvent(self, event):
        if self.colorPosition != (None, None):
            if event.key() == Qt.Key_1:
                self.filledNumberInButton(self.colorPosition[0],
                                          self.colorPosition[1], 1)
            elif event.key() == Qt.Key_2:
                self.filledNumberInButton(self.colorPosition[0],
                                          self.colorPosition[1], 2)
            elif event.key() == Qt.Key_3:
                self.filledNumberInButton(self.colorPosition[0],
                                          self.colorPosition[1], 3)
            elif event.key() == Qt.Key_4:
                self.filledNumberInButton(self.colorPosition[0],
                                          self.colorPosition[1], 4)
            elif event.key() == Qt.Key_5:
                self.filledNumberInButton(self.colorPosition[0],
                                          self.colorPosition[1], 5)
            elif event.key() == Qt.Key_6:
                self.filledNumberInButton(self.colorPosition[0],
                                          self.colorPosition[1], 6)
            elif event.key() == Qt.Key_7:
                self.filledNumberInButton(self.colorPosition[0],
                                          self.colorPosition[1], 7)
            elif event.key() == Qt.Key_8:
                self.filledNumberInButton(self.colorPosition[0],
                                          self.colorPosition[1], 8)
            elif event.key() == Qt.Key_9:
                self.filledNumberInButton(self.colorPosition[0],
                                          self.colorPosition[1], 9)

    def filledNumberInButton(self, x, y, num):
        num = str(num)
        if x == 0 and y == 0:
            self.ui.pushButton00.setText(num)
        if x == 0 and y == 1:
            self.ui.pushButton01.setText(num)
        if x == 0 and y == 2:
            self.ui.pushButton02.setText(num)
        if x == 0 and y == 3:
            self.ui.pushButton03.setText(num)
        if x == 0 and y == 4:
            self.ui.pushButton04.setText(num)
        if x == 0 and y == 5:
            self.ui.pushButton05.setText(num)
        if x == 0 and y == 6:
            self.ui.pushButton06.setText(num)
        if x == 0 and y == 7:
            self.ui.pushButton07.setText(num)
        if x == 0 and y == 8:
            self.ui.pushButton08.setText(num)
        if x == 1 and y == 0:
            self.ui.pushButton10.setText(num)
        if x == 1 and y == 1:
            self.ui.pushButton11.setText(num)
        if x == 1 and y == 2:
            self.ui.pushButton12.setText(num)
        if x == 1 and y == 3:
            self.ui.pushButton13.setText(num)
        if x == 1 and y == 4:
            self.ui.pushButton14.setText(num)
        if x == 1 and y == 5:
            self.ui.pushButton15.setText(num)
        if x == 1 and y == 6:
            self.ui.pushButton16.setText(num)
        if x == 1 and y == 7:
            self.ui.pushButton17.setText(num)
        if x == 1 and y == 8:
            self.ui.pushButton18.setText(num)
        if x == 2 and y == 0:
            self.ui.pushButton20.setText(num)
        if x == 2 and y == 1:
            self.ui.pushButton21.setText(num)
        if x == 2 and y == 2:
            self.ui.pushButton22.setText(num)
        if x == 2 and y == 3:
            self.ui.pushButton23.setText(num)
        if x == 2 and y == 4:
            self.ui.pushButton24.setText(num)
        if x == 2 and y == 5:
            self.ui.pushButton25.setText(num)
        if x == 2 and y == 6:
            self.ui.pushButton26.setText(num)
        if x == 2 and y == 7:
            self.ui.pushButton27.setText(num)
        if x == 2 and y == 8:
            self.ui.pushButton28.setText(num)
        if x == 3 and y == 0:
            self.ui.pushButton30.setText(num)
        if x == 3 and y == 1:
            self.ui.pushButton31.setText(num)
        if x == 3 and y == 2:
            self.ui.pushButton32.setText(num)
        if x == 3 and y == 3:
            self.ui.pushButton33.setText(num)
        if x == 3 and y == 4:
            self.ui.pushButton34.setText(num)
        if x == 3 and y == 5:
            self.ui.pushButton35.setText(num)
        if x == 3 and y == 6:
            self.ui.pushButton36.setText(num)
        if x == 3 and y == 7:
            self.ui.pushButton37.setText(num)
        if x == 3 and y == 8:
            self.ui.pushButton38.setText(num)
        if x == 4 and y == 0:
            self.ui.pushButton40.setText(num)
        if x == 4 and y == 1:
            self.ui.pushButton41.setText(num)
        if x == 4 and y == 2:
            self.ui.pushButton42.setText(num)
        if x == 4 and y == 3:
            self.ui.pushButton43.setText(num)
        if x == 4 and y == 4:
            self.ui.pushButton44.setText(num)
        if x == 4 and y == 5:
            self.ui.pushButton45.setText(num)
        if x == 4 and y == 6:
            self.ui.pushButton46.setText(num)
        if x == 4 and y == 7:
            self.ui.pushButton47.setText(num)
        if x == 4 and y == 8:
            self.ui.pushButton48.setText(num)
        if x == 5 and y == 0:
            self.ui.pushButton50.setText(num)
        if x == 5 and y == 1:
            self.ui.pushButton51.setText(num)
        if x == 5 and y == 2:
            self.ui.pushButton52.setText(num)
        if x == 5 and y == 3:
            self.ui.pushButton53.setText(num)
        if x == 5 and y == 4:
            self.ui.pushButton54.setText(num)
        if x == 5 and y == 5:
            self.ui.pushButton55.setText(num)
        if x == 5 and y == 6:
            self.ui.pushButton56.setText(num)
        if x == 5 and y == 7:
            self.ui.pushButton57.setText(num)
        if x == 5 and y == 8:
            self.ui.pushButton58.setText(num)
        if x == 6 and y == 0:
            self.ui.pushButton60.setText(num)
        if x == 6 and y == 1:
            self.ui.pushButton61.setText(num)
        if x == 6 and y == 2:
            self.ui.pushButton62.setText(num)
        if x == 6 and y == 3:
            self.ui.pushButton63.setText(num)
        if x == 6 and y == 4:
            self.ui.pushButton64.setText(num)
        if x == 6 and y == 5:
            self.ui.pushButton65.setText(num)
        if x == 6 and y == 6:
            self.ui.pushButton66.setText(num)
        if x == 6 and y == 7:
            self.ui.pushButton67.setText(num)
        if x == 6 and y == 8:
            self.ui.pushButton68.setText(num)
        if x == 7 and y == 0:
            self.ui.pushButton70.setText(num)
        if x == 7 and y == 1:
            self.ui.pushButton71.setText(num)
        if x == 7 and y == 2:
            self.ui.pushButton72.setText(num)
        if x == 7 and y == 3:
            self.ui.pushButton73.setText(num)
        if x == 7 and y == 4:
            self.ui.pushButton74.setText(num)
        if x == 7 and y == 5:
            self.ui.pushButton75.setText(num)
        if x == 7 and y == 6:
            self.ui.pushButton76.setText(num)
        if x == 7 and y == 7:
            self.ui.pushButton77.setText(num)
        if x == 7 and y == 8:
            self.ui.pushButton78.setText(num)
        if x == 8 and y == 0:
            self.ui.pushButton80.setText(num)
        if x == 8 and y == 1:
            self.ui.pushButton81.setText(num)
        if x == 8 and y == 2:
            self.ui.pushButton82.setText(num)
        if x == 8 and y == 3:
            self.ui.pushButton83.setText(num)
        if x == 8 and y == 4:
            self.ui.pushButton84.setText(num)
        if x == 8 and y == 5:
            self.ui.pushButton85.setText(num)
        if x == 8 and y == 6:
            self.ui.pushButton86.setText(num)
        if x == 8 and y == 7:
            self.ui.pushButton87.setText(num)
        if x == 8 and y == 8:
            self.ui.pushButton88.setText(num)

        self.removeButtonColor(x, y)

    def GoButtonEvent(self):
        question = [[0 for a in range(9)] for b in range(9)]
        if self.ui.pushButton00:
            question[0][0] = int(self.ui.pushButton00.text())
        if self.ui.pushButton01:
            question[0][1] = int(self.ui.pushButton01.text())
        if self.ui.pushButton02:
            question[0][2] = int(self.ui.pushButton02.text())
        if self.ui.pushButton03:
            question[0][3] = int(self.ui.pushButton03.text())
        if self.ui.pushButton04:
            question[0][4] = int(self.ui.pushButton04.text())
        if self.ui.pushButton05:
            question[0][5] = int(self.ui.pushButton05.text())
        if self.ui.pushButton06:
            question[0][6] = int(self.ui.pushButton06.text())
        if self.ui.pushButton07:
            question[0][7] = int(self.ui.pushButton07.text())
        if self.ui.pushButton08:
            question[0][8] = int(self.ui.pushButton08.text())
        if self.ui.pushButton10:
            question[1][0] = int(self.ui.pushButton10.text())
        if self.ui.pushButton11:
            question[1][1] = int(self.ui.pushButton11.text())
        if self.ui.pushButton12:
            question[1][2] = int(self.ui.pushButton12.text())
        if self.ui.pushButton13:
            question[1][3] = int(self.ui.pushButton13.text())
        if self.ui.pushButton14:
            question[1][4] = int(self.ui.pushButton14.text())
        if self.ui.pushButton15:
            question[1][5] = int(self.ui.pushButton15.text())
        if self.ui.pushButton16:
            question[1][6] = int(self.ui.pushButton16.text())
        if self.ui.pushButton17:
            question[1][7] = int(self.ui.pushButton17.text())
        if self.ui.pushButton18:
            question[1][8] = int(self.ui.pushButton18.text())
        if self.ui.pushButton20:
            question[2][0] = int(self.ui.pushButton20.text())
        if self.ui.pushButton21:
            question[2][1] = int(self.ui.pushButton21.text())
        if self.ui.pushButton22:
            question[2][2] = int(self.ui.pushButton22.text())
        if self.ui.pushButton23:
            question[2][3] = int(self.ui.pushButton23.text())
        if self.ui.pushButton24:
            question[2][4] = int(self.ui.pushButton24.text())
        if self.ui.pushButton25:
            question[2][5] = int(self.ui.pushButton25.text())
        if self.ui.pushButton26:
            question[2][6] = int(self.ui.pushButton26.text())
        if self.ui.pushButton27:
            question[2][7] = int(self.ui.pushButton27.text())
        if self.ui.pushButton28:
            question[2][8] = int(self.ui.pushButton28.text())
        if self.ui.pushButton30:
            question[3][0] = int(self.ui.pushButton30.text())
        if self.ui.pushButton31:
            question[3][1] = int(self.ui.pushButton31.text())
        if self.ui.pushButton32:
            question[3][2] = int(self.ui.pushButton32.text())
        if self.ui.pushButton33:
            question[3][3] = int(self.ui.pushButton33.text())
        if self.ui.pushButton34:
            question[3][4] = int(self.ui.pushButton34.text())
        if self.ui.pushButton35:
            question[3][5] = int(self.ui.pushButton35.text())
        if self.ui.pushButton36:
            question[3][6] = int(self.ui.pushButton36.text())
        if self.ui.pushButton37:
            question[3][7] = int(self.ui.pushButton37.text())
        if self.ui.pushButton38:
            question[3][8] = int(self.ui.pushButton38.text())
        if self.ui.pushButton40:
            question[4][0] = int(self.ui.pushButton40.text())
        if self.ui.pushButton41:
            question[4][1] = int(self.ui.pushButton41.text())
        if self.ui.pushButton42:
            question[4][2] = int(self.ui.pushButton42.text())
        if self.ui.pushButton43:
            question[4][3] = int(self.ui.pushButton43.text())
        if self.ui.pushButton44:
            question[4][4] = int(self.ui.pushButton44.text())
        if self.ui.pushButton45:
            question[4][5] = int(self.ui.pushButton45.text())
        if self.ui.pushButton46:
            question[4][6] = int(self.ui.pushButton46.text())
        if self.ui.pushButton47:
            question[4][7] = int(self.ui.pushButton47.text())
        if self.ui.pushButton48:
            question[4][8] = int(self.ui.pushButton48.text())
        if self.ui.pushButton50:
            question[5][0] = int(self.ui.pushButton50.text())
        if self.ui.pushButton51:
            question[5][1] = int(self.ui.pushButton51.text())
        if self.ui.pushButton52:
            question[5][2] = int(self.ui.pushButton52.text())
        if self.ui.pushButton53:
            question[5][3] = int(self.ui.pushButton53.text())
        if self.ui.pushButton54:
            question[5][4] = int(self.ui.pushButton54.text())
        if self.ui.pushButton55:
            question[5][5] = int(self.ui.pushButton55.text())
        if self.ui.pushButton56:
            question[5][6] = int(self.ui.pushButton56.text())
        if self.ui.pushButton57:
            question[5][7] = int(self.ui.pushButton57.text())
        if self.ui.pushButton58:
            question[5][8] = int(self.ui.pushButton58.text())
        if self.ui.pushButton60:
            question[6][0] = int(self.ui.pushButton60.text())
        if self.ui.pushButton61:
            question[6][1] = int(self.ui.pushButton61.text())
        if self.ui.pushButton62:
            question[6][2] = int(self.ui.pushButton62.text())
        if self.ui.pushButton63:
            question[6][3] = int(self.ui.pushButton63.text())
        if self.ui.pushButton64:
            question[6][4] = int(self.ui.pushButton64.text())
        if self.ui.pushButton65:
            question[6][5] = int(self.ui.pushButton65.text())
        if self.ui.pushButton66:
            question[6][6] = int(self.ui.pushButton66.text())
        if self.ui.pushButton67:
            question[6][7] = int(self.ui.pushButton67.text())
        if self.ui.pushButton68:
            question[6][8] = int(self.ui.pushButton68.text())
        if self.ui.pushButton70:
            question[7][0] = int(self.ui.pushButton70.text())
        if self.ui.pushButton71:
            question[7][1] = int(self.ui.pushButton71.text())
        if self.ui.pushButton72:
            question[7][2] = int(self.ui.pushButton72.text())
        if self.ui.pushButton73:
            question[7][3] = int(self.ui.pushButton73.text())
        if self.ui.pushButton74:
            question[7][4] = int(self.ui.pushButton74.text())
        if self.ui.pushButton75:
            question[7][5] = int(self.ui.pushButton75.text())
        if self.ui.pushButton76:
            question[7][6] = int(self.ui.pushButton76.text())
        if self.ui.pushButton77:
            question[7][7] = int(self.ui.pushButton77.text())
        if self.ui.pushButton78:
            question[7][8] = int(self.ui.pushButton78.text())
        if self.ui.pushButton80:
            question[8][0] = int(self.ui.pushButton80.text())
        if self.ui.pushButton81:
            question[8][1] = int(self.ui.pushButton81.text())
        if self.ui.pushButton82:
            question[8][2] = int(self.ui.pushButton82.text())
        if self.ui.pushButton83:
            question[8][3] = int(self.ui.pushButton83.text())
        if self.ui.pushButton84:
            question[8][4] = int(self.ui.pushButton84.text())
        if self.ui.pushButton85:
            question[8][5] = int(self.ui.pushButton85.text())
        if self.ui.pushButton86:
            question[8][6] = int(self.ui.pushButton86.text())
        if self.ui.pushButton87:
            question[8][7] = int(self.ui.pushButton87.text())
        if self.ui.pushButton88:
            question[8][8] = int(self.ui.pushButton88.text())

        sudoku = Sudoku(question)
        sudoku.run()