def home(self): btn = QPushButton("Quit", self) btn.clicked.connect(self.close_application) btn.resize(btn.minimumSizeHint()) btn.move(100, 100) checkBox = QCheckBox('Enlarge Window', self) checkBox.stateChanged.connect(self.enlarge_window) checkBox.move(100, 60) checkBox.adjustSize() self.progress = QProgressBar(self) self.progress.setGeometry(200, 80, 250, 20) self.download_btn = QPushButton("Download", self) self.download_btn.move(200, 120) self.download_btn.clicked.connect(self.download) self.styleChoice = QLabel("Styles:", self) self.styleChoice.move(50, 150) comboBox = QComboBox(self) comboBox.addItems(QStyleFactory.keys()) # comboBox.addItem("motif") # comboBox.addItem("Windows") # comboBox.addItem("cde") # comboBox.addItem("Plastique") # comboBox.addItem("Cleanlooks") # comboBox.addItem("windowsvista") comboBox.move(50, 250) comboBox.activated[str].connect(self.style_choice) self.show()
def basicCheckBox(self, func=None, text='test', X=25, Y=75, isTri=False): checkBox = QCheckBox(text, self) checkBox.adjustSize() checkBox.move(X, Y) if isTri == True: checkBox.setTristate(True) if func is not None: checkBox.stateChanged.connect(func) return checkBox
def home(self): btn = QPushButton("Quit", self) btn.clicked.connect(self.close_application) btn.resize(btn.minimumSizeHint()) btn.move(100, 100) checkBox = QCheckBox('Enlarge Window', self) checkBox.stateChanged.connect(self.enlarge_window) checkBox.move(100, 60) checkBox.adjustSize() self.show()
def home(self): btn = QPushButton("Quit", self) btn.clicked.connect(self.close_application) btn.resize(btn.minimumSizeHint()) btn.move(100, 100) checkBox = QCheckBox('Enlarge Window', self) checkBox.stateChanged.connect(self.enlarge_window) checkBox.move(100, 60) checkBox.adjustSize() self.progress = QProgressBar(self) self.progress.setGeometry(200, 80, 250, 20) self.download_btn = QPushButton("Download", self) self.download_btn.move(200, 120) self.download_btn.clicked.connect(self.download) self.show()
class Window(QMainWindow): def __init__(self): super(Window, self).__init__() self.setGeometry(50,50, 2000,1200) self.setWindowTitle("TdLog : betting sports") self.home() self.flag = 0 self.setAutoFillBackground(True) p = self.palette() p.setColor(self.backgroundRole(), Qt.lightGray) self.setPalette(p) self.details_over_dtree_triggered = 0 self.details_over_bayes_triggered = 0 self.details_over_knn_triggered = 0 def home(self): # we use the next button to recompute the overview in case we change threshold and we already had pushed # the method buttons (knn, decision tree and bayes) self.knn_method_triggered = 0 self.decision_tree_method_triggered = 0 self.bayes_method_triggered = 0 self.flag = 0 # labels are used to print the overview results under the method buttons self.label_1 = QLabel(self) self.label_1.setText("") self.label_2 = QLabel(self) self.label_2.setText("") self.label_3 = QLabel(self) self.label_3.setText("") self.btn_Quit = QPushButton("Quit", self) self.btn_Quit.clicked.connect(self.quitt) # we can change the used threshold with the QLineEdit and then push threshold button to save that threshold # value self.threshold = 0.5 self.btn_Thresh = QPushButton("Threshold value", self) self.btn_Thresh.clicked.connect(self.threshold_value) self.label_Thresh = QLineEdit(self) self.label_Thresh.setText("0.5") self.label_Thresh_text = QLabel(self) self.label_Thresh_text.setText("") # at the beginning of the process, the user has to process data (cf the other file) self.btn_0 = QPushButton("Process data", self) self.btn_0.clicked.connect(self.processed_data) self.label_0 = QLabel(self) self.label_0.setText("Please process data") # these are the method buttons self.btn_1 = QPushButton("KNN method", self) self.btn_1.clicked.connect(self.launch_knn) self.details_knn = QPushButton("details..", self) self.details_knn.clicked.connect(self.details) self.details_bayes = QPushButton("details..", self) self.details_bayes.clicked.connect(self.details) self.details_dtree = QPushButton("details..", self) self.details_dtree.clicked.connect(self.details) self.btn_2 = QPushButton("Bayes", self) self.btn_2.clicked.connect(self.launch_bayes) self.btn_3 = QPushButton("Decision_tree", self) self.btn_3.clicked.connect(self.launch_decision_tree) # these are the next games buttons, with labels to print the next game the user has to bet on # to follow the path of the relating method self.btn_6 = QCheckBox("Next games you will bet on according to Decision Tree", self) self.btn_6.clicked.connect(self.next_games) self.label_6 = QLabel(self) self.label_6.setText("Please process data and try knn method \nbefore checking the box") self.btn_5 = QCheckBox("Next games you will bet on according to Bayes",self) self.btn_5.clicked.connect(self.next_games) self.label_5 = QLabel(self) self.label_5.setText("Please process data and try Bayes method \nbefore checking the box") self.btn_4 = QCheckBox("Next games you will bet on according to KNN", self) self.btn_4.clicked.connect(self.next_games) self.label_4 = QLabel(self) self.label_4.setText("Please process data and try decision tree \nmethod before checking the box") self.position() self.show() def position(self): # Here, we organize the user interface # This interface fits to gregoire's screen, but not to badr screen. # If it not fits your screen, please let us know your screen dimension and we will fastly # edit this code to make it great. self.btn_Quit.move(1500,0) self.btn_0.move(0,10) self.btn_0.adjustSize() self.label_0.move(0,50) self.label_0.adjustSize() self.btn_Thresh.move(600,0) self.btn_Thresh.adjustSize() self.label_Thresh.move(650,50) self.label_Thresh_text.move(650,100) self.label_Thresh_text.adjustSize() self.btn_1.move(250,350) self.btn_1.adjustSize() self.details_knn.move(120,470) self.details_knn.adjustSize() self.label_1.move(250,400) self.btn_2.move(650,350) self.btn_2.adjustSize() self.details_bayes.move(520,470) self.details_bayes.adjustSize() self.label_2.move(650,400) self.btn_3.move(1000,350) self.btn_3.adjustSize() self.details_dtree.move(870,470) self.details_dtree.adjustSize() self.label_3.move(1000,400) self.btn_6.move(1350,600) self.btn_6.adjustSize() self.label_4.move(1350,620) self.label_4.adjustSize() self.btn_5.move(770,600) self.btn_5.adjustSize() self.label_5.move(770,620) self.btn_4.move(120,600) self.btn_4.adjustSize() self.label_6.move(120,620) self.label_5.adjustSize() self.label_6.adjustSize() def processed_data(self): dataprocess.process_files() self.threshold = 0.5 # Creating a training files from seasons 07-08 to 18-19 self.keys_to_keep = ["FTR","B365H","B365D","B365A","HTGDBG","ATGDBG","HTPBG","ATPBG"] self.X =[] self.Y = [] file_name_total = "" for k in range(7,19) : file_name = str(k)+"-"+str(k+1)+"_processed.csv" file_name_total = file_name_total+""" """+file_name df=pd.read_csv('Training_Files/France/'+file_name, sep=',') # sep = "," fot F1_processed or sep = ";" for training_file # We only keep "before-game data" except FTR which we will use to train our classification algorithm dataset = {} df_dict = df.to_dict() print(file_name) for key in self.keys_to_keep : dataset[key] = df_dict[key] dataset_df = pd.DataFrame.from_dict(dataset) df_dict = dataset_df.T.to_dict() self.X+=[list(df_dict[i].values())[1:] for i in df_dict.keys()] self.Y+=[list(df_dict[i].values())[0] for i in df_dict.keys()] #check for NaN values flag = 0 X_copy=[] Y_copy=[] for i in range(len(self.X)) : for k in range(len(self.X[i])): if math.isnan(self.X[i][k]): flag = 1 if flag ==0 : X_copy+=[self.X[i]] Y_copy+=[self.Y[i]] else : print("Incorrect data : " + str(i)) flag = 0 self.X = X_copy self.Y=Y_copy for i in range(len(self.Y)) : if self.Y[i]=="H" : self.Y[i]=0 elif self.Y[i] =="D" : self.Y[i]=1 else : self.Y[i]=2 self.label_0.setText(file_name_total +"\n data successfully processed") self.label_0.adjustSize() # allow user to use the other buttons self.flag = 1 def quitt(self): self.close() def threshold_value(self): # we compare the threshold with a probability so it has to stand between 0 and 1 if (float(self.label_Thresh.text()) > 1 or float(self.label_Thresh.text()) < 0): self.label_Thresh_text.setText("please enter a value between 0 and 1") self.label_Thresh_text.adjustSize() else : self.threshold = float(self.label_Thresh.text()) if self.flag == 1: if self.knn_method_triggered == 1 : self.launch_knn() if self.bayes_method_triggered == 1: self.launch_bayes() if self.decision_tree_method_triggered == 1 : self.launch_decision_tree() if self.btn_4.checkState()==2 : self.used_method = 2 self.print_next_games(self.used_method) if self.btn_5.checkState() == 2: self.used_method = 1 self.print_next_games(self.used_method) if self.btn_6.checkState() : self.used_method = 0 self.print_next_games(self.used_method) self.details() def launch_knn(self): self.method_number = 2 self.method() def launch_decision_tree(self): self.method_number = 0 self.method() def launch_bayes(self): self.method_number = 1 self.method() def method(self): if self.flag == 1: r = random.random() random.shuffle(self.X, lambda:r) random.shuffle(self.Y, lambda:r) # we train the model with 80% of data then test it with the remaining part training_X = self.X[:int(len(self.X)-len(self.X)/5)] testing_X = self.X[int(len(self.X)-len(self.X)/5):] training_Y = self.Y[:int(len(self.Y)-len(self.Y)/5)] testing_Y = self.Y[int(len(self.Y)-len(self.Y)/5):] if self.method_number == 0: self.decision_tree_method_triggered = 1 self.dtree_model = DecisionTreeClassifier(max_depth = 10).fit(training_X, training_Y) predictions = self.dtree_model.predict_proba(testing_X) if self.method_number == 1: self.bayes_method_triggered = 1 self.gnb = GaussianNB().fit(training_X, training_Y) predictions = self.gnb.predict_proba(testing_X) if self.method_number == 2: self.knn_method_triggered = 1 self.knn = KNeighborsClassifier(n_neighbors = 3).fit(training_X, training_Y) # creating a confusion matrix predictions = self.knn.predict_proba(testing_X) accepted_games = [] accepted_Y = [] accepted_odd =[] sum_true_odd = 0 number_of_won_games = 0 # X_bet stands for the current cash over time X_bet = [20] for k in range (len(predictions)) : for i in range(len(predictions[k])) : if predictions[k][i]>self.threshold : accepted_games+=[i] accepted_Y+=[testing_Y[k]] accepted_odd+=[testing_X[k][i]] l = len(X_bet) if testing_Y[k] == i: sum_true_odd += testing_X[k][i] number_of_won_games += 1 X_bet.append(X_bet[l-1]+20*((sum_true_odd/number_of_won_games) - 1)) else : X_bet.append(X_bet[l-1]-20) if self.method_number == 0: self.X_bet_dtree = X_bet if self.method_number == 1: self.X_bet_bayes = X_bet if self.method_number == 2: self.X_bet_knn = X_bet cm = confusion_matrix(accepted_Y, accepted_games) # true class stands for the right answers true_class = cm[0][0]+cm[1][1]+cm[2][2] correct_answers = true_class/len(accepted_Y) correct_answers = round(correct_answers,4) correct_answers = str(correct_answers) average_bet = sum_true_odd/number_of_won_games average_bet = round(average_bet,4) average_bet = str(average_bet) average_gain = (true_class/len(accepted_Y))*(sum_true_odd/(true_class))*20-20 average_gain = round(average_gain,4) average_gain = str(average_gain) if self.method_number == 2: # it prints an overview self.label_1.setText("KNN correct answers (%):"+correct_answers+" \nAverage won odd :"+average_bet+" \nWhat you got betting 20 £ :"+average_gain) self.label_1.adjustSize() # if we checked the box it prints the next games if self.btn_4.checkState() == 2: self.used_method = 2 self.print_next_games(self.used_method) # if we pushed knn details button it plots again the graph if self.details_over_knn_triggered == 1: self.details() if self.method_number ==1: self.label_2.setText("Bayes correct answers (%):"+correct_answers+" \nAverage won odd :"+average_bet+" \nWhat you got betting 20 £ :"+average_gain) self.label_2.adjustSize() if self.btn_5.checkState()==2: self.used_method = 1 self.print_next_games(self.used_method) if self.details_over_bayes_triggered == 1: self.details() if self.method_number == 0: self.label_3.setText("Decision tree correct answers (%):"+correct_answers+" \nAverage won odd :"+average_bet+" \nWhat you got betting 20 £ :"+average_gain) self.label_3.adjustSize() if self.btn_6.checkState()==2: self.used_method = 0 self.print_next_games(self.used_method) if self.details_over_dtree_triggered == 1: self.details() else : self.label_1.setText("""Please process the data before starting analyse them ...""") self.label_1.adjustSize() self.label_2.setText("""Please process the data before starting analyse them ...""") self.label_2.adjustSize() self.label_3.setText("""Please process the data before starting analyse them ...""") self.label_3.adjustSize() ### Those functions print on the user interface the next games and teams he has to bet on def next_games(self): if self.flag == 1 : if self.btn_4.checkState() == 2 : self.used_method = 2 self.print_next_games(self.used_method) if self.btn_5.checkState() == 2 : self.used_method = 1 self.print_next_games(self.used_method) if self.btn_6.checkState() == 2: self.used_method = 0 self.print_next_games(self.used_method) def print_next_games(self, method_name): df = pd.read_csv("Next_games.csv", sep=';') dataset = {} df_dict_origin = df.to_dict() for key in self.keys_to_keep : dataset[key] = df_dict_origin[key] dataset_df = pd.DataFrame.from_dict(dataset) df_dict = dataset_df.T.to_dict() X =[] X +=[list(df_dict[i].values())[1:] for i in df_dict.keys()] if method_name == 0 : predictions = self.dtree_model.predict_proba(X) if method_name == 1 : predictions = self.gnb.predict_proba(X) if method_name == 2 : predictions = self.knn.predict_proba(X) Games_you_need_to_bet_on = [] number_of_bets = 0 for i in range(len(predictions)) : # we browse predictions and print the team and the game if our prediction are good enough to bet on it if (predictions[i][0] > self.threshold) : # if probability of home team victory is higher than the threshold, we bet on home team Games_you_need_to_bet_on.append("\nBet on %s during %s against %s on %s" %(df_dict_origin["HomeTeam"][i],df_dict_origin["HomeTeam"][i],df_dict_origin["AwayTeam"][i],df_dict_origin["Date"][i])) number_of_bets += 1 if (predictions[i][1] > self.threshold) : Games_you_need_to_bet_on.append("\nBet on a draw during %s against %s on %s"%(df_dict_origin["HomeTeam"][i],df_dict_origin["AwayTeam"][i],df_dict_origin["Date"][i])) number_of_bets += 1 if (predictions[i][2] > self.threshold) : Games_you_need_to_bet_on.append("\nBet on %s during %s against %s on %s"%(df_dict_origin["AwayTeam"][i],df_dict_origin["HomeTeam"][i],df_dict_origin["AwayTeam"][i],df_dict_origin["Date"][i])) number_of_bets += 1 if method_name == 0: self.label_4.setText(' '.join(Games_you_need_to_bet_on)) self.label_4.adjustSize() if method_name == 1: self.label_5.setText(' '.join(Games_you_need_to_bet_on)) self.label_5.adjustSize() if method_name == 2: self.label_6.setText(' '.join(Games_you_need_to_bet_on)) self.label_6.adjustSize() ### Those functions plot the details of current cash over time according relating to the differents kinds of method we consider def details(self): if self.flag == 1: if self.decision_tree_method_triggered == 1: self.details_over_dtree_triggered = 1 if self.bayes_method_triggered == 1: self.details_over_bayes_triggered = 1 if self.knn_method_triggered == 1: self.details_over_knn_triggered = 1 self.draw() def draw(self): # we plot the three graphs on the same window to compare them easily plt.figure(1) plt.clf() plt.subplot(221) if self.details_over_dtree_triggered == 1: l = len(self.X_bet_dtree) Y = [1]*(l) for i in range(1,l): Y[i] = Y[i-1]+1 plt.figure(1) plt.plot(Y, self.X_bet_dtree, 'b') plt.title("Decision Tree method") plt.ylabel("Current_cash") plt.xlabel("Time") plt.subplot(222) if self.details_over_bayes_triggered == 1: l = len(self.X_bet_bayes) Y = [1]*(l) for i in range(1,l): Y[i] = Y[i-1]+1 plt.plot(Y, self.X_bet_bayes, 'm') plt.title("Bayes method") plt.ylabel("Current_cash") plt.xlabel("Time") plt.subplot (223) if self.details_over_knn_triggered == 1: l = len(self.X_bet_knn) Y = [1]*(l) for i in range(1,l): Y[i] = Y[i-1]+1 plt.plot(Y, self.X_bet_knn, 'g') plt.title("KNN method") plt.ylabel("Current_cash") plt.xlabel("Time") plt.draw()
class Example(QMainWindow): # settings={} def __init__(self): super().__init__() self.movieObj = whole_movie() self.movieObj.signal.connect(self.update_status) self.movieObj.sig_tqdm.connect(self.update_tqdm) self.movieObj.sig_state.connect(self.update_state) self.initUI() def initUI(self): # self.initSettings() # self.settings = self.importSettings() self.statusBar() defaultFontSize = 10 # 左揃えのX座標 defaultLineLeft = 40 # メニューバーのアイコン設定 openFile = QAction('Open', self) # ショートカット設定 openFile.setShortcut('Ctrl+O') # ステータスバー設定 openFile.setStatusTip('Open new File') openFile.triggered.connect(self.showDialog) # メニューバー作成 menubar = self.menuBar() fileMenu = menubar.addMenu('&File') fileMenu.addAction(openFile) openFileButton = QPushButton("ファイルを開く", self) openFileButton.setFont(QFont('Arial', defaultFontSize)) openFileButton.move(defaultLineLeft, 48) openFileButton.clicked.connect(self.showDialog) self.openFileLabel = QLabel(self) self.openFileLabel.setFont(QFont('Arial', defaultFontSize)) self.openFileLabel.move(160, 53) self.openFileLabel.setText("ファイルが開かれていません") self.openFileLabel.adjustSize() self.writeWholeButton = QCheckBox('全試合を繋げた動画ファイル書き出す', self) self.writeWholeButton.toggle() self.writeWholeButton.move(defaultLineLeft, 200) self.writeWholeButton.adjustSize() self.forceExecButton = QCheckBox('前回のログを無視して再実行(非推奨)', self) self.forceExecButton.move(defaultLineLeft, 225) self.forceExecButton.adjustSize() executeButton = QPushButton("処理開始", self) executeButton.setFont(QFont('Arial', defaultFontSize)) executeButton.move(315, 98) # クリックされたらbuttonClickedの呼び出し executeButton.clicked.connect(self.requestButtonClicked) self.pbar = QProgressBar(self) # self.pbar.setTextVisible(False) self.pbar.setMinimumWidth(255) self.pbar.move(defaultLineLeft, 98) self.ETALabel = QLabel(self) self.ETALabel.move(defaultLineLeft + 120, 138) self.ETALabel.setMinimumWidth(120) self.ETALabel.setFont(QFont('Arial', defaultFontSize - 2)) self.stateLabel = QLabel(self) self.stateLabel.move(defaultLineLeft, 138) self.stateLabel.setMinimumWidth(120) self.stateLabel.setFont(QFont('Arial', defaultFontSize - 2)) self.setGeometry(300, 300, 450, 270) self.setWindowTitle('イカカット') self.show() def requestButtonClicked(self): # fname[0]は選択したファイルのパス(ファイル名を含む # self.exportSettings() self.exec_process() def showDialog(self): open_path = "c://" user_name = os.getlogin() # 第二引数はダイアログのタイトル、第三引数は表示するパス if os.path.exists("c://Users/" + user_name + "/Videos"): open_path = "c://Users/" + user_name + "/Videos" self.fname = QFileDialog.getOpenFileName( self, 'Open file', open_path, "Video files(*.mp4 *.mkv *.flv *.avi);;All files(*)") if self.fname[0]: self.openFileLabel.setText(self.fname[0]) self.openFileLabel.adjustSize() # def initSettings(self): # if not os.path.exists("settings.json"): # self.exportSettings() # def importSettings(self): # with open("settings.json") as sjson: # try: # sjson_load = json.load(sjson) # return sjson_load # except Exception as e: # return # def exportSettings(self): # self.settings={} # with open("settings.json","w") as sjson: # json.dump(self.settings,sjson) # def closeEvent(self, event): # self.exportSettings() @pyqtSlot(int) def update_status(self, progress): self.pbar.setValue(progress) # progressBarを進める @pyqtSlot(str) def update_tqdm(self, output): self.ETALabel.setText(output) @pyqtSlot(str) def update_state(self, output): self.stateLabel.setText(output) @pyqtSlot() def exec_process(self): if self.fname[0]: # ファイル読み込み self.movieObj.initialize(src_path=self.fname[0]) self.pbar.setValue(0) self.pbar.setMinimum(0) self.pbar.setMaximum(int(self.movieObj.num_of_frames)) self.movieObj.setOptions( force_exec=self.forceExecButton.checkState(), write_clips=1, write_whole=self.writeWholeButton.checkState()) self.movieObj.start()
class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.timer = QTimer() self.timer.timeout.connect(self.tick) self.days = 0 self.totalPapers = 0 self.perfect = { '1': [[6, 2], [1, 4, 5, 8], [3, 7]], '2': [[1, 2, 8], [6, 7], [3, 4, 5]], '3': [[4, 5, 6, 1, 3], [8], [2, 7]], '4': [[7], [], [1, 2, 3, 4, 5, 6, 8]], '5': [[1, 7], [8, 2], [3, 4, 5, 6]], '6': [[2, 8, 1, 7], [3], [4, 5, 6]], '7': [[6, 3, 7, 4, 5], [1], [2, 8]], '8': [[8, 2, 6, 4], [1, 5], [3, 7]] } self.levelOfKnowledge = 0 self.setFont(QtGui.QFont("Bahnschrift Light SemiCondensed", 20)) self.setMouseTracking(True) self.setWindowTitle('Game maker') self.setGeometry(10, 10, 1024, 768) self.setFixedSize(1024, 768) palette = QPalette() img = QImage('mainWindow.png') scaled = img.scaled(self.size(), Qt.KeepAspectRatioByExpanding, transformMode=Qt.SmoothTransformation) palette.setBrush(QPalette.Window, QBrush(scaled)) self.setPalette(palette) pixmap = QPixmap('shopButton.png') self.shopButton = QLabel('', self) self.shopButton.setPixmap(pixmap) self.shopButton.setMouseTracking(True) self.shopButton.move(500, 7) pixmap = QPixmap('devButton.png') self.devButton = QLabel('', self) self.devButton.setMouseTracking(True) self.devButton.setPixmap(pixmap) self.devButton.move(700, 7) self.cash = 100 self.money = QLabel("Деньги:\n 100$", self) self.money.move(10, 7) self.subs = QLabel("Фанаты:\n 0", self) self.subs.move(140, 7) self.date = QLabel("Дни:\n 0", self) self.date.move(280, 7) self.table = QLabel( 'Создайте свою первую игру! \n \nЗаработано за все дни: \n 0', self) self.table.move(150, 200) self.table.setStyleSheet( 'border-style: solid; border-width: 3px; border-color: black;' 'background-color: rgb(207, 162, 98);') self.nalog = QLabel("До налога: 30 \n Налог: 0", self) self.nalog.move(800, 105) self.nalog.setStyleSheet( 'border-style: solid; border-width: 3px; border-color: black;' 'background-color: rgb(207, 162, 98);') self.shop = QWidget(self) self.shop.move(10000, 10000) self.shop.resize(400, 353) self.shop.setMouseTracking(True) self.shopItem1 = QLabel('', self.shop) self.shopItem1.setPixmap(QPixmap('shopItem1.png')) self.shopItem1.move(10, 10) self.shopItem1.setMouseTracking(True) self.shopItem2 = QLabel('', self.shop) self.shopItem2.setPixmap(QPixmap('shopItem22.png')) self.shopItem2.move(200, 10) self.shopItem2.setMouseTracking(True) self.shopItem3 = QLabel('', self.shop) self.shopItem3.setPixmap(QPixmap('shopItem4.png')) self.shopItem3.move(10, 250) self.shopItem3.setMouseTracking(True) self.shopItem4 = QLabel('', self.shop) self.shopItem4.setPixmap(QPixmap('shopItem4.png')) self.shopItem4.move(200, 250) self.shopItem4.setMouseTracking(True) self.shopExit = QLabel('', self.shop) self.shopExit.setPixmap(QPixmap('shopExit.png')) self.shopExit.move(360, 10) self.shopExit.setMouseTracking(True) self.shop.setStyleSheet( 'border-style: solid; border-width: 3px; border-color: black;' 'background-color: rgb(207, 162, 98);') self.shopOn = False self.devPage1 = QWidget(self) self.devPage1.move(10000, 10000) self.devPage1.resize(600, 330) self.devPage1.setMouseTracking(True) self.devPage1.setStyleSheet( 'border-style: solid; border-width: 3px; border-color: black;' 'background-color: rgb(207, 162, 98);') self.theme = 0 self.style = 0 self.type = 0 self.platform = 0 self.styles = QGroupBox('Жанры', self.devPage1) self.styles.move(10, 10) self.styles.setMouseTracking(True) self.style1 = QRadioButton('Приключения', self.styles) self.style1.move(10, 20) self.style1.toggle() self.style2 = QRadioButton('Шутер', self.styles) self.style2.move(100, 20) self.style3 = QRadioButton('Слэшэр', self.styles) self.style3.move(10, 45) self.style4 = QRadioButton('MMO', self.styles) self.style4.move(100, 45) self.style5 = QRadioButton('MOBA', self.styles) self.style5.move(10, 70) self.style6 = QRadioButton('RPG', self.styles) self.style6.move(100, 70) self.style7 = QRadioButton('Симулятор', self.styles) self.style7.move(10, 95) self.style8 = QRadioButton('Кооператив', self.styles) self.style8.move(100, 95) self.styles.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;') self.styles.setFont(QtGui.QFont("Bahnschrift Light SemiCondensed", 12)) self.style1.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.style2.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.style3.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.style4.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.style5.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.style6.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.style7.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.style8.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.style1.adjustSize() self.style2.adjustSize() self.style3.adjustSize() self.style4.adjustSize() self.style5.adjustSize() self.style6.adjustSize() self.style7.adjustSize() self.style8.adjustSize() self.styles.adjustSize() self.themes = QGroupBox('Темы', self.devPage1) self.themes.move(300, 10) self.themes.setMouseTracking(True) self.theme1 = QRadioButton('Космос', self.themes) self.theme1.move(10, 20) self.theme1.toggle() self.theme2 = QRadioButton('Вестерн', self.themes) self.theme2.move(120, 20) self.theme3 = QRadioButton('Фэнтэзи', self.themes) self.theme3.move(10, 45) self.theme4 = QRadioButton('Ферма', self.themes) self.theme4.move(120, 45) self.theme5 = QRadioButton('Детектив', self.themes) self.theme5.move(10, 70) self.theme6 = QRadioButton('Война', self.themes) self.theme6.move(120, 70) self.theme7 = QRadioButton('Средневековье', self.themes) self.theme7.move(10, 95) self.theme8 = QRadioButton('Будущее', self.themes) self.theme8.move(120, 95) self.themes.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;') self.themes.setFont(QtGui.QFont("Bahnschrift Light SemiCondensed", 12)) self.theme1.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.theme2.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.theme3.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.theme4.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.theme5.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.theme6.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.theme7.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.theme8.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.theme1.adjustSize() self.theme2.adjustSize() self.theme3.adjustSize() self.theme4.adjustSize() self.theme5.adjustSize() self.theme6.adjustSize() self.theme7.adjustSize() self.theme8.adjustSize() self.themes.adjustSize() self.platforms = QGroupBox('Платформы', self.devPage1) self.platforms.move(10, 150) self.platforms.setMouseTracking(True) self.platform1 = QRadioButton('MacOs', self.platforms) self.platform1.move(10, 20) self.platform1.toggle() self.platform2 = QRadioButton('Android', self.platforms) self.platform2.move(120, 20) self.platform3 = QRadioButton('IOS', self.platforms) self.platform3.move(10, 45) self.platform4 = QRadioButton('PC', self.platforms) self.platform4.move(120, 45) self.platforms.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;') self.platforms.setFont( QtGui.QFont("Bahnschrift Light SemiCondensed", 12)) self.platform1.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.platform2.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.platform3.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.platform4.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.platform1.adjustSize() self.platform2.adjustSize() self.platform3.adjustSize() self.platform4.adjustSize() self.platforms.adjustSize() self.types = QGroupBox('Тип', self.devPage1) self.types.move(300, 150) self.types.setMouseTracking(True) self.type1 = QRadioButton('Инди', self.types) self.type1.move(10, 20) self.type1.toggle() self.type2 = QRadioButton('A', self.types) self.type2.move(120, 20) self.type3 = QRadioButton('AA', self.types) self.type3.move(10, 45) self.type4 = QRadioButton('AAA', self.types) self.type4.move(120, 45) self.types.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;') self.types.setFont(QtGui.QFont("Bahnschrift Light SemiCondensed", 12)) self.type1.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.type2.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.type3.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.type4.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.type1.adjustSize() self.type2.adjustSize() self.type3.adjustSize() self.type4.adjustSize() self.types.adjustSize() self.pushToDev = QPushButton('Начать', self.devPage1) self.pushToDev.setMouseTracking(True) self.pushToDev.move(280, 270) self.pushToDev.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;' 'background-color: rgb(207, 162, 198);') self.pushToDev.clicked.connect(self.showDevPage2) self.devPage2 = QWidget(self) self.devPage2.move(10000, 10000) self.devPage2.resize(600, 330) self.devPage2.setMouseTracking(True) self.devPage2.setStyleSheet( 'border-style: solid; border-width: 3px; border-color: black;' 'background-color: rgb(207, 162, 98);') self.devPage1On = False self.devPage2On = False self.levelOne = QGroupBox('Знания I', self.devPage2) self.levelOne.move(10, 10) self.levelOne.setMouseTracking(True) self.techno11 = QCheckBox('2D(5$)', self.levelOne) self.techno11.move(10, 20) self.techno11.setMouseTracking(True) self.techno12 = QCheckBox('6 Bit Sound(15$)', self.levelOne) self.techno12.move(150, 20) self.techno13 = QCheckBox('HD(25$)', self.levelOne) self.techno13.move(10, 80) self.techno14 = QCheckBox('C++(35$)', self.levelOne) self.techno14.move(150, 80) self.levelOne.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;') self.levelOne.setFont( QtGui.QFont("Bahnschrift Light SemiCondensed", 12)) self.techno11.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno12.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno13.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno14.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno14.adjustSize() self.techno13.adjustSize() self.techno12.adjustSize() self.techno11.adjustSize() self.levelOne.adjustSize() self.techno12.setMouseTracking(True) self.techno13.setMouseTracking(True) self.techno14.setMouseTracking(True) self.levelTwo = QGroupBox('Знания II', self.devPage2) self.levelTwo.move(10, 170) self.levelTwo.setMouseTracking(True) self.techno21 = QCheckBox('3D(100$)', self.levelTwo) self.techno21.move(10, 20) self.techno21.setMouseTracking(True) self.techno22 = QCheckBox('8 Bit Sound(300$)', self.levelTwo) self.techno22.move(150, 20) self.techno23 = QCheckBox('Full HD(500$)', self.levelTwo) self.techno23.move(10, 80) self.techno24 = QCheckBox('C(1000$)', self.levelTwo) self.techno24.move(150, 80) self.levelTwo.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;') self.levelTwo.setFont( QtGui.QFont("Bahnschrift Light SemiCondensed", 12)) self.techno21.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno22.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno23.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno24.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno24.adjustSize() self.techno23.adjustSize() self.techno22.adjustSize() self.techno21.adjustSize() self.levelTwo.adjustSize() self.techno22.setMouseTracking(True) self.techno23.setMouseTracking(True) self.techno24.setMouseTracking(True) self.levelThree = QGroupBox('Знания III', self.devPage2) self.levelThree.move(280, 10) self.levelThree.setMouseTracking(True) self.techno31 = QCheckBox('4D(3500$)', self.levelThree) self.techno31.move(10, 20) self.techno31.setMouseTracking(True) self.techno32 = QCheckBox('16 Bit Sound(7000$)', self.levelThree) self.techno32.move(150, 20) self.techno33 = QCheckBox('2K HD(13000$)', self.levelThree) self.techno33.move(10, 80) self.techno34 = QCheckBox('C#(20000$)', self.levelThree) self.techno34.move(150, 80) self.levelThree.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;') self.levelThree.setFont( QtGui.QFont("Bahnschrift Light SemiCondensed", 12)) self.techno31.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno32.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno33.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno34.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno34.adjustSize() self.techno33.adjustSize() self.techno32.adjustSize() self.techno31.adjustSize() self.techno31.setMouseTracking(True) self.techno32.setMouseTracking(True) self.techno34.setMouseTracking(True) self.techno33.setMouseTracking(True) self.levelThree.adjustSize() self.timeToEnd = 0 self.timeDev = False self.levelFour = QGroupBox('Знания IV', self.devPage2) self.levelFour.move(280, 170) self.levelFour.setMouseTracking(True) self.techno41 = QCheckBox('5D(50000$)', self.levelFour) self.techno41.setMouseTracking(True) self.techno41.move(10, 20) self.techno42 = QCheckBox('24 Bit Sound(60000$)', self.levelFour) self.techno42.move(150, 20) self.techno43 = QCheckBox('Ultra HD(70000$)', self.levelFour) self.techno43.move(10, 80) self.techno44 = QCheckBox('Python(90000$)', self.levelFour) self.techno44.move(150, 80) self.levelFour.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;') self.levelFour.setFont( QtGui.QFont("Bahnschrift Light SemiCondensed", 12)) self.techno41.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno42.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno43.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno44.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.techno44.adjustSize() self.techno43.adjustSize() self.techno42.adjustSize() self.techno41.adjustSize() self.techno42.setMouseTracking(True) self.techno44.setMouseTracking(True) self.techno43.setMouseTracking(True) self.levelFour.adjustSize() self.pushToStartDev = QPushButton('Начать', self.devPage2) self.pushToStartDev.setMouseTracking(True) self.pushToStartDev.move(280, 290) self.pushToStartDev.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;' 'background-color: rgb(207, 162, 198);') self.pushToStartDev.clicked.connect(self.showDevPage3) self.timeToEnd = 5 self.totalMoney = QLabel('Итого: 0', self.devPage2) self.totalMoney.move(100, 290) self.totalMoney.setStyleSheet( 'border-style: solid; border-width: 1px; border-color: black;' 'background-color: rgb(207, 162, 198);') self.devPage1Exit = QLabel('', self.devPage1) self.devPage1Exit.setPixmap(QPixmap('shopExit.png')) self.devPage1Exit.move(560, 5) self.devPage1Exit.adjustSize() self.devPage1Exit.setMouseTracking(True) self.devPage2Exit = QLabel('', self.devPage2) self.devPage2Exit.setPixmap(QPixmap('shopExit.png')) self.devPage2Exit.move(560, 5) self.devPage2Exit.adjustSize() self.devPage2Exit.setMouseTracking(True) self.devPage3 = QWidget(self) self.devPage3.move(10000, 10000) self.devPage3.resize(600, 330) self.devPage3.setMouseTracking(True) self.devPage3.setStyleSheet( 'border-style: solid; border-width: 3px; border-color: black;' 'background-color: rgb(207, 162, 98);') self.warning = QLabel('', self.devPage2) self.warning.move(400, 290) self.warning.setFont(QtGui.QFont("Bahnschrift Light SemiCondensed", 10)) self.warning.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;') self.timeDev = False self.timeSale = False self.fans = 0 # //// self.startPage = QWidget(self) self.startPage.move(0, 0) self.startPage.setFont( QtGui.QFont("Bahnschrift Light SemiCondensed", 30)) self.startPage.resize(1024, 768) self.startPage.setStyleSheet( 'border-style: solid; border-width: 3px; border-color: black;' 'background-color: rgb(207, 162, 98);') self.startText = QLabel( 'Здравствуй, начинающий разработчик! Начиная игру, сначала \n тебе потребуются' 'купить набор "Знания I" в магазине, затем \nты можешь начать разработку своей ' 'первой игры в разделе\n "Разработка". на первом этапе ты можешь выбрать тему и ' 'жанр\n игры, а также платформу и тип,\которые открываются с каждым\n набором знаний. ' 'На втором этапе тебе будет доступен выбор \nтехнологий, который с каждым набором ' 'знаний\n будет увеличиваться. Так же каждые 30 дней тебе придется \nплатить налог, ' 'так что будь осторожен!. Удачи!! ', self.startPage) self.startText.setStyleSheet( 'border-style: solid; border-width: 0px; border-color: black;' 'background-color: rgb(207, 162, 98);') self.startText.move(10, 10) self.startButton = QPushButton('Начать', self.startPage) self.startButton.move(700, 600) self.startButton.adjustSize() self.startButton.clicked.connect(self.start) def start(self): # начало игры self.startPage.move(10000, 10000) self.timer.start(1550) def mouseMoveEvent(self, event): # обработка передвижения мыши if 500 <= event.x() <= 645 and 7 <= event.y() <= 95: self.shopButton.setPixmap(QPixmap('shopButton2.png')) elif 700 <= event.x() <= 845 and 7 <= event.y() <= 95: self.devButton.setPixmap(QPixmap('devButton2.png')) elif 310 <= event.x() <= 455 and 211 <= event.y( ) <= 297 and self.shopOn: self.shopItem1.setPixmap(QPixmap('shopItem12.png')) elif 500 <= event.x() <= 644 and 211 <= event.y( ) <= 297 and self.shopOn: self.shopItem2.setPixmap(QPixmap('shopItem2.png')) elif 310 <= event.x() <= 455 and 461 <= event.y( ) <= 547 and self.shopOn: self.shopItem3.setPixmap(QPixmap('shopItem32.png')) elif 500 <= event.x() <= 644 and 461 <= event.y( ) <= 547 and self.shopOn: self.shopItem4.setPixmap(QPixmap('shopItem42.png')) elif self.devPage2On: self.totalMon = self.cashToDev if self.techno11.isChecked(): self.totalMon += 5 if self.techno12.isChecked(): self.totalMon += 10 if self.techno13.isChecked(): self.totalMon += 20 if self.techno14.isChecked(): self.totalMon += 35 if self.techno21.isChecked(): self.totalMon += 100 if self.techno22.isChecked(): self.totalMon += 300 if self.techno23.isChecked(): self.totalMon += 500 if self.techno24.isChecked(): self.totalMon += 1000 if self.techno31.isChecked(): self.totalMon += 3500 if self.techno32.isChecked(): self.totalMon += 7000 if self.techno33.isChecked(): self.totalMon += 13000 if self.techno34.isChecked(): self.totalMon += 20000 if self.techno41.isChecked(): self.totalMon += 50000 if self.techno42.isChecked(): self.totalMon += 60000 if self.techno43.isChecked(): self.totalMon += 70000 if self.techno44.isChecked(): self.totalMon += 90000 self.totalMoney.setText('Итого: ' + str(self.totalMon)) self.totalMoney.adjustSize() else: self.shopButton.setPixmap(QPixmap('shopButton.png')) self.shopItem1.setPixmap(QPixmap('shopItem1.png')) self.devButton.setPixmap(QPixmap('devButton.png')) self.shopItem2.setPixmap(QPixmap('shopItem22.png')) self.shopItem3.setPixmap(QPixmap('shopItem3.png')) self.shopItem4.setPixmap(QPixmap('shopItem4.png')) def mousePressEvent(self, event): # обработка нажатия кнопок мыши if event.button() == Qt.LeftButton: if 500 <= event.x() <= 645 and 7 <= event.y() <= 95: self.showShop() elif 700 <= event.x() <= 845 and 7 <= event.y() <= 95: self.showDev() elif 660 <= event.x() <= 690 and 211 <= event.y( ) <= 241 and self.shopOn: self.shopOn = False self.shop.move(10000, 10000) elif 760 <= event.x() <= 790 and 105 <= event.y( ) <= 135 and self.devPage1On: self.devPage1On = False self.devPage1.move(1000, 1000) self.timer.start() elif 760 <= event.x() <= 790 and 105 <= event.y( ) <= 135 and self.devPage2On: self.devPage2On = False self.timer.start() self.devPage2.move(10000, 10000) elif 310 <= event.x() <= 455 and 211 <= event.y( ) <= 297 and self.shopOn: if self.levelOfKnowledge < 1 and self.cash >= 5: self.levelOfKnowledge = 1 self.cash -= 5 self.money.setText('Деньги: \n ' + str(self.cash)) elif 500 <= event.x() <= 644 and 211 <= event.y( ) <= 297 and self.shopOn: if self.levelOfKnowledge < 2 and self.cash >= 500: self.levelOfKnowledge = 2 self.cash -= 500 self.money.setText('Деньги: \n ' + str(self.cash)) elif 310 <= event.x() <= 455 and 461 <= event.y( ) <= 547 and self.shopOn: if self.levelOfKnowledge < 3 and self.cash >= 20000: self.levelOfKnowledge = 3 self.cash -= 20000 self.money.setText('Деньги: \n ' + str(self.cash)) elif 500 <= event.x() <= 644 and 461 <= event.y( ) <= 547 and self.shopOn: if self.levelOfKnowledge < 4 and self.cash >= 200000: self.levelOfKnowledge = 4 self.cash -= 200000 self.money.setText('Деньги: \n ' + str(self.cash)) def showShop(self): # активация окошка магазина self.shopOn = True self.shop.move(300, 200) def showDev(self): # активация окошка первого этапа разработки игры self.devPage1On = True self.timer.stop() self.platform1.setEnabled(False) self.platform2.setEnabled(False) self.platform3.setEnabled(False) self.platform4.setEnabled(False) self.type1.setEnabled(False) self.type2.setEnabled(False) self.type3.setEnabled(False) self.type4.setEnabled(False) if self.levelOfKnowledge >= 1: self.platform1.setEnabled(True) self.type1.setEnabled(True) if self.levelOfKnowledge >= 2: self.platform2.setEnabled(True) self.type2.setEnabled(True) if self.levelOfKnowledge >= 3: self.platform3.setEnabled(True) self.type3.setEnabled(True) if self.levelOfKnowledge >= 4: self.platform4.setEnabled(True) self.type4.setEnabled(True) self.devPage1.move(200, 100) def tick(self): # описание действия таймера if self.cash < 0: msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setText("Вы проиграли!:(") msg.setWindowTitle("Проигрыш") retval = msg.exec_() if retval == QMessageBox.Ok: sys.exit(app.exec_()) self.days += 1 self.date.setText('Дни:\n ' + str(self.days)) self.date.adjustSize() if self.timeDev: if self.timeToEnd > 1: self.timeToEnd -= 1 self.table.setText('Дней до релиза: \n' + str(self.timeToEnd)) self.table.adjustSize() else: self.relise() elif self.timeSale: if self.timeToEnd > 0: self.timeToEnd -= 1 self.sale() else: self.table.setText( 'Конец продаж! \n \nЗаработано за все дни: \n' + str(self.totalPapers)) self.table.adjustSize() self.timeSale = False self.timeToEnd = 5 if self.days % 30 == 0: print(2) self.nalog.setText('Плоти Налог!!') self.nalog.adjustSize() self.cash -= int( (self.totalPapers / (self.days / 30) + self.fans / (self.days / 30))) + self.levelOfKnowledge * self.days * 2 self.money.setText('Деньги: \n ' + str(self.cash)) self.money.adjustSize() else: self.nalog.setText("До налога:" + str(30 - self.days % 30) + "\n Налог: " + str( int((self.totalPapers / (self.days / 30) + self.fans / (self.days / 30))) + self.levelOfKnowledge * self.days * 2)) self.nalog.adjustSize() def showDevPage2(self): # показывается окошко второго этапа разработки self.cashToDev = 0 if self.levelOfKnowledge > 0: if self.theme1.isChecked(): self.theme = 1 elif self.theme2.isChecked(): self.theme = 2 elif self.theme3.isChecked(): self.theme = 3 elif self.theme4.isChecked(): self.theme = 4 elif self.theme5.isChecked(): self.theme = 5 elif self.theme6.isChecked(): self.theme = 6 elif self.theme7.isChecked(): self.theme = 7 elif self.theme8.isChecked(): self.theme = 8 if self.style1.isChecked(): self.style = 1 elif self.style2.isChecked(): self.style = 2 elif self.style3.isChecked(): self.style = 3 elif self.style4.isChecked(): self.style = 4 elif self.style5.isChecked(): self.style = 5 elif self.style6.isChecked(): self.style = 6 elif self.style7.isChecked(): self.style = 7 elif self.style8.isChecked(): self.style = 8 elif self.type1.isChecked(): self.type = 1 self.cashToDev += 10 elif self.type2.isChecked(): self.type = 2 self.cashToDev += 300 elif self.type3.isChecked(): self.type = 3 self.cashToDev += 4000 elif self.type4.isChecked(): self.cashToDev += 40000 self.type = 4 if self.platform1.isChecked(): self.platform = 1 self.cashToDev += 10 elif self.platform2.isChecked(): self.platform = 2 self.cashToDev += 400 elif self.platform3.isChecked(): self.platform = 3 self.cashToDev += 10000 elif self.platform4.isChecked(): self.platform = 4 self.cashToDev += 60000 self.devPage1On = False self.totalMoney.setText('Итого: ' + str(self.cashToDev)) self.totalMoney.adjustSize() self.devPage1.move(10000, 10000) self.levelOne.setEnabled(False) self.levelTwo.setEnabled(False) self.levelThree.setEnabled(False) self.levelFour.setEnabled(False) self.type4.setEnabled(False) if self.levelOfKnowledge >= 1: self.levelOne.setEnabled(True) if self.levelOfKnowledge >= 2: self.levelTwo.setEnabled(True) if self.levelOfKnowledge >= 3: self.levelThree.setEnabled(True) if self.levelOfKnowledge >= 4: self.levelFour.setEnabled(True) self.devPage2On = True self.devPage2.move(200, 100) def showDevPage3(self): self.totalTechno = 0 if self.techno11.isChecked(): self.totalTechno += 0.5 if self.techno12.isChecked(): self.totalTechno += 0.5 if self.techno13.isChecked(): self.totalTechno += 0.5 if self.techno14.isChecked(): self.totalTechno += 1 if self.techno21.isChecked(): self.totalTechno += 4 if self.techno22.isChecked(): self.totalTechno += 4 if self.techno23.isChecked(): self.totalTechno += 4 if self.techno24.isChecked(): self.totalTechno += 8 if self.techno31.isChecked(): self.totalTechno += 64 if self.techno32.isChecked(): self.totalTechno += 64 if self.techno33.isChecked(): self.totalTechno += 64 if self.techno34.isChecked(): self.totalTechno += 64 if self.techno41.isChecked(): self.totalTechno += 256 if self.techno42.isChecked(): self.totalTechno += 256 if self.techno43.isChecked(): self.totalTechno += 512 if self.techno44.isChecked(): self.totalTechno += 512 if self.cash < self.totalMon: self.warning.setText('Недостаточно денег') self.warning.adjustSize() elif self.totalTechno == 0: self.warning.setText('Выберите хотя бы 1 технологию') self.warning.adjustSize() else: self.cash -= self.totalMon self.money.setText("Деньги: \n" + str(self.cash)) self.startDev() def relise(self): # метод для релиза игры self.table.setText('Релиз! \n \nЗаработано за все дни: \n' + str(self.totalPapers)) self.table.adjustSize() self.timeDev = False self.timeToEnd = 5 self.timeSale = True def startDev(self): # метод для описания процесса разработки self.timeDev = True self.tick() self.timer.start() self.devPage2On = False self.devPage2.move(10000, 10000) self.table.setText('Дней до релиза: \n' + str(self.timeToEnd)) self.table.adjustSize() def sale(self): # метод для процесса продажи игры myltiply1 = 10 + self.platform + self.type if self.style in self.perfect[str(self.theme)][0]: myltiply2 = 2 elif self.style in self.perfect[str(self.theme)][1]: myltiply2 = 1 else: myltiply2 = 0.5 a = int( randint(self.totalTechno * 10, self.totalTechno * 20) * myltiply2 / 10 * myltiply1 + (self.fans * 10 + 1)) if myltiply2 > 1: self.fans += a // 10 elif myltiply2 < 1: self.fans -= a // 10 self.totalPapers += a self.cash += a self.subs.setText('Фанаты: \n ' + str(self.fans)) self.money.setText('Деньги: \n ' + str(self.cash)) self.money.adjustSize() self.subs.adjustSize() self.table.setText('Заработано сегодня: \n' + str(a) + '\nЗаработано за все дни: \n' + str(self.totalPapers)) self.table.adjustSize()
class SettingsDialog(QWidget): "A settings dialog" scroll_speed_changed = pyqtSignal() init_gallery_rebuild = pyqtSignal(bool) init_gallery_eximport = pyqtSignal(object) def __init__(self, parent=None): super().__init__(parent, flags=Qt.Window) self.init_gallery_rebuild.connect(self.accept) self.parent_widget = parent self.setAttribute(Qt.WA_DeleteOnClose) self.resize(700, 500) self.restore_values() self.initUI() self.setWindowTitle('Settings') self.show() def initUI(self): main_layout = QVBoxLayout(self) sub_layout = QHBoxLayout() # Left Panel left_panel = QListWidget() left_panel.setViewMode(left_panel.ListMode) #left_panel.setIconSize(QSize(40,40)) left_panel.setTextElideMode(Qt.ElideRight) left_panel.setMaximumWidth(200) left_panel.itemClicked.connect(self.change) #web.setText('Web') self.application = QListWidgetItem() self.application.setText('Application') self.web = QListWidgetItem() self.web.setText('Web') self.visual = QListWidgetItem() self.visual.setText('Visual') self.advanced = QListWidgetItem() self.advanced.setText('Advanced') self.about = QListWidgetItem() self.about.setText('About') #main.setIcon(QIcon(os.path.join(app_constants.static_dir, 'plus2.png'))) left_panel.addItem(self.application) left_panel.addItem(self.web) left_panel.addItem(self.visual) left_panel.addItem(self.advanced) left_panel.addItem(self.about) left_panel.setMaximumWidth(100) # right panel self.right_panel = QStackedLayout() self.init_right_panel() # bottom bottom_layout = QHBoxLayout() ok_btn = QPushButton('Ok') ok_btn.clicked.connect(self.accept) cancel_btn = QPushButton('Cancel') cancel_btn.clicked.connect(self.close) info_lbl = QLabel() info_lbl.setText('<a href="https://github.com/Pewpews/happypanda">'+ 'Visit GitHub Repo</a> | Options marked with * requires application restart.') info_lbl.setTextFormat(Qt.RichText) info_lbl.setTextInteractionFlags(Qt.TextBrowserInteraction) info_lbl.setOpenExternalLinks(True) self.spacer = QWidget() self.spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) bottom_layout.addWidget(info_lbl, 0, Qt.AlignLeft) bottom_layout.addWidget(self.spacer) bottom_layout.addWidget(ok_btn, 0, Qt.AlignRight) bottom_layout.addWidget(cancel_btn, 0, Qt.AlignRight) sub_layout.addWidget(left_panel) sub_layout.addLayout(self.right_panel) main_layout.addLayout(sub_layout) main_layout.addLayout(bottom_layout) self.restore_options() def change(self, item): def curr_index(index): if index != self.right_panel.currentIndex(): self.right_panel.setCurrentIndex(index) if item == self.application: curr_index(self.application_index) elif item == self.web: curr_index(self.web_index) elif item == self.visual: curr_index(self.visual_index) elif item == self.advanced: curr_index(self.advanced_index) elif item == self.about: curr_index(self.about_index) def restore_values(self): #Web self.exprops = settings.ExProperties() # Visual self.high_quality_thumbs = app_constants.HIGH_QUALITY_THUMBS self.popup_width = app_constants.POPUP_WIDTH self.popup_height = app_constants.POPUP_HEIGHT self.style_sheet = app_constants.user_stylesheet_path # Advanced self.scroll_speed = app_constants.SCROLL_SPEED self.cache_size = app_constants.THUMBNAIL_CACHE_SIZE self.prefetch_item_amnt = app_constants.PREFETCH_ITEM_AMOUNT def restore_options(self): # App / General self.subfolder_as_chapters.setChecked(app_constants.SUBFOLDER_AS_GALLERY) self.extract_gallery_before_opening.setChecked(app_constants.EXTRACT_CHAPTER_BEFORE_OPENING) self.open_galleries_sequentially.setChecked(app_constants.OPEN_GALLERIES_SEQUENTIALLY) self.scroll_to_new_gallery.setChecked(app_constants.SCROLL_TO_NEW_GALLERIES) self.move_imported_gs.setChecked(app_constants.MOVE_IMPORTED_GALLERIES) self.move_imported_def_path.setText(app_constants.IMPORTED_GALLERY_DEF_PATH) self.open_random_g_chapters.setChecked(app_constants.OPEN_RANDOM_GALLERY_CHAPTERS) self.rename_g_source_group.setChecked(app_constants.RENAME_GALLERY_SOURCE) self.path_to_unrar.setText(app_constants.unrar_tool_path) # App / General / External Viewer self.external_viewer_path.setText(app_constants.EXTERNAL_VIEWER_PATH) # App / Monitor / Misc self.enable_monitor.setChecked(app_constants.ENABLE_MONITOR) self.look_new_gallery_startup.setChecked(app_constants.LOOK_NEW_GALLERY_STARTUP) self.auto_add_new_galleries.setChecked(app_constants.LOOK_NEW_GALLERY_AUTOADD) # App / Monitor / Folders for path in app_constants.MONITOR_PATHS: self.add_folder_monitor(path) # App / Monitor / Ignore list for path in app_constants.IGNORE_PATHS: self.add_ignore_path(path) # Web / General if 'g.e-hentai' in app_constants.DEFAULT_EHEN_URL: self.default_ehen_url.setChecked(True) else: self.exhentai_ehen_url.setChecked(True) self.replace_metadata.setChecked(app_constants.REPLACE_METADATA) self.always_first_hit.setChecked(app_constants.ALWAYS_CHOOSE_FIRST_HIT) self.web_time_offset.setValue(app_constants.GLOBAL_EHEN_TIME) self.continue_a_metadata_fetcher.setChecked(app_constants.CONTINUE_AUTO_METADATA_FETCHER) self.use_jpn_title.setChecked(app_constants.USE_JPN_TITLE) self.use_gallery_link.setChecked(app_constants.USE_GALLERY_LINK) # Web / Download if app_constants.HEN_DOWNLOAD_TYPE == 0: self.archive_download.setChecked(True) else: self.torrent_download.setChecked(True) self.download_directory.setText(app_constants.DOWNLOAD_DIRECTORY) self.torrent_client.setText(app_constants.TORRENT_CLIENT) # Web / Exhentai self.ipbid_edit.setText(self.exprops.ipb_id) self.ipbpass_edit.setText(self.exprops.ipb_pass) # Visual / Grid View / Tooltip self.grid_tooltip_group.setChecked(app_constants.GRID_TOOLTIP) self.visual_grid_tooltip_title.setChecked(app_constants.TOOLTIP_TITLE) self.visual_grid_tooltip_author.setChecked(app_constants.TOOLTIP_AUTHOR) self.visual_grid_tooltip_chapters.setChecked(app_constants.TOOLTIP_CHAPTERS) self.visual_grid_tooltip_status.setChecked(app_constants.TOOLTIP_STATUS) self.visual_grid_tooltip_type.setChecked(app_constants.TOOLTIP_TYPE) self.visual_grid_tooltip_lang.setChecked(app_constants.TOOLTIP_LANG) self.visual_grid_tooltip_descr.setChecked(app_constants.TOOLTIP_DESCR) self.visual_grid_tooltip_tags.setChecked(app_constants.TOOLTIP_TAGS) self.visual_grid_tooltip_last_read.setChecked(app_constants.TOOLTIP_LAST_READ) self.visual_grid_tooltip_times_read.setChecked(app_constants.TOOLTIP_TIMES_READ) self.visual_grid_tooltip_pub_date.setChecked(app_constants.TOOLTIP_PUB_DATE) self.visual_grid_tooltip_date_added.setChecked(app_constants.TOOLTIP_DATE_ADDED) # Visual / Grid View / Gallery self.external_viewer_ico.setChecked(app_constants.USE_EXTERNAL_PROG_ICO) self.gallery_type_ico.setChecked(app_constants.DISPLAY_GALLERY_TYPE) if app_constants.GALLERY_FONT_ELIDE: self.gallery_text_elide.setChecked(True) else: self.gallery_text_fit.setChecked(True) self.font_lbl.setText(app_constants.GALLERY_FONT[0]) self.font_size_lbl.setValue(app_constants.GALLERY_FONT[1]) def re_enforce(s): if s: self.search_on_enter.setChecked(True) self.search_allow_regex.clicked.connect(re_enforce) if app_constants.SEARCH_ON_ENTER: self.search_on_enter.setChecked(True) else: self.search_every_keystroke.setChecked(True) # Visual / Grid View / Colors self.grid_label_color.setText(app_constants.GRID_VIEW_LABEL_COLOR) self.grid_title_color.setText(app_constants.GRID_VIEW_TITLE_COLOR) self.grid_artist_color.setText(app_constants.GRID_VIEW_ARTIST_COLOR) # Advanced / Gallery / Gallery Text Fixer self.g_data_regex_fix_edit.setText(app_constants.GALLERY_DATA_FIX_REGEX) self.g_data_replace_fix_edit.setText(app_constants.GALLERY_DATA_FIX_REPLACE) self.g_data_fixer_title.setChecked(app_constants.GALLERY_DATA_FIX_TITLE) self.g_data_fixer_artist.setChecked(app_constants.GALLERY_DATA_FIX_ARTIST) # About / DB Overview self.tags_treeview_on_start.setChecked(app_constants.TAGS_TREEVIEW_ON_START) def accept(self): set = settings.set # App / General / Gallery app_constants.SUBFOLDER_AS_GALLERY = self.subfolder_as_chapters.isChecked() set(app_constants.SUBFOLDER_AS_GALLERY, 'Application', 'subfolder as gallery') app_constants.EXTRACT_CHAPTER_BEFORE_OPENING = self.extract_gallery_before_opening.isChecked() set(app_constants.EXTRACT_CHAPTER_BEFORE_OPENING, 'Application', 'extract chapter before opening') app_constants.OPEN_GALLERIES_SEQUENTIALLY = self.open_galleries_sequentially.isChecked() set(app_constants.OPEN_GALLERIES_SEQUENTIALLY, 'Application', 'open galleries sequentially') app_constants.SCROLL_TO_NEW_GALLERIES = self.scroll_to_new_gallery.isChecked() set(app_constants.SCROLL_TO_NEW_GALLERIES, 'Application', 'scroll to new galleries') app_constants.MOVE_IMPORTED_GALLERIES = self.move_imported_gs.isChecked() set(app_constants.MOVE_IMPORTED_GALLERIES, 'Application', 'move imported galleries') if not self.move_imported_def_path.text() or os.path.exists(self.move_imported_def_path.text()): app_constants.IMPORTED_GALLERY_DEF_PATH = self.move_imported_def_path.text() set(app_constants.IMPORTED_GALLERY_DEF_PATH, 'Application', 'imported gallery def path') app_constants.OPEN_RANDOM_GALLERY_CHAPTERS = self.open_random_g_chapters.isChecked() set(app_constants.OPEN_RANDOM_GALLERY_CHAPTERS, 'Application', 'open random gallery chapters') app_constants.RENAME_GALLERY_SOURCE = self.rename_g_source_group.isChecked() set(app_constants.RENAME_GALLERY_SOURCE, 'Application', 'rename gallery source') app_constants.unrar_tool_path = self.path_to_unrar.text() set(app_constants.unrar_tool_path, 'Application', 'unrar tool path') # App / General / Search app_constants.ALLOW_SEARCH_REGEX = self.search_allow_regex.isChecked() set(app_constants.ALLOW_SEARCH_REGEX, 'Application', 'allow search regex') app_constants.SEARCH_AUTOCOMPLETE = self.search_autocomplete.isChecked() set(app_constants.SEARCH_AUTOCOMPLETE, 'Application', 'search autocomplete') if self.search_on_enter.isChecked(): app_constants.SEARCH_ON_ENTER = True else: app_constants.SEARCH_ON_ENTER = False set(app_constants.SEARCH_ON_ENTER, 'Application', 'search on enter') # App / General / External Viewer if not self.external_viewer_path.text(): app_constants.USE_EXTERNAL_VIEWER = False set(False, 'Application', 'use external viewer') else: app_constants.USE_EXTERNAL_VIEWER = True set(True, 'Application', 'use external viewer') app_constants._REFRESH_EXTERNAL_VIEWER = True app_constants.EXTERNAL_VIEWER_PATH = self.external_viewer_path.text() set(app_constants.EXTERNAL_VIEWER_PATH,'Application', 'external viewer path') # App / Monitor / misc app_constants.ENABLE_MONITOR = self.enable_monitor.isChecked() set(app_constants.ENABLE_MONITOR, 'Application', 'enable monitor') app_constants.LOOK_NEW_GALLERY_STARTUP = self.look_new_gallery_startup.isChecked() set(app_constants.LOOK_NEW_GALLERY_STARTUP, 'Application', 'look new gallery startup') app_constants.LOOK_NEW_GALLERY_AUTOADD = self.auto_add_new_galleries.isChecked() set(app_constants.LOOK_NEW_GALLERY_AUTOADD, 'Application', 'look new gallery autoadd') # App / Monitor / folders paths = [] folder_p_widgets = self.take_all_layout_widgets(self.folders_layout) for x, l_edit in enumerate(folder_p_widgets): p = l_edit.text() if p: paths.append(p) set(paths, 'Application', 'monitor paths') app_constants.MONITOR_PATHS = paths # App / Monitor / ignore list paths = [] ignore_p_widgets = self.take_all_layout_widgets(self.ignore_path_l) for x, l_edit in enumerate(ignore_p_widgets): p = l_edit.text() if p: paths.append(p) set(paths, 'Application', 'ignore paths') app_constants.IGNORE_PATHS = paths # Web / Downloader if self.archive_download.isChecked(): app_constants.HEN_DOWNLOAD_TYPE = 0 else: app_constants.HEN_DOWNLOAD_TYPE = 1 set(app_constants.HEN_DOWNLOAD_TYPE, 'Web', 'hen download type') app_constants.DOWNLOAD_DIRECTORY = self.download_directory.text() set(app_constants.DOWNLOAD_DIRECTORY, 'Web', 'download directory') app_constants.TORRENT_CLIENT = self.torrent_client.text() set(app_constants.TORRENT_CLIENT, 'Web', 'torrent client') # Web / Metdata if self.default_ehen_url.isChecked(): app_constants.DEFAULT_EHEN_URL = 'http://g.e-hentai.org/' else: app_constants.DEFAULT_EHEN_URL = 'http://exhentai.org/' set(app_constants.DEFAULT_EHEN_URL, 'Web', 'default ehen url') app_constants.REPLACE_METADATA = self.replace_metadata.isChecked() set(app_constants.REPLACE_METADATA, 'Web', 'replace metadata') app_constants.ALWAYS_CHOOSE_FIRST_HIT = self.always_first_hit.isChecked() set(app_constants.ALWAYS_CHOOSE_FIRST_HIT, 'Web', 'always choose first hit') app_constants.GLOBAL_EHEN_TIME = self.web_time_offset.value() set(app_constants.GLOBAL_EHEN_TIME, 'Web', 'global ehen time offset') app_constants.CONTINUE_AUTO_METADATA_FETCHER = self.continue_a_metadata_fetcher.isChecked() set(app_constants.CONTINUE_AUTO_METADATA_FETCHER, 'Web', 'continue auto metadata fetcher') app_constants.USE_JPN_TITLE = self.use_jpn_title.isChecked() set(app_constants.USE_JPN_TITLE, 'Web', 'use jpn title') app_constants.USE_GALLERY_LINK = self.use_gallery_link.isChecked() set(app_constants.USE_GALLERY_LINK, 'Web', 'use gallery link') # Web / ExHentai self.exprops.ipb_id = self.ipbid_edit.text() self.exprops.ipb_pass = self.ipbpass_edit.text() # Visual / Grid View / Tooltip app_constants.GRID_TOOLTIP = self.grid_tooltip_group.isChecked() set(app_constants.GRID_TOOLTIP, 'Visual', 'grid tooltip') app_constants.TOOLTIP_TITLE = self.visual_grid_tooltip_title.isChecked() set(app_constants.TOOLTIP_TITLE, 'Visual', 'tooltip title') app_constants.TOOLTIP_AUTHOR = self.visual_grid_tooltip_author.isChecked() set(app_constants.TOOLTIP_AUTHOR, 'Visual', 'tooltip author') app_constants.TOOLTIP_CHAPTERS = self.visual_grid_tooltip_chapters.isChecked() set(app_constants.TOOLTIP_CHAPTERS, 'Visual', 'tooltip chapters') app_constants.TOOLTIP_STATUS = self.visual_grid_tooltip_status.isChecked() set(app_constants.TOOLTIP_STATUS, 'Visual', 'tooltip status') app_constants.TOOLTIP_TYPE = self.visual_grid_tooltip_type.isChecked() set(app_constants.TOOLTIP_TYPE, 'Visual', 'tooltip type') app_constants.TOOLTIP_LANG = self.visual_grid_tooltip_lang.isChecked() set(app_constants.TOOLTIP_LANG, 'Visual', 'tooltip lang') app_constants.TOOLTIP_DESCR = self.visual_grid_tooltip_descr.isChecked() set(app_constants.TOOLTIP_DESCR, 'Visual', 'tooltip descr') app_constants.TOOLTIP_TAGS = self.visual_grid_tooltip_tags.isChecked() set(app_constants.TOOLTIP_TAGS, 'Visual', 'tooltip tags') app_constants.TOOLTIP_LAST_READ = self.visual_grid_tooltip_last_read.isChecked() set(app_constants.TOOLTIP_LAST_READ, 'Visual', 'tooltip last read') app_constants.TOOLTIP_TIMES_READ = self.visual_grid_tooltip_times_read.isChecked() set(app_constants.TOOLTIP_TIMES_READ, 'Visual', 'tooltip times read') app_constants.TOOLTIP_PUB_DATE = self.visual_grid_tooltip_pub_date.isChecked() set(app_constants.TOOLTIP_PUB_DATE, 'Visual', 'tooltip pub date') app_constants.TOOLTIP_DATE_ADDED = self.visual_grid_tooltip_date_added.isChecked() set(app_constants.TOOLTIP_DATE_ADDED, 'Visual', 'tooltip date added') # Visual / Grid View / Gallery app_constants.USE_EXTERNAL_PROG_ICO = self.external_viewer_ico.isChecked() set(app_constants.USE_EXTERNAL_PROG_ICO, 'Visual', 'use external prog ico') app_constants.DISPLAY_GALLERY_TYPE = self.gallery_type_ico.isChecked() set(app_constants.DISPLAY_GALLERY_TYPE, 'Visual', 'display gallery type') if self.gallery_text_elide.isChecked(): app_constants.GALLERY_FONT_ELIDE = True else: app_constants.GALLERY_FONT_ELIDE = False set(app_constants.GALLERY_FONT_ELIDE, 'Visual', 'gallery font elide') app_constants.GALLERY_FONT = (self.font_lbl.text(), self.font_size_lbl.value()) set(app_constants.GALLERY_FONT[0], 'Visual', 'gallery font family') set(app_constants.GALLERY_FONT[1], 'Visual', 'gallery font size') # Visual / Grid View / Colors if self.color_checker(self.grid_title_color.text()): app_constants.GRID_VIEW_TITLE_COLOR = self.grid_title_color.text() set(app_constants.GRID_VIEW_TITLE_COLOR, 'Visual', 'grid view title color') if self.color_checker(self.grid_artist_color.text()): app_constants.GRID_VIEW_ARTIST_COLOR = self.grid_artist_color.text() set(app_constants.GRID_VIEW_ARTIST_COLOR, 'Visual', 'grid view artist color') if self.color_checker(self.grid_label_color.text()): app_constants.GRID_VIEW_LABEL_COLOR = self.grid_label_color.text() set(app_constants.GRID_VIEW_LABEL_COLOR, 'Visual', 'grid view label color') # Advanced / Misc # Advanced / Misc / Grid View app_constants.SCROLL_SPEED = self.scroll_speed set(self.scroll_speed, 'Advanced', 'scroll speed') self.scroll_speed_changed.emit() app_constants.THUMBNAIL_CACHE_SIZE = self.cache_size set(self.cache_size[1], 'Advanced', 'cache size') QPixmapCache.setCacheLimit(self.cache_size[0]* self.cache_size[1]) # Advanced / General / Gallery Text Fixer app_constants.GALLERY_DATA_FIX_REGEX = self.g_data_regex_fix_edit.text() set(app_constants.GALLERY_DATA_FIX_REGEX, 'Advanced', 'gallery data fix regex') app_constants.GALLERY_DATA_FIX_TITLE = self.g_data_fixer_title.isChecked() set(app_constants.GALLERY_DATA_FIX_TITLE, 'Advanced', 'gallery data fix title') app_constants.GALLERY_DATA_FIX_ARTIST = self.g_data_fixer_artist.isChecked() set(app_constants.GALLERY_DATA_FIX_ARTIST, 'Advanced', 'gallery data fix artist') app_constants.GALLERY_DATA_FIX_REPLACE = self.g_data_replace_fix_edit.text() set(app_constants.GALLERY_DATA_FIX_REPLACE, 'Advanced', 'gallery data fix replace') # About / DB Overview app_constants.TAGS_TREEVIEW_ON_START = self.tags_treeview_on_start.isChecked() set(app_constants.TAGS_TREEVIEW_ON_START, 'Application', 'tags treeview on start') settings.save() self.close() def init_right_panel(self): #def title_def(title): # title_lbl = QLabel(title) # f = QFont() # f.setPixelSize(16) # title_lbl.setFont(f) # return title_lbl def groupbox(name, layout, parent, add_in_layout=None): """ Makes a groupbox and a layout for you Returns groupbox and layout """ g = QGroupBox(name, parent) l = layout(g) if add_in_layout: if isinstance(add_in_layout, QFormLayout): add_in_layout.addRow(g) else: add_in_layout.addWidget(g) return g, l def option_lbl_checkbox(text, optiontext, parent=None): l = QLabel(text) c = QCheckBox(text, parent) return l, c def new_tab(name, parent, scroll=False): """ Creates a new tab. Returns new tab page widget and it's layout """ new_t = QWidget(parent) new_l = QFormLayout(new_t) if scroll: scr = QScrollArea(parent) scr.setBackgroundRole(QPalette.Base) scr.setWidget(new_t) scr.setWidgetResizable(True) parent.addTab(scr, name) return new_t, new_l else: parent.addTab(new_t, name) return new_t, new_l # App application = QTabWidget(self) self.application_index = self.right_panel.addWidget(application) application_general, app_general_m_l = new_tab('General', application, True) # App / General / gallery app_gallery_page, app_gallery_l = new_tab('Gallery', application, True) self.subfolder_as_chapters = QCheckBox("Subdirectiories should be treated as standalone galleries instead of chapters (applies in archives too)") self.subfolder_as_chapters.setToolTip("This option will enable creating standalone galleries for each subdirectiories found recursively when importing."+ "\nDefault action is treating each subfolder found as chapters of a gallery.") extract_gallery_info = QLabel("Note: This option has no effect when turned off if path to viewer is not specified.") self.extract_gallery_before_opening = QCheckBox("Extract archive before opening (only turn off if your viewer supports it)") self.open_galleries_sequentially = QCheckBox("Open chapters sequentially (Note: has no effect if path to viewer is not specified)") subf_info = QLabel("Behaviour of 'Scan for new galleries on startup' option will be affected.") subf_info.setWordWrap(True) app_gallery_l.addRow('Note:', subf_info) app_gallery_l.addRow(self.subfolder_as_chapters) app_gallery_l.addRow(extract_gallery_info) app_gallery_l.addRow(self.extract_gallery_before_opening) app_gallery_l.addRow(self.open_galleries_sequentially) self.scroll_to_new_gallery = QCheckBox("Scroll to newly added gallery") self.scroll_to_new_gallery.setDisabled(True) app_gallery_l.addRow(self.scroll_to_new_gallery) self.move_imported_gs, move_imported_gs_l = groupbox('Move imported galleries', QFormLayout, app_gallery_page) self.move_imported_gs.setCheckable(True) self.move_imported_gs.setToolTip("Move imported galleries to specified folder.") self.move_imported_def_path = PathLineEdit() move_imported_gs_l.addRow('Directory:', self.move_imported_def_path) app_gallery_l.addRow(self.move_imported_gs) self.rename_g_source_group, rename_g_source_l = groupbox('Rename gallery source', QFormLayout, app_gallery_page) self.rename_g_source_group.setCheckable(True) self.rename_g_source_group.setDisabled(True) app_gallery_l.addRow(self.rename_g_source_group) rename_g_source_l.addRow(QLabel("Check what to include when renaming gallery source. (Same order)")) rename_g_source_flow_l = FlowLayout() rename_g_source_l.addRow(rename_g_source_flow_l) self.rename_artist = QCheckBox("Artist") self.rename_title = QCheckBox("Title") self.rename_lang = QCheckBox("Language") self.rename_title.setChecked(True) self.rename_title.setDisabled(True) rename_g_source_flow_l.addWidget(self.rename_artist) rename_g_source_flow_l.addWidget(self.rename_title) rename_g_source_flow_l.addWidget(self.rename_lang) random_gallery_opener, random_g_opener_l = groupbox('Random Gallery Opener', QFormLayout, app_gallery_page) app_gallery_l.addRow(random_gallery_opener) self.open_random_g_chapters = QCheckBox("Open random gallery chapters") random_g_opener_l.addRow(self.open_random_g_chapters) # App / General / Search app_search, app_search_layout = groupbox('Search', QFormLayout, application_general) app_general_m_l.addRow(app_search) search_allow_regex_l = QHBoxLayout() self.search_allow_regex = QCheckBox() self.search_allow_regex.setChecked(app_constants.ALLOW_SEARCH_REGEX) self.search_allow_regex.adjustSize() self.search_allow_regex.setToolTip('A regex cheatsheet is located at About->Regex Cheatsheet') search_allow_regex_l.addWidget(self.search_allow_regex) search_allow_regex_l.addWidget(QLabel('A regex cheatsheet is located at About->Regex Cheatsheet')) search_allow_regex_l.addWidget(Spacer('h')) app_search_layout.addRow('Regex:', search_allow_regex_l) # App / General / Search / autocomplete self.search_autocomplete = QCheckBox('*') self.search_autocomplete.setChecked(app_constants.SEARCH_AUTOCOMPLETE) self.search_autocomplete.setToolTip('Turn autocomplete on/off') app_search_layout.addRow('Autocomplete', self.search_autocomplete) # App / General / Search / search behaviour self.search_every_keystroke = QRadioButton('Search on every keystroke *', app_search) app_search_layout.addRow(self.search_every_keystroke) self.search_on_enter = QRadioButton('Search on return-key *', app_search) app_search_layout.addRow(self.search_on_enter) # App / General / External Viewer app_external_viewer, app_external_viewer_l = groupbox('External Viewer', QFormLayout, application_general, app_general_m_l) app_external_viewer_l.addRow(QLabel("Most image viewers should work. Incase it doesn't," + " hit me up on email/github/gitter-chat to add support.")) self.external_viewer_path = PathLineEdit(app_external_viewer, False, '') self.external_viewer_path.setPlaceholderText('Right/Left-click to open folder explorer.'+ ' Leave empty to use default viewer') self.external_viewer_path.setToolTip('Right/Left-click to open folder explorer.'+ ' Leave empty to use default viewer') self.external_viewer_path.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) app_external_viewer_l.addRow('Path:', self.external_viewer_path) # App / General / Rar Support app_rar_group, app_rar_layout = groupbox('RAR Support *', QFormLayout, self) app_general_m_l.addRow(app_rar_group) rar_info = QLabel('Specify the path to the unrar tool to enable rar support.\n'+ 'Windows: "unrar.exe" should be in the "bin" directory if you installed from the'+ ' self-extracting archive provided on github.\nOSX: You can install this via HomeBrew.'+ ' Path should be something like: "/usr/local/bin/unrar".\nLinux: Should already be'+ ' installed. You can just type "unrar". If it\'s not installed, use your package manager: pacman -S unrar') rar_info.setWordWrap(True) app_rar_layout.addRow(rar_info) self.path_to_unrar = PathLineEdit(self, False, filters='') app_rar_layout.addRow('UnRAR tool path:', self.path_to_unrar) # App / Monitor app_monitor_page = QScrollArea() app_monitor_page.setBackgroundRole(QPalette.Base) app_monitor_dummy = QWidget() app_monitor_page.setWidgetResizable(True) app_monitor_page.setWidget(app_monitor_dummy) application.addTab(app_monitor_page, 'Monitoring') app_monitor_m_l = QVBoxLayout(app_monitor_dummy) # App / Monitor / misc app_monitor_misc_group = QGroupBox('General *', self) app_monitor_m_l.addWidget(app_monitor_misc_group) app_monitor_misc_m_l = QFormLayout(app_monitor_misc_group) monitor_info = QLabel('Directory monitoring will monitor the specified directories for any'+ ' filesystem events. For example if you delete a gallery source in one of your'+ ' monitored directories the application will inform you and ask if'+ ' you want to delete the gallery from the application as well.') monitor_info.setWordWrap(True) app_monitor_misc_m_l.addRow(monitor_info) self.enable_monitor = QCheckBox('Enable directory monitoring') app_monitor_misc_m_l.addRow(self.enable_monitor) self.look_new_gallery_startup = QGroupBox('Scan for new galleries on startup', self) app_monitor_misc_m_l.addRow(self.look_new_gallery_startup) self.look_new_gallery_startup.setCheckable(True) look_new_gallery_startup_m_l = QVBoxLayout(self.look_new_gallery_startup) self.auto_add_new_galleries = QCheckBox('Automatically add found galleries') look_new_gallery_startup_m_l.addWidget(self.auto_add_new_galleries) # App / Monitor / folders app_monitor_group = QGroupBox('Directories *', self) app_monitor_m_l.addWidget(app_monitor_group, 1) app_monitor_folders_m_l = QVBoxLayout(app_monitor_group) app_monitor_folders_add = QPushButton('+') app_monitor_folders_add.clicked.connect(self.add_folder_monitor) app_monitor_folders_add.setMaximumWidth(20) app_monitor_folders_add.setMaximumHeight(20) app_monitor_folders_m_l.addWidget(app_monitor_folders_add, 0, Qt.AlignRight) self.folders_layout = QFormLayout() app_monitor_folders_m_l.addLayout(self.folders_layout) # App / Ignore app_ignore, app_ignore_m_l = new_tab('Ignore', application, True) app_ignore_group, app_ignore_list_l = groupbox('List', QVBoxLayout, app_monitor_dummy) app_ignore_m_l.addRow(app_ignore_group) add_buttons_l = QHBoxLayout() app_ignore_add_a = QPushButton('Add archive') app_ignore_add_a.clicked.connect(lambda: self.add_ignore_path(dir=False)) app_ignore_add_f = QPushButton('Add directory') app_ignore_add_f.clicked.connect(self.add_ignore_path) add_buttons_l.addWidget(app_ignore_add_a, 0, Qt.AlignRight) add_buttons_l.addWidget(app_ignore_add_f, 1, Qt.AlignRight) app_ignore_list_l.addLayout(add_buttons_l) self.ignore_path_l = QFormLayout() app_ignore_list_l.addLayout(self.ignore_path_l) # Web web = QTabWidget(self) self.web_index = self.right_panel.addWidget(web) # Web / Downloader web_downloader, web_downloader_l = new_tab('Downloader', web) hen_download_group, hen_download_group_l = groupbox('g.e-hentai/exhentai', QFormLayout, web_downloader) web_downloader_l.addRow(hen_download_group) self.archive_download = QRadioButton('Archive', hen_download_group) self.torrent_download = QRadioButton('Torrent', hen_download_group) download_type_l = QHBoxLayout() download_type_l.addWidget(self.archive_download) download_type_l.addWidget(self.torrent_download, 1) hen_download_group_l.addRow('Download Type:', download_type_l) self.download_directory = PathLineEdit(web_downloader) web_downloader_l.addRow('Destination:', self.download_directory) self.torrent_client = PathLineEdit(web_downloader, False, '') web_downloader_l.addRow(QLabel("Leave empty to use default torrent client."+ "\nIt is NOT recommended to import a file while it's still downloading.")) web_downloader_l.addRow('Torrent client:', self.torrent_client) # Web / Metadata web_metadata_page = QScrollArea() web_metadata_page.setBackgroundRole(QPalette.Base) web_metadata_page.setWidgetResizable(True) web.addTab(web_metadata_page, 'Metadata') web_metadata_dummy = QWidget() web_metadata_page.setWidget(web_metadata_dummy) web_metadata_m_l = QFormLayout(web_metadata_dummy) self.default_ehen_url = QRadioButton('g.e-hentai.org', web_metadata_page) self.exhentai_ehen_url = QRadioButton('exhentai.org', web_metadata_page) ehen_url_l = QHBoxLayout() ehen_url_l.addWidget(self.default_ehen_url) ehen_url_l.addWidget(self.exhentai_ehen_url, 1) web_metadata_m_l.addRow('Default URL:', ehen_url_l) self.continue_a_metadata_fetcher = QCheckBox('Continue from where auto metadata fetcher left off') web_metadata_m_l.addRow(self.continue_a_metadata_fetcher) self.use_jpn_title = QCheckBox('Use japanese title') self.use_jpn_title.setToolTip('Choose the japenese title over the english one') web_metadata_m_l.addRow(self.use_jpn_title) time_offset_info = QLabel('We need to impose a delay between our requests to avoid getting banned.'+ ' I have made it so you cannot set the delay lower than the recommended (I don\'t'+ ' want you to get banned, anon!).\nSpecify the delay between requests in seconds.') time_offset_info.setWordWrap(True) self.web_time_offset = QSpinBox() self.web_time_offset.setMaximumWidth(40) self.web_time_offset.setMinimum(4) self.web_time_offset.setMaximum(99) web_metadata_m_l.addRow(time_offset_info) web_metadata_m_l.addRow('Requests delay in seconds', self.web_time_offset) replace_metadata_info = QLabel('When fetching for metadata the new metadata will be appended'+ ' to the gallery by default. This means that new data will only be added if'+ ' the field was empty. There is however a special case for namespace & tags.'+ ' We go through all the new namespace & tags to only add those that'+ ' do not already exists.\n\nEnabling this option makes it so that a gallery\'s old data'+ ' are deleted and replaced with the new data.') replace_metadata_info.setWordWrap(True) self.replace_metadata = QCheckBox('Replace old metadata with new metadata') web_metadata_m_l.addRow(replace_metadata_info) web_metadata_m_l.addRow(self.replace_metadata) first_hit_info = QLabel('By default, you get to choose which gallery to extract metadata from when'+ ' there is more than one gallery found when searching.\n'+ 'Enabling this option makes it choose the first hit, saving you from moving your mouse.') first_hit_info.setWordWrap(True) self.always_first_hit = QCheckBox('Always choose first hit') web_metadata_m_l.addRow(first_hit_info) web_metadata_m_l.addRow(self.always_first_hit) self.use_gallery_link = QCheckBox('Use current gallery link') self.use_gallery_link.setToolTip("Metadata will be fetched from the current gallery link"+ " if it's a valid ex/g.e gallery url") web_metadata_m_l.addRow(self.use_gallery_link) # Web / Exhentai exhentai_page = QWidget(self) web.addTab(exhentai_page, 'ExHentai') ipb_layout = QFormLayout() exhentai_page.setLayout(ipb_layout) self.ipbid_edit = QLineEdit() self.ipbpass_edit = QLineEdit() exh_tutorial = QLabel(app_constants.EXHEN_COOKIE_TUTORIAL) exh_tutorial.setTextFormat(Qt.RichText) ipb_layout.addRow('IPB Member ID:', self.ipbid_edit) ipb_layout.addRow('IPB Pass Hash:', self.ipbpass_edit) ipb_layout.addRow(exh_tutorial) # Visual visual = QTabWidget(self) self.visual_index = self.right_panel.addWidget(visual) visual_general_page = QWidget() visual.addTab(visual_general_page, 'General') grid_view_general_page = QWidget() visual.addTab(grid_view_general_page, 'Grid View') grid_view_layout = QVBoxLayout() grid_view_layout.addWidget(QLabel('Options marked with * requires application restart'), 0, Qt.AlignTop) grid_view_general_page.setLayout(grid_view_layout) # grid view # grid view / tooltip self.grid_tooltip_group = QGroupBox('Tooltip', grid_view_general_page) self.grid_tooltip_group.setCheckable(True) grid_view_layout.addWidget(self.grid_tooltip_group, 0, Qt.AlignTop) grid_tooltip_layout = QFormLayout() self.grid_tooltip_group.setLayout(grid_tooltip_layout) grid_tooltip_layout.addRow(QLabel('Control what is'+ ' displayed in the tooltip when hovering a gallery')) grid_tooltips_hlayout = FlowLayout() grid_tooltip_layout.addRow(grid_tooltips_hlayout) self.visual_grid_tooltip_title = QCheckBox('Title') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_title) self.visual_grid_tooltip_author = QCheckBox('Author') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_author) self.visual_grid_tooltip_chapters = QCheckBox('Chapters') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_chapters) self.visual_grid_tooltip_status = QCheckBox('Status') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_status) self.visual_grid_tooltip_type = QCheckBox('Type') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_type) self.visual_grid_tooltip_lang = QCheckBox('Language') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_lang) self.visual_grid_tooltip_descr = QCheckBox('Description') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_descr) self.visual_grid_tooltip_tags = QCheckBox('Tags') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_tags) self.visual_grid_tooltip_last_read = QCheckBox('Last read') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_last_read) self.visual_grid_tooltip_times_read = QCheckBox('Times read') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_times_read) self.visual_grid_tooltip_pub_date = QCheckBox('Publication Date') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_pub_date) self.visual_grid_tooltip_date_added = QCheckBox('Date added') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_date_added) # grid view / gallery grid_gallery_group = QGroupBox('Gallery', grid_view_general_page) grid_view_layout.addWidget(grid_gallery_group, 0, Qt.AlignTop) grid_gallery_main_l = QFormLayout() grid_gallery_main_l.setFormAlignment(Qt.AlignLeft) grid_gallery_group.setLayout(grid_gallery_main_l) grid_gallery_display = FlowLayout() grid_gallery_main_l.addRow('Display icon on gallery:', grid_gallery_display) self.external_viewer_ico = QCheckBox('External Viewer') grid_gallery_display.addWidget(self.external_viewer_ico) self.gallery_type_ico = QCheckBox('File Type') grid_gallery_display.addWidget(self.gallery_type_ico) if sys.platform.startswith('darwin'): grid_gallery_group.setEnabled(False) gallery_text_mode = QWidget() grid_gallery_main_l.addRow('Text Mode:', gallery_text_mode) gallery_text_mode_l = QHBoxLayout() gallery_text_mode.setLayout(gallery_text_mode_l) self.gallery_text_elide = QRadioButton('Elide text', gallery_text_mode) self.gallery_text_fit = QRadioButton('Fit text', gallery_text_mode) gallery_text_mode_l.addWidget(self.gallery_text_elide, 0, Qt.AlignLeft) gallery_text_mode_l.addWidget(self.gallery_text_fit, 0, Qt.AlignLeft) gallery_text_mode_l.addWidget(Spacer('h'), 1, Qt.AlignLeft) gallery_font = QHBoxLayout() grid_gallery_main_l.addRow('Font:*', gallery_font) self.font_lbl = QLabel() self.font_size_lbl = QSpinBox() self.font_size_lbl.setMaximum(100) self.font_size_lbl.setMinimum(1) self.font_size_lbl.setToolTip('Font size in pixels') choose_font = QPushButton('Choose font') choose_font.clicked.connect(self.choose_font) gallery_font.addWidget(self.font_lbl, 0, Qt.AlignLeft) gallery_font.addWidget(self.font_size_lbl, 0, Qt.AlignLeft) gallery_font.addWidget(choose_font, 0, Qt.AlignLeft) gallery_font.addWidget(Spacer('h'), 1, Qt.AlignLeft) # grid view / colors grid_colors_group = QGroupBox('Colors', grid_view_general_page) grid_view_layout.addWidget(grid_colors_group, 1, Qt.AlignTop) grid_colors_l = QFormLayout() grid_colors_group.setLayout(grid_colors_l) def color_lineedit(): l = QLineEdit() l.setPlaceholderText('Hex colors. Eg.: #323232') l.setMaximumWidth(200) return l self.grid_label_color = color_lineedit() self.grid_title_color = color_lineedit() self.grid_artist_color = color_lineedit() grid_colors_l.addRow('Label color:', self.grid_label_color) grid_colors_l.addRow('Title color:', self.grid_title_color) grid_colors_l.addRow('Artist color:', self.grid_artist_color) style_page = QWidget(self) visual.addTab(style_page, 'Style') visual.setTabEnabled(0, False) visual.setTabEnabled(2, False) visual.setCurrentIndex(1) # Advanced advanced = QTabWidget(self) self.advanced_index = self.right_panel.addWidget(advanced) advanced_misc_scroll = QScrollArea(self) advanced_misc_scroll.setBackgroundRole(QPalette.Base) advanced_misc_scroll.setWidgetResizable(True) advanced_misc = QWidget() advanced_misc_scroll.setWidget(advanced_misc) advanced.addTab(advanced_misc_scroll, 'Misc') advanced_misc_main_layout = QVBoxLayout() advanced_misc.setLayout(advanced_misc_main_layout) misc_controls_layout = QFormLayout() advanced_misc_main_layout.addLayout(misc_controls_layout) # Advanced / Misc / Grid View misc_gridview = QGroupBox('Grid View') misc_controls_layout.addWidget(misc_gridview) misc_gridview_layout = QFormLayout() misc_gridview.setLayout(misc_gridview_layout) # Advanced / Misc / Grid View / scroll speed scroll_speed_spin_box = QSpinBox() scroll_speed_spin_box.setFixedWidth(60) scroll_speed_spin_box.setToolTip('Control the speed when scrolling in'+ ' grid view. DEFAULT: 7') scroll_speed_spin_box.setValue(self.scroll_speed) def scroll_speed(v): self.scroll_speed = v scroll_speed_spin_box.valueChanged[int].connect(scroll_speed) misc_gridview_layout.addRow('Scroll speed:', scroll_speed_spin_box) # Advanced / Misc / Grid View / cache size cache_size_spin_box = QSpinBox() cache_size_spin_box.setFixedWidth(120) cache_size_spin_box.setMaximum(999999999) cache_size_spin_box.setToolTip('This can greatly reduce lags/freezes in the grid view.' + ' Increase the value if you experience lag when scrolling'+ ' through galleries. DEFAULT: 200 MiB') def cache_size(c): self.cache_size = (self.cache_size[0], c) cache_size_spin_box.setValue(self.cache_size[1]) cache_size_spin_box.valueChanged[int].connect(cache_size) misc_gridview_layout.addRow('Cache Size (MiB):', cache_size_spin_box) # Advanced / Gallery advanced_gallery, advanced_gallery_m_l = new_tab('Gallery', advanced) def rebuild_thumbs(): confirm_msg = QMessageBox(QMessageBox.Question, '', 'Are you sure you want to regenerate your thumbnails.', QMessageBox.Yes | QMessageBox.No, self) if confirm_msg.exec() == QMessageBox.Yes: clear_cache_confirm = QMessageBox(QMessageBox.Question, '', 'Do you want to delete all old thumbnails before regenerating?', QMessageBox.Yes | QMessageBox.No, self) clear_cache = False if clear_cache_confirm.exec() == QMessageBox.Yes: clear_cache = True gallerydb.DatabaseEmitter.RUN = False def start_db_activity(): gallerydb.DatabaseEmitter.RUN = True app_popup = ApplicationPopup(self.parent_widget) app_popup.info_lbl.setText("Regenerating thumbnails...") app_popup.admin_db = gallerydb.AdminDB() app_popup.admin_db.moveToThread(app_constants.GENERAL_THREAD) app_popup.admin_db.DONE.connect(app_popup.admin_db.deleteLater) app_popup.admin_db.DONE.connect(start_db_activity) app_popup.admin_db.DATA_COUNT.connect(app_popup.prog.setMaximum) app_popup.admin_db.PROGRESS.connect(app_popup.prog.setValue) self.init_gallery_rebuild.connect(app_popup.admin_db.rebuild_thumbs) app_popup.adjustSize() self.init_gallery_rebuild.emit(clear_cache) app_popup.show() rebuild_thumbs_info = QLabel("Clears thumbnail cache and rebuilds it, which can take a while. Tip: Useful when changing thumbnail size.") rebuild_thumbs_btn = QPushButton('Regenerate Thumbnails') rebuild_thumbs_btn.adjustSize() rebuild_thumbs_btn.setFixedWidth(rebuild_thumbs_btn.width()) rebuild_thumbs_btn.clicked.connect(rebuild_thumbs) advanced_gallery_m_l.addRow(rebuild_thumbs_info) advanced_gallery_m_l.addRow(rebuild_thumbs_btn) g_data_fixer_group, g_data_fixer_l = groupbox('Gallery Renamer', QFormLayout, advanced_gallery) g_data_fixer_group.setEnabled(False) advanced_gallery_m_l.addRow(g_data_fixer_group) g_data_regex_fix_lbl = QLabel("Rename a gallery through regular expression."+ " A regex cheatsheet is located at About -> Regex Cheatsheet.") g_data_regex_fix_lbl.setWordWrap(True) g_data_fixer_l.addRow(g_data_regex_fix_lbl) self.g_data_regex_fix_edit = QLineEdit() self.g_data_regex_fix_edit.setPlaceholderText("Valid regex") g_data_fixer_l.addRow('Regex:', self.g_data_regex_fix_edit) self.g_data_replace_fix_edit = QLineEdit() self.g_data_replace_fix_edit.setPlaceholderText("Leave empty to delete matches") g_data_fixer_l.addRow('Replace with:', self.g_data_replace_fix_edit) g_data_fixer_options = FlowLayout() g_data_fixer_l.addRow(g_data_fixer_options) self.g_data_fixer_title = QCheckBox("Title", g_data_fixer_group) self.g_data_fixer_artist = QCheckBox("Artist", g_data_fixer_group) g_data_fixer_options.addWidget(self.g_data_fixer_title) g_data_fixer_options.addWidget(self.g_data_fixer_artist) # Advanced / Database advanced_db_page, advanced_db_page_l = new_tab('Database', advanced) # Advanced / Database / Import/Export def init_export(): confirm_msg = QMessageBox(QMessageBox.Question, '', 'Are you sure you want to export your database? This might take a long time.', QMessageBox.Yes | QMessageBox.No, self) if confirm_msg.exec() == QMessageBox.Yes: app_popup = ApplicationPopup(self.parent_widget) app_popup.info_lbl.setText("Exporting database...") app_popup.export_instance = io_misc.ImportExport() app_popup.export_instance.moveToThread(app_constants.GENERAL_THREAD) app_popup.export_instance.finished.connect(app_popup.export_instance.deleteLater) app_popup.export_instance.finished.connect(app_popup.close) app_popup.export_instance.amount.connect(app_popup.prog.setMaximum) app_popup.export_instance.progress.connect(app_popup.prog.setValue) self.init_gallery_eximport.connect(app_popup.export_instance.export_data) self.init_gallery_eximport.emit(None) app_popup.adjustSize() app_popup.show() self.close() def init_import(): path = QFileDialog.getOpenFileName(self, 'Choose happypanda database file', filter='*.hpdb') path = path[0] if len(path) != 0: app_popup = ApplicationPopup(self.parent_widget) app_popup.restart_info.hide() app_popup.info_lbl.setText("Importing database file...") app_popup.note_info.setText("Application requires a restart after importing") app_popup.import_instance = io_misc.ImportExport() app_popup.import_instance.moveToThread(app_constants.GENERAL_THREAD) app_popup.import_instance.finished.connect(app_popup.import_instance.deleteLater) app_popup.import_instance.finished.connect(app_popup.init_restart) app_popup.import_instance.amount.connect(app_popup.prog.setMaximum) app_popup.import_instance.imported_g.connect(app_popup.info_lbl.setText) app_popup.import_instance.progress.connect(app_popup.prog.setValue) self.init_gallery_eximport.connect(app_popup.import_instance.import_data) self.init_gallery_eximport.emit(path) app_popup.adjustSize() app_popup.show() self.close() advanced_impexp, advanced_impexp_l = groupbox('Import/Export', QFormLayout, advanced_db_page) advanced_db_page_l.addRow(advanced_impexp) self.export_format = QComboBox(advanced_db_page) #self.export_format.addItem('Text File', 0) self.export_format.addItem('HPDB', 1) self.export_format.adjustSize() self.export_format.setFixedWidth(self.export_format.width()) advanced_impexp_l.addRow('Export Format:', self.export_format) self.export_path = PathLineEdit(advanced_impexp, filters='') advanced_impexp_l.addRow('Export Path:', self.export_path) import_btn = QPushButton('Import database') import_btn.clicked.connect(init_import) export_btn = QPushButton('Export database') export_btn.clicked.connect(init_export) ex_imp_btn_l = QHBoxLayout() ex_imp_btn_l.addWidget(import_btn) ex_imp_btn_l.addWidget(export_btn) advanced_impexp_l.addRow(ex_imp_btn_l) # About about = QTabWidget(self) self.about_index = self.right_panel.addWidget(about) about_happypanda_page, about_layout = new_tab("About Happypanda", about, False) info_lbl = QLabel(app_constants.ABOUT) info_lbl.setWordWrap(True) info_lbl.setOpenExternalLinks(True) about_layout.addWidget(info_lbl) about_layout.addWidget(Spacer('v')) open_hp_folder = QPushButton('Open Happypanda Directory') open_hp_folder.clicked.connect(self.open_hp_folder) open_hp_folder.adjustSize() open_hp_folder.setFixedWidth(open_hp_folder.width()) about_layout.addWidget(open_hp_folder) # About / DB Overview about_db_overview, about_db_overview_m_l = new_tab('DB Overview', about) about_stats_tab_widget = misc_db.DBOverview(self.parent_widget) about_db_overview_options = QHBoxLayout() self.tags_treeview_on_start = QCheckBox('Start with application', about_db_overview) make_window_btn = QPushButton('Open in window', about_db_overview) make_window_btn.adjustSize() make_window_btn.setFixedWidth(make_window_btn.width()) about_db_overview_options.addWidget(self.tags_treeview_on_start) about_db_overview_options.addWidget(make_window_btn) def mk_btn_false(): try: make_window_btn.setDisabled(False) except RuntimeError: pass def make_tags_treeview_window(): self.parent_widget.tags_treeview = misc_db.DBOverview(self.parent_widget, True) self.parent_widget.tags_treeview.about_to_close.connect(mk_btn_false) make_window_btn.setDisabled(True) self.parent_widget.tags_treeview.show() if self.parent_widget.tags_treeview: self.parent_widget.tags_treeview.about_to_close.connect(mk_btn_false) make_window_btn.setDisabled(True) make_window_btn.clicked.connect(make_tags_treeview_window) about_db_overview_m_l.addRow(about_db_overview_options) about_db_overview_m_l.addRow(about_stats_tab_widget) # About / Troubleshooting about_troubleshoot_page = QWidget() about.addTab(about_troubleshoot_page, 'Bug Reporting') troubleshoot_layout = QVBoxLayout() about_troubleshoot_page.setLayout(troubleshoot_layout) guide_lbl = QLabel(app_constants.TROUBLE_GUIDE) guide_lbl.setTextFormat(Qt.RichText) guide_lbl.setOpenExternalLinks(True) guide_lbl.setWordWrap(True) troubleshoot_layout.addWidget(guide_lbl, 0, Qt.AlignTop) troubleshoot_layout.addWidget(Spacer('v')) # About / Search tutorial about_search_tut, about_search_tut_l = new_tab("Search Guide", about, True) g_search_lbl = QLabel(app_constants.SEARCH_TUTORIAL_TAGS) g_search_lbl.setWordWrap(True) about_search_tut_l.addRow(g_search_lbl) # About / Regex Cheatsheet about_s_regex, about_s_regex_l = new_tab("Regex Cheatsheet", about, True) reg_info = QLabel(app_constants.REGEXCHEAT) reg_info.setWordWrap(True) about_s_regex_l.addRow(reg_info) def add_folder_monitor(self, path=''): if not isinstance(path, str): path = '' l_edit = PathLineEdit() l_edit.setText(path) n = self.folders_layout.rowCount() + 1 self.folders_layout.addRow('{}'.format(n), l_edit) def add_ignore_path(self, path='', dir=True): if not isinstance(path, str): path = '' l_edit = PathLineEdit(dir=dir) l_edit.setText(path) n = self.ignore_path_l.rowCount() + 1 self.ignore_path_l.addRow('{}'.format(n), l_edit) def color_checker(self, txt): allow = False if len(txt) == 7: if txt[0] == '#': allow = True return allow def take_all_layout_widgets(self, l): n = l.rowCount() items = [] for x in range(n): item = l.takeAt(x+1) items.append(item.widget()) return items def choose_font(self): tup = QFontDialog.getFont(self) font = tup[0] if tup[1]: self.font_lbl.setText(font.family()) self.font_size_lbl.setValue(font.pointSize()) def open_hp_folder(self): if os.name == 'posix': utils.open_path(app_constants.posix_program_dir) else: utils.open_path(os.getcwd()) def reject(self): self.close()
class SettingsDialog(QWidget): "A settings dialog" scroll_speed_changed = pyqtSignal() def __init__(self, parent=None): super().__init__(parent, flags=Qt.Window) self.resize(700, 500) self.show() self.restore_values() self.initUI() def initUI(self): main_layout = QVBoxLayout() sub_layout = QHBoxLayout() # Left Panel left_panel = QListWidget() left_panel.setViewMode(left_panel.ListMode) #left_panel.setIconSize(QSize(40,40)) left_panel.setTextElideMode(Qt.ElideRight) left_panel.setMaximumWidth(200) left_panel.itemClicked.connect(self.change) #web.setText('Web') self.application = QListWidgetItem() self.application.setText('Application') self.web = QListWidgetItem() self.web.setText('Web') self.visual = QListWidgetItem() self.visual.setText('Visual') self.advanced = QListWidgetItem() self.advanced.setText('Advanced') self.about = QListWidgetItem() self.about.setText('About') #main.setIcon(QIcon(os.path.join(gui_constants.static_dir, 'plus2.png'))) left_panel.addItem(self.application) left_panel.addItem(self.web) left_panel.addItem(self.visual) left_panel.addItem(self.advanced) left_panel.addItem(self.about) left_panel.setMaximumWidth(100) # right panel self.right_panel = QStackedLayout() self.init_right_panel() # bottom bottom_layout = QHBoxLayout() ok_btn = QPushButton('Ok') ok_btn.clicked.connect(self.accept) cancel_btn = QPushButton('Cancel') cancel_btn.clicked.connect(self.close) info_lbl = QLabel() info_lbl.setText('<a href="https://github.com/Pewpews/happypanda">'+ 'Visit GitHub Repo</a> | Options marked with * requires application restart.') info_lbl.setTextFormat(Qt.RichText) info_lbl.setTextInteractionFlags(Qt.TextBrowserInteraction) info_lbl.setOpenExternalLinks(True) self.spacer = QWidget() self.spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) bottom_layout.addWidget(info_lbl, 0, Qt.AlignLeft) bottom_layout.addWidget(self.spacer) bottom_layout.addWidget(ok_btn, 0, Qt.AlignRight) bottom_layout.addWidget(cancel_btn, 0, Qt.AlignRight) sub_layout.addWidget(left_panel) sub_layout.addLayout(self.right_panel) main_layout.addLayout(sub_layout) main_layout.addLayout(bottom_layout) self.restore_options() self.setLayout(main_layout) self.setWindowTitle('Settings') def change(self, item): def curr_index(index): if index != self.right_panel.currentIndex(): self.right_panel.setCurrentIndex(index) if item == self.application: curr_index(self.application_index) elif item == self.web: curr_index(self.web_index) elif item == self.visual: curr_index(self.visual_index) elif item == self.advanced: curr_index(self.advanced_index) elif item == self.about: curr_index(self.about_index) def restore_values(self): #Web self.exprops = settings.ExProperties() # Visual self.high_quality_thumbs = gui_constants.HIGH_QUALITY_THUMBS self.popup_width = gui_constants.POPUP_WIDTH self.popup_height = gui_constants.POPUP_HEIGHT self.style_sheet = gui_constants.user_stylesheet_path # Advanced self.scroll_speed = gui_constants.SCROLL_SPEED self.cache_size = gui_constants.THUMBNAIL_CACHE_SIZE self.prefetch_item_amnt = gui_constants.PREFETCH_ITEM_AMOUNT def restore_options(self): # App / Monitor / Misc self.enable_monitor.setChecked(gui_constants.ENABLE_MONITOR) self.look_new_gallery_startup.setChecked(gui_constants.LOOK_NEW_GALLERY_STARTUP) self.auto_add_new_galleries.setChecked(gui_constants.LOOK_NEW_GALLERY_AUTOADD) # App / Monitor / Folders for path in gui_constants.MONITOR_PATHS: self.add_folder_monitor(path) # Web / General if 'g.e-hentai' in gui_constants.DEFAULT_EHEN_URL: self.default_ehen_url.setChecked(True) else: self.exhentai_ehen_url.setChecked(True) self.replace_metadata.setChecked(gui_constants.REPLACE_METADATA) self.always_first_hit.setChecked(gui_constants.ALWAYS_CHOOSE_FIRST_HIT) self.web_time_offset.setValue(gui_constants.GLOBAL_EHEN_TIME) self.continue_a_metadata_fetcher.setChecked(gui_constants.CONTINUE_AUTO_METADATA_FETCHER) self.use_jpn_title.setChecked(gui_constants.USE_JPN_TITLE) # Web / Exhentai self.ipbid_edit.setText(self.exprops.ipb_id) self.ipbpass_edit.setText(self.exprops.ipb_pass) # Visual / Grid View / Tooltip self.grid_tooltip_group.setChecked(gui_constants.GRID_TOOLTIP) self.visual_grid_tooltip_title.setChecked(gui_constants.TOOLTIP_TITLE) self.visual_grid_tooltip_author.setChecked(gui_constants.TOOLTIP_AUTHOR) self.visual_grid_tooltip_chapters.setChecked(gui_constants.TOOLTIP_CHAPTERS) self.visual_grid_tooltip_status.setChecked(gui_constants.TOOLTIP_STATUS) self.visual_grid_tooltip_type.setChecked(gui_constants.TOOLTIP_TYPE) self.visual_grid_tooltip_lang.setChecked(gui_constants.TOOLTIP_LANG) self.visual_grid_tooltip_descr.setChecked(gui_constants.TOOLTIP_DESCR) self.visual_grid_tooltip_tags.setChecked(gui_constants.TOOLTIP_TAGS) self.visual_grid_tooltip_last_read.setChecked(gui_constants.TOOLTIP_LAST_READ) self.visual_grid_tooltip_times_read.setChecked(gui_constants.TOOLTIP_TIMES_READ) self.visual_grid_tooltip_pub_date.setChecked(gui_constants.TOOLTIP_PUB_DATE) self.visual_grid_tooltip_date_added.setChecked(gui_constants.TOOLTIP_DATE_ADDED) # Visual / Grid View / Gallery self.external_viewer_ico.setChecked(gui_constants.USE_EXTERNAL_PROG_ICO) self.gallery_type_ico.setChecked(gui_constants.DISPLAY_GALLERY_TYPE) if gui_constants.GALLERY_FONT_ELIDE: self.gallery_text_elide.setChecked(True) else: self.gallery_text_fit.setChecked(True) self.font_lbl.setText(gui_constants.GALLERY_FONT[0]) self.font_size_lbl.setValue(gui_constants.GALLERY_FONT[1]) def re_enforce(s): if s: self.search_on_enter.setChecked(True) self.search_allow_regex.clicked.connect(re_enforce) if gui_constants.SEARCH_ON_ENTER: self.search_on_enter.setChecked(True) else: self.search_every_keystroke.setChecked(True) # Visual / Grid View / Colors self.grid_label_color.setText(gui_constants.GRID_VIEW_LABEL_COLOR) self.grid_title_color.setText(gui_constants.GRID_VIEW_TITLE_COLOR) self.grid_artist_color.setText(gui_constants.GRID_VIEW_ARTIST_COLOR) # Advanced / Misc / External Viewer self.external_viewer_path.setText(gui_constants.EXTERNAL_VIEWER_PATH) def accept(self): set = settings.set # App / Monitor / misc gui_constants.ENABLE_MONITOR = self.enable_monitor.isChecked() set(gui_constants.ENABLE_MONITOR, 'Application', 'enable monitor') gui_constants.LOOK_NEW_GALLERY_STARTUP = self.look_new_gallery_startup.isChecked() set(gui_constants.LOOK_NEW_GALLERY_STARTUP, 'Application', 'look new gallery startup') gui_constants.LOOK_NEW_GALLERY_AUTOADD = self.auto_add_new_galleries.isChecked() set(gui_constants.LOOK_NEW_GALLERY_AUTOADD, 'Application', 'look new gallery autoadd') # App / Monitor / folders n = self.folders_layout.rowCount() paths = '' for x in range(n): item = self.folders_layout.takeAt(x+1) l_edit = item.widget() p = l_edit.text() if p: if x == n-1: paths += '{}'.format(p) else: paths += '{},'.format(p) set(paths, 'Application', 'monitor paths') gui_constants.MONITOR_PATHS = paths.split(',') # Web / General if self.default_ehen_url.isChecked(): gui_constants.DEFAULT_EHEN_URL = 'http://g.e-hentai.org/' else: gui_constants.DEFAULT_EHEN_URL = 'http://exhentai.org/' set(gui_constants.DEFAULT_EHEN_URL, 'Web', 'default ehen url') gui_constants.REPLACE_METADATA = self.replace_metadata.isChecked() set(gui_constants.REPLACE_METADATA, 'Web', 'replace metadata') gui_constants.ALWAYS_CHOOSE_FIRST_HIT = self.always_first_hit.isChecked() set(gui_constants.ALWAYS_CHOOSE_FIRST_HIT, 'Web', 'always choose first hit') gui_constants.GLOBAL_EHEN_TIME = self.web_time_offset.value() set(gui_constants.GLOBAL_EHEN_TIME, 'Web', 'global ehen time offset') gui_constants.CONTINUE_AUTO_METADATA_FETCHER = self.continue_a_metadata_fetcher.isChecked() set(gui_constants.CONTINUE_AUTO_METADATA_FETCHER, 'Web', 'continue auto metadata fetcher') gui_constants.USE_JPN_TITLE = self.use_jpn_title.isChecked() set(gui_constants.USE_JPN_TITLE, 'Web', 'use jpn title') # Web / ExHentai self.exprops.ipb_id = self.ipbid_edit.text() self.exprops.ipb_pass = self.ipbpass_edit.text() # Visual / Grid View / Tooltip gui_constants.GRID_TOOLTIP = self.grid_tooltip_group.isChecked() set(gui_constants.GRID_TOOLTIP, 'Visual', 'grid tooltip') gui_constants.TOOLTIP_TITLE = self.visual_grid_tooltip_title.isChecked() set(gui_constants.TOOLTIP_TITLE, 'Visual', 'tooltip title') gui_constants.TOOLTIP_AUTHOR = self.visual_grid_tooltip_author.isChecked() set(gui_constants.TOOLTIP_AUTHOR, 'Visual', 'tooltip author') gui_constants.TOOLTIP_CHAPTERS = self.visual_grid_tooltip_chapters.isChecked() set(gui_constants.TOOLTIP_CHAPTERS, 'Visual', 'tooltip chapters') gui_constants.TOOLTIP_STATUS = self.visual_grid_tooltip_status.isChecked() set(gui_constants.TOOLTIP_STATUS, 'Visual', 'tooltip status') gui_constants.TOOLTIP_TYPE = self.visual_grid_tooltip_type.isChecked() set(gui_constants.TOOLTIP_TYPE, 'Visual', 'tooltip type') gui_constants.TOOLTIP_LANG = self.visual_grid_tooltip_lang.isChecked() set(gui_constants.TOOLTIP_LANG, 'Visual', 'tooltip lang') gui_constants.TOOLTIP_DESCR = self.visual_grid_tooltip_descr.isChecked() set(gui_constants.TOOLTIP_DESCR, 'Visual', 'tooltip descr') gui_constants.TOOLTIP_TAGS = self.visual_grid_tooltip_tags.isChecked() set(gui_constants.TOOLTIP_TAGS, 'Visual', 'tooltip tags') gui_constants.TOOLTIP_LAST_READ = self.visual_grid_tooltip_last_read.isChecked() set(gui_constants.TOOLTIP_LAST_READ, 'Visual', 'tooltip last read') gui_constants.TOOLTIP_TIMES_READ = self.visual_grid_tooltip_times_read.isChecked() set(gui_constants.TOOLTIP_TIMES_READ, 'Visual', 'tooltip times read') gui_constants.TOOLTIP_PUB_DATE = self.visual_grid_tooltip_pub_date.isChecked() set(gui_constants.TOOLTIP_PUB_DATE, 'Visual', 'tooltip pub date') gui_constants.TOOLTIP_DATE_ADDED = self.visual_grid_tooltip_date_added.isChecked() set(gui_constants.TOOLTIP_DATE_ADDED, 'Visual', 'tooltip date added') # Visual / Grid View / Gallery gui_constants.USE_EXTERNAL_PROG_ICO = self.external_viewer_ico.isChecked() set(gui_constants.USE_EXTERNAL_PROG_ICO, 'Visual', 'use external prog ico') gui_constants.DISPLAY_GALLERY_TYPE = self.gallery_type_ico.isChecked() set(gui_constants.DISPLAY_GALLERY_TYPE, 'Visual', 'display gallery type') if self.gallery_text_elide.isChecked(): gui_constants.GALLERY_FONT_ELIDE = True else: gui_constants.GALLERY_FONT_ELIDE = False set(gui_constants.GALLERY_FONT_ELIDE, 'Visual', 'gallery font elide') gui_constants.GALLERY_FONT = (self.font_lbl.text(), self.font_size_lbl.value()) set(gui_constants.GALLERY_FONT[0], 'Visual', 'gallery font family') set(gui_constants.GALLERY_FONT[1], 'Visual', 'gallery font size') # Visual / Grid View / Colors if self.color_checker(self.grid_title_color.text()): gui_constants.GRID_VIEW_TITLE_COLOR = self.grid_title_color.text() set(gui_constants.GRID_VIEW_TITLE_COLOR, 'Visual', 'grid view title color') if self.color_checker(self.grid_artist_color.text()): gui_constants.GRID_VIEW_ARTIST_COLOR = self.grid_artist_color.text() set(gui_constants.GRID_VIEW_ARTIST_COLOR, 'Visual', 'grid view artist color') if self.color_checker(self.grid_label_color.text()): gui_constants.GRID_VIEW_LABEL_COLOR = self.grid_label_color.text() set(gui_constants.GRID_VIEW_LABEL_COLOR, 'Visual', 'grid view label color') # Advanced / Misc # Advanced / Misc / Grid View gui_constants.SCROLL_SPEED = self.scroll_speed set(self.scroll_speed, 'Advanced', 'scroll speed') self.scroll_speed_changed.emit() gui_constants.THUMBNAIL_CACHE_SIZE = self.cache_size set(self.cache_size[1], 'Advanced', 'cache size') QPixmapCache.setCacheLimit(self.cache_size[0]* self.cache_size[1]) # Advanced / Misc / Search gui_constants.ALLOW_SEARCH_REGEX = self.search_allow_regex.isChecked() set(gui_constants.ALLOW_SEARCH_REGEX, 'Advanced', 'allow search regex') gui_constants.SEARCH_AUTOCOMPLETE = self.search_autocomplete.isChecked() set(gui_constants.SEARCH_AUTOCOMPLETE, 'Advanced', 'search autocomplete') if self.search_on_enter.isChecked(): gui_constants.SEARCH_ON_ENTER = True else: gui_constants.SEARCH_ON_ENTER = False set(gui_constants.SEARCH_ON_ENTER, 'Advanced', 'search on enter') # Advanced / Misc / External Viewer if not self.external_viewer_path.text(): gui_constants.USE_EXTERNAL_VIEWER = False set(False, 'Advanced', 'use external viewer') else: gui_constants.USE_EXTERNAL_VIEWER = True set(True, 'Advanced', 'use external viewer') gui_constants._REFRESH_EXTERNAL_VIEWER = True gui_constants.EXTERNAL_VIEWER_PATH = self.external_viewer_path.text() set(gui_constants.EXTERNAL_VIEWER_PATH,'Advanced', 'external viewer path') settings.save() self.close() def init_right_panel(self): #def title_def(title): # title_lbl = QLabel(title) # f = QFont() # f.setPixelSize(16) # title_lbl.setFont(f) # return title_lbl # App application = QTabWidget() self.application_index = self.right_panel.addWidget(application) application_general = QWidget() application.addTab(application_general, 'General') application.setTabEnabled(0, False) # App / Monitor app_monitor_page = QScrollArea() app_monitor_page.setBackgroundRole(QPalette.Base) app_monitor_dummy = QWidget() app_monitor_page.setWidgetResizable(True) app_monitor_page.setWidget(app_monitor_dummy) application.addTab(app_monitor_page, 'Monitoring') application.setCurrentIndex(1) app_monitor_m_l = QVBoxLayout(app_monitor_dummy) # App / Monitor / misc app_monitor_misc_group = QGroupBox('General *', self) app_monitor_m_l.addWidget(app_monitor_misc_group) app_monitor_misc_m_l = QFormLayout(app_monitor_misc_group) monitor_info = QLabel('Directory monitoring will monitor the specified directories for any'+ ' gallery events. For example if you delete a gallery source in one of your'+ ' monitored directories the application will inform you about it, and ask if'+ ' you want to delete the gallery from the application as well.') monitor_info.setWordWrap(True) app_monitor_misc_m_l.addRow(monitor_info) self.enable_monitor = QCheckBox('Enable directory monitoring') app_monitor_misc_m_l.addRow(self.enable_monitor) self.look_new_gallery_startup = QGroupBox('Scan for new galleries on startup', self) app_monitor_misc_m_l.addRow(self.look_new_gallery_startup) self.look_new_gallery_startup.setCheckable(True) look_new_gallery_startup_m_l = QVBoxLayout(self.look_new_gallery_startup) self.auto_add_new_galleries = QCheckBox('Automatically add found galleries') look_new_gallery_startup_m_l.addWidget(self.auto_add_new_galleries) # App / Monitor / folders app_monitor_group = QGroupBox('Directories *', self) app_monitor_m_l.addWidget(app_monitor_group, 1) app_monitor_folders_m_l = QVBoxLayout(app_monitor_group) app_monitor_folders_add = QPushButton('+') app_monitor_folders_add.clicked.connect(self.add_folder_monitor) app_monitor_folders_add.setMaximumWidth(20) app_monitor_folders_add.setMaximumHeight(20) app_monitor_folders_m_l.addWidget(app_monitor_folders_add, 0, Qt.AlignRight) self.folders_layout = QFormLayout() app_monitor_folders_m_l.addLayout(self.folders_layout) # Web web = QTabWidget() self.web_index = self.right_panel.addWidget(web) web_general_page = QScrollArea() web_general_page.setBackgroundRole(QPalette.Base) web_general_page.setWidgetResizable(True) web.addTab(web_general_page, 'General') web_general_dummy = QWidget() web_general_page.setWidget(web_general_dummy) web_general_m_l = QVBoxLayout(web_general_dummy) metadata_fetcher_group = QGroupBox('Metadata', self) web_general_m_l.addWidget(metadata_fetcher_group) metadata_fetcher_m_l = QFormLayout(metadata_fetcher_group) self.default_ehen_url = QRadioButton('g.e-hentai.org', metadata_fetcher_group) self.exhentai_ehen_url = QRadioButton('exhentai.org', metadata_fetcher_group) ehen_url_l = QHBoxLayout() ehen_url_l.addWidget(self.default_ehen_url) ehen_url_l.addWidget(self.exhentai_ehen_url, 1) metadata_fetcher_m_l.addRow('Default URL:', ehen_url_l) self.continue_a_metadata_fetcher = QCheckBox('Continue from where auto metadata fetcher left off') metadata_fetcher_m_l.addRow(self.continue_a_metadata_fetcher) self.use_jpn_title = QCheckBox('Use japanese title') metadata_fetcher_m_l.addRow(self.use_jpn_title) time_offset_info = QLabel('To avoid getting banned, we need to impose a delay between our requests.'+ ' I have made it so you cannot set the delay lower than the recommended (I don\'t'+ ' want you to get banned, anon).\nSpecify the delay between requests in seconds.') time_offset_info.setWordWrap(True) self.web_time_offset = QSpinBox() self.web_time_offset.setMaximumWidth(40) self.web_time_offset.setMinimum(4) self.web_time_offset.setMaximum(99) metadata_fetcher_m_l.addRow(time_offset_info) metadata_fetcher_m_l.addRow('Requests delay in', self.web_time_offset) replace_metadata_info = QLabel('When fetching for metadata the new metadata will be appended'+ ' to the gallery by default. This means that new data will only be set if'+ ' the field was empty. There is however a special case for namespace & tags.'+ ' We go through all the new namespace & tags to only add those that'+ ' do not already exists.\n\nEnabling this option makes it so that a gallery\'s old data'+ ' are deleted and replaced with the new data.') replace_metadata_info.setWordWrap(True) self.replace_metadata = QCheckBox('Replace old metadata with new metadata') metadata_fetcher_m_l.addRow(replace_metadata_info) metadata_fetcher_m_l.addRow(self.replace_metadata) first_hit_info = QLabel('By default, you get to choose which gallery to extract metadata from when'+ ' there is more than one gallery found when searching.\n'+ 'Enabling this option makes it choose the first hit, saving you from moving your mouse.') first_hit_info.setWordWrap(True) self.always_first_hit = QCheckBox('Always choose first hit') metadata_fetcher_m_l.addRow(first_hit_info) metadata_fetcher_m_l.addRow(self.always_first_hit) # Web / Exhentai exhentai_page = QWidget() web.addTab(exhentai_page, 'ExHentai') ipb_layout = QFormLayout() exhentai_page.setLayout(ipb_layout) self.ipbid_edit = QLineEdit() self.ipbpass_edit = QLineEdit() exh_tutorial = QLabel(gui_constants.EXHEN_COOKIE_TUTORIAL) exh_tutorial.setTextFormat(Qt.RichText) ipb_layout.addRow('IPB Member ID:', self.ipbid_edit) ipb_layout.addRow('IPB Pass Hash:', self.ipbpass_edit) ipb_layout.addRow(exh_tutorial) # Visual visual = QTabWidget() self.visual_index = self.right_panel.addWidget(visual) visual_general_page = QWidget() visual.addTab(visual_general_page, 'General') grid_view_general_page = QWidget() visual.addTab(grid_view_general_page, 'Grid View') grid_view_layout = QVBoxLayout() grid_view_layout.addWidget(QLabel('Options marked with * requires application restart'), 0, Qt.AlignTop) grid_view_general_page.setLayout(grid_view_layout) # grid view # grid view / tooltip self.grid_tooltip_group = QGroupBox('Tooltip', grid_view_general_page) self.grid_tooltip_group.setCheckable(True) grid_view_layout.addWidget(self.grid_tooltip_group, 0, Qt.AlignTop) grid_tooltip_layout = QFormLayout() self.grid_tooltip_group.setLayout(grid_tooltip_layout) grid_tooltip_layout.addRow(QLabel('Control what is'+ ' displayed in the tooltip')) grid_tooltips_hlayout = FlowLayout() grid_tooltip_layout.addRow(grid_tooltips_hlayout) self.visual_grid_tooltip_title = QCheckBox('Title') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_title) self.visual_grid_tooltip_author = QCheckBox('Author') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_author) self.visual_grid_tooltip_chapters = QCheckBox('Chapters') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_chapters) self.visual_grid_tooltip_status = QCheckBox('Status') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_status) self.visual_grid_tooltip_type = QCheckBox('Type') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_type) self.visual_grid_tooltip_lang = QCheckBox('Language') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_lang) self.visual_grid_tooltip_descr = QCheckBox('Description') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_descr) self.visual_grid_tooltip_tags = QCheckBox('Tags') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_tags) self.visual_grid_tooltip_last_read = QCheckBox('Last read') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_last_read) self.visual_grid_tooltip_times_read = QCheckBox('Times read') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_times_read) self.visual_grid_tooltip_pub_date = QCheckBox('Publication Date') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_pub_date) self.visual_grid_tooltip_date_added = QCheckBox('Date added') grid_tooltips_hlayout.addWidget(self.visual_grid_tooltip_date_added) # grid view / gallery grid_gallery_group = QGroupBox('Gallery', grid_view_general_page) grid_view_layout.addWidget(grid_gallery_group, 0, Qt.AlignTop) grid_gallery_main_l = QFormLayout() grid_gallery_main_l.setFormAlignment(Qt.AlignLeft) grid_gallery_group.setLayout(grid_gallery_main_l) grid_gallery_display = FlowLayout() grid_gallery_main_l.addRow('Display on gallery:', grid_gallery_display) self.external_viewer_ico = QCheckBox('External Viewer') self.external_viewer_ico.setDisabled(True) grid_gallery_display.addWidget(self.external_viewer_ico) self.gallery_type_ico = QCheckBox('File Type') self.gallery_type_ico.setDisabled(True) grid_gallery_display.addWidget(self.gallery_type_ico) gallery_text_mode = QWidget() grid_gallery_main_l.addRow('Text Mode:', gallery_text_mode) gallery_text_mode_l = QHBoxLayout() gallery_text_mode.setLayout(gallery_text_mode_l) self.gallery_text_elide = QRadioButton('Elide text', gallery_text_mode) self.gallery_text_fit = QRadioButton('Fit text', gallery_text_mode) gallery_text_mode_l.addWidget(self.gallery_text_elide, 0, Qt.AlignLeft) gallery_text_mode_l.addWidget(self.gallery_text_fit, 0, Qt.AlignLeft) gallery_text_mode_l.addWidget(Spacer('h'), 1, Qt.AlignLeft) gallery_font = QHBoxLayout() grid_gallery_main_l.addRow('Font:*', gallery_font) self.font_lbl = QLabel() self.font_size_lbl = QSpinBox() self.font_size_lbl.setMaximum(100) self.font_size_lbl.setMinimum(1) self.font_size_lbl.setToolTip('Font size in pixels') choose_font = QPushButton('Choose font') choose_font.clicked.connect(self.choose_font) gallery_font.addWidget(self.font_lbl, 0, Qt.AlignLeft) gallery_font.addWidget(self.font_size_lbl, 0, Qt.AlignLeft) gallery_font.addWidget(choose_font, 0, Qt.AlignLeft) gallery_font.addWidget(Spacer('h'), 1, Qt.AlignLeft) # grid view / colors grid_colors_group = QGroupBox('Colors', grid_view_general_page) grid_view_layout.addWidget(grid_colors_group, 1, Qt.AlignTop) grid_colors_l = QFormLayout() grid_colors_group.setLayout(grid_colors_l) def color_lineedit(): l = QLineEdit() l.setPlaceholderText('Hex colors. Eg.: #323232') l.setMaximumWidth(200) return l self.grid_label_color = color_lineedit() self.grid_title_color = color_lineedit() self.grid_artist_color = color_lineedit() grid_colors_l.addRow('Label color:', self.grid_label_color) grid_colors_l.addRow('Title color:', self.grid_title_color) grid_colors_l.addRow('Artist color:', self.grid_artist_color) style_page = QWidget() visual.addTab(style_page, 'Style') visual.setTabEnabled(0, False) visual.setTabEnabled(2, False) visual.setCurrentIndex(1) # Advanced advanced = QTabWidget() self.advanced_index = self.right_panel.addWidget(advanced) advanced_misc = QWidget() advanced.addTab(advanced_misc, 'Misc') advanced_misc_main_layout = QVBoxLayout() advanced_misc.setLayout(advanced_misc_main_layout) misc_controls_layout = QFormLayout() misc_controls_layout.addWidget(QLabel('Options marked with * requires application restart')) advanced_misc_main_layout.addLayout(misc_controls_layout) # Advanced / Misc / Grid View misc_gridview = QGroupBox('Grid View') misc_controls_layout.addWidget(misc_gridview) misc_gridview_layout = QFormLayout() misc_gridview.setLayout(misc_gridview_layout) # Advanced / Misc / Grid View / scroll speed scroll_speed_spin_box = QSpinBox() scroll_speed_spin_box.setFixedWidth(60) scroll_speed_spin_box.setToolTip('Control the speed when scrolling in'+ ' grid view. DEFAULT: 7') scroll_speed_spin_box.setValue(self.scroll_speed) def scroll_speed(v): self.scroll_speed = v scroll_speed_spin_box.valueChanged[int].connect(scroll_speed) misc_gridview_layout.addRow('Scroll speed:', scroll_speed_spin_box) # Advanced / Misc / Grid View / cache size cache_size_spin_box = QSpinBox() cache_size_spin_box.setFixedWidth(120) cache_size_spin_box.setMaximum(999999999) cache_size_spin_box.setToolTip('This will greatly improve the grid view.' + ' Increase the value if you experience lag when scrolling'+ ' through galleries. DEFAULT: 200 MiB') def cache_size(c): self.cache_size = (self.cache_size[0], c) cache_size_spin_box.setValue(self.cache_size[1]) cache_size_spin_box.valueChanged[int].connect(cache_size) misc_gridview_layout.addRow('Cache Size (MiB):', cache_size_spin_box) # Advanced / Misc / Regex misc_search = QGroupBox('Search') misc_controls_layout.addWidget(misc_search) misc_search_layout = QFormLayout() misc_search.setLayout(misc_search_layout) search_allow_regex_l = QHBoxLayout() self.search_allow_regex = QCheckBox() self.search_allow_regex.setChecked(gui_constants.ALLOW_SEARCH_REGEX) self.search_allow_regex.adjustSize() self.search_allow_regex.setToolTip('A regex cheatsheet is located at About->Regex Cheatsheet') search_allow_regex_l.addWidget(self.search_allow_regex) search_allow_regex_l.addWidget(QLabel('A regex cheatsheet is located at About->Regex Cheatsheet')) search_allow_regex_l.addWidget(Spacer('h')) misc_search_layout.addRow('Regex:', search_allow_regex_l) # Advanced / Misc / Regex / autocomplete self.search_autocomplete = QCheckBox('*') self.search_autocomplete.setChecked(gui_constants.SEARCH_AUTOCOMPLETE) self.search_autocomplete.setToolTip('Turn autocomplete on/off') misc_search_layout.addRow('Autocomplete', self.search_autocomplete) # Advanced / Misc / Regex / search behaviour self.search_every_keystroke = QRadioButton('Search on every keystroke *', misc_search) misc_search_layout.addRow(self.search_every_keystroke) self.search_on_enter = QRadioButton('Search on enter-key *', misc_search) misc_search_layout.addRow(self.search_on_enter) # Advanced / Misc / External Viewer misc_external_viewer = QGroupBox('External Viewer') misc_controls_layout.addWidget(misc_external_viewer) misc_external_viewer_l = QFormLayout() misc_external_viewer.setLayout(misc_external_viewer_l) misc_external_viewer_l.addRow(QLabel(gui_constants.SUPPORTED_EXTERNAL_VIEWER_LBL)) self.external_viewer_path = PathLineEdit(misc_external_viewer, False) self.external_viewer_path.setPlaceholderText('Right/Left-click to open folder explorer.'+ ' Leave empty to use default viewer') self.external_viewer_path.setToolTip('Right/Left-click to open folder explorer.'+ ' Leave empty to use default viewer') self.external_viewer_path.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) misc_external_viewer_l.addRow('Path:', self.external_viewer_path) # Advanced / Database advanced_db_page = QWidget() advanced.addTab(advanced_db_page, 'Database') advanced.setTabEnabled(1, False) # About about = QTabWidget() self.about_index = self.right_panel.addWidget(about) about_happypanda_page = QWidget() about_troubleshoot_page = QWidget() about.addTab(about_happypanda_page, 'About Happypanda') about_layout = QVBoxLayout() about_happypanda_page.setLayout(about_layout) info_lbl = QLabel('<b>Author:</b> <a href=\'https://github.com/Pewpews\'>'+ 'Pewpews</a><br/>'+ 'Chat: <a href=\'https://gitter.im/Pewpews/happypanda\'>'+ 'Gitter chat</a><br/>'+ 'Email: [email protected]<br/>'+ '<b>Current version {}</b><br/>'.format(gui_constants.vs)+ 'Happypanda was created using:<br/>'+ '- Python 3.4<br/>'+ '- The Qt5 Framework') info_lbl.setOpenExternalLinks(True) about_layout.addWidget(info_lbl, 0, Qt.AlignTop) gpl_lbl = QLabel(gui_constants.GPL) gpl_lbl.setOpenExternalLinks(True) gpl_lbl.setWordWrap(True) about_layout.addWidget(gpl_lbl, 0, Qt.AlignTop) about_layout.addWidget(Spacer('v')) # About / Tags about_tags_page = QWidget() about.addTab(about_tags_page, 'Tags') about.setTabEnabled(1, False) # list of tags/namespaces here # About / Troubleshooting about.addTab(about_troubleshoot_page, 'Troubleshooting Guide') troubleshoot_layout = QVBoxLayout() about_troubleshoot_page.setLayout(troubleshoot_layout) guide_lbl = QLabel(gui_constants.TROUBLE_GUIDE) guide_lbl.setTextFormat(Qt.RichText) guide_lbl.setOpenExternalLinks(True) troubleshoot_layout.addWidget(guide_lbl, 0, Qt.AlignTop) troubleshoot_layout.addWidget(Spacer('v')) # About / Regex Cheatsheet about_s_regex = QGroupBox('Regex') about.addTab(about_s_regex, 'Regex Cheatsheet') about_s_regex_l = QFormLayout() about_s_regex.setLayout(about_s_regex_l) about_s_regex_l.addRow('\\\\\\\\', QLabel('Match literally \\')) about_s_regex_l.addRow('.', QLabel('Match any single character')) about_s_regex_l.addRow('^', QLabel('Start of string')) about_s_regex_l.addRow('$', QLabel('End of string')) about_s_regex_l.addRow('\\d', QLabel('Match any decimal digit')) about_s_regex_l.addRow('\\D', QLabel('Match any non-digit character')) about_s_regex_l.addRow('\\s', QLabel('Match any whitespace character')) about_s_regex_l.addRow('\\S', QLabel('Match any non-whitespace character')) about_s_regex_l.addRow('\\w', QLabel('Match any alphanumeric character')) about_s_regex_l.addRow('\\W', QLabel('Match any non-alphanumeric character')) about_s_regex_l.addRow('*', QLabel('Repeat previous character zero or more times')) about_s_regex_l.addRow('+', QLabel('Repeat previous character one or more times')) about_s_regex_l.addRow('?', QLabel('Repeat previous character one or zero times')) about_s_regex_l.addRow('{m, n}', QLabel('Repeat previous character atleast <i>m</i> times but no more than <i>n</i> times')) about_s_regex_l.addRow('(...)', QLabel('Match everything enclosed')) about_s_regex_l.addRow('(a|b)', QLabel('Match either a or b')) about_s_regex_l.addRow('[abc]', QLabel('Match a single character of: a, b or c')) about_s_regex_l.addRow('[^abc]', QLabel('Match a character except: a, b or c')) about_s_regex_l.addRow('[a-z]', QLabel('Match a character in the range')) about_s_regex_l.addRow('[^a-z]', QLabel('Match a character not in the range')) # About / Search tutorial about_search_scroll = QScrollArea() about_search_scroll.setBackgroundRole(QPalette.Base) about_search_scroll.setWidgetResizable(True) about_search_tut = QWidget() about.addTab(about_search_scroll, 'Search Guide') about_search_tut_l = QVBoxLayout() about_search_tut.setLayout(about_search_tut_l) # General about_search_general = QGroupBox('General') about_search_tut_l.addWidget(about_search_general) about_search_general_l = QFormLayout() about_search_general.setLayout(about_search_general_l) about_search_general_l.addRow(QLabel(gui_constants.SEARCH_TUTORIAL_GENERAL)) # Title & Author about_search_tit_aut = QGroupBox('Title and Author') about_search_tut_l.addWidget(about_search_tit_aut) about_search_tit_l = QFormLayout() about_search_tit_aut.setLayout(about_search_tit_l) about_search_tit_l.addRow(QLabel(gui_constants.SEARCH_TUTORIAL_TIT_AUT)) # Namespace & Tags about_search_tags = QGroupBox('Namespace and Tags') about_search_tut_l.addWidget(about_search_tags) about_search_tags_l = QFormLayout() about_search_tags.setLayout(about_search_tags_l) about_search_tags_l.addRow(QLabel(gui_constants.SEARCH_TUTORIAL_TAGS)) about_search_scroll.setWidget(about_search_tut) def add_folder_monitor(self, path=''): if not isinstance(path, str): path = '' l_edit = PathLineEdit() l_edit.setText(path) n = self.folders_layout.rowCount() + 1 self.folders_layout.addRow('Dir {}'.format(n), l_edit) def color_checker(self, txt): allow = False if len(txt) == 7: if txt[0] == '#': allow = True return allow def choose_font(self): tup = QFontDialog.getFont(self) font = tup[0] if tup[1]: self.font_lbl.setText(font.family()) self.font_size_lbl.setValue(font.pointSize()) def reject(self): self.close()
class Window(QMainWindow): def __init__(self): super().__init__() self.title = "Project Babymonitor - IoT" self.top = 1000 self.left = 1000 self.width = 2000 self.height = 2000 self.button_bm = False self.button_smp = False self.button_smtv = False self.button_smp_confirm = False self.is_adapted = False self.InitWindow() def start_middleware(self): main(self.is_adapted) def button_pressed_start(self, device): global position_x_bm, position_x_smp, position_x_smtv if device == 'baby_monitor': baby_monitor_start() self.button_bm = True thread_bm_data = threading.Thread( target=self.baby_monitor_show_message, args=()) thread_bm_data.start() self.connection_bm.setText( '<strong>Open connection Baby Monitor<\strong>') self.connection_bm.setFont(QtGui.QFont('Arial', 12)) self.connection_bm.adjustSize() self.connection_bm.move(position_x_bm, 550) start_emma = threading.Thread(target=self.show_status_emma, args=()) start_emma.start() elif device == 'smartphone': smartphone_start() self.button_smp = True thread_smp_data = threading.Thread( target=self.smartphone_show_message, args=()) thread_smp_data.start() self.connection_smp.setText( '<strong>Open connection Smartphone<\strong>') self.connection_smp.setFont(QtGui.QFont('Arial', 12)) self.connection_smp.adjustSize() self.connection_smp.move(position_x_smp, 550) elif device == 'tv': smart_tv_turn_on() self.button_smtv = True thread_smtv_data = threading.Thread( target=self.smart_tv_show_message, args=()) thread_smtv_data.start() self.connection_smtv.setText( '<strong>Open connection Smart TV<\strong>') self.connection_smtv.setFont(QtGui.QFont('Arial', 12)) self.connection_smtv.adjustSize() self.connection_smtv.move(position_x_smtv, 550) self.adaptation.setEnabled(False) self.start_middleware() def button_pressed_stop(self, device): if device == 'baby_monitor': self.button_bm = False baby_monitor_stop() self.connection_bm.setText( '<strong>Closed connection Baby Monitor<\strong>') self.connection_bm.setFont(QtGui.QFont('Arial', 12)) self.connection_bm.adjustSize() self.connection_bm.move(position_x_bm, 550) elif device == 'smartphone': self.button_smp = False smartphone_stop() self.connection_smp.setText( '<strong>Closed connection Smartphone<\strong>') self.connection_smp.setFont(QtGui.QFont('Arial', 12)) self.connection_smp.adjustSize() self.connection_smp.move(position_x_smp, 550) elif device == 'tv': self.button_smtv = False smart_tv_turn_off() self.connection_smtv.setText( '<strong>Closed connection Smart TV<\strong>') self.connection_smtv.setFont(QtGui.QFont('Arial', 12)) self.connection_smtv.adjustSize() self.connection_smtv.move(position_x_smtv, 550) def button_pressed_start_app(self, device): smart_tv_start_app() def button_pressed_stop_app(self, device): smart_tv_stop_app() def button_pressed_confirm(self): smartphone_confirm_notification() data = baby_monitor_get_data() self.button_smp_confirm = True self.button_confirm.setEnabled(False) #sleep(1) '''self.alert.setText("") smartphone_consumer.is_notification = False self.message_confirm.setText("Notification Confirmed") self.message_confirm.setFont(QtGui.QFont('Arial', 12)) self.message_confirm.adjustSize() self.message_confirm.move(500, 500) sleep(2) self.message_confirm.setText('')''' def check_adaptation(self, state): if state == QtCore.Qt.Checked: self.is_adapted = True else: self.is_adapted = False def baby_monitor_show_message(self): global position_x_bm while self.button_bm: data = baby_monitor_get_data() if data: if 'STATUS' in data: data = data.replace('STATUS: ', '') data = eval(data) self.send_breathing_bm.setText('Breathing: {}'.format( data['breathing'])) self.send_breathing_bm.setFont(QtGui.QFont('Arial', 12)) self.send_breathing_bm.adjustSize() self.send_breathing_bm.move(position_x_bm, 230) self.send_time_no_breathing_bm.setText( 'Time no Breathing: {}'.format( data['time_no_breathing'])) self.send_time_no_breathing_bm.setFont( QtGui.QFont('Arial', 12)) self.send_time_no_breathing_bm.adjustSize() self.send_time_no_breathing_bm.move(position_x_bm, 250) self.send_crying_bm.setText('Crying: {}'.format( data['crying'])) self.send_crying_bm.setFont(QtGui.QFont('Arial', 12)) self.send_crying_bm.adjustSize() self.send_crying_bm.move(position_x_bm, 270) self.send_sleeping_bm.setText('Sleeping: {}'.format( data['sleeping'])) self.send_sleeping_bm.setFont(QtGui.QFont('Arial', 12)) self.send_sleeping_bm.adjustSize() self.send_sleeping_bm.move(position_x_bm, 290) self.notification_bm.setText("") self.notification_bm.setWordWrap(False) self.notification_bm.adjustSize() else: self.send_breathing_bm.setText('') self.send_sleeping_bm.setText('') self.send_crying_bm.setText('') self.send_time_no_breathing_bm.setText('') self.notification_bm.setFixedWidth(150) self.notification_bm.setWordWrap(True) self.notification_bm.setFont(QtGui.QFont('Arial', 12)) self.notification_bm.adjustSize() self.notification_bm.move(position_x_bm, 230) self.notification_bm.setText( data.replace('NOTIFICATION', 'Notification')) if 'Pending' in baby_monitor_get_confirmation(): self.pending.setText(baby_monitor_get_confirmation()) self.pending.setFont(QtGui.QFont('Arial', 12)) self.pending.adjustSize() self.pending.move(position_x_bm, 500) self.message_from_smartphone.setText("") else: self.message_from_smartphone.setText( baby_monitor_get_confirmation()) self.message_from_smartphone.setFont(QtGui.QFont('Arial', 12)) self.message_from_smartphone.adjustSize() self.message_from_smartphone.move(position_x_bm, 500) self.pending.setText("") sleep(1) def smartphone_show_message(self): global position_x_smp while self.button_smp: data = smartphone_get_message() if isinstance(data, dict): self.receive_breathing_smp.setText('Breathing: {}'.format( data['breathing'])) self.receive_breathing_smp.setFont(QtGui.QFont('Arial', 12)) self.receive_breathing_smp.adjustSize() self.receive_breathing_smp.move(position_x_smp, 370) self.receive_time_no_breathing_smp.setText( 'Time no Breathing: {}'.format(data['time_no_breathing'])) self.receive_time_no_breathing_smp.setFont( QtGui.QFont('Arial', 12)) self.receive_time_no_breathing_smp.adjustSize() self.receive_time_no_breathing_smp.move(position_x_smp, 390) self.receive_crying_smp.setText('Crying: {}'.format( data['crying'])) self.receive_crying_smp.setFont(QtGui.QFont('Arial', 12)) self.receive_crying_smp.adjustSize() self.receive_crying_smp.move(position_x_smp, 410) self.receive_sleeping_smp.setText('Sleeping: {}'.format( data['sleeping'])) self.receive_sleeping_smp.setFont(QtGui.QFont('Arial', 12)) self.receive_sleeping_smp.adjustSize() self.receive_sleeping_smp.move(position_x_smp, 430) self.alert.setText("Everything's fine :)") self.alert.setFont(QtGui.QFont('Arial', 12)) self.alert.adjustSize() self.alert.move(position_x_smp, 500) self.notification.setText("") self.notification.setWordWrap(False) self.notification.adjustSize() self.send_confirmation_smp.setText("") self.button_smp_confirm = False #self.button_confirm.setEnabled(False) else: self.notification.setFixedWidth(150) self.notification.setWordWrap(True) self.notification.setFont(QtGui.QFont('Arial', 12)) self.notification.adjustSize() self.notification.move(position_x_smp, 370) self.notification.setText( data.replace('NOTIFICATION', 'Notification')[1:]) self.receive_breathing_smp.setText('') self.receive_time_no_breathing_smp.setText('') self.receive_crying_smp.setText('') self.receive_sleeping_smp.setText('') self.alert.setText("") if self.button_smp_confirm: self.send_confirmation_smp.setText('Confirmation Sent.') self.send_confirmation_smp.setFont(QtGui.QFont('Arial', 12)) self.send_confirmation_smp.adjustSize() self.send_confirmation_smp.move(position_x_smp, 240) else: self.send_confirmation_smp.setText('') if smartphone_get_notification(): self.button_confirm.setEnabled(True) else: self.button_confirm.setEnabled(True) def smart_tv_show_message(self): global position_x_tv while self.button_smtv: if smart_tv_get_status(): self.status_smtv.setText('TV is unlocked') self.status_smtv.setFont(QtGui.QFont('Arial', 12)) self.status_smtv.adjustSize() self.status_smtv.move(position_x_smtv, 500) else: self.status_smtv.setText('TV is locked') self.status_smtv.setFont(QtGui.QFont('Arial', 12)) self.status_smtv.adjustSize() self.status_smtv.move(position_x_smtv, 500) self.receive_message_smtv.setText('') if smart_tv_get_application(): self.app_smtv.setText('App is running') self.app_smtv.setFont(QtGui.QFont('Arial', 12)) self.app_smtv.adjustSize() self.app_smtv.move(position_x_smtv, 520) self.receive_message_smtv.setText('') else: self.app_smtv.setText('No app running') self.app_smtv.setFont(QtGui.QFont('Arial', 12)) self.app_smtv.adjustSize() self.app_smtv.move(position_x_smtv, 520) data = smart_tv_get_message() self.receive_message_smtv.setFixedWidth(150) self.receive_message_smtv.setWordWrap(True) self.receive_message_smtv.setFont(QtGui.QFont('Arial', 12)) self.receive_message_smtv.adjustSize() self.receive_message_smtv.move(position_x_smtv, 370) if data == '': self.receive_message_smtv.setText('') else: data = data.replace("b'", "") data = data.replace('"', '') self.receive_message_smtv.setText( data.replace('NOTIFICATION', 'Notification')) def show_status_emma(self): while self.button_bm: check_ = baby_monitor_get_status() self.status_breathing.setText('Breathing: {}'.format( check_['breathing'])) self.status_breathing.setFont(QtGui.QFont('Arial', 12)) self.status_breathing.adjustSize() self.status_breathing.move(position_x_smtv + 310, 430) self.status_time_no_breathing.setText( 'Time no Breathing: {}'.format(check_['time_no_breathing'])) self.status_time_no_breathing.setFont(QtGui.QFont('Arial', 12)) self.status_time_no_breathing.adjustSize() self.status_time_no_breathing.move(position_x_smtv + 310, 450) self.status_crying.setText('Crying: {}'.format(check_['crying'])) self.status_crying.setFont(QtGui.QFont('Arial', 12)) self.status_crying.adjustSize() self.status_crying.move(position_x_smtv + 310, 470) self.status_sleeping.setText('Sleeping: {}'.format( check_['sleeping'])) self.status_sleeping.setFont(QtGui.QFont('Arial', 12)) self.status_sleeping.adjustSize() self.status_sleeping.move(position_x_smtv + 310, 490) def create_interface(self, position_x, name_interface): # Define title device self.title_baby_monitor = QLabel(self) self.title_baby_monitor.setText( '<strong>{}<\strong>'.format(name_interface)) self.title_baby_monitor.setFont(QtGui.QFont('Arial', 16)) self.title_baby_monitor.adjustSize() self.title_baby_monitor.move(position_x, 10) self.send = QLabel(self) self.send.setText('<strong>Send<\strong>') self.send.setFont(QtGui.QFont('Arial', 14)) self.send.adjustSize() self.send.move(position_x, 200) self.receive = QLabel(self) self.receive.setText('<strong>Receive<\strong>') self.receive.setFont(QtGui.QFont('Arial', 14)) self.receive.adjustSize() self.receive.move(position_x, 340) self.information = QLabel(self) self.information.setText('<strong>Information<\strong>') self.information.setFont(QtGui.QFont('Arial', 14)) self.information.adjustSize() self.information.move(position_x, 470) self.connection_bm = QLabel(self) self.send_breathing_bm = QLabel(self) self.send_time_no_breathing_bm = QLabel(self) self.send_crying_bm = QLabel(self) self.send_sleeping_bm = QLabel(self) self.message_from_smartphone = QLabel(self) self.pending = QLabel(self) self.image_bm = QLabel(self) self.connection_smp = QLabel(self) self.receive_breathing_smp = QLabel(self) self.receive_time_no_breathing_smp = QLabel(self) self.receive_crying_smp = QLabel(self) self.receive_sleeping_smp = QLabel(self) self.send_confirmation_smp = QLabel(self) self.alert = QLabel(self) self.image_smp = QLabel(self) self.connection_smtv = QLabel(self) self.notification_bm = QLabel(self) self.notification = QLabel(self) self.status_smtv = QLabel(self) self.app_smtv = QLabel(self) self.receive_message_smtv = QLabel(self) self.image_smtv = QLabel(self) if name_interface == 'Baby Monitor': self.button_start = QPushButton('Start', self) self.button_start.move(position_x - 20, 600) self.button_start.clicked.connect( partial(self.button_pressed_start, 'baby_monitor')) self.button_stop = QPushButton('Stop', self) self.button_stop.move(position_x + 100, 600) self.button_stop.clicked.connect( partial(self.button_pressed_stop, 'baby_monitor')) elif name_interface == 'Smartphone': self.button_start = QPushButton('Start', self) self.button_start.move(position_x - 20, 600) self.button_start.clicked.connect( partial(self.button_pressed_start, 'smartphone')) self.button_stop = QPushButton('Stop', self) self.button_stop.move(position_x + 100, 600) self.button_stop.clicked.connect( partial(self.button_pressed_stop, 'smartphone')) self.button_confirm = QPushButton('Confirm', self) self.button_confirm.move(position_x - 20, 640) self.button_confirm.clicked.connect(self.button_pressed_confirm) self.button_confirm.setEnabled(False) else: self.button_start = QPushButton('Start', self) self.button_start.move(position_x - 20, 600) self.button_start.clicked.connect( partial(self.button_pressed_start, 'tv')) self.button_stop = QPushButton('Stop', self) self.button_stop.move(position_x + 100, 600) self.button_stop.clicked.connect( partial(self.button_pressed_stop, 'tv')) self.button_start_app = QPushButton('Start App', self) self.button_start_app.move(position_x - 20, 640) self.button_start_app.clicked.connect( self.button_pressed_start_app) self.button_stop_app = QPushButton('Stop App', self) self.button_stop_app.move(position_x + 100, 640) self.button_stop_app.clicked.connect(self.button_pressed_stop_app) def InitWindow(self): global position_x_bm, position_x_smp, position_x_smtv self.status_breathing = QLabel(self) self.status_time_no_breathing = QLabel(self) self.status_sleeping = QLabel(self) self.status_crying = QLabel(self) self.setGeometry(self.top, self.left, self.width, self.height) self.label = QLabel(self) self.label.setPixmap(QPixmap("./imgs/babymonitor.png")) self.label.setGeometry(position_x_bm + 10, 10, 200, 200) self.label = QLabel(self) self.label.setPixmap(QPixmap("./imgs/smartphone.png")) self.label.setGeometry(position_x_smp + 10, 60, 100, 100) self.label = QLabel(self) self.label.setPixmap(QPixmap("./imgs/monitor.svg")) self.label.setGeometry(position_x_smtv - 10, 10, 200, 200) self.label = QLabel(self) self.label.setPixmap(QPixmap("./imgs/emma.png")) self.label.setGeometry(position_x_smtv + 280, 200, 200, 200) self.create_interface(position_x_bm, 'Baby Monitor') self.create_interface(position_x_smp, 'Smartphone') self.create_interface(position_x_smtv, 'Smart Tv') self.setWindowIcon(QtGui.QIcon("./imgs/babymonitor.png")) self.title_device = QLabel(self) self.title_device.setText('<strong>BabyMonitor - IoT<\strong>') self.title_device.setFont(QtGui.QFont('Arial', 30)) self.title_device.adjustSize() self.title_device.move(position_x_smtv + 200, 80) self.adaptation = QCheckBox('Cautious adaptation?', self) self.adaptation.setFont(QtGui.QFont('Arial', 12)) self.adaptation.adjustSize() self.adaptation.stateChanged.connect(self.check_adaptation) self.adaptation.move(position_x_smtv + 280, 150) self.show()
class MainWidg(QWidget): def __init__(self, main_win_ex): super().__init__() self.main_win_ex = main_win_ex self.init_var() self.init_ui() def init_var(self): self.sourse = None self.fname_db = '' self.object = '' self.type = '' self.subtype = '' self.country = '' self.rlname = '' self.main_fr_prm = [] self.channels = [] self.slctd_chan = [] self.fname_gts = '' self.dmx = None def init_ui(self): # Кнопка Старт self.start_btn = self.start_btn_init() # Кнопка выхода self.quit_btn = self.quit_btn_init() ############################################################################################################### # Кнопка выбора файла базы данных self.select_db_btn = self.select_db_btn_init() self.lbl_db_path = QLabel(self) self.lbl_db_path.setStatusTip('Путь к файлу базы данных') ############################################################################################################### # Кнопка выбора файла ГТС self.select_GTS_btn = self.select_GTS_btn_init() self.lbl_GTS_path = QLabel(self) self.lbl_GTS_path.setStatusTip('Путь к файлу ГТС') self.chk_revers = QCheckBox('Реверс бит в байте') self.chk_revers.setStatusTip( 'Если файл ГТС уже был обработан, то реверс был произведен') self.chk_revers.setChecked(True) self.chk_revers.adjustSize() ############################################################################################################### # Выбор исследуемого источника self.gbox_object = QGroupBox('Выбор исследуемого источника', self) self.gbox_object.setStatusTip( 'Последовательно выберите каждый из критериев классификации источников' ) self.lbl_object = QLabel(self) self.lbl_type = QLabel(self) self.lbl_subtype = QLabel(self) self.lbl_country = QLabel(self) self.combo_obj = QComboBox(self) self.combo_obj.setMinimumWidth(80) self.combo_obj.setStatusTip('Выберите объект') self.combo_type = QComboBox(self) self.combo_type.setMinimumWidth(50) self.combo_type.setStatusTip('Выберите тип источника') self.combo_subtype = QComboBox(self) self.combo_subtype.setMinimumWidth(80) self.combo_subtype.setStatusTip('Выберите подтип источника') self.combo_country = QComboBox(self) self.combo_country.setMinimumWidth(150) self.combo_country.setStatusTip( 'Выберите страну, которой принадлежит исследуемый объект') ############################################################################################################### # Выбор радиолинии self.gbox_rl = QGroupBox('Выбор радиолинии ', self) self.gbox_rl.setStatusTip( 'Выберите одну из радиолиний, принадлежащих указанному источнику') self.lbl_rlname = QLabel(self) self.combo_rlname = QComboBox(self) self.combo_rlname.setMinimumWidth(250) ############################################################################################################### # Отображение параметров основного коммутатора self.gbox_fr_prm = QGroupBox('Характеристики основного коммутатора', self) self.gbox_fr_prm.setStatusTip('Характеристики основного коммутатора') self.lbl_fr_name = QLabel(self) self.lbl_fr_len = QLabel(self) self.lbl_fr_wlen = QLabel(self) self.lbl_fr_freq = QLabel(self) ############################################################################################################### # Выбор коммутатора для демультиплексирования self.gbox_sel_chan = QGroupBox('Выбор демультиплексируемого канала', self) self.gbox_sel_chan.setStatusTip( 'Сначала выберите тип, а затем имя демультиплексируемого канала') self.lbl_type_chan = QLabel(self) self.lbl_type_chan.setMinimumWidth(100) self.lbl_name_chan = QLabel(self) self.lbl_type_chan.setMinimumWidth(150) self.combo_chtype = QComboBox(self) self.combo_chtype.setMinimumWidth(100) self.combo_chtype.setStatusTip('Выберите тип канала') self.combo_chname = QComboBox(self) self.combo_chname.setMinimumWidth(200) self.combo_chname.setStatusTip('Выберите имя канала') ################################################################################################################ # Отображение параметров выбранного для демультиплексирования канала self.gbox_chan_prm = QGroupBox( 'Характеристики демультиплексируемого канала', self) self.gbox_chan_prm.setStatusTip( 'Характеристики демультиплексируемого канала') self.lbl_chan_frlen = QLabel(self) self.lbl_chan_wlen = QLabel(self) # Прогресс БАР self.progrbar_dmx = QProgressBar() self.progrbar_dmx.setStatusTip('Прогресс выполнения декоммутации') ############################ self.combo_obj_rm() # Управление макетом self.cur_layout = self.layout_init() self.setLayout(self.cur_layout) def start_btn_init(self): self.start_btn = QPushButton( 'Старт') # QPushButton(string_text, QWidget parent = None) self.start_btn.resize( self.start_btn.sizeHint()) # Рекомедуемый размер кнопки self.start_btn.setStatusTip('Запуск и остановка декоммутациии') self.start_btn.setDisabled(True) self.start_btn.clicked.connect(self.start_dmx_thread) return self.start_btn def quit_btn_init(self): self.quit_btn = QPushButton('Выход') self.quit_btn.clicked.connect(self.main_win_ex.exit_msg) self.quit_btn.resize( self.quit_btn.sizeHint()) # Рекомедуемый размер кнопки self.quit_btn.setStatusTip('Выход из приложения') return self.quit_btn def select_db_btn_init(self): self.select_db_btn = QPushButton('Выбор файла БД...') self.select_db_btn.setStatusTip('Выбор файла БД...') self.select_db_btn.resize( self.select_db_btn.sizeHint()) # Рекомедуемый размер кнопки self.select_db_btn.clicked.connect(self.dialog_select_db) return self.select_db_btn def select_GTS_btn_init(self): self.select_GTS_btn = QPushButton('Выбор файла ГТС...') self.select_GTS_btn.setStatusTip('Выбор файла ГТС...') self.select_GTS_btn.resize(self.select_GTS_btn.sizeHint()) self.select_GTS_btn.setDisabled(True) self.select_GTS_btn.clicked.connect(self.dialog_select_gts) return self.select_GTS_btn def dialog_select_gts(self): self.fname_gts = QFileDialog.getOpenFileName(self, 'Выберите файл GTS', './', '*.bit') if len(self.fname_gts[0]) > 0: if self.dmx != None: self.dmx.disconnect() self.dmx = None try: self.dmx = Thread_dmx(self.fname_gts[0], self.slctd_chan, self.chk_revers.isChecked()) except BaseException as err: self.main_win_ex.err_msg(err) return self.lbl_GTS_path.setText(self.fname_gts[0]) self.lbl_GTS_path.adjustSize() self.start_btn.setEnabled(True) self.dmx.sprogress_br.connect(self.progrbar_dmx.setValue) self.dmx.started.connect(self.dmx_on_started) self.dmx.finished.connect(self.dmx_on_finished) self.dmx.s_eof.connect(self.main_win_ex.exit_msg) self.dmx.s_error.connect(self.main_win_ex.err_msg) def dialog_select_db(self): self.fname_db = QFileDialog.getOpenFileName(self, 'Выберите файл БД', './', '*.sqb') if len(self.fname_db[0]) > 0: self.combo_obj_rm() self.lbl_db_path.setText(self.fname_db[0]) self.lbl_db_path.adjustSize() try: self.sourse = DbQuery(self.fname_db[0], self.main_win_ex) combo_init(self.sourse.get_objects(), self.combo_obj) except BaseException as err: self.main_win_ex.err_msg(err) self.combo_obj.activated[str].connect(self.activ_combo_obj) self.combo_obj.setEnabled(True) def start_dmx_thread(self): self.combo_obj.setDisabled(True) self.combo_type.setDisabled(True) self.combo_subtype.setDisabled(True) self.combo_country.setDisabled(True) self.combo_rlname.setDisabled(True) self.combo_chtype.setDisabled(True) self.combo_chname.setDisabled(True) self.select_GTS_btn.setDisabled(True) self.select_db_btn.setDisabled(True) self.start_btn.setDisabled(True) self.dmx.stop_flag = False # Обвязка для ошибок self.dmx.start() def stop_dmx_thread(self): self.combo_obj.setEnabled(True) self.combo_type.setEnabled(True) self.combo_subtype.setEnabled(True) self.combo_country.setEnabled(True) self.combo_rlname.setEnabled(True) self.combo_chtype.setEnabled(True) self.combo_chname.setEnabled(True) self.select_GTS_btn.setEnabled(True) self.select_db_btn.setEnabled(True) self.start_btn.setDisabled(True) self.dmx.stop_flag = True def dmx_on_started(self): self.start_btn.setText('Стоп') self.start_btn.disconnect() self.start_btn.clicked.connect(self.stop_dmx_thread) self.start_btn.setEnabled(True) def dmx_on_finished(self): self.combo_obj.setEnabled(True) self.combo_type.setEnabled(True) self.combo_subtype.setEnabled(True) self.combo_country.setEnabled(True) self.combo_rlname.setEnabled(True) self.combo_chtype.setEnabled(True) self.combo_chname.setEnabled(True) self.select_GTS_btn.setEnabled(True) self.select_db_btn.setEnabled(True) self.progrbar_dmx.reset() if self.dmx != None: self.dmx.disconnect() self.dmx = None try: self.dmx = Thread_dmx(self.fname_gts[0], self.slctd_chan, self.chk_revers.isChecked()) except BaseException as err: self.main_win_ex.err_msg(err) return self.dmx.sprogress_br.connect(self.progrbar_dmx.setValue) self.dmx.started.connect(self.dmx_on_started) self.dmx.finished.connect(self.dmx_on_finished) self.dmx.s_eof.connect(self.main_win_ex.exit_msg) self.dmx.s_error.connect(self.main_win_ex.err_msg) self.start_btn.setText('Cтарт') self.start_btn.disconnect() self.start_btn.clicked.connect(self.start_dmx_thread) self.start_btn.setEnabled(True) ######################################################################################################################################################################### def activ_combo_obj(self, text): self.combo_type_rm() if text == '--': self.lbl_object.setText('Объект: ') self.lbl_object.adjustSize() return self.lbl_object.setText('Объект: ' + text) self.lbl_object.adjustSize() self.object = text try: combo_init(self.sourse.get_types(self.object), self.combo_type) except BaseException as err: self.main_win_ex.err_msg(err) self.combo_type.activated[str].connect(self.active_combo_type) self.combo_type.setEnabled(True) def active_combo_type(self, text): self.combo_subtype_rm() if text == '--': self.lbl_type.setText('Тип: ') self.lbl_type.adjustSize() return self.lbl_type.setText('Тип: ' + text) self.lbl_type.adjustSize() self.type = text try: combo_init(self.sourse.get_subtypes(self.object, self.type), self.combo_subtype) except BaseException as err: self.main_win_ex.err_msg(err) self.combo_subtype.activated[str].connect(self.active_combo_subtype) self.combo_subtype.setEnabled(True) def active_combo_subtype(self, text): self.combo_country_rm() if text == '--': self.lbl_subtype.setText('Подтип: ') self.lbl_subtype.adjustSize() return self.lbl_subtype.setText('Подтип: ' + text) self.lbl_subtype.adjustSize() self.subtype = text try: combo_init( self.sourse.get_country(self.object, self.type, self.subtype), self.combo_country) except BaseException as err: self.main_win_ex.err_msg(err) self.combo_country.activated[str].connect(self.active_combo_country) self.combo_country.setEnabled(True) def active_combo_country(self, text): self.combo_rlname_rm() if text == '--': self.lbl_country.setText('Страна: ') self.lbl_country.adjustSize() return self.lbl_country.setText('Страна: ' + text) self.lbl_country.adjustSize() self.country = text try: combo_init( self.sourse.get_rl(self.object, self.type, self.subtype, self.country), self.combo_rlname) except BaseException as err: self.main_win_ex.err_msg(err) self.combo_rlname.activated[str].connect(self.active_combo_rlname) self.combo_rlname.setEnabled(True) def active_combo_rlname(self, text): self.combo_chtype_rm() if text == '--': self.lbl_rlname.setText('Тип радиолинии: ') self.lbl_rlname.adjustSize() return self.lbl_rlname.setText('Тип радиолинии: ' + text) self.lbl_rlname.adjustSize() self.rlname = text try: self.main_fr_prm = self.sourse.get_main_frame(self.rlname) except BaseException as err: self.main_win_ex.err_msg(err) self.gbox_fr_prm_set() self.channels.append([]) self.channels[0] = self.main_fr_prm try: self.sourse.get_all_commuts(self.main_fr_prm[0], self.channels) except BaseException as err: self.main_win_ex.err_msg(err) self.combo_chantype_init() self.combo_chtype.setEnabled(True) self.combo_chtype.activated[str].connect(self.active_combo_chtype) def active_combo_chtype(self, text): self.combo_chname_rm() if text == '--': self.lbl_type_chan.setText('Тип канала: ') self.lbl_type_chan.adjustSize() return self.lbl_type_chan.setText('Тип канала: ' + text) self.lbl_type_chan.adjustSize() self.combo_channame_init(text) self.combo_chname.setEnabled(True) self.combo_chname.activated[str].connect(self.active_combo_chname) def active_combo_chname(self, text): if self.dmx != None: self.dmx.disconnect() self.dmx = None self.lbl_GTS_path.setText('') self.lbl_GTS_path.adjustSize() self.start_btn.setDisabled(True) if text == '--': self.lbl_name_chan.setText('Имя канала: ') self.lbl_name_chan.adjustSize() self.lbl_chan_frlen.setText('Длина канала в битах: ') self.lbl_chan_frlen.adjustSize() self.lbl_chan_wlen.setText('Длина слова в битах: ') self.lbl_chan_wlen.adjustSize() self.select_GTS_btn.setDisabled(True) return self.lbl_name_chan.setText('Имя канала: ' + text) self.lbl_name_chan.adjustSize() self.slctd_chan = [] self.gbox_chan_prm_set(text) self.select_GTS_btn.setEnabled(True) ######################################################################################################################################################################### def combo_obj_rm(self): while self.combo_obj.count() > 0: self.combo_obj.removeItem(0) self.lbl_object.setText('Объект: ') self.lbl_object.adjustSize() self.object = '' self.combo_obj.addItem('--') self.combo_obj.setDisabled(True) self.combo_type_rm() def combo_type_rm(self): while self.combo_type.count() > 0: self.combo_type.removeItem(0) self.lbl_type.setText('Тип: ') self.lbl_type.adjustSize() self.type = '' self.combo_type.addItem('--') self.combo_type.setDisabled(True) self.combo_subtype_rm() def combo_subtype_rm(self): while self.combo_subtype.count() > 0: self.combo_subtype.removeItem(0) self.lbl_subtype.setText('Подтип: ') self.lbl_subtype.adjustSize() self.subtype = '' self.combo_subtype.addItem('--') self.combo_subtype.setDisabled(True) self.combo_country_rm() def combo_country_rm(self): while self.combo_country.count() > 0: self.combo_country.removeItem(0) self.lbl_country.setText('Страна: ') self.lbl_country.adjustSize() self.country = '' self.combo_country.addItem('--') self.combo_country.setDisabled(True) self.combo_rlname_rm() def combo_rlname_rm(self): while self.combo_rlname.count() > 0: self.combo_rlname.removeItem(0) self.lbl_rlname.setText('Тип радиолинии: ') self.lbl_rlname.adjustSize() self.rlname = '' self.combo_rlname.addItem('--') self.combo_rlname.setDisabled(True) self.lbl_fr_name.setText('Условное имя коммутатора: ') self.lbl_fr_name.adjustSize() self.lbl_fr_len.setText('Длина кадра в битах: ') self.lbl_fr_len.adjustSize() self.lbl_fr_wlen.setText('Длина слова в битах: ') self.lbl_fr_wlen.adjustSize() self.lbl_fr_freq.setText('Частота следования кадров в кадр/с: ') self.lbl_fr_freq.adjustSize() self.main_fr_prm = [] self.combo_chtype_rm() def combo_chtype_rm(self): self.lbl_type_chan.setText('Тип канала: ') self.lbl_type_chan.adjustSize() while self.combo_chtype.count() > 0: self.combo_chtype.removeItem(0) self.combo_chtype.addItem('--') self.combo_chtype.setDisabled(True) self.channels = [] self.combo_chname_rm() def combo_chname_rm(self): self.lbl_name_chan.setText('Имя канала: ') self.lbl_name_chan.adjustSize() while self.combo_chname.count() > 0: self.combo_chname.removeItem(0) self.combo_chname.addItem('--') self.combo_chname.setDisabled(True) self.lbl_chan_frlen.setText('Длина канала в битах: ') self.lbl_chan_frlen.adjustSize() self.lbl_chan_wlen.setText('Длина слова в битах: ') self.lbl_chan_wlen.adjustSize() self.slctd_chan = [] self.fname_gts = '' if self.dmx != None: self.dmx.disconnect() self.dmx = None self.lbl_GTS_path.setText('') self.lbl_GTS_path.adjustSize() self.select_GTS_btn.setDisabled(True) self.start_btn.setDisabled(True) ######################################################################################################################################################################### def select_db_btn_click(self): self.select_db_btn.click() def layout_init(self): hbox_1 = QHBoxLayout() hbox_1.addWidget(self.select_db_btn) hbox_1.addWidget(self.lbl_db_path) hbox_1.addStretch(1) vbox_gb_obj_1 = QVBoxLayout() vbox_gb_obj_1.addWidget(self.lbl_object) vbox_gb_obj_1.addWidget(self.combo_obj) vbox_gb_obj_2 = QVBoxLayout() vbox_gb_obj_2.addWidget(self.lbl_type) vbox_gb_obj_2.addWidget(self.combo_type) vbox_gb_obj_3 = QVBoxLayout() vbox_gb_obj_3.addWidget(self.lbl_subtype) vbox_gb_obj_3.addWidget(self.combo_subtype) vbox_gb_obj_4 = QVBoxLayout() vbox_gb_obj_4.addWidget(self.lbl_country) vbox_gb_obj_4.addWidget(self.combo_country) gbox_obj_layout = QHBoxLayout() gbox_obj_layout.addLayout(vbox_gb_obj_1) gbox_obj_layout.addLayout(vbox_gb_obj_2) gbox_obj_layout.addLayout(vbox_gb_obj_3) gbox_obj_layout.addLayout(vbox_gb_obj_4) self.gbox_object.setLayout(gbox_obj_layout) vbox_gb_rl_1 = QVBoxLayout() vbox_gb_rl_1.addWidget(self.lbl_rlname) vbox_gb_rl_1.addWidget(self.combo_rlname) gbox_rl_layout = QHBoxLayout() gbox_rl_layout.addLayout(vbox_gb_rl_1) self.gbox_rl.setLayout(gbox_rl_layout) vbox_obj_rl = QVBoxLayout() vbox_obj_rl.addWidget(self.gbox_object) vbox_obj_rl.addWidget(self.gbox_rl) vbox_gbox_frame_layout = QVBoxLayout() vbox_gbox_frame_layout.addWidget(self.lbl_fr_name) vbox_gbox_frame_layout.addWidget(self.lbl_fr_len) vbox_gbox_frame_layout.addWidget(self.lbl_fr_wlen) vbox_gbox_frame_layout.addWidget(self.lbl_fr_freq) self.gbox_fr_prm.setLayout(vbox_gbox_frame_layout) hbox_2 = QHBoxLayout() hbox_2.addLayout(vbox_obj_rl) hbox_2.addWidget(self.gbox_fr_prm) hbox_2.addStretch(1) vbox_type_chan = QVBoxLayout() vbox_type_chan.addWidget(self.lbl_type_chan) vbox_type_chan.addWidget(self.combo_chtype) vbox_name_chan = QVBoxLayout() vbox_name_chan.addWidget(self.lbl_name_chan) vbox_name_chan.addWidget(self.combo_chname) gbox_chan_layout = QHBoxLayout() gbox_chan_layout.addLayout(vbox_type_chan) gbox_chan_layout.addLayout(vbox_name_chan) self.gbox_sel_chan.setLayout(gbox_chan_layout) gbox_chan_prm_layout = QVBoxLayout() gbox_chan_prm_layout.addWidget(self.lbl_chan_frlen) gbox_chan_prm_layout.addWidget(self.lbl_chan_wlen) self.gbox_chan_prm.setLayout(gbox_chan_prm_layout) hbox_3 = QHBoxLayout() hbox_3.addWidget(self.gbox_sel_chan) hbox_3.addWidget(self.gbox_chan_prm) hbox_3.addStretch(1) hbox_4 = QHBoxLayout() hbox_4.addWidget(self.select_GTS_btn) hbox_4.addWidget(self.lbl_GTS_path) hbox_4.addStretch(1) hbox_5 = QHBoxLayout() hbox_5.addWidget(self.chk_revers) hbox_5.addStretch(1) hbox_lower = QHBoxLayout() # hbox_lower.addStretch(1) hbox_lower.addWidget(self.progrbar_dmx) hbox_lower.addWidget(self.start_btn) hbox_lower.addWidget(self.quit_btn) vbox = QVBoxLayout() vbox.addLayout(hbox_1) vbox.addLayout(hbox_2) vbox.addLayout(hbox_3) vbox.addLayout(hbox_4) vbox.addLayout(hbox_5) vbox.addStretch(1) vbox.addLayout(hbox_lower) return vbox def gbox_fr_prm_set(self): self.lbl_fr_name.setText('Условное имя коммутатора: ' + self.main_fr_prm[1]) self.lbl_fr_name.adjustSize() self.lbl_fr_len.setText('Длина кадра в битах: ' + str(self.main_fr_prm[3])) self.lbl_fr_len.adjustSize() self.lbl_fr_wlen.setText('Длина слова в битах: ' + str(self.main_fr_prm[4])) self.lbl_fr_wlen.adjustSize() self.lbl_fr_freq.setText('Частота следования кадров в кадр/с: ' + str(self.main_fr_prm[5])) self.lbl_fr_freq.adjustSize() def gbox_chan_prm_set(self, chname): for i in range(len(self.channels)): if self.channels[i][1] == chname: self.form_slctd_chan_tab(i) self.lbl_chan_frlen.setText('Длина канала в битах: ' + str(self.slctd_chan[0][3])) self.lbl_chan_frlen.adjustSize() self.lbl_chan_wlen.setText('Длина слова в битах: ' + str(self.slctd_chan[0][4])) self.lbl_chan_wlen.adjustSize() def form_slctd_chan_tab(self, number_chan): self.slctd_chan.append([]) self.slctd_chan[len(self.slctd_chan) - 1] = self.channels[number_chan] for i in range(len(self.channels)): if self.slctd_chan[len(self.slctd_chan) - 1][2] == self.channels[i][0]: self.form_slctd_chan_tab(i) def combo_chantype_init(self): for i in range(len(self.channels)): if self.combo_chtype.count() > 0: if self.combo_chtype.findText(self.channels[i][6]) >= 0: continue else: self.combo_chtype.addItem(self.channels[i][6]) else: self.combo_chtype.addItem(self.channels[i][6]) def combo_channame_init(self, chantype): for i in range(len(self.channels)): if self.channels[i][6] == chantype: if self.combo_chname.count() > 0: if self.combo_chname.findText(self.channels[i][1]) >= 0: continue else: self.combo_chname.addItem(self.channels[i][1]) else: self.combo_chname.addItem(self.channels[i][1])
def initUI(self): self.setGeometry(300, 300, 600, 600) self.setWindowTitle('Drawing home') self.width = 175 #default settings self.height = 100 self.roofHeight = 50 self.mainColor1 = QColor(255, 255, 127) self.mainColor2 = QColor(255, 85, 0) self.roofColor = QColor(199, 250, 252) self.doorColor = QColor(255, 255, 255) self.lightColor = QColor(255, 219, 41) self.windowStyle = "Round window" self.roomNumber = 1 drawButton = QPushButton( "Move cursor here to update the object, if it was not happened", self) drawButton.setFont(QFont("Comic Sans MS", 11, QFont.Normal)) drawButton.move(40, 60) drawButton.adjustSize() #sliders etc. self.changeWidth = QSlider(Qt.Horizontal, self) self.changeWidth.setFocusPolicy(Qt.NoFocus) self.changeWidth.setStyleSheet(sldStyle) #use our own style! self.changeWidth.setGeometry(30, 150, 100, 30) self.changeWidth.valueChanged[int].connect(self.changeWidthF) self.changeHeight = QSlider(Qt.Horizontal, self) self.changeHeight.setFocusPolicy(Qt.NoFocus) self.changeHeight.setStyleSheet(sldStyle) self.changeHeight.setGeometry(30, 220, 100, 30) self.changeHeight.valueChanged[int].connect(self.changeHeightF) self.changeRoofHeight = QSlider(Qt.Horizontal, self) self.changeRoofHeight.setFocusPolicy(Qt.NoFocus) self.changeRoofHeight.setStyleSheet(sldStyle) self.changeRoofHeight.setGeometry(30, 290, 100, 30) self.changeRoofHeight.valueChanged[int].connect(self.changeRoofHeightF) changeWindowStyle = QComboBox(self) changeWindowStyle.addItem("Round window") changeWindowStyle.addItem("2-part window") changeWindowStyle.addItem("No window") changeWindowStyle.move(30, 365) changeWindowStyle.setFont(QFont("Tahoma", 10, QFont.Normal)) changeWindowStyle.activated[str].connect(self.changeWindowStyle) changeWindowStyle.adjustSize() changeIllumination = QCheckBox('Neon Light', self) changeIllumination.move(30, 410) changeIllumination.setFont(QFont("Segoe Print", 10, QFont.Normal)) changeIllumination.adjustSize() changeIllumination.stateChanged.connect(self.changeIllumination) changeRoomNumber = QComboBox(self) changeRoomNumber.addItem("1") changeRoomNumber.addItem("2") changeRoomNumber.move(30, 505) changeRoomNumber.setFont(QFont("Tahoma", 10, QFont.Normal)) changeRoomNumber.activated[int].connect(self.changeRoomNumber) #labels changeW = QLabel("Width", self) changeW.move(30, 120) changeW.setFont(QFont("Segoe Print", 10, QFont.Normal)) changeH = QLabel("Height", self) changeH.move(30, 190) changeH.setFont(QFont("Segoe Print", 10, QFont.Normal)) changeRH = QLabel("Roof level", self) changeRH.move(30, 260) changeRH.setFont(QFont("Segoe Print", 10, QFont.Normal)) changeWS = QLabel("Window style", self) changeWS.move(30, 330) changeWS.setFont(QFont("Segoe Print", 10, QFont.Normal)) changeWS.adjustSize() changeRN = QLabel("Number of rooms", self) changeRN.move(30, 450) changeRN.setFont(QFont("Segoe Print", 10, QFont.Normal)) changeRN.adjustSize() changeRN1 = QLabel("on the 2nd floor", self) changeRN1.move(30, 470) changeRN1.setFont(QFont("Segoe Print", 10, QFont.Normal)) changeRN1.adjustSize() #toolbar actions roofColorAction = QAction(QIcon('colorR.png'), 'Change color of the roof', self) roofColorAction.triggered.connect(self.changeRoofColor) color1Action = QAction(QIcon('color2.png'), 'Change color of the upper part', self) color1Action.triggered.connect(self.changeColor1) color2Action = QAction(QIcon('color1.png'), 'Change color of the lower part', self) color2Action.triggered.connect(self.changeColor2) doorColorAction = QAction(QIcon('colorD.png'), 'Change color of the door', self) doorColorAction.triggered.connect(self.changeDoorColor) randomizeAction = QAction(QIcon('random.png'), 'Randonize your house', self) randomizeAction.triggered.connect(self.randomize) toolbar = self.addToolBar('Menu') toolbar.setIconSize(QSize(45, 45)) toolbar.addAction(roofColorAction) toolbar.addAction(color2Action) toolbar.addAction(color1Action) toolbar.addAction(doorColorAction) toolbar.addAction(randomizeAction) self.show()