def createAndDeleteButtonClicked(self): appctx = ApplicationContext() alert = QMessageBox() alert.setIcon(QMessageBox.Question) alert.setText("All information present " "on the current spreadsheet " "will be lost. " "Are you sure you wish to continue?") alert.setWindowTitle("Spreadsheet Reset Confirmation") alert.setWindowIcon(QIcon(appctx.get_resource("sheets.ico"))) alert.setStandardButtons(QMessageBox.Yes | QMessageBox.No) alert.setDefaultButton(QMessageBox.No) reply = alert.exec_() if reply == alert.Yes: spreadsheet_hdl = SpreadsheetHandler() spreadsheet_hdl.delete_spreadsheet() spreadsheet_hdl.create_spreadsheet() self.resetCategoriesComboBox() alert = QMessageBox() alert.setWindowTitle("Spreadsheet Reset") alert.setWindowIcon(QIcon(appctx.get_resource("sheets.ico"))) alert.setText("A new spreadsheet was created!") alert.exec_()
def addCategoryButtonClicked(self): spreadsheet_hdl = SpreadsheetHandler() appctx = ApplicationContext() new_category = self.addCategoryLine.text() categories = spreadsheet_hdl.read_categories() if new_category in categories: alert = QMessageBox() alert.setWindowTitle("Category Adding") alert.setWindowIcon(QIcon(appctx.get_resource("sheets.ico"))) alert.setText("The category " + new_category + " already exists.") alert.exec_() return spreadsheet_hdl.add_category(new_category) self.resetCategoriesComboBox() alert = QMessageBox() alert.setWindowTitle("Category Adding") alert.setWindowIcon(QIcon(appctx.get_resource("sheets.ico"))) alert.setText("The category " + new_category + " was succesfully added!") alert.exec_()
def parse(): global data, css appctxt = ApplicationContext() datafile = appctxt.get_resource('dictionary_data/english.json') cssfile = appctxt.get_resource('styles/english.css') with open(datafile, encoding='utf8') as df: raw = df.read() data = json.loads(raw) with open(cssfile, encoding='utf8') as cf: css = cf.read()
def __init__(self, parent=None, submit_icon=None): super(WidgetGallery, self).__init__(parent) appctx = ApplicationContext() spreadsheet_hdl = SpreadsheetHandler() categories = spreadsheet_hdl.read_categories() self.tabsWidget = QTabWidget() # Add 'Expenses' tab to main widget self.createExpensesLayout() self.tabsWidget.addTab(self.expensesWidget, QIcon(appctx.get_resource("submit.ico")), "Expenses") # Add 'Incomes' tab to main widget self.createIncomesLayout() self.tabsWidget.addTab(self.incomesWidget, QIcon(appctx.get_resource("submit.ico")), "Incomes") # Add 'Latest Uploads' tab to main widget self.createLatestUploads() self.tabsWidget.addTab(self.latestUploadsWidget, QIcon(appctx.get_resource("sheets.ico")), "Latest Uploads") # Add 'Spreadsheet Actions' tab to main widget self.createSpreadsheetActionsLayout() self.tabsWidget.addTab(self.spreadsheetActionsWidget, QIcon(appctx.get_resource("sheets.ico")), "Spreadsheet Actions") # Set the current available expenses categories self.addCategories(categories) # Set main window size self.resize(570, 320) self.tabsWidget.currentChanged.connect(self.adjustTabWidgetSize) self.layout = QVBoxLayout() self.layout.addWidget(self.tabsWidget) self.setLayout(self.layout) self.setWindowTitle("Expenses Tracker") QApplication.setStyle(QStyleFactory.create("Fusion"))
def submitExpenseButtonClicked(self): spreadsheet_hdl = SpreadsheetHandler() appctx = ApplicationContext() if self.nonRecurringExpenseBox.checkState() == 2: recurring_status = "Non-Recurring" else: recurring_status = "Recurring" data = [ ["=MONTH(\""+self.expenseDateEdit.date().toString("MM/dd/yyyy")+"\")", self.expenseDateEdit.date().toString("MM/dd/yyyy"), str(self.expenseDoubleSpinBox.value()), self.expenseCategoriesComboBox.currentText(), self.expenseSpecificationLine.text(), recurring_status, self.expenseObservationLine.text() ] ] for index in range(len(data[0])): if data[0][index] == "": data[0][index] = "-" spreadsheet_hdl.append_data(data, range="Expenses") spreadsheet_hdl.expenses_sort_by_date() alert = QMessageBox() alert.setWindowTitle("Expense Submitted") alert.setWindowIcon(QIcon(appctx.get_resource("submit.ico"))) alert.setText("The expense was submitted!") alert.exec_()
def submitIncomeButtonClicked(self): spreadsheet_hdl = SpreadsheetHandler() appctx = ApplicationContext() data = [ ["=MONTH(\""+self.incomesDateEdit.date().toString("MM/dd/yyyy")+"\")", self.incomesDateEdit.date().toString("MM/dd/yyyy"), str(self.incomesDoubleSpinBox.value()), self.incomesSpecificationLine.text(), self.incomesObservationLine.text() ] ] for index in range(len(data[0])): if data[0][index] == "": data[0][index] = "-" spreadsheet_hdl.append_data(data, range="Incomes") spreadsheet_hdl.income_sort_by_date() alert = QMessageBox() alert.setWindowTitle("Income Submitted") alert.setWindowIcon(QIcon(appctx.get_resource("submit.ico"))) alert.setText("The income was submitted!") alert.exec_()
def __init__(self, ctx: ApplicationContext): super(self.__class__, self).__init__() self.setupUi(self) song_path = ctx.get_resource('sounds\good.wav') self.song = QSound(song_path) self.song.play() self.song.setLoops(99999999)
def parse(): global data, css appctxt = ApplicationContext() datafile = appctxt.get_resource('dictionary_data/hindi.txt') cssfile = appctxt.get_resource('styles/hindi.css') with open(datafile, encoding='utf8') as df: dlim = '\t' ilim = ',' data = {} for line in df: l = line.split(dlim) data[l[0]] = l[1].split(ilim) with open(cssfile, encoding='utf8') as cf: css = cf.read()
class Window(): def __init__(self, url): super().__init__() generate_qr_code(url) self.appctxt = ApplicationContext() stylesheet = self.appctxt.get_resource('styles.qss') self.appctxt.app.setStyleSheet(open(stylesheet).read()) self.v_window = VideoWindow() self.s_window = SearchWindow()
def main(): appctxt = ApplicationContext() template_path = appctxt.get_resource("pattern.png") appctxt.app.setStyle("Fusion") window = MainWindow(template_path) window.show() exit_code = appctxt.app.exec_() sys.exit(exit_code) return exit_code
class MainCore: def __init__(self): self.appctxt = ApplicationContext() def resource(self, source_name): return self.appctxt.get_resource(source_name) def exit(self): exit_code = self.appctxt.app.exec_() return sys.exit(exit_code)
def __init__(self, app_context: ApplicationContext, flashcard_manager: FlashcardManager, *args, **kwargs): super(CardListWindow, self).__init__(*args, **kwargs) self.app_context = app_context self.flashcard_manager = flashcard_manager self.current_language = Language(0) self.setFixedSize(400, 600) self.setWindowTitle("Meine Lernkarteien - TangoCards") main_widget = QWidget() main_widget.setProperty("cssClass", "background") main_layout = QVBoxLayout() # Initialized up here because the combobox already fires the currentIndexChanged signal on creation self.card_list_model = QStringListModel(self.flashcard_manager.get_flashcard_list_names(self.current_language)) self.card_list = QListView() self.card_list.setEditTriggers(QAbstractItemView.NoEditTriggers) self.card_list.doubleClicked.connect(self.on_list_doubleclick) language_select = QComboBox() language_select.currentIndexChanged.connect(self.on_select_language) for language in Language: # if len(self.flashcard_manager.get_flashcard_lists(language)) < 1: # continue language_select.insertItem(language.value, language.get_display_name(), language.value) language_select.setItemIcon(language.value, QIcon(app_context.get_resource("icons/flag_" + language.name + ".png"))) main_layout.addWidget(language_select) main_layout.addWidget(self.card_list) tool_buttons_widget = QWidget() tool_buttons_layout = QHBoxLayout() tool_buttons_widget.setLayout(tool_buttons_layout) learn_button = QPushButton("Lernen") learn_button.clicked.connect(self.on_click_learn) add_button = QPushButton("Hinzufügen") add_button.clicked.connect(self.on_click_add) delete_button = QPushButton("Löschen") delete_button.clicked.connect(self.on_click_delete) tool_buttons_layout.addWidget(learn_button) tool_buttons_layout.addWidget(add_button) tool_buttons_layout.addWidget(delete_button) main_layout.addWidget(tool_buttons_widget) main_widget.setLayout(main_layout) self.setCentralWidget(main_widget)
def __init__(self, ctx: ApplicationContext): super(EulaQuizDialog, self).__init__() self.setupUi(self) # inherited method from the Designer file self.setWindowIcon(QIcon(ctx.get_resource('crocpad.ico'))) self.submitButton.clicked.connect(self.submit_clicked) # Set up button groups: otherwise only one radio button can be selected at once. self.group_1 = QtWidgets.QButtonGroup() self.group_2 = QtWidgets.QButtonGroup() self.group_3 = QtWidgets.QButtonGroup() self.group_4 = QtWidgets.QButtonGroup() self.group_5 = QtWidgets.QButtonGroup() self.group_6 = QtWidgets.QButtonGroup() # Only the "correct" buttons were given non-default names in Qt Designer. self.group_1.addButton(self.radioButton_16) self.group_1.addButton(self.quiz1_Correct) self.group_1.addButton(self.radioButton_18) self.group_1.addButton(self.radioButton_19) self.group_1.addButton(self.radioButton_20) self.group_2.addButton(self.radioButton_11) self.group_2.addButton(self.radioButton_12) self.group_2.addButton(self.radioButton_13) self.group_2.addButton(self.radioButton_14) self.group_2.addButton(self.quiz2_Correct) self.group_3.addButton(self.radioButton) self.group_3.addButton(self.radioButton_2) self.group_3.addButton(self.radioButton_3) self.group_3.addButton(self.radioButton_4) self.group_3.addButton(self.quiz3_Correct) self.group_4.addButton(self.radioButton_21) self.group_4.addButton(self.radioButton_22) self.group_4.addButton(self.radioButton_23) self.group_4.addButton(self.radioButton_24) self.group_4.addButton(self.quiz4_Correct) self.group_5.addButton(self.radioButton_26) self.group_5.addButton(self.radioButton_27) self.group_5.addButton(self.quiz5_Correct) self.group_5.addButton(self.radioButton_29) self.group_5.addButton(self.radioButton_30) self.group_6.addButton(self.radioButton_31) self.group_6.addButton(self.radioButton_32) self.group_6.addButton(self.radioButton_33) self.group_6.addButton(self.radioButton_34) self.group_6.addButton(self.quiz6_Correct) # Disable Help Menu, Close Button and System Menu self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint) self.setWindowFlags(self.windowFlags() & ~Qt.WindowSystemMenuHint)
def delCategoryButtonClicked(self): spreadsheet_hdl = SpreadsheetHandler() appctx = ApplicationContext() category_to_be_del = self.delCategoryComboBox.currentText() spreadsheet_hdl.delete_category(category_to_be_del) self.resetCategoriesComboBox() alert = QMessageBox() alert.setWindowTitle("Category Deleting") alert.setWindowIcon(QIcon(appctx.get_resource("sheets.ico"))) alert.setText("The category " + category_to_be_del + " was succesfully deleted!") alert.exec_()
def createAndMaintainButtonClicked(self): appctx = ApplicationContext() spreadsheet_hdl = SpreadsheetHandler() spreadsheet_hdl.rename_spreadsheet(spreadsheet_hdl.file_name + '_OLD') spreadsheet_hdl.create_spreadsheet() self.resetCategoriesComboBox() alert = QMessageBox() alert.setWindowTitle("Spreadsheet Reset") alert.setWindowIcon(QIcon(appctx.get_resource("sheets.ico"))) alert.setText("A new spreadsheet was created! To access the old " "spreadsheet, look for Expenses Tracker_OLD in your Drive.") alert.exec_()
class DesignerUI(object): def __init__(self, design_name): self.appctxt = ApplicationContext() design_path = self.appctxt.get_resource(design_name) Form, Window = uic.loadUiType(design_path) self.window = Window() self.ui = Form() self.ui.setupUi(self.window) self.file_dialog = QFileDialog() def start(self): self.window.show() self.exit_code = self.appctxt.app.exec_() def getWidgets(self): return self.appctxt.app.allWidgets() def getWidgetNames(self): return [w.objectName() for w in self.getWidgets()]
def __init__(self): QWidget.__init__(self) self.ui = Ui_inspection() self.ui.setupUi(self) # camera preview settings self.camera_model = CameraModel.default() self.camera_model.set_selected_camera_to_view_finder( self.ui.camera_preview) self.camera_model.image_saved.connect(self.on_image_saved) self.ui.camera_preview.setFixedSize(self.__VIEW_FINDER) self.learning_model = LearningModel.default() self.learning_model.predicting_finished.connect( self.on_finished_predicting) self.select_camera_widget = CameraList() self.select_camera_widget.clicked.connect(self.on_clicked_camera_list) self.select_camera_widget.closed.connect(self.on_closed_camera_list) self.ui.select_camera_button.clicked.connect( self.on_clicked_select_camera_button) self.ui.inspect_button.clicked.connect(self.on_clicked_inspect_button) self.ui.inspect_existing_image_button.clicked.connect( self.on_clicked_inspection_existing_image_button) self.ui.result.setCurrentWidget(self.ui.default_result) appctxt = ApplicationContext() loader_gif_path = appctxt.get_resource('images/loader.gif') self.loader_movie = QMovie(loader_gif_path) self.loader_movie.setScaledSize(QSize(30, 8)) self.loader_movie.start() self.__ng_counter = 0 self.__ok_counter = 0 self.ui.OK_counter_label.setText(str(self.ok_counter)) self.ui.NG_counter_label.setText(str(self.ng_counter)) self.msgBox = None
def setup_tool_bar(self): self.inspection_widget_id = self.ui.main_stacked_widget.addWidget(InspectionWidget()) self.ai_optimization_widget_id = self.ui.main_stacked_widget.addWidget(AIOptimizationWidget()) self.past_result_widget_id = self.ui.main_stacked_widget.addWidget(PastResultWidget()) self.ui.optimization_action.triggered.connect(self.on_clicked_optimization_button) self.ui.inspection_action.triggered.connect(self.on_clicked_inspection_button) self.ui.past_result_action.triggered.connect(self.on_clicked_past_result_button) self.ui.action_group = QActionGroup(self) self.ui.action_group.addAction(self.ui.optimization_action) self.ui.action_group.addAction(self.ui.inspection_action) self.ui.action_group.addAction(self.ui.past_result_action) self.ui.inspection_action.setChecked(True) self.ui.action_group.setExclusive(True) try: self.on_clicked_inspection_button() self.ui.inspection_action.setChecked(True) LearningModel.default().load_weights() except FileNotFoundError: self.on_clicked_optimization_button() self.ui.optimization_action.setChecked(True) appctxt = ApplicationContext() loader_gif_path = appctxt.get_resource('images/loader.gif') self.loader = QMovie(loader_gif_path) self.loader.start() self.loader_label = QLabel() self.loader_label.setMovie(self.loader) self.loader_label.hide() self.training_message = QLabel() spacer = QWidget() spacer.setFixedWidth(2) self.statusBar().addPermanentWidget(self.training_message) self.statusBar().addPermanentWidget(self.loader_label) self.statusBar().addPermanentWidget(spacer) self.statusBar().setSizeGripEnabled(False)
def __init__(self, ctx: ApplicationContext, eula: str): super(EulaDialog, self).__init__() self.setupUi(self) # inherited method from the Designer file self.setWindowIcon(QIcon(ctx.get_resource('crocpad.ico'))) self.eula_TextEdit.setPlainText(eula) self.eula_TextEdit.ensureCursorVisible() self.clicked_button = None self.scrolled_to_bottom = 0 self.scrolled_to_top = 0 self.eula_agree_button.clicked.connect(self.clicked_agree) self.eula_disagree_button.clicked.connect(self.clicked_disagree) self.eula_TextEdit.verticalScrollBar().sliderMoved.connect( self.slider_moved) self.eula_agree_button.setEnabled( False) # disable the Agree button until conditions met # Disable Help Menu, Close Button and System Menu self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint) self.setWindowFlags(self.windowFlags() & ~Qt.WindowSystemMenuHint)
def __init__(self): self.learning_model = LearningModel.default() # initの引数で渡したい… super().__init__() self.ui = Ui_Test() self.ui.setupUi(self) appctxt = ApplicationContext() loader_gif_path = appctxt.get_resource('images/loader.gif') self.loader = QMovie(loader_gif_path) self.loader.setScaledSize(QSize(30, 8)) self.ui.loading_gif_label.setMovie(self.loader) self.loader.start() self.ui.about_threshold_button.clicked.connect( self.on_clicked_about_threshold_button) self.ui.threshold_slider.valueChanged.connect( self.on_threshold_changed) self.ui.details_button.clicked.connect(self.on_clicked_details_button) self.distance_figure: Figure = plt.figure(figsize=(4, 3)) self.distance_canvas = FigureCanvas(self.distance_figure) self.distance_canvas.setParent(self.ui.distance_chart_widget) # sns.set_palette(['#3FDA68', '#E66643']) performance_figure = Figure(figsize=(3.5, 3.5)) self.performance_axes: Axes = performance_figure.add_subplot(111) performance_figure.patch.set_alpha(0) self.performance_axes.set_position( pos=[-0.1, 0.1, 1, 1]) # FIXME: adjust position automatically self.performance_center_circle = plt.Circle(xy=(0, 0), radius=0.75, fc='#F5F5F5', linewidth=1.25) self.performance_canvas = FigureCanvas(performance_figure) self.performance_canvas.setParent(self.ui.performance_chart_widget) self.test_report_widget = TestReportWidget()
#region imports import PyQt5 from PyQt5.QtCore import QDir, QPoint, QRect, QSize, Qt, pyqtSignal from PyQt5.QtGui import QImage, QImageWriter, QPainter, QPen, qRgb, QPixmap from PyQt5.QtWidgets import (QAction, QApplication, QColorDialog, QFileDialog, QInputDialog, QMainWindow, QMenu, QMessageBox, QWidget, QTableWidgetItem) from PyQt5.QtPrintSupport import QPrintDialog, QPrinter from fbs_runtime.application_context.PyQt5 import ApplicationContext import sys import webbrowser #------ from rectmap import Ui_MainWindow #------ appctxt = ApplicationContext() imgpath = appctxt.get_resource( 'rovercourse.png') #gets relative/absolute path through fbs #endregion imports class ScribbleArea(QWidget): #this is a custom signal #it must be a class variable; it won't work if placed in __init__ dataChanged = pyqtSignal() posChanged = pyqtSignal(int, int) def __init__(self, parent=None): super(ScribbleArea, self).__init__(parent) #self.setAttribute(Qt.WA_StaticContents) self.modified = False self.scribbling = False
import sys import imageio from imageio.plugins.ffmpeg import get_exe as get_ffmpeg_exe from PyQt5 import QtCore, QtGui, QtWidgets from fbs_runtime.application_context.PyQt5 import ApplicationContext #------ from windowui import Ui_MainWindow from demo_functs import generate_and_save #------ appctxt = ApplicationContext() try: checkpoint_path = appctxt.get_resource('vox-adv-cpk.pth.tar') except FileNotFoundError: checkpoint_path = None #config_path = 'config/vox-256.yaml' config_path = appctxt.get_resource('vox-256.yaml') #endregion imports class ApplicationWindow(QtWidgets.QMainWindow, Ui_MainWindow): '''The main window. Instantiated once.''' def __init__(self): QtWidgets.QMainWindow.__init__(self) self.setupUi(self) self.setWindowTitle("first-order-model-ui") self.browse_image_button.clicked.connect(self.open_source_image) self.browse_video_button.clicked.connect(self.open_driving_video) self.generate_and_save_button.clicked.connect(self.save_output) try:
class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.appctxt = ApplicationContext() self.sounds = self.initSounds() self.difficulty = "easy" # fonts # QFontDatabase.addApplicationFont(self.appctxt.get_resource('fonts/LLPIXEL3.ttf')) QFontDatabase.addApplicationFont(self.appctxt.get_resource('fonts/batmfo__.ttf')) QFontDatabase.addApplicationFont(self.appctxt.get_resource('fonts/batmfa__.ttf')) ################### ### Main Window ### ################### msgBarHeight = 10 startBtnHeight = 75 difficultyBtnHeight = 15 windowWidth = 500 windowHeight = windowWidth + msgBarHeight + difficultyBtnHeight self.setFixedSize(windowWidth, windowHeight) self.setStyleSheet("QMainWindow { color:rgb(255,255,255);" "background-color:#606060;" "font-family: BatmanForeverOutline; }" "QPushButton { font-size: 26pt; color: black; font-family: BatmanForeverAlternate;" "border: 5px solid black;" "border-radius: 15px;" "background: transparent; }" "QPushButton:hover { color: white; border: 5px solid white; }" "QPushButton:pressed { color: rgb(150,255,150); border: 5px solid rgb(150,255,150); }" ) MainVBoxLayout = QVBoxLayout() MainWidgetContainer = QWidget() MainWidgetContainer.setLayout(MainVBoxLayout) self.setCentralWidget(MainWidgetContainer) # status bar # self.status = QStatusBar() self.status.setStyleSheet("color:rgb(255,255,255);") self.setStatusBar(self.status) ##################### # Message Display # ##################### self.msgBar = QLineEdit("press START to begin new game") font = QFont("Serif", 9) self.msgBar.setFont(font) self.msgBar.setStyleSheet("font-size: 16pt; font-family: Consolas;" "color:rgb(255,255,255);" "border: 2px ridge #707070;" "border-radius: 10px;" "padding: 5px;" "background-color:qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #393939, stop: 1 #343434);") self.msgBar.setReadOnly(True) self.msgBar.setAlignment(Qt.AlignCenter) msgBarWidth = 200 self.msgBar.resize(msgBarWidth, msgBarHeight) policy = self.msgBar.sizePolicy() policy.setHorizontalPolicy(QSizePolicy.Expanding) self.msgBar.setSizePolicy(policy) ################ # START button # ################ self.startBtn = QPushButton("S T A R T") self.startBtn.setMinimumHeight(startBtnHeight) self.startBtn.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) # MainVBoxLayout.addWidget(self.startBtn) ################ # EASY button # ################ self.easyBtn = QPushButton("EASY") self.easyBtn.setStyleSheet("QPushButton { font-size: 22pt; font-family: BatmanForeverAlternate; color: black;" "padding: 5px;" "border: 5px solid black;" "border-radius: 15px;" "background: transparent; }" "QPushButton:hover { color: white; border: 5px solid white; }" "QPushButton:checked { color: rgb(0,255,0); border: 5px solid rgb(0,255,0); }" ) self.easyBtn.setCheckable(True) self.easyBtn.setChecked(True) self.easyBtn.setStatusTip("Classic ~ Simon adds on to the previous pattern every round") self.easyBtn.clicked.connect(self.SLOT_easyBtn) ################ # HARD button # ################ self.hardBtn = QPushButton("HARD") self.hardBtn.setStyleSheet("QPushButton { font-size: 22pt; font-family: BatmanForeverAlternate; color: black;" "padding: 5px;" "border: 5px solid black;" "border-radius: 15px;" "background: transparent; }" "QPushButton:hover { color: white; border: 5px solid white; }" "QPushButton:checked { color: rgb(255,0,0); border: 5px solid rgb(255,0,0); }" ) self.hardBtn.setCheckable(True) self.hardBtn.setChecked(False) self.hardBtn.setStatusTip("Challenger ~ Simon plays a new random pattern every round") self.hardBtn.clicked.connect(self.SLOT_hardBtn) # EASY-HARD button sizing difficultyBtnWidth = 175 self.easyBtn.setMinimumWidth(difficultyBtnWidth) self.easyBtn.setMinimumHeight(difficultyBtnHeight) self.hardBtn.setMinimumWidth(difficultyBtnWidth) self.hardBtn.setMinimumHeight(difficultyBtnHeight) # spacers # spacerEasy = QWidget() spacerEasyHard = QWidget() spacerHard = QWidget() spacerEasy.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) spacerEasyHard.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) spacerHard.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) # EASY-HARD button row difficultyLayout = QHBoxLayout() MainVBoxLayout.addLayout(difficultyLayout) difficultyLayout.addWidget(spacerEasy) difficultyLayout.addWidget(self.easyBtn) difficultyLayout.addWidget(spacerEasyHard) difficultyLayout.addWidget(self.hardBtn) difficultyLayout.addWidget(spacerHard) ################ # GAME BUTTONS # ################ # Layout # btnLayout = QVBoxLayout() row1Layout = QHBoxLayout() row2Layout = QHBoxLayout() btnLayout.addLayout(row1Layout) btnLayout.addLayout(row2Layout) MainVBoxLayout.addLayout(btnLayout) # button 1 # self.btn1 = QPushButton() self.btn1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) row1Layout.addWidget(self.btn1) # button 2 # self.btn2 = QPushButton() self.btn2.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) row1Layout.addWidget(self.btn2) # button 3 # self.btn3 = QPushButton() self.btn3.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) row2Layout.addWidget(self.btn3) # button 4 # self.btn4 = QPushButton() self.btn4.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) row2Layout.addWidget(self.btn4) # START # self.startBtn = QPushButton(MainWidgetContainer) self.startBtn.setText("START") self.startBtn.setStatusTip("Start a new game") startBtnWidth = 200 startBtnHeight = startBtnWidth self.startBtn.resize(startBtnWidth,startBtnHeight) pos = QPoint(windowWidth/2 - startBtnWidth/2, windowHeight/2 - startBtnHeight/2) self.startBtn.move(pos) self.startBtn.clicked.connect(self.SLOT_start) # style game buttons self.styleBtn(0) self.styleBtn(1) self.styleBtn(2) self.styleBtn(3) self.styleBtn(4) # connect game button press to synth sounds self.btn1.pressed.connect(self.sounds[1].play) self.btn2.pressed.connect(self.sounds[2].play) self.btn3.pressed.connect(self.sounds[3].play) self.btn4.pressed.connect(self.sounds[4].play) # connect game button press / release to style center START button self.btn1.pressed.connect(lambda: self.flashStart(1)) self.btn2.pressed.connect(lambda: self.flashStart(2)) self.btn3.pressed.connect(lambda: self.flashStart(3)) self.btn4.pressed.connect(lambda: self.flashStart(4)) self.btn1.released.connect(self.styleBtn) self.btn2.released.connect(self.styleBtn) self.btn3.released.connect(self.styleBtn) self.btn4.released.connect(self.styleBtn) # add MsgBar at bottom MainVBoxLayout.addWidget(self.msgBar) self.updateTitle() self.show() # start Simon Says def SLOT_start(self): # disable difficulty selection self.enableDifficultyButtons(False) # create Simon Says back-end thread self.simonThread = Simon.SimonSays(self.difficulty) # connect Simon Says thread signals to main thread methods self.simonThread.flash.connect(self.flashBtn) self.simonThread.delay.connect(self.runDelayTimer) self.simonThread.sound.connect(self.playSound) self.simonThread.revert.connect(self.styleBtn) self.simonThread.setStatus.connect(self.status.showMessage) self.simonThread.setMsgBar.connect(self.msgBar.setText) self.simonThread.setWinTitle.connect(self.updateTitle) self.simonThread.btnEnable.connect(self.enableButtons) self.simonThread.finished.connect(self.enableDifficultyButtons) # connect GUI button signals to Simon Says thread SLOTs self.btn1.clicked.connect(self.simonThread.SLOT_btn1Clicked) self.btn2.clicked.connect(self.simonThread.SLOT_btn2Clicked) self.btn3.clicked.connect(self.simonThread.SLOT_btn3Clicked) self.btn4.clicked.connect(self.simonThread.SLOT_btn4Clicked) # run Simon Says thread self.simonThread.start() # set button stylesheet to normal def styleBtn(self, btn=0, sem=None): if (btn == 0): self.startBtn.setStyleSheet("QPushButton { font-size: 26pt; font-family: BatmanForeverAlternate; color: black;" "border: 5px solid black;" "border-radius: 100px;" "background: gray; }" "QPushButton:hover { color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF0000, stop: 0.4 #FFFF00, stop: 0.45 #00FF00, stop: 1.0 #0000FF);" "border-bottom-color: rgb(0,255,0);" "border-left-color: rgb(255,0,0);" "border-top-color: rgb(0,0,255);" "border-right-color: rgb(255,255,0); }" "QPushButton:pressed { color: rgb(0,255,0); border: 5px solid rgb(0,255,0); }" ) if (btn == 1): self.btn1.setStyleSheet("QPushButton{ background-color: rgb(175,255,175);" "border: 5px solid black;" "border-radius: 15px;" "border-top-left-radius: 75px; }" "QPushButton:hover{ border-color: rgb(0,255,0); }" "QPushButton:pressed{ border-width: 7px; border-color: rgb(0,100,0); background-color: rgb(0,255,0); }") elif (btn == 2): self.btn2.setStyleSheet("QPushButton{ background-color: rgb(255,175,175);" "border: 5px solid black;" "border-radius: 15px;" "border-top-right-radius: 75px; }" "QPushButton:hover{ border-color: rgb(255,0,0); }" "QPushButton:pressed{ border-width: 7px; border-color: rgb(100,0,0); background-color: rgb(255,0,0); }") elif (btn == 3): self.btn3.setStyleSheet("QPushButton{ background-color: rgb(255,255,175);" "border: 5px solid black;" "border-radius: 15px;" "border-bottom-left-radius: 75px; }" "QPushButton:hover{ border-color: rgb(255,255,0); }" "QPushButton:pressed{ border-width: 7px; border-color: rgb(75,75,0); background-color: rgb(255,255,0); }") elif (btn == 4): self.btn4.setStyleSheet("QPushButton{ background-color: rgb(175,175,255);" "border: 5px solid black;" "border-radius: 15px;" "border-bottom-right-radius: 75px; }" "QPushButton:hover{ border-color: rgb(0,0,255); }" "QPushButton:pressed{ border-width: 7px; border-color: rgb(0,0,100); background-color: rgb(0,0,255); }") if (sem): sem.release() # flash START button def flashStart(self, btn): if (btn == 1): self.startBtn.setStyleSheet("QPushButton { font-size: 26pt; font-family: BatmanForeverAlternate; color: rgb(0,255,0);" "border: 5px solid black;" "border-radius: 100px;" "background: gray; }" ) elif (btn == 2): self.startBtn.setStyleSheet("QPushButton { font-size: 26pt; font-family: BatmanForeverAlternate; color: rgb(255,0,0);" "border: 5px solid black;" "border-radius: 100px;" "background: gray; }" ) elif (btn == 3): self.startBtn.setStyleSheet("QPushButton { font-size: 26pt; font-family: BatmanForeverAlternate; color: rgb(255,255,0);" "border: 5px solid black;" "border-radius: 100px;" "background: gray; }" ) elif (btn == 4): self.startBtn.setStyleSheet("QPushButton { font-size: 26pt; font-family: BatmanForeverAlternate; color: rgb(0,0,255);" "border: 5px solid black;" "border-radius: 100px;" "background: gray; }" ) # flash button def flashBtn(self, btn, ms, sem): if (btn == 1): self.flashStart(1) self.btn1.setStyleSheet("QPushButton{ background-color: rgb(0,255,0);" "border: 5px ridge black;" "border-radius: 15px;" "border-top-left-radius: 75px; }") elif (btn == 2): self.flashStart(2) self.btn2.setStyleSheet("QPushButton{ background-color: rgb(255,0,0);" "border: 5px ridge black;" "border-radius: 15px; " "border-top-right-radius: 75px; }") elif (btn == 3): self.flashStart(3) self.btn3.setStyleSheet("QPushButton{ background-color: rgb(255,255,0);" "border: 5px ridge black;" "border-radius: 15px;" "border-bottom-left-radius: 75px; }") elif (btn == 4): self.flashStart(4) self.btn4.setStyleSheet("QPushButton{ background-color: rgb(0,0,255);" "border: 5px ridge black;" "border-radius: 15px;" "border-bottom-right-radius: 75px; }") self.runFlashTimer(btn, ms, sem) # flash button timer def runFlashTimer(self, btn, ms, sem): self.timer = QTimer() self.timer.timeout.connect( lambda: self.styleBtn(btn, sem) ) self.timer.start(ms) # delay timer used in between pattern flashes def runDelayTimer(self, ms, sem): self.timer = QTimer() self.timer.timeout.connect(sem.release) self.timer.start(ms) # enable / disable game buttons def enableButtons(self, en): self.btn1.setEnabled(en) self.btn2.setEnabled(en) self.btn3.setEnabled(en) self.btn4.setEnabled(en) # enable / disable difficulty selection buttons def enableDifficultyButtons(self, en=True): self.easyBtn.setEnabled(en) self.hardBtn.setEnabled(en) self.startBtn.setEnabled(en) # init synth sounds from sounds/*.wav files def initSounds(self): soundsPath = "../sounds/" sounds = { # START-UP # # 0: QSound(self.appctxt.get_resource('/home/mojo/devel/git/Simon/src/main/resources/base/sounds/Cymatics - Mothership Dubstep Sample Pack/Synths - Loops/Cymatics - Mothership Drop Loop 1 - 150 BPM F.wav')), 0: QSound(self.appctxt.get_resource('/home/mojo/devel/git/Simon/src/main/resources/base/sounds/Cymatics - Mothership Dubstep Sample Pack/Synths - Loops/Cymatics - Mothership Drop Loop 2 - 150 BPM F.wav')), # 0: QSound(self.appctxt.get_resource('/home/mojo/devel/git/Simon/src/main/resources/base/sounds/Cymatics - Mothership Dubstep Sample Pack/Synths - Loops/Cymatics - Mothership Drop Loop 3 - 150 BPM F.wav')), # 0: QSound(self.appctxt.get_resource('/home/mojo/devel/git/Simon/src/main/resources/base/sounds/Cymatics - Mothership Dubstep Sample Pack/Synths - Loops/Cymatics - Mothership Drop Loop 4 - 150 BPM F.wav')) # WUB-SYNTH # 1: QSound(self.appctxt.get_resource('sounds/Cymatics - Mothership Dubstep Sample Pack/Synths - One Shots/Cymatics - Mothership Bass One Shot 10 - F.wav')), 2: QSound(self.appctxt.get_resource('sounds/Cymatics - Mothership Dubstep Sample Pack/Synths - One Shots/Cymatics - Mothership Bass One Shot 9 - F.wav')), # w/ snare 3: QSound(self.appctxt.get_resource('sounds/Cymatics - Mothership Dubstep Sample Pack/Synths - One Shots/Cymatics - Mothership Bass One Shot 1 - E.wav')), 4: QSound(self.appctxt.get_resource('sounds/Cymatics - Mothership Dubstep Sample Pack/Synths - One Shots/Cymatics - Mothership Bass One Shot 3 - E.wav')) # # SNARE # # 1: QSound(self.appctxt.get_resource('sounds/Drums - One Shots/Snares/Cymatics - Terror Heavy Snare 014.wav')), # 2: QSound(self.appctxt.get_resource('sounds/Drums - One Shots/Snares/Cymatics - Terror Heavy Snare 038.wav')), # 3: QSound(self.appctxt.get_resource('sounds/Drums - One Shots/Snares/Cymatics - Ultimate Snare 20 - D#.wav')), # 4: QSound(self.appctxt.get_resource('sounds/Drums - One Shots/Snares/Cymatics - Ultimate Snare 36 - G#.wav')) } return sounds # play sound effect def playSound(self, i): self.sounds[i].play() # EASY button pressed def SLOT_easyBtn(self): self.difficulty = "easy" self.easyBtn.setChecked(True) self.hardBtn.setChecked(False) # HARD button pressed def SLOT_hardBtn(self): self.difficulty = "hard" self.hardBtn.setChecked(True) self.easyBtn.setChecked(False) # critical dialog pop-up def SLOT_dialogCritical(self, s): dlg = QMessageBox(self) dlg.setText(s) dlg.setIcon(QMessageBox.Critical) dlg.show() # update main window title def updateTitle(self, str=""): self.setWindowTitle("SiMoN sAyS "+ str)
from os import path import sys DIR = path.join(path.dirname(__file__)) sys.path.append(path.join(DIR, '..')) from PyQt5 import QtCore, QtGui, QtWidgets from Ui.UiLoader import getUiClass from Logic.languages import langs from fbs_runtime.application_context.PyQt5 import ApplicationContext ApplicationContext = ApplicationContext() UI_FILE = ApplicationContext.get_resource(path.join('ui', 'PickLanguageDialog.ui')) # On exist options CREATE = 0 EDIT = 1 ASK = 3 class PickLanguageDialog(getUiClass(UI_FILE)): # Signals acceptedSignal = QtCore.pyqtSignal('PyQt_PyObject', arguments=['ReturnDict']) rejectedSignal = QtCore.pyqtSignal('PyQt_PyObject', arguments=['ReturnDictNoLang']) def __init__(self, *args, langs=langs, setupUi=True, default="Hebrew", existLangs={}, onExist=CREATE, **kwargs): super(PickLanguageDialog, self).__init__( *args, setupUi=False, **kwargs) self.default = default self._langs = dict() self.langs = langs
import sys class Main_Window(QtWidgets.QMainWindow): def __init__(self): super(Main_Window, self).__init__() # Load UI uic.loadUi(appctxt.get_resource("main_window.ui"), self) if __name__ == '__main__': appctxt = ApplicationContext() # 1. Instantiate ApplicationContext # Instanciate main window window = Main_Window() # Instanciate controllers test_bench_controller = Test_Bench_Controller(window, appctxt) data_recovery_controller = Data_Recovery_Controller(window, appctxt) # Display splash screen splash = QtWidgets.QSplashScreen() splash.setPixmap(QtGui.QPixmap(appctxt.get_resource('splash.png'))) splash.show() QtCore.QTimer.singleShot(2500, splash.close) QtCore.QTimer.singleShot(2550, window.show) exit_code = appctxt.app.exec_() # 2. Invoke appctxt.app.exec_() sys.exit(exit_code)
'status': ('Q', 'P')[len(self.pobTabs.queue) == 0], 'UID': UI.uid } UI.uid += 1 self.pobTabs.addToQueue(pob) self.renderPane.renderSTL({ 'header': header, 'tris': tris, 'bounds': bounds }) def _test(self): pob = { 'fileUrl': 'Bulba.stl', 'thumb': self.testImg, 'status': ('Q', 'P')[len(self.pobTabs.queue) == 0], 'UID': UI.uid } UI.uid += 1 self.pobTabs.addToQueue(pob) if __name__ == '__main__': appctxt = ApplicationContext() appctxt.app.setStyle('fusion') testImg = QPixmap(appctxt.get_resource('bulba.jpg')) ui = UI(testImg) sys.exit(appctxt.app.exec_())
"chooseOutputImage").clicked.connect(chooseOutputImage) w.findChild(QtWidgets.QSlider, "blockSizeSlider").valueChanged.connect(blockSizeSlider) w.findChild( QtWidgets.QComboBox, "blockCalcDropdown").currentTextChanged.connect(blockCalcDropdown) w.findChild(QtWidgets.QComboBox, "scaleDropdown").currentTextChanged.connect(scaleDropdown) # ---- Main ---- if __name__ == "__main__": # Startup PyQt code appctxt = ApplicationContext() window = uic.loadUi(appctxt.get_resource("window.ui")) window.show() register_ui(window) inputPath = "" # Initializing block size elements blockSlider = window.findChild(QtWidgets.QSlider, "blockSizeSlider") blockNumber = window.findChild(QtWidgets.QLCDNumber, "blockSizeNumber") blockCalc = window.findChild(QtWidgets.QComboBox, "blockCalcDropdown") blockSize = blockSlider.value() blockNumber.display(blockSize) blockStrategy = blockCalc.currentText() scaleDropdown = window.findChild(QtWidgets.QComboBox, "scaleDropdown") blockScale = None
class MsUiDesign(QMainWindow): def __init__(self, parent=None): self.appctxt = ApplicationContext() super(MsUiDesign, self).__init__(parent) self.setWindowTitle("MikroScript") self.setStyleSheet(COLOR_BG) self.resize(1128, 768) self.setMinimumSize(1128, 768) self.setWindowIcon(QIcon(self.appctxt.get_resource("favicon.png"))) # Updated by Pinkesh Shah on 29-Apr-20 # Start Region self.activeJobTabs = [] # End Region self.tabCtr = 0 self.tabview = QTabWidget() # self.tabview.setStyleSheet(CSS.CSS_TAB) self.conn = sqlite3.connect("MikroScript.db") self.changeStyle('Windows') self.createMenuBar() self.tree_dock_widget() self.card_dock_widget() self.create_dock_widget_area() # self.createBottomArea() # mainLayout = QGridLayout() # # mainLayout.addLayout(self.TopArea , 0, 0, 1, 3) # # mainLayout.addLayout(self.LeftArea , 1, 0, 1, 1) # mainLayout.addLayout(self.RightArea , 1, 1, 1, 2) # # mainLayout.addLayout(self.BottomArea, 2, 0, 1, 3) # # mainLayout.addWidget(self.topLeftGroupBox, 1, 0) # # mainLayout.addWidget(self.topRightGroupBox, 1, 1) # # mainLayout.addWidget(self.bottomLeftTabWidget, 2, 0) # # mainLayout.addWidget(self.bottomRightGroupBox, 2, 1) # # mainLayout.addWidget(self.progressBar, 3, 0, 1, 2) # # mainLayout.setRowStretch(1, 1) # mainLayout.setColumnStretch(1, 1) # mainLayout.setColumnStretch(2, 1) # self.plusButton.setFixedSize(20, 20) # Small Fixed size addButton = QPushButton( QIcon(self.appctxt.get_resource("add-24px.svg")), "") addButton.clicked.connect(self.ActionNew) self.tabview.setMovable(True) self.tabview.setTabsClosable(True) self.tabview.tabCloseRequested.connect(self.removeTab) self.tabview.setCornerWidget(addButton) # self.tabview = CustomTabWidget() self.setCentralWidget(self.tabview) self.ActionNew() self.get_job_list() def removeTab(self, index): tab = self.tabview.widget(index) # Updated by Pinkesh Shah on 30-Apr-20 # Start Region tab_Name = self.tabview.tabText(index) self.activeJobTabs.remove(tab_Name) # End Region if tab is not None: tab = None self.tabview.removeTab(index) def createMenuBar(self): actNew = QAction( QIcon( self.appctxt.get_resource( "outline_insert_drive_file_black_18dp.png")), "&New") actNew.triggered.connect(self.ActionNew) actNew.setShortcut(QKeySequence.New) # actOpen = QAction(QIcon(self.appctxt.get_resource("outline_folder_black_18dp.png")), "&Open") # actOpen.triggered.connect(self.ActionOpen) # actOpen.setShortcut(QKeySequence.Open) actSave = QAction( QIcon(self.appctxt.get_resource("outline_save_black_18dp.png")), "&Save") actSave.triggered.connect(self.ActionSave) actSave.setShortcut(QKeySequence.Save) actQuit = QAction( QIcon( self.appctxt.get_resource( "outline_exit_to_app_black_18dp.png")), "&Quit") actQuit.triggered.connect(self.ActionQuit) actQuit.setShortcut(QKeySequence.Quit) self.actExecute = QAction( QIcon( self.appctxt.get_resource( "outline_play_circle_outline_black_18dp.png")), "E&xecute") self.actExecute.triggered.connect(self.ActionExecute) self.actExecute.setShortcut(QKeySequence.Refresh) actPause = QAction( QIcon(self.appctxt.get_resource("pause_circle_outline-24px.svg")), "Pause") actPause.triggered.connect(self.ActionPause) actPause.setShortcut(QKeySequence.Refresh) actStop = QAction(QIcon(self.appctxt.get_resource("stop-24px.svg")), "Stop") actStop.triggered.connect(self.ActionStop) actStop.setShortcut(QKeySequence.Refresh) actReset = QAction( QIcon(self.appctxt.get_resource("outline_replay_black_18dp.png")), "&Reset") actReset.triggered.connect(self.ActionReset) actReset.setShortcut(QKeySequence.Replace) # actCut = QAction(QIcon(self.appctxt.get_resource("outline_file_copy_black_18dp.png")), "Cu&t") # actCut.setShortcut(QKeySequence.Cut) # # actCopy = QAction(QIcon(self.appctxt.get_resource("outline_insert_drive_file_black_18dp.png")), "&Copy") # actCopy.setShortcut(QKeySequence.Copy) # # actPaste = QAction(QIcon(self.appctxt.get_resource("outline_insert_drive_file_black_18dp.png")), "&Paste") # actPaste.setShortcut(QKeySequence.Paste) # actAbout = QAction("&About") # menuFile = self.menuBar().addMenu("&File") # menuFile.addAction(actNew) # # menuFile.addAction(actOpen) # menuFile.addAction(actSave) # menuFile.addSeparator() # menuFile.addAction(actQuit) # menuEdit = self.menuBar().addMenu("&Edit") # menuEdit.addAction(actCut) # menuEdit.addAction(actCopy) # menuEdit.addAction(actPaste) # menuView = self.menuBar().addMenu("&View") # menuRun = self.menuBar().addMenu("&Run") # menuRun.addAction(self.actExecute) # menuWin = self.menuBar().addMenu("&Window") # menuHelp = self.menuBar().addMenu("Help") # menuHelp.addAction(actAbout) ################################################################### toolbtnNew = QToolButton() toolbtnNew.setDefaultAction(actNew) toolbtnNew.setToolTip("New Job - CTRL + N") # toolbtnOpen = QToolButton() # toolbtnOpen.setDefaultAction(actOpen) # toolbtnOpen.setToolTip("Open File") toolbtnSave = QToolButton() toolbtnSave.setDefaultAction(actSave) toolbtnSave.setToolTip("Save File") toolbtnExecute = QToolButton() toolbtnExecute.setDefaultAction(self.actExecute) toolbtnExecute.setToolTip("Execute - F5") toolbtnPause = QToolButton() toolbtnPause.setDefaultAction(actPause) toolbtnPause.setToolTip("Pause") toolbtnStop = QToolButton() toolbtnStop.setDefaultAction(actStop) toolbtnStop.setToolTip("Stop") toolbtnReset = QToolButton() toolbtnReset.setDefaultAction(actReset) toolbtnReset.setToolTip("Reset") styleComboBox = QComboBox() styleComboBox.addItems(QStyleFactory.keys()) styleLabel = QLabel("&Style:") styleLabel.setBuddy(styleComboBox) styleComboBox.activated[str].connect(self.changeStyle) self.toolBar = QToolBar() self.toolBar.addWidget(toolbtnNew) # toolBar.addWidget(toolbtnOpen) self.toolBar.addWidget(toolbtnSave) self.toolBar.addSeparator() self.toolBar.addWidget(toolbtnExecute) self.toolBar.addWidget(toolbtnPause) self.toolBar.addWidget(toolbtnStop) self.toolBar.addWidget(toolbtnReset) self.toolBar.addWidget(styleComboBox) self.toolBar.setMovable(False) self.toolBar.addSeparator() # toolBar.addWidget(styleLabel) # toolBar.addWidget(styleComboBox) self.addToolBar(self.toolBar) def build_job_frame(self, name): job_frame = QFrame() # job_frame. connect(self.load_job) job_frame.setMinimumSize(220, 80) # job_frame.setFrameShape(QFrame.Box) # job_frame.setFrameShadow(QFrame.Raised) job_frame.setFrameShape(QFrame.StyledPanel) job_frame.setFrameShadow(QFrame.Plain) job_frame.setLineWidth(0) job_frame.setMidLineWidth(0) # job_frame.setFrameStyle() job_frame.setStyleSheet(CSS.CSS_FRAME) layout = QHBoxLayout() label = QLabel(name) label.setStyleSheet(CSS.CSS_FRAME_MIKROTIK_LABEL) # label.setStyleSheet(CSS.CSS_FRAME_LABEL) layout.addWidget(label, 0, Qt.AlignTop) # layout.addWidget(QPushButton(QIcon(self.appctxt.get_resource("outline_play_circle_outline_black_18dp.png")), "")) # Updated by Pinkesh Shah on 27-Apr-20 # Start Region layout.addSpacing(2) vendorLabel = QLabel("Mikrotik") vendorLabel.setFixedSize(50, 15) vendorLabel.setStyleSheet(CSS.CSS_FRAME_LABEL) # mikrotikLabel.setStyleSheet(CSS.CSS_FRAME_MIKROTIK_LABEL) layout.addWidget(vendorLabel, 0, Qt.AlignTop) # End Region img = QImage( self.appctxt.get_resource( "outline_play_circle_outline_black_18dp.png")) lbl_img = QLabel("") lbl_img.setPixmap(QPixmap.fromImage(img)) # lbl_img.resize(img.width(), img.height()) job_frame.setLayout(layout) # count = self.dock_layout.count() self.dock_layout.addWidget(job_frame) # Updated by Pinkesh Shah on 27-Apr-20 # Start Region self.dock_layout.setSpacing(10) # End Region # Updated by Pinkesh Shah on 05-May-20 to disable Scheduler layout # Start Region self.groupBox.setMinimumHeight(self.groupBox.sizeHint().height() + FRAME_SIZE) # self.jobsGroupBox.setMinimumHeight(self.jobsGroupBox.sizeHint().height() + FRAME_SIZE) # End Region # Updated by Pinkesh Shah on 05-May-20 to disable Scheduler layout # Start Region # Updated by Pinkesh Shah on 28-Apr-20 # Start Region self.groupBox.setMaximumWidth(250) # End Region # self.jobsGroupBox.setMaximumWidth(250) # End Region # Updated by Pinkesh Shah on 05-May-20 to disable Scheduler layout # Start Region # self.groupBox.setStyleSheet(CSS.CSS_FRAME_GROUP_BOX) # self.jobsGroupBox.setStyleSheet(CSS.CSS_GROUP_BOX) # End Region return job_frame def tree_dock_widget(self): self.dock_widget = QTreeView() def card_dock_widget(self): # Updated by Pinkesh Shah on 05-May-20 to disable Scheduler layout # Start Region # self.dockWidgetGroupBox = QGroupBox("") # self.dockWidgetLayout = QVBoxLayout() # self.jobsGroupBox = QGroupBox("Jobs") # Scheduler # self.scheduledGroupBox = QGroupBox("Scheduled") # self.scheduledLayout = QVBoxLayout() # self.scheduledGroupBox.setLayout(self.scheduledLayout) # self.scheduledScroll = QScrollArea() # self.scheduledScroll.setWidget(self.scheduledGroupBox) # self.scheduledScroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) # self.scheduledLayout.addWidget(QLabel("Test Label")) # self.dockWidgetGroupBox.setLayout(self.dockWidgetLayout) # End Region self.dock_layout = QVBoxLayout() # Updated by Pinkesh Shah on 05-May-20 to disable Scheduler layout # Start Region self.groupBox = QGroupBox("") self.groupBox.setLayout(self.dock_layout) self.groupBox.setStyleSheet(CSS.CSS_FRAME_GROUP_BOX) # self.jobsGroupBox.setLayout(self.dock_layout) # End Region # Updated by Pinkesh Shah on 05-May-20 to disable Scheduler layout # Start Region # Updated by Pinkesh Shah on 27-Apr-20 # Start Region # self.groupBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.groupBox.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) # End Region # self.jobsGroupBox.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) # End Region self.dock_widget = QScrollArea() self.dock_widget.setStyleSheet(CSS.CSS_SCROLLBAR) # Updated by Pinkesh Shah on 05-May-20 to disable Scheduler layout # Start Region self.dock_widget.setWidget(self.groupBox) # self.dock_widget.setWidget(self.jobsGroupBox) # End Region self.dock_widget.setWidgetResizable(True) # Updated by Pinkesh Shah on 28-Apr-20 # Start Region self.dock_widget.setMinimumWidth(270) self.dock_widget.setMaximumWidth(400) self.dock_widget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # End Region # Updated by Pinkesh Shah on 05-May-20 to disable Scheduler layout # Start Region # self.dockWidgetLayout.addWidget(self.dock_widget) # self.dockWidgetLayout.addWidget(self.scheduledScroll) # End Region def create_dock_widget_area(self): docWidget = QDockWidget("Script Jobs") # Updated by Pinkesh Shah on 05-May-20 to disable Scheduler layout # Start Region docWidget.setWidget(self.dock_widget) # docWidget.setWidget(self.dockWidgetGroupBox) # End Region # docWidget.setLayout(layout) docWidget.DockWidgetFeatures(QDockWidget.DockWidgetVerticalTitleBar) docWidget.setFloating(False) self.addDockWidget(Qt.LeftDockWidgetArea, docWidget, Qt.Vertical) docWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) def createBottomArea(self): status = QStatusBar() self.setStatusBar(status) ################# All Action starts from here def ActionOpen(self): print("Open") def ActionPause(self): print("Pause") def ActionStop(self): print("Stop") def ActionReset(self): print("Reset") def ActionQuit(self): print("Quit") def ActionSave(self): self.create_table() current_tab_index = self.tabview.currentIndex() if current_tab_index >= 0: tab = self.tabview.currentWidget() job_data = tab.property("OBJECT").get_job_data() if len(job_data) > 0: if tab.property("NAME") == "": win = SaveWindow() if win.is_accepted(): name = win.get_name() _id = self.get_id() tab.setToolTip(name) tab.setWindowTitle(name) tab.setProperty("NAME", name) tab.setProperty("_ID", _id) string = "insert into jobs (id, name, jobs_data, created_on) values (?, ?, ?, ?)" values = [ _id, name, json.dumps(job_data), datetime.now() ] self.build_job_frame(name) self.conn.execute(string, values) self.conn.commit() else: string = "update jobs set name = ?, jobs_data = ?, updated_on = ? where id = ?" values = [ tab.property("NAME"), json.dumps(job_data), datetime.now(), tab.property("_ID") ] self.conn.execute(string, values) self.conn.commit() def ActionNew(self, name=None): try: print("Sub-class") self.tabCtr += 1 tab = QWidget() ## tab.setStyleSheet(CSS.CSS_TAB_BASE) ## tab.setStyleSheet("{ border-style: solid; background-color:#FBFBFB }") center = ScriptExecutor() result = center.getExecutorLayout() tab.setLayout(result) tab.setProperty("OBJECT", center) tab.setProperty("TAB_CTR", self.tabCtr) tab.setProperty("NAME", "") tab.setProperty("_ID", 0) # center.getFirstWidget().setFocus(Qt.ActiveWindowFocusReason) if name == None: name = "Untitled " + str(self.tabCtr) self.tabview.addTab(tab, name) self.tabview.setCurrentWidget(tab) center.host.setFocus() except Exception: raise return tab def ActionExecute(self): current_tab_index = self.tabview.currentIndex() if current_tab_index >= 0: tab = self.tabview.currentWidget() tab.property("OBJECT").Execute() def load_job(self, frame, event): job_data = json.loads(frame.property(JOB_DATA)) # Updated by Pinkesh Shah on 30-Apr-20 # Start Region if frame.property(NAME) not in self.activeJobTabs: self.activeJobTabs.append(frame.property(NAME)) tab = self.ActionNew(frame.property(NAME)) center = tab.property("OBJECT") center.LoadData(job_data) # End Region # Updated by Pinkesh Shah on 02-May-20 # Start Region else: for i in range(self.tabview.count()): if frame.property(NAME) == self.tabview.tabText(i): self.tabview.setCurrentIndex(i) # End Region def create_table(self): cursor = self.conn.execute( ''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='Jobs' ''' ) # if the count is 1, then table exists if not cursor.fetchone()[0] == 1: string = "create table Jobs (id INT PRIMARY KEY NOT NULL, name text, jobs_data json, " \ "created_on CURRENT_TIMESTAMP, " \ "updated_on CURRENT_TIMESTAMP )" self.conn.execute(string) print("Create Statement:", string) def get_id(self): cursor = self.conn.execute(''' SELECT MAX(id) as id FROM jobs ''') _id = 0 for rec in cursor: _id = (0 if rec[0] == None else rec[0]) _id = _id + 1 cursor.close() return _id def get_job_list(self): string = "select id, name, jobs_data from Jobs order by id" cursor = self.conn.execute(string) for rec in cursor: frame = self.build_job_frame(rec[1]) frame.setProperty(_ID, rec[0]) frame.setProperty(NAME, rec[1]) frame.setProperty(JOB_DATA, rec[2]) frame.mouseDoubleClickEvent = partial(self.load_job, frame) def changeStyle(self, styleName): QApplication.setStyle(QStyleFactory.create(styleName))
import requests import sys class MainWindow(QWidget): def __init__(self): super().__init__() text = QLabel() text.setWordWrap(True) button = QPushButton('Next quote >') button.clicked.connect(lambda: text.setText(_get_quote())) layout = QVBoxLayout() layout.addWidget(text) layout.addWidget(button) layout.setAlignment(button, Qt.AlignHCenter) self.setLayout(layout) def _get_quote(): return requests.get('https://build-system.fman.io/quote').text if __name__ == '__main__': appctxt = ApplicationContext() stylesheet = appctxt.get_resource('../styles.qss') appctxt.app.setStyleSheet(open(stylesheet).read()) window = MainWindow() window.show() exit_code = appctxt.app.exec_() sys.exit(exit_code)
from fbs_runtime.application_context.PyQt5 import ApplicationContext from gui import TransparentWindow, SystemTrayIcon, SettingsQWidget from logic import Logic, ScreenSaveInhibit import sys if __name__ == '__main__': appctxt = ApplicationContext() appctxt.app.setApplicationName("Break Reminder") appctxt.app.setQuitOnLastWindowClosed(False) break_window = TransparentWindow() system_tray_icon = SystemTrayIcon(appctxt.get_resource('assets'), break_window) config_window = SettingsQWidget() logic = Logic(appctxt.get_resource('config.json')) screen_inhibitor = ScreenSaveInhibit() # emitted in show() method to prevent computer from going screen save # mode and stop execution of break timer break_window.prevent_window_sleep_signal.connect( screen_inhibitor.inhibit_screen_saver) logic.display_break_ui_signal.connect(break_window.show) logic.hide_break_ui_signal.connect(break_window.hide) logic.update_timer_signal.connect(break_window.update_UI_timer) logic.update_timer_signal.connect(system_tray_icon.update_timer_countdown) logic.message_signal.connect(system_tray_icon.showMessage)