class MainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.setWindowTitle("Salary Manager") self.setGeometry(50,50, 800, 600) self.setWindowIcon(QIcon("Resources/rupee.png")) self.widgetStack = QStackedWidget() self.setCentralWidget(self.widgetStack) self.pages = { "Login": LoginWidget, "Home": HomeWidget, "Add Employee": AddEmployeeWidget, "Del Employee": DelEmployeeWidget, "Edit Employee": EditEmployeeWidget, "Show Employee": ShowEmployeeWidget, "Add Designation": AddDesignationWidget, "Show Designation": ShowDesigationWidget, "Calc Salary": CalculateSalaryWidget, "Result": ShowPaySlipWidget } self.gotoPage("Login") def gotoPage(self, name, args=()): print "Goto page", name, "; args=", args try: if len(args) == 0: newPage = self.pages[name](self) else: newPage = self.pages[name](self, *args) self.widgetStack.addWidget(newPage) self.widgetStack.setCurrentWidget(newPage) except mysql.connector.Error as e: ShowMysqlError(e, self) def goBack(self): print "Going Back" try: currentIndex = self.widgetStack.currentIndex() if currentIndex > 0: currentPage = self.widgetStack.currentWidget() self.widgetStack.setCurrentIndex(currentIndex-1) currentPage.deleteLater() self.widgetStack.removeWidget(currentPage) except mysql.connector.Error as e: ShowMysqlError(e, self)
def __init__(self, parent=None): super(EditPreferencesDlg, self).__init__(parent) self.setWindowTitle("Preferences") # define widgets pref_list = QListWidget() pref_list.addItem("General") pref_list.addItem("Display") pref_list.setMaximumWidth(150) pref_list.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) button_box = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) general_page = QWidget() general_layout = QGridLayout() general_layout.setAlignment(Qt.AlignTop) general_layout.addWidget(QLabel("<b>General</b>"), 0, 0) general_page.setLayout(general_layout) display_page = QWidget() display_layout = QGridLayout() display_layout.setAlignment(Qt.AlignTop) display_layout.addWidget(QLabel("<b>Display Options</b>"), 0, 0) self.multitabs_checkbox = QCheckBox("Limit the display of tabs to one relief device (and the device's scenarios) at a time") if parent.limit_tabs is True: self.multitabs_checkbox.setChecked(True) display_layout.addWidget(self.multitabs_checkbox, 1, 0) display_page.setLayout(display_layout) stacked_widget = QStackedWidget() for page in general_page, display_page: stacked_widget.addWidget(page) main_layout = QVBoxLayout() widgets_layout = QHBoxLayout() widgets_layout.addWidget(pref_list) widgets_layout.addWidget(stacked_widget) buttons_layout = QHBoxLayout() buttons_layout.addStretch() buttons_layout.addWidget(button_box) main_layout.addLayout(widgets_layout) main_layout.addLayout(buttons_layout) self.setLayout(main_layout) pref_list.currentRowChanged.connect(stacked_widget.setCurrentIndex) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject)
class StackedPage(QWidget): def __init__(self, parent = None): super(StackedPage, self).__init__(parent) layout = QHBoxLayout(self) leftpane = QVBoxLayout() self.buttongroup = QButtonGroup(self) self.buttongroup.setExclusive(True) self.groupbox = QGroupBox(self) self.groupbox.setMinimumWidth(200) QVBoxLayout(self.groupbox) leftpane.addWidget(self.groupbox) leftpane.addStretch(1) layout.addLayout(leftpane) self.rightpane = QStackedWidget(self) layout.addWidget(self.rightpane) self.buttongroup.buttonClicked[int].connect(self.rightpane.setCurrentIndex) self.rightpane.currentChanged[int].connect(self.activate) def addPage(self, buttontext, widget): button = QPushButton(buttontext) button.setCheckable(True) button.setChecked(self.rightpane.count() == 0) self.buttongroup.addButton(button, self.rightpane.count()) self.groupbox.layout().addWidget(button) self.rightpane.addWidget(widget) def pages(self): return [ self.rightpane.widget(i) for i in range(self.rightpane.count()) ] def activate(self, ix): page = self.rightpane.currentWidget() if hasattr(page, "activate") and callable(page.activate): page.activate() def showEvent(self, *args, **kwargs): self.activate(0) return QWidget.showEvent(self, *args, **kwargs)
class ConfigEditor(QMainWindow): def __init__(self, app, cfg, title='Config Editor'): super(ConfigEditor, self).__init__() self.app = app self.config = cfg self.title = title def setup(self): self.dirty = False self.def_cfg = copy.deepcopy(self.config) self.config.update_from_user_file() self.base_cfg = copy.deepcopy(self.config) self.categories = QListWidget() #self.categories.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Expanding) self.settings = QStackedWidget() #self.categories.setSizePolicy(QSizePolicy.MinimumExpanding,QSizePolicy.Expanding) QObject.connect(self.categories, SIGNAL('itemSelectionChanged()'), self.category_selected) self.widget_list = {} for cat in self.config.get_categories(): self.widget_list[cat] = {} longest_cat = 0 for cat in self.config.get_categories(): if len(cat) > longest_cat: longest_cat = len(cat) self.categories.addItem(cat) settings_layout = QGridLayout() r = 0 c = 0 for setting in self.config.get_settings(cat): info = self.config.get_setting(cat, setting, True) s = QWidget() s.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Fixed) sl = QVBoxLayout() label = QLabel() if info.has_key('alias'): label.setText(info['alias']) else: label.setText(setting) if info.has_key('about'): label.setToolTip(info['about']) sl.addWidget(label) if info['type'] == constants.CT_LINEEDIT: w = LineEdit(self, self.config,cat,setting,info) elif info['type'] == constants.CT_CHECKBOX: w = CheckBox(self, self.config,cat,setting,info) elif info['type'] == constants.CT_SPINBOX: w = SpinBox(self, self.config,cat,setting,info) elif info['type'] == constants.CT_DBLSPINBOX: w = DoubleSpinBox(self, self.config,cat,setting,info) elif info['type'] == constants.CT_COMBO: w = ComboBox(self, self.config,cat,setting,info) w.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Fixed) self.widget_list[cat][setting] = w sl.addWidget(w) s.setLayout(sl) c = self.config.config[cat].index(setting) % 2 settings_layout.addWidget(s, r, c) if c == 1: r += 1 settings = QWidget() settings.setLayout(settings_layout) settings_scroller = QScrollArea() settings_scroller.setWidget(settings) settings_scroller.setWidgetResizable(True) self.settings.addWidget(settings_scroller) font = self.categories.font() fm = QFontMetrics(font) self.categories.setMaximumWidth(fm.widthChar('X')*(longest_cat+4)) self.main = QWidget() self.main_layout = QVBoxLayout() self.config_layout = QHBoxLayout() self.config_layout.addWidget(self.categories) self.config_layout.addWidget(self.settings) self.mainButtons = QDialogButtonBox(QDialogButtonBox.RestoreDefaults | QDialogButtonBox.Reset | QDialogButtonBox.Apply) self.main_apply = self.mainButtons.button(QDialogButtonBox.StandardButton.Apply) self.main_reset = self.mainButtons.button(QDialogButtonBox.StandardButton.Reset) self.main_defaults = self.mainButtons.button(QDialogButtonBox.StandardButton.LastButton) QObject.connect(self.mainButtons, SIGNAL('clicked(QAbstractButton *)'), self.mainbutton_clicked) self.dirty_check() self.main_layout.addLayout(self.config_layout) self.main_layout.addWidget(self.mainButtons) self.main.setLayout(self.main_layout) self.setCentralWidget(self.main) self.setWindowTitle(self.title) self.setUnifiedTitleAndToolBarOnMac(True) self.categories.setCurrentItem(self.categories.item(0)) self.menuBar = QMenuBar() self.filemenu = QMenu('&File') self.quitAction = QAction(self) self.quitAction.setText('&Quit') if platform.system() != 'Darwin': self.quitAction.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Q)) QObject.connect(self.quitAction, SIGNAL('triggered()'), self.quitApp) self.filemenu.addAction(self.quitAction) self.menuBar.addMenu(self.filemenu) self.setMenuBar(self.menuBar) self.show() self.activateWindow() self.raise_() self.setMinimumWidth(self.geometry().width()*1.2) screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2) def category_selected(self): self.settings.setCurrentIndex(self.config.config.index(self.categories.selectedItems()[0].text())) def mainbutton_clicked(self, button): if button == self.main_reset: for cat in self.base_cfg.get_categories(): for setting in self.base_cfg.get_settings(cat): self.widget_list[cat][setting].updateValue(self.base_cfg.get_setting(cat,setting)) elif button == self.main_defaults: for cat in self.def_cfg.get_categories(): for setting in self.def_cfg.get_settings(cat): self.widget_list[cat][setting].updateValue(self.def_cfg.get_setting(cat,setting)) elif button == self.main_apply: bad_settings = self.validate_settings() if bad_settings == []: self.save_settings() self.main_apply.setEnabled(False) self.main_reset.setEnabled(False) else: msgBox = QMessageBox() msgBox.setText("Must fix the following invalid settings before quitting:") msgBox.setStandardButtons(QMessageBox.Ok) info = '' for setting in bad_settings: new = '%s,%s<br>' % setting info = '%s%s' % (info, new) msgBox.setInformativeText(info) msgBox.exec_() def quitApp(self): self.app.closeAllWindows() def get_changes(self): enc = MyEncoder() if enc.encode(self.def_cfg.config) == enc.encode(self.config.config): return False if enc.encode(self.base_cfg.config) != enc.encode(self.config.config): newC = Config() for c in self.config.config.keys(): for s in self.config.config[c].keys(): if self.config.config[c][s]['value'] != self.def_cfg.config[c][s]['value']: newC.add_setting(c, s, self.config.config[c][s]['value'], stub=True) return json.dumps(newC.config, separators=(',',': '), indent=4, sort_keys=True) else: return None def validate_settings(self): ret = [] for cat in self.config.get_categories(): for setting in self.config.get_settings(cat): info = self.config.get_setting(cat, setting, True) if info.has_key('validate'): if not info['validate'](info): ret.append((cat,setting)) return ret def dirty_check(self): if str(self.base_cfg) != str(self.config): self.dirty = True self.main_apply.setEnabled(True) self.main_reset.setEnabled(True) else: self.dirty = False self.main_apply.setEnabled(False) self.main_reset.setEnabled(False) if str(self.def_cfg) == str(self.config): self.main_defaults.setEnabled(False) else: self.main_defaults.setEnabled(True) def save_settings(self): config = self.get_changes() if config == False: if os.path.isfile(self.config.user_file): os.remove(self.config.user_file) elif config != None: with open(self.config.user_file, 'w+') as f: f.write(config) self.base_cfg = copy.deepcopy(self.config) def closeEvent(self, event=None): self.quitApp()
class GeometryWizardPage(_ExpandableOptionsWizardPage): def __init__(self, options, parent=None): _ExpandableOptionsWizardPage.__init__(self, options, parent) self.setTitle('Geometry') def _initUI(self): # Variables self._widgets = {} # Widgets self._cb_geometry = QComboBox() self._wdg_geometry = QStackedWidget() policy = self._wdg_geometry.sizePolicy() policy.setVerticalStretch(True) self._wdg_geometry.setSizePolicy(policy) # Layouts layout = _ExpandableOptionsWizardPage._initUI(self) layout.addRow("Type of geometry", self._cb_geometry) layout.addRow(self._wdg_geometry) # Signals self._cb_geometry.currentIndexChanged.connect(self._onGeometryChanged) self._cb_geometry.currentIndexChanged.connect(self.valueChanged) return layout def _onGeometryChanged(self): newindex = self._cb_geometry.currentIndex() oldwidget = self._wdg_geometry.currentWidget() newwidget = self._wdg_geometry.widget(newindex) if newwidget is None: return try: newwidget.setValue(oldwidget.value()) except: newwidget.setValue(self.options().geometry) self._wdg_geometry.setCurrentIndex(newindex) # See https://qt-project.org/faq/answer/how_can_i_get_a_qstackedwidget_to_automatically_switch_size_depending_on_th oldwidget.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) newwidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._wdg_geometry.adjustSize() def _find_material_class(self, programs): highest_class = Material for program in programs: converter = program.converter_class for clasz in converter.MATERIALS: if issubclass(clasz, highest_class): highest_class = clasz return highest_class def initializePage(self): _ExpandableOptionsWizardPage.initializePage(self) # Clear self._widgets.clear() for i in reversed(range(self._cb_geometry.count())): self._cb_geometry.removeItem(i) self._wdg_geometry.removeWidget(self._wdg_geometry.widget(i)) # Populate combo box it = self._iter_widgets('pymontecarlo.ui.gui.options.geometry', 'GEOMETRIES') for clasz, widget_class, programs in it: widget = widget_class() widget.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) widget.setMaterialClass(self._find_material_class(programs)) self._widgets[clasz] = widget program_text = ', '.join(map(attrgetter('name'), programs)) text = '{0} ({1})'.format(widget.accessibleName(), program_text) self._cb_geometry.addItem(text) self._wdg_geometry.addWidget(widget) widget.valueChanged.connect(self.valueChanged) # Select geometry geometry = self.options().geometry widget = self._widgets.get(geometry.__class__) if widget is None: widget = next(iter(self._widgets.values())) widget.setValue(geometry) self._wdg_geometry.setCurrentWidget(widget) self._cb_geometry.setCurrentIndex(self._wdg_geometry.currentIndex()) def validatePage(self): if not self._wdg_geometry.currentWidget().hasAcceptableInput(): return False self.options().geometry = self._wdg_geometry.currentWidget().value() return True def expandCount(self): try: return len(expand(self._wdg_geometry.currentWidget().value())) except: return 0
class MainWindow(QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.resize(800, 480) self.setWindowTitle('PySide GUI') #self.setWindowFlags(PySide.QtCore.Qt.FramelessWindowHint) self.wgHome, self.dcHome = self.createHomePage() # serial page self.wgSerial = QWidget(self) gridLayout = QGridLayout(self.wgSerial) self.lb1 = QLabel('serial page') self.lb2 = QLabel('label 2') self.lb3 = QLabel('label 3') gridLayout.addWidget(self.lb1, 0, 0) gridLayout.addWidget(self.lb2, 1, 0) gridLayout.addWidget(self.lb3, 2, 0) self.sw = QStackedWidget(self) self.sw.addWidget(self.wgHome) self.sw.addWidget(self.wgSerial) self.setCentralWidget(self.sw) menubar = QMenuBar(self) menubar.setGeometry(QRect(0, 0, 731, 29)) menu_File = QMenu(menubar) self.setMenuBar(menubar) statusbar = QStatusBar(self) self.setStatusBar(statusbar) actionHome = QAction(self) actionHome.setIcon(QIcon("icon/Home-50.png")) actionHome.setStatusTip("Home content") actionHome.triggered.connect( lambda: self.sw.setCurrentWidget(self.wgHome)) actionSerial = QAction(self) actionSerial.setIcon(QIcon("icon/Unicast-50.png")) actionSerial.setStatusTip("Serial polling task status") actionSerial.triggered.connect( lambda: self.sw.setCurrentWidget(self.wgSerial)) actionLogging = QAction(self) actionLogging.setIcon(QIcon("icon/Database-50.png")) actionLogging.setStatusTip("Logging task status") actionLogging.triggered.connect( lambda: self.sw.setCurrentWidget(self.wgLogging)) actionUpload = QAction(self) actionUpload.setIcon(QIcon("icon/Upload to Cloud-50.png")) actionUpload.setStatusTip("Uploading task status") actionUpload.triggered.connect( lambda: self.sw.setCurrentWidget(self.wgLogging)) actionDebug = QAction(self) actionDebug.setIcon(QIcon("icon/Bug-50.png")) actionDebug.setStatusTip("debug") actionDebug.triggered.connect(self.debug) actionAbout = QAction(self) actionAbout.triggered.connect(self.about) actionAbout.setIcon(QIcon("icon/Info-50.png")) actionAbout.setStatusTip("Pop up the About dialog.") actionSetting = QAction(self) actionSetting.setCheckable(False) actionSetting.setObjectName('action_clear') actionSetting.setIcon(QIcon("icon/Settings-50.png")) actionLeft = QAction(self) actionLeft.setIcon(QIcon("icon/Left-50.png")) actionLeft.setStatusTip("Left page") actionLeft.triggered.connect(self.switchLeftWidget) actionRight = QAction(self) actionRight.setIcon(QIcon("icon/Right-50.png")) actionRight.setStatusTip("Right page") actionRight.triggered.connect(self.switchRightWidget) actionClose = QAction(self) actionClose.setCheckable(False) actionClose.setObjectName("action_Close") actionClose.setIcon(QIcon("icon/Delete-50.png")) actionClose.setStatusTip("Close the program.") actionClose.triggered.connect(self.close) #------------------------------------------------------ menu_File.addAction(actionHome) menu_File.addAction(actionAbout) menu_File.addAction(actionClose) menu_File.addAction(actionSetting) menubar.addAction(menu_File.menuAction()) iconToolBar = self.addToolBar("iconBar.png") iconToolBar.addAction(actionHome) iconToolBar.addAction(actionSerial) iconToolBar.addAction(actionLogging) iconToolBar.addAction(actionUpload) iconToolBar.addAction(actionDebug) iconToolBar.addAction(actionAbout) iconToolBar.addAction(actionSetting) iconToolBar.addAction(actionLeft) iconToolBar.addAction(actionRight) iconToolBar.addAction(actionClose) def createHomePage(self): WIDTH_LEFT = 3 WIDTH_RIGHT = 7 dc = dict() wg = QWidget(self) gridLayout = QGridLayout(wg) row = 0 gridLayout.addWidget(QLabel('Home'), row, 0) row = 1 gridLayout.addWidget(QLabel('Tx'), row, 0, 1, WIDTH_LEFT) lbtx = QLabel('tx data') lbtx.setMinimumWidth(400) dc['pvtx_label'] = lbtx gridLayout.addWidget(lbtx, row, 1, 1, WIDTH_RIGHT) row = 2 gridLayout.addWidget(QLabel('Rx'), row, 0, 1, WIDTH_LEFT) lbrx = QLabel('rx data') dc['pvrx_label'] = lbrx gridLayout.addWidget(lbrx, row, 1, 1, WIDTH_RIGHT) row = 3 gridLayout.addWidget(QLabel('Serial485'), row, 0, 1, WIDTH_LEFT) ser_label = QLabel('serial 485') dc['ser_label'] = ser_label gridLayout.addWidget(ser_label, row, 1, 1, WIDTH_RIGHT) row = 4 gridLayout.addWidget(QLabel('Log'), row, 0, 1, WIDTH_LEFT) elogging_label = QLabel('event logging') dc['elogging_label'] = elogging_label gridLayout.addWidget(elogging_label, row+0, 1, 1, WIDTH_RIGHT) mlogging_label = QLabel('minute logging') dc['mlogging_label'] = mlogging_label gridLayout.addWidget(mlogging_label, row+1, 1, 1, WIDTH_RIGHT) hlogging_label = QLabel('hour logging') dc['hlogging_label'] = hlogging_label gridLayout.addWidget(hlogging_label, row+2, 1, 1, WIDTH_RIGHT) row = 7 gridLayout.addWidget(QLabel('Upload'), row, 0, 1, WIDTH_LEFT) eupload_label = QLabel('event uploading') dc['eupload_label'] = eupload_label gridLayout.addWidget(eupload_label, row+0, 1, 1, WIDTH_RIGHT) mupload_label = QLabel('minute uploading') dc['mupload_label'] = mupload_label gridLayout.addWidget(mupload_label, row+1, 1, 1, WIDTH_RIGHT) hupload_label = QLabel('hour uploading') dc['hupload_label'] = hupload_label gridLayout.addWidget(hupload_label, row+2, 1, 1, WIDTH_RIGHT) row = 10 gridLayout.addWidget(QLabel('Main'), row, 0, 1, WIDTH_LEFT) mainthread_label = QLabel('main thread') dc['mainthread_label'] = mainthread_label gridLayout.addWidget(mainthread_label, row+0, 1, 1, WIDTH_RIGHT) return wg, dc def debug(self): self.dcHome['pvtx_label'].setText(str(time.time())) def switchLeftWidget(self): i = self.sw.currentIndex() - 1 if i < 0: i = 0 self.sw.setCurrentIndex(i) #print('{}, {}'.format(self.sw.currentIndex(), self.sw.count())) def switchRightWidget(self): i = self.sw.currentIndex() + 1 if i > self.sw.count(): i = self.sw.count() self.sw.setCurrentIndex(i) #print('{}, {}'.format(self.sw.currentIndex(), self.sw.count())) def about(self): '''Popup a box with about message.''' QMessageBox.about(self, "About PySide, Platform and version.", """<b> about.py version %s </b> <p>Copyright © 2013 by Algis Kabaila. This work is made available under the terms of Creative Commons Attribution-ShareAlike 3.0 license, http://creativecommons.org/licenses/by-sa/3.0/. <p>This application is useful for displaying Qt version and other details. <p>Python %s - PySide version %s - Qt version %s on %s""" % (__version__, platform.python_version(), PySide.__version__, PySide.QtCore.__version__, platform.system()))
class BeamWizardPage(_ExpandableOptionsWizardPage): def __init__(self, options, parent=None): _ExpandableOptionsWizardPage.__init__(self, options, parent) self.setTitle("Beam") def _initUI(self): # Variables self._widgets = {} # Widgets self._cb_beam = QComboBox() self._wdg_beam = QStackedWidget() # Layouts layout = _ExpandableOptionsWizardPage._initUI(self) layout.addRow("Type of beam", self._cb_beam) layout.addRow(self._wdg_beam) # Signals self._cb_beam.currentIndexChanged.connect(self._onBeamChanged) self._cb_beam.currentIndexChanged.connect(self.valueChanged) return layout def _onBeamChanged(self): newindex = self._cb_beam.currentIndex() oldwidget = self._wdg_beam.currentWidget() newwidget = self._wdg_beam.widget(newindex) if newwidget is None: return try: newwidget.setValue(oldwidget.value()) except: newwidget.setValue(self.options().beam) self._wdg_beam.setCurrentIndex(newindex) def initializePage(self): _ExpandableOptionsWizardPage.initializePage(self) # Clear self._widgets.clear() for i in reversed(range(self._cb_beam.count())): self._cb_beam.removeItem(i) self._wdg_beam.removeWidget(self._wdg_beam.widget(i)) # Populate combo box it = self._iter_widgets("pymontecarlo.ui.gui.options.beam", "BEAMS") for clasz, widget_class, programs in it: widget = widget_class() self._widgets[clasz] = widget program_text = ", ".join(map(attrgetter("name"), programs)) text = "{0} ({1})".format(widget.accessibleName(), program_text) self._cb_beam.addItem(text) self._wdg_beam.addWidget(widget) widget.setParticlesEnabled(False) for program in programs: converter = program.converter_class for particle in converter.PARTICLES: widget.setParticleEnabled(particle, True) widget.valueChanged.connect(self.valueChanged) # Select beam beam = self.options().beam widget = self._widgets.get(beam.__class__) if widget is None: widget = next(iter(self._widgets.values())) widget.setValue(beam) self._wdg_beam.setCurrentWidget(widget) self._cb_beam.setCurrentIndex(self._wdg_beam.currentIndex()) def validatePage(self): if not self._wdg_beam.currentWidget().hasAcceptableInput(): return False self.options().beam = self._wdg_beam.currentWidget().value() return True def expandCount(self): try: return len(expand(self._wdg_beam.currentWidget().value())) except: return 0
class MainWindow(QMainWindow): def __init__(self, controller): super(MainWindow, self).__init__() self.controller = controller self.setWindowTitle("av-control") self.resize(1024, 600) self.setWindowIcon(QIcon(":icons/video-display")) self.mainScreen = VideoSwitcher(controller, self) self.stack = QStackedWidget() self.stack.addWidget(self.mainScreen) outer = QWidget() mainLayout = QGridLayout() mainLayout.addWidget(self.stack, 0, 0, 1, 7) column = 0 self.spc = SystemPowerWidget(controller, self) syspower = ExpandingButton() syspower.setText("Power") syspower.clicked.connect(self.showSystemPower) syspower.setIcon(QIcon(":icons/system-shutdown")) syspower.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(syspower, 1, column) column += 1 self.bc = BlindsControl(controller["Blinds"], self) blinds = ExpandingButton() blinds.setText("Blinds") blinds.clicked.connect(lambda: self.showScreen(self.bc)) blinds.setIcon(QIcon(":icons/blinds")) blinds.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(blinds, 1, column) column += 1 self.sc = ProjectorScreensControl(controller["Screens"], self) screens = ExpandingButton() screens.setText("Screens") screens.clicked.connect(lambda: self.showScreen(self.sc)) screens.setIcon(QIcon(":icons/screens")) screens.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(screens, 1, column) column += 1 if controller.hasDevice("Lights"): self.lightsMenu = LightingControl(controller["Lights"], self) lights = ExpandingButton() lights.setText("Lights") lights.clicked.connect(lambda: self.showScreen(self.lightsMenu)) lights.setIcon(QIcon(":icons/lightbulb_on")) lights.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(lights, 1, column) column += 1 self.advMenu = AdvancedMenu(self.controller, self) adv = ExpandingButton() adv.setText("Advanced") adv.setIcon(QIcon(":icons/applications-system")) adv.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) adv.clicked.connect(lambda: self.showScreen(self.advMenu)) mainLayout.addWidget(adv, 1, column) column += 1 for i in range(column): mainLayout.setColumnStretch(i, 1) tray = QHBoxLayout() tray.addWidget(Clock()) tray.addWidget(SystemStatus(controller)) mainLayout.addLayout(tray, 1, column) mainLayout.setRowStretch(0, 8) mainLayout.setRowStretch(1, 0) outer.setLayout(mainLayout) self.setCentralWidget(outer) self.pnd = PowerNotificationDialog(self) self.pnd.accepted.connect(self.hidePowerDialog) def showScreen(self, screenWidget): if self.stack.currentWidget() == screenWidget: self.stepBack() else: self.stack.insertWidget(0, screenWidget) self.stack.setCurrentWidget(screenWidget) def showSystemPower(self): self.showScreen(self.spc) def stepBack(self): self.stack.removeWidget(self.stack.currentWidget()) def errorBox(self, text): Dialogs.errorBox(text) def showPowerDialog(self, message): self.pnd.message = message self.pnd.exec_() def hidePowerDialog(self): self.pnd.close() if self.stack.currentWidget() == self.spc: self.stepBack() def updateOutputMappings(self, mapping): self.mainScreen.updateOutputMappings(mapping)
class QtReducePreferencePane(QDialog): # QtReducePreferencePane are the dialog windows for setting preferences. # Instances are created via menu or keyboard shortcut in QtReduceMainWindow. def __init__(self, parent=None): super(QtReducePreferencePane, self).__init__(parent) self.__createContents() self.toolBar = QtReducePreferencesToolBar(self) self.worksheet = QtReducePreferencesWorksheet(self) self.computation = QtReducePreferencesComputation(self) self.pagesWidget = QStackedWidget() self.pagesWidget.addWidget(self.toolBar) self.pagesWidget.addWidget(self.worksheet) self.pagesWidget.addWidget(self.computation) self.pagesWidget.setCurrentIndex( self.contentsWidget.row(self.contentsWidget.currentItem())) closeButton = QPushButton(self.tr("Close")) closeButton.clicked.connect(self.close) horizontalLayout = QHBoxLayout() horizontalLayout.addWidget(self.contentsWidget) horizontalLayout.addWidget(self.pagesWidget) buttonsLayout = QHBoxLayout() buttonsLayout.addStretch(1) buttonsLayout.addWidget(closeButton) mainLayout = QVBoxLayout() mainLayout.addLayout(horizontalLayout) mainLayout.addLayout(buttonsLayout) self.setLayout(mainLayout) self.setWindowTitle(self.tr("QReduce Preferences")) def changePage(self,current,previous): if not current: current = previous QSettings().setValue("preferences/currentitem",current.text()) self.pagesWidget.setCurrentIndex(self.contentsWidget.row(current)) def __createContents(self): self.contentsWidget = QListWidget() self.contentsWidget.setViewMode(QListView.ListMode) self.contentsWidget.setMovement(QListView.Static) toolBar = QListWidgetItem(self.contentsWidget) toolBar.setText(self.tr("Toolbar")) toolBar.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) worksheet = QListWidgetItem(self.contentsWidget) worksheet.setText(self.tr("Worksheet")) worksheet.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) computation = QListWidgetItem(self.contentsWidget) computation.setText(self.tr("Computation")) computation.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) currentItem = QSettings().value("preferences/currentitem", self.tr(QtReduceDefaults.CURRENTITEM)) if currentItem == self.tr("Toolbar"): self.contentsWidget.setCurrentItem(toolBar) elif currentItem == self.tr("Worksheet"): self.contentsWidget.setCurrentItem(worksheet) elif currentItem == self.tr("Computation"): self.contentsWidget.setCurrentItem(computation) self.contentsWidget.currentItemChanged.connect(self.changePage)
class MainWindow(QMainWindow): def __init__(self, controller): super(MainWindow, self).__init__() self.controller = controller self.setWindowTitle("AldatesX") self.resize(1024, 600) self.mainScreen = VideoSwitcher(controller, self) self.stack = QStackedWidget() self.stack.addWidget(self.mainScreen) outer = QWidget() mainLayout = QGridLayout() mainLayout.addWidget(self.stack, 0, 0, 1, 7) self.spc = SystemPowerWidget(controller, self) syspower = ExpandingButton() syspower.setText("Power") syspower.clicked.connect(self.showSystemPower) syspower.setIcon(QIcon("icons/system-shutdown.svg")) syspower.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(syspower, 1, 0) self.bc = BlindsControl(controller, self) blinds = ExpandingButton() blinds.setText("Blinds") blinds.clicked.connect(lambda: self.showScreen(self.bc)) blinds.setIcon(QIcon("icons/blinds.svg")) blinds.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(blinds, 1, 2) self.sc = ProjectorScreensControl(self.controller, self) screens = ExpandingButton() screens.setText("Screens") screens.clicked.connect(lambda: self.showScreen(self.sc)) screens.setIcon(QIcon("icons/screens.svg")) screens.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(screens, 1, 3) self.advMenu = AdvancedMenu(self.controller, self) adv = ExpandingButton() adv.setText("Advanced") adv.setIcon(QIcon("icons/applications-system.svg")) adv.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) adv.clicked.connect(lambda: self.showScreen(self.advMenu)) mainLayout.addWidget(adv, 1, 5) mainLayout.addWidget(Clock(), 1, 6) mainLayout.setRowStretch(0, 8) mainLayout.setRowStretch(1, 0) outer.setLayout(mainLayout) self.setCentralWidget(outer) self.pnd = PowerNotificationDialog(self) self.pnd.accepted.connect(self.hidePowerDialog) def showScreen(self, screenWidget): if self.stack.currentWidget() == screenWidget: self.stepBack() else: self.stack.insertWidget(0, screenWidget) self.stack.setCurrentWidget(screenWidget) def showSystemPower(self): self.showScreen(self.spc) def stepBack(self): self.stack.removeWidget(self.stack.currentWidget()) def errorBox(self, text): Dialogs.errorBox(text) def showPowerDialog(self, message): self.pnd.message = message self.pnd.exec_() def hidePowerDialog(self): self.pnd.close() if self.stack.currentWidget() == self.spc: self.stepBack() def updateOutputMappings(self, mapping): self.mainScreen.updateOutputMappings(mapping)
class MainWindow(QMainWindow, Ui_MainWindow): """Main interface""" # Custom Signals dock_destroyed = Signal(str) def __init__(self, user_data, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) self.set_username(user_data[0]) self._docks = [] self._stackedWidget = QStackedWidget() self.setCentralWidget(self._stackedWidget) self._overview = OverviewDock() self._stackedWidget.addWidget(self._overview) self._edit_mode = False self._stackedWidget.currentChanged.connect(self.dock_changed) # permission stuff self.set_access(user_data[1]) def dock_changed(self, new_index): new_dock = self._stackedWidget.widget(new_index).objectName() if "Edit" in new_dock: # it's an editing dock self.set_editing(True) def set_editing(self, state): self._edit_mode = state def is_editing(self): return self._edit_mode def set_username(self, username): statics.username = username message = QLabel(unicode("Usuário: ".decode('utf-8')) + username) self.statusbar.addWidget(message) def set_access(self, access_level): statics.access_level = access_level # set availability for QAction objects for action in self.findChildren(QAction): action.setVisible(check_access(access_level, action.objectName())) for menu in self.findChildren(QMenu): if menu.isEmpty(): # no visible actions under this menu menu.menuAction().setVisible(False) @QtCore.Slot() def on_actionExit_activated(self): self.close() @QtCore.Slot() def on_actionAddBook_activated(self): self.show_on_top(AddBookDock, self.actionAddBook) @QtCore.Slot() def on_actionAddAssociate_activated(self): self.show_on_top(AddAssociateDock, self.actionAddAssociate) @QtCore.Slot() def on_actionAddActivity_activated(self): self.show_on_top(AddActivityDock, self.actionAddActivity) @QtCore.Slot() def on_actionPendencies_activated(self): self.show_on_top(PendenciesDock, self.actionPendencies) @QtCore.Slot() def on_actionSellProduct_activated(self): self.show_on_top(OrderProductDock, self.actionSellProduct) @QtCore.Slot() def on_actionSellBook_activated(self): self.show_on_top(OrderBookDock, self.actionSellBook) def show_on_top(self, widget_type, related_action=None, param=None): """ makes the dock related to 'widget_type' the central widget of the mainwindow (by stacking it on front of other widgets), grays out respective action while visible """ if self.is_editing(): # edit dock is being swapped out message = unicode("Todos os dados não salvos serão perdidos".decode('utf-8')) reply = QMessageBox.warning(self, unicode("Atenção".decode('utf-8')), message, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.No: return else: self.remove_instance(self._stackedWidget.currentWidget()) # there's a need to gray out the corresponding menu option if related_action: related_action.setDisabled(True) widget = self.get_instance(widget_type) if widget is None: # create a new instance of referenced widget if it doesn't exist yet if param: # when a parameter is passed widget = widget_type(param) else: widget = widget_type() self._docks.append(widget) self._stackedWidget.addWidget(widget) # else: # widget.clear() # connects a connection cleanup method when needed # if hasattr(widget, 'cleanup_conn'): # widget.cleanup_conn.connect(self.clean_connection) self._stackedWidget.setCurrentWidget(widget) def get_instance(self, type): for inst in self._docks: if isinstance(inst, type): return inst return None def remove_instance(self, inst): if self.is_editing(): self.set_editing(False) self._docks.remove(inst) self._stackedWidget.removeWidget(inst) self._stackedWidget.setCurrentWidget(self._overview) self._overview.refresh() def closeEvent(self, event): message = unicode("Deseja mesmo sair?".decode('utf-8')) reply = QMessageBox.question(self, 'Seareiros', message, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()
class Gui(): """main gui class""" def __init__(self): self.mainwindow = QMainWindow() settings.get_settings() self.access = tuple(settings.access.items()) self.progress = QProgressDialog("Setting up modules...", "cancel", 0, 7, self.mainwindow) self.progress.setWindowTitle( QApplication.translate("MainWindow", str(settings.company), None, QApplication.UnicodeUTF8)) def setup(self): """initializes the uio of the erp client""" self.progress.setFixedWidth(1000) self.progress.setCancelButton(None) # self.progress.setWindowModality(Qt.WindowModal) self.progress.setValue(1) self.mainwindow.setObjectName("MainWindow") self.mainwindow.resize(832, 668) self.mainwindow.setStyleSheet( "QToolBar{\n" "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,\n" "stop:0 rgba(0,0,0),stop:1 rgb(162, 162, 162, 162));\n" "border: 0px;\n" "}\n" "QToolBar > QWidget{\n" "color:white;\n" "}\n" "QToolBar > QWidget:hover {\n" "background:transparent;\n" " }\n" "QToolBar > QWidget:checked {\n" "background:transparent;\n" " }\n" "#MainWindow{\n" "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,\n" "stop:0 rgba(0,0,0),stop:1 rgb(162, 162, 162, 162));\n" "border: 0px;\n" "}\n" "") self.centralWidget = QWidget(self.mainwindow) self.centralWidget.setObjectName("centralWidget") self.gridLayout_2 = QGridLayout(self.centralWidget) self.gridLayout_2.setObjectName("gridLayout_2") self.stackedWidget = QStackedWidget(self.centralWidget) self.stackedWidget.setStyleSheet("") self.stackedWidget.setObjectName("stackedWidget") self.shortcut = NewShortcut() scroll = QScrollArea() scroll.setWidget(self.shortcut.shortcut_setting) self.stackedWidget.addWidget(self.shortcut.shortcut_setting) self.home_page = QWidget() self.home_page.setObjectName("home_page") self.gridLayout = QGridLayout(self.home_page) self.gridLayout.setObjectName("gridLayout") self.billing_frame_2 = QFrame(self.home_page) self.billing_frame_2.setStyleSheet( "background-image:url(:/images/billing_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#6CBED2;") self.billing_frame_2.setFrameShape(QFrame.StyledPanel) self.billing_frame_2.setFrameShadow(QFrame.Raised) self.billing_frame_2.setObjectName("billing_frame_2") self.verticalLayout_4 = QVBoxLayout(self.billing_frame_2) self.verticalLayout_4.setObjectName("verticalLayout_4") spacerItem = QSpacerItem(20, 217, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_4.addItem(spacerItem) self.label_10 = QLabel(self.billing_frame_2) self.label_10.setStyleSheet("background:transparent;") self.label_10.setObjectName("label_10") self.verticalLayout_4.addWidget(self.label_10) self.gridLayout.addWidget(self.billing_frame_2, 0, 1, 1, 1) self.employee_frame_3 = QFrame(self.home_page) self.employee_frame_3.setStyleSheet( "background-image:url(:/images/employee_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#0099CC;") self.employee_frame_3.setFrameShape(QFrame.StyledPanel) self.employee_frame_3.setFrameShadow(QFrame.Raised) self.employee_frame_3.setObjectName("employee_frame_3") self.verticalLayout_5 = QVBoxLayout(self.employee_frame_3) self.verticalLayout_5.setObjectName("verticalLayout_5") spacerItem1 = QSpacerItem(20, 217, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_5.addItem(spacerItem1) self.label_11 = QLabel(self.employee_frame_3) self.label_11.setStyleSheet("background:transparent;") self.label_11.setObjectName("label_11") self.verticalLayout_5.addWidget(self.label_11) self.gridLayout.addWidget(self.employee_frame_3, 0, 2, 1, 1) self.menu_frame_4 = QFrame(self.home_page) self.menu_frame_4.setStyleSheet( "background-image:url(:/images/menu_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#297ACC;") self.menu_frame_4.setFrameShape(QFrame.StyledPanel) self.menu_frame_4.setFrameShadow(QFrame.Raised) self.menu_frame_4.setObjectName("menu_frame_4") self.verticalLayout_3 = QVBoxLayout(self.menu_frame_4) self.verticalLayout_3.setObjectName("verticalLayout_3") spacerItem2 = QSpacerItem(20, 216, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_3.addItem(spacerItem2) self.label_12 = QLabel(self.menu_frame_4) self.label_12.setStyleSheet("background:transparent;") self.label_12.setObjectName("label_12") self.verticalLayout_3.addWidget(self.label_12) self.gridLayout.addWidget(self.menu_frame_4, 1, 0, 1, 1) self.report_frame_5 = QFrame(self.home_page) self.report_frame_5.setStyleSheet( "background-image:url(:/images/report_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#006BB2;") self.report_frame_5.setFrameShape(QFrame.StyledPanel) self.report_frame_5.setFrameShadow(QFrame.Raised) self.report_frame_5.setObjectName("report_frame_5") self.verticalLayout_6 = QVBoxLayout(self.report_frame_5) self.verticalLayout_6.setObjectName("verticalLayout_6") spacerItem3 = QSpacerItem(20, 216, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_6.addItem(spacerItem3) self.label_13 = QLabel(self.report_frame_5) self.label_13.setStyleSheet("background:transparent;") self.label_13.setObjectName("label_13") self.verticalLayout_6.addWidget(self.label_13) self.gridLayout.addWidget(self.report_frame_5, 1, 1, 1, 1) self.waste_frame_6 = QFrame(self.home_page) self.waste_frame_6.setStyleSheet( "background-image:url(:/images/waste_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#003D7A;") self.waste_frame_6.setFrameShape(QFrame.StyledPanel) self.waste_frame_6.setFrameShadow(QFrame.Raised) self.waste_frame_6.setObjectName("waste_frame_6") self.verticalLayout_7 = QVBoxLayout(self.waste_frame_6) self.verticalLayout_7.setObjectName("verticalLayout_7") spacerItem4 = QSpacerItem(20, 216, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_7.addItem(spacerItem4) self.label_14 = QLabel(self.waste_frame_6) self.label_14.setStyleSheet("background:transparent;") self.label_14.setObjectName("label_14") self.verticalLayout_7.addWidget(self.label_14) self.gridLayout.addWidget(self.waste_frame_6, 1, 2, 1, 1) self.inventory_frame_1 = QFrame(self.home_page) self.inventory_frame_1.setStyleSheet( "background-image:url(:/images/inventory_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#ADEBFF;") self.inventory_frame_1.setFrameShape(QFrame.StyledPanel) self.inventory_frame_1.setFrameShadow(QFrame.Raised) self.inventory_frame_1.setObjectName("inventory_frame_1") self.verticalLayout_2 = QVBoxLayout(self.inventory_frame_1) self.verticalLayout_2.setObjectName("verticalLayout_2") spacerItem5 = QSpacerItem(20, 217, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem5) self.label_9 = QLabel(self.inventory_frame_1) self.label_9.setStyleSheet("background:transparent;") self.label_9.setObjectName("label_9") self.verticalLayout_2.addWidget(self.label_9) self.gridLayout.addWidget(self.inventory_frame_1, 0, 0, 1, 1) self.stackedWidget.addWidget(self.home_page) self.detail_page = QWidget() self.detail_page.setObjectName("detail_page") self.horizontalLayout_2 = QHBoxLayout(self.detail_page) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.main_tabWidget = QTabWidget(self.detail_page) self.main_tabWidget.setAutoFillBackground(False) self.main_tabWidget.setStyleSheet("") self.main_tabWidget.setTabPosition(QTabWidget.West) self.main_tabWidget.setIconSize(QSize(60, 60)) self.main_tabWidget.setElideMode(Qt.ElideNone) self.main_tabWidget.setObjectName("main_tabWidget") ##initializes the tabs self.add_tabs() self.main_tabWidget.setFocusPolicy(Qt.StrongFocus) self.main_tabWidget.focusInEvent = self.change_focus self.main_tabWidget.currentChanged.connect(self.change_focus) self.stackedWidget.currentChanged.connect(self.change_focus) ###### self.horizontalLayout_2.addWidget(self.main_tabWidget) self.stackedWidget.addWidget(self.detail_page) if ('Admin', True) in self.access: self.stackedWidget.addWidget(Admin(self.mainwindow)) notification = NotificationTab() tab = notification.notificationTab_tab_4 tab.custom_class_object = notification # class_object is used to access the api through the self.stackedWidget.addWidget(tab) self.gridLayout_2.addWidget(self.stackedWidget, 0, 0, 1, 1) self.mainwindow.setCentralWidget(self.centralWidget) self.menuBar = QMenuBar(self.mainwindow) self.menuBar.setGeometry(QRect(0, 0, 832, 29)) self.menuBar.setObjectName("menuBar") self.mainwindow.setMenuBar(self.menuBar) self.mainToolBar = QToolBar(self.mainwindow) self.mainToolBar.setLayoutDirection(Qt.RightToLeft) self.mainToolBar.setStyleSheet("") self.mainToolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.mainToolBar.setObjectName("mainToolBar") self.mainwindow.addToolBar(Qt.TopToolBarArea, self.mainToolBar) self.statusBar = QStatusBar(self.mainwindow) self.statusBar.setObjectName("statusBar") self.mainwindow.setStatusBar(self.statusBar) self.toolBar = QToolBar(self.mainwindow) self.toolBar.setLayoutDirection(Qt.RightToLeft) self.toolBar.setStyleSheet("") self.toolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.toolBar.setObjectName("toolBar") self.mainwindow.addToolBar(Qt.TopToolBarArea, self.toolBar) self.actionNotification = QAction(self.mainwindow) self.actionNotification.setCheckable(True) self.actionNotification.setChecked(False) self.actionNotification.setEnabled(True) icon6 = QIcon() icon6.addPixmap(QPixmap(":/images/notification.png"), QIcon.Normal, QIcon.Off) self.actionNotification.setIcon(icon6) self.actionNotification.setAutoRepeat(True) self.actionNotification.setVisible(True) self.actionNotification.setIconVisibleInMenu(False) self.actionNotification.setObjectName("actionNotification") self.actionNotification self.actionAdmin = QAction(self.mainwindow) # self.actionAdmin.setCheckable(True) icon7 = QIcon() icon7.addPixmap(QPixmap(":/images/admin.png"), QIcon.Normal, QIcon.Off) self.actionAdmin.setIcon(icon7) self.actionAdmin.setObjectName("actionAdmin") self.actionRefresh = QAction(self.mainwindow) icon8 = QIcon() icon8.addPixmap(QPixmap(":/images/refresh.png"), QIcon.Normal, QIcon.Off) self.actionRefresh.setIcon(icon8) self.actionRefresh.setObjectName("actionRefresh") self.actionHome = QAction(self.mainwindow) # self.actionHome.setCheckable(True) icon9 = QIcon() icon9.addPixmap(QPixmap(":/images/home.png"), QIcon.Normal, QIcon.Off) self.actionHome.setIcon(icon9) self.actionHome.setObjectName("actionHome") self.actionSettings = QAction(self.mainwindow) icon10 = QIcon() icon10.addPixmap(QPixmap(":/images/settings.png"), QIcon.Normal, QIcon.Off) self.actionSettings.setIcon(icon10) self.actionSettings.setObjectName("actionRefresh") self.toolBar.addAction(self.actionNotification) self.toolBar.addSeparator() self.toolBar.addAction(self.actionAdmin) if ('Admin', True) in self.access: self.toolBar.addSeparator() else: self.actionAdmin.setVisible(False) self.toolBar.addAction(self.actionHome) self.toolBar.addSeparator() self.toolBar.addAction(self.actionRefresh) self.toolBar.addSeparator() self.toolBar.addAction(self.actionSettings) ##retranslates self.mainwindow.setWindowTitle( QApplication.translate("MainWindow", settings.company, None, QApplication.UnicodeUTF8)) self.label_10.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">BILLING</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_11.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">EMPLOYEE</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_12.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">MENU</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_13.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">REPORT</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_14.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">WASTE</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_9.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">INVENTORY</p></body></html>", None, QApplication.UnicodeUTF8)) self.inventory_frame_1.setToolTip( QApplication.translate("MainWindow", "Go to the Inventory Tab", None, QApplication.UnicodeUTF8)) self.billing_frame_2.setToolTip( QApplication.translate("MainWindow", "Go to the Billing Tab", None, QApplication.UnicodeUTF8)) self.employee_frame_3.setToolTip( QApplication.translate("MainWindow", "Go to the Employee Tab", None, QApplication.UnicodeUTF8)) self.menu_frame_4.setToolTip( QApplication.translate("MainWindow", "Go to the Menu Tab", None, QApplication.UnicodeUTF8)) self.report_frame_5.setToolTip( QApplication.translate("MainWindow", "Go to the Report Tab", None, QApplication.UnicodeUTF8)) self.waste_frame_6.setToolTip( QApplication.translate("MainWindow", "Go to the Waste Tab", None, QApplication.UnicodeUTF8)) self.toolBar.setWindowTitle( QApplication.translate("MainWindow", "toolBar", None, QApplication.UnicodeUTF8)) self.actionNotification.setText("&&Notification") # QApplication.translate("MainWindow", "&Notification", None, QApplication.UnicodeUTF8)) self.actionNotification.setToolTip( QApplication.translate("MainWindow", "Click to see new notifications", None, QApplication.UnicodeUTF8)) # self.actionNotification.setShortcut( # QApplication.translate("MainWindow", "Ctrl+Shift+N", None, QApplication.UnicodeUTF8)) self.actionAdmin.setText('&&Admin') # QApplication.translate("MainWindow", "Admin", None, QApplication.UnicodeUTF8)) self.actionAdmin.setToolTip( QApplication.translate("MainWindow", "Click to go to admin interface", None, QApplication.UnicodeUTF8)) # self.actionAdmin.setShortcut( # QApplication.translate("MainWindow", "Ctrl+Shift+A", None, QApplication.UnicodeUTF8)) self.actionRefresh.setText("&&Refresh") # QApplication.translate("MainWindow", "Refresh", None, QApplication.UnicodeUTF8)) self.actionRefresh.setToolTip( QApplication.translate("MainWindow", "refreshes the data from the server", None, QApplication.UnicodeUTF8)) # self.actionRefresh.setShortcut( # QApplication.translate("MainWindow", "Ctrl+Shift+R", None, QApplication.UnicodeUTF8)) self.actionHome.setText('&&Home') # QApplication.translate("MainWindow", "Home", None, QApplication.UnicodeUTF8)) self.actionHome.setToolTip( QApplication.translate("MainWindow", "Go back to the home screen", None, QApplication.UnicodeUTF8)) self.actionSettings.setText('&&Settings') # QApplication.translate("MainWindow", "Settings", None, QApplication.UnicodeUTF8)) self.actionSettings.setToolTip( QApplication.translate("MainWindow", "Go to the settings panel", None, QApplication.UnicodeUTF8)) # self.actionHome.setShortcut( # QApplication.translate("MainWindow", "Ctrl+Shift+H", None, QApplication.UnicodeUTF8)) self.stackedWidget.setCurrentIndex(1) self.main_tabWidget.setCurrentIndex(0) self.ob = self.main_tabWidget.tabBar() # self.add_tool_tip(self.ob) todo avoided due to segmentation fault error, left for future fixes self.tb = EventHandlerForTabBar() self.ob.installEventFilter(self.tb) QMetaObject.connectSlotsByName(self.mainwindow) def add_tabs(self): """ adds new tabs """ global logger if ('Inventory', True) in self.access: logger.info('initiating Inventory') icon = QIcon() icon.addPixmap(QPixmap(":/images/inventory.png"), QIcon.Normal, QIcon.Off) from inventory.inventory import Inventory inventory = Inventory() # inventory.inventory_tab_1.setToolTip("Inventory Section") self.main_tabWidget.addTab(inventory.inventory_tab_1, icon, "") inventory.inventory_detail_tabWidget.setCurrentIndex(0) else: self.inventory_frame_1.setVisible(False) self.progress.setLabelText('Inventory Done....') self.progress.setValue(2) if ('Billing', True) in self.access: logger.info('initiating Billing') icon1 = QIcon() icon1.addPixmap(QPixmap(":/images/billing.png"), QIcon.Normal, QIcon.Off) from billing.billing import Billing bill = Billing() # bill.billing_tab_2.setToolTip("Billing Section") self.main_tabWidget.addTab(bill.billing_tab_2, icon1, "") bill.billing_detail_tabWidget.setCurrentIndex(0) else: self.billing_frame_2.setVisible(False) self.progress.setLabelText('Billing Done...') self.progress.setValue(3) if ('Employee', True) in self.access: logger.info('initiating Employee') icon2 = QIcon() icon2.addPixmap(QPixmap(":/images/employee.png"), QIcon.Normal, QIcon.Off) from employee.employee import Employee employee = Employee() # employee.employee_tab_3.setToolTip("Employee Section") self.main_tabWidget.addTab(employee.employee_tab_3, icon2, "") employee.employee_detail_tabWidget.setCurrentIndex(0) else: self.employee_frame_3.setVisible(False) self.progress.setLabelText('Employee Done...') self.progress.setValue(4) if ('Menu', True) in self.access: logger.info('initiating Menu') icon3 = QIcon() icon3.addPixmap(QPixmap(":/images/menu.png"), QIcon.Normal, QIcon.Off) from menu.menu import Menu menu = Menu() # menu.menu_tab_4.setToolTip("Menu Section") self.main_tabWidget.addTab(menu.menu_tab_4, icon3, "") menu.menu_detail_tabWidget.setCurrentIndex(0) else: self.menu_frame_4.setVisible(False) self.progress.setLabelText('Menu Done....') self.progress.setValue(5) if ('Report', True) in self.access: logger.info('initiating Report') icon4 = QIcon() icon4.addPixmap(QPixmap(":/images/report.png"), QIcon.Normal, QIcon.Off) from report.report import Report report = Report() # report.report_tab_5.setToolTip("Report Section") self.main_tabWidget.addTab(report.report_tab_5, icon4, "") report.report_detail_tabWidget.setCurrentIndex(0) else: self.report_frame_5.setVisible(False) self.progress.setLabelText('Report Done....') self.progress.setValue(6) if ('Waste', True) in self.access: logger.info('initiating Waste') icon5 = QIcon() icon5.addPixmap(QPixmap(":/images/waste.png"), QIcon.Normal, QIcon.Off) from waste.waste import Waste waste = Waste() # waste.waste_tab_6.setToolTip("Waste Section") self.main_tabWidget.addTab(waste.waste_tab_6, icon5, "") waste.waste_detail_tabWidget.setCurrentIndex(0) else: self.waste_frame_6.setVisible(False) self.progress.setLabelText('Waste Done....') self.progress.setValue(7) def change_focus(self, event=None): """ focus method to set focus to a tab to initialize the corresponding events of the tab """ wid = self.main_tabWidget.currentWidget() if wid: if wid.isVisible(): # print wid.objectName() # print '1y' wid.setFocus() def add_tool_tip( self, ob ): # todo not working causing segmentation fault, avoided calling this function """ method to add tool tip to the tabs :param ob: Tab bar """ obj = ob count = obj.count() hardcode = { 0: 'Inventory Section', 1: "Billing Section", 2: "Employee Section", 3: "Menu Section", 4: "Report Section", 5: "Waste Section" } for i in range(count): obj.setTabToolTip(i, hardcode[i])
class MainWindow(QMainWindow): def __init__(self, controller, joystickAdapter=None): super(MainWindow, self).__init__() self.controller = controller self.setWindowTitle("av-control") self.resize(1024, 600) self.setWindowIcon(QIcon(":icons/video-display")) atem = controller['ATEM'] self.switcherState = SwitcherState(atem) self.mainScreen = VideoSwitcher(controller, self, self.switcherState, joystickAdapter) # This is possibly a bad / too complicated idea... # self.mainScreen.setEnabled(self.switcherState.connected) # self.switcherState.connectionChanged.connect(self.mainScreen.setEnabled) self.stack = QStackedWidget() self.stack.addWidget(self.mainScreen) outer = QWidget() mainLayout = QGridLayout() mainLayout.addWidget(self.stack, 0, 0, 1, 7) column = 0 self.spc = SystemPowerWidget(controller, self) syspower = ExpandingButton() syspower.setText("Power") syspower.clicked.connect(self.showSystemPower) syspower.setIcon(QIcon(":icons/system-shutdown")) syspower.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(syspower, 1, column) column += 1 if controller.hasDevice("Blinds"): self.bc = BlindsControl(controller["Blinds"], self) blinds = ExpandingButton() blinds.setText("Blinds") blinds.clicked.connect(lambda: self.showScreen(self.bc)) blinds.setIcon(QIcon(":icons/blinds")) blinds.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(blinds, 1, column) column += 1 if controller.hasDevice("Lights"): self.lightsMenu = LightingControl(controller["Lights"], self) lights = ExpandingButton() lights.setText("Lights") lights.clicked.connect(lambda: self.showScreen(self.lightsMenu)) lights.setIcon(QIcon(":icons/lightbulb_on")) lights.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) mainLayout.addWidget(lights, 1, column) column += 1 if controller.hasDevice("Recorder"): hyperdeck = controller['Recorder'] self.hyperdeckState = HyperdeckState(hyperdeck) self.recorderScreen = RecorderControl(hyperdeck, atem, self.hyperdeckState, self) recorder = ExpandingButton() recorder.setText("Recorder") recorder.setIcon(QIcon(":icons/drive-optical")) recorder.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) recorder.clicked.connect(lambda: self.showScreen(self.recorderScreen)) mainLayout.addWidget(recorder, 1, column) column += 1 def update_recorder_icon(transport): if 'status' in transport: if transport['status'] == TransportState.RECORD: recorder.setIcon(QIcon(":icons/media-record")) elif transport['status'] == TransportState.PLAYING: recorder.setIcon(QIcon(":icons/media-playback-start")) else: recorder.setIcon(QIcon(":icons/drive-optical")) self.hyperdeckState.transportChange.connect(update_recorder_icon) self.advMenu = AdvancedMenu(self.controller, self.switcherState.mixTransition, atem, self) adv = ExpandingButton() adv.setText("Advanced") adv.setIcon(QIcon(":icons/applications-system")) adv.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) adv.clicked.connect(lambda: self.showScreen(self.advMenu)) mainLayout.addWidget(adv, 1, column) column += 1 for i in range(column): mainLayout.setColumnStretch(i, 1) tray = QHBoxLayout() tray.addWidget(Clock()) tray.addWidget(SystemStatus(controller)) mainLayout.addLayout(tray, 1, column) mainLayout.setRowStretch(0, 8) mainLayout.setRowStretch(1, 0) outer.setLayout(mainLayout) self.setCentralWidget(outer) self.pnd = PowerNotificationDialog(self) self.pnd.accepted.connect(self.hidePowerDialog) def showScreen(self, screenWidget): if self.stack.currentWidget() == screenWidget: self.stepBack() else: self.stack.insertWidget(0, screenWidget) self.stack.setCurrentWidget(screenWidget) def showSystemPower(self): self.showScreen(self.spc) def stepBack(self): self.stack.removeWidget(self.stack.currentWidget()) def errorBox(self, text): Dialogs.errorBox(text) def showPowerDialog(self, message): self.pnd.message = message self.pnd.exec_() def hidePowerDialog(self): self.pnd.close() if self.stack.currentWidget() == self.spc: self.stepBack() def updateOutputMappings(self, deviceID, mapping): self.mainScreen.updateOutputMappings({deviceID: mapping}) def handleMessage(self, msgType, sourceDeviceID, data): if msgType == MessageTypes.SHOW_POWER_ON: self.showPowerDialog(StringConstants.poweringOn) elif msgType == MessageTypes.SHOW_POWER_OFF: self.showPowerDialog(StringConstants.poweringOff) elif msgType == MessageTypes.HIDE_POWER: self.hidePowerDialog() elif sourceDeviceID == "ATEM": self.switcherState.handleMessage(msgType, data) elif sourceDeviceID == "Recorder": self.hyperdeckState.handleMessage(msgType, data)
class PysideGui(generic.GenericGui): def __init__(self): generic.GenericGui.__init__(self) window = QWidget() window.setWindowTitle('quichem-pyside') self.compiler_view = QListWidget() self.compiler_view.currentRowChanged.connect(self.show_source) self.stacked_widget = QStackedWidget() self.stacked_widget.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) self.edit = QLineEdit() self.edit.setPlaceholderText('Type quichem input...') self.edit.textChanged.connect(self.change_value) self.view = QWebView() self.view.page().mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff) self.view.page().action(QWebPage.Reload).setVisible(False) self.view.setMaximumHeight(0) self.view.setUrl('qrc:/web/page.html') self.view.setZoomFactor(2) self.view.page().mainFrame().contentsSizeChanged.connect( self._resize_view) # For debugging JS: ## from PySide.QtWebKit import QWebSettings ## QWebSettings.globalSettings().setAttribute( ## QWebSettings.DeveloperExtrasEnabled, True) button_image = QPushButton('Copy as Image') button_image.clicked.connect(self.set_clipboard_image) button_image.setToolTip('Then paste into any graphics program') button_word = QPushButton('Copy as MS Word Equation') button_word.clicked.connect(self.set_clipboard_word) button_html = QPushButton('Copy as Formatted Text') button_html.clicked.connect(self.set_clipboard_html) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) button_layout = QHBoxLayout() button_layout.addStretch() button_layout.addWidget(button_image) button_layout.addWidget(button_word) button_layout.addWidget(button_html) source_layout = QHBoxLayout() source_layout.addWidget(self.compiler_view) source_layout.addWidget(self.stacked_widget, 1) QVBoxLayout(window) window.layout().addWidget(self.edit) window.layout().addWidget(self.view) window.layout().addLayout(button_layout) window.layout().addWidget(line) window.layout().addLayout(source_layout, 1) window.show() window.resize(window.minimumWidth(), window.height()) # To prevent garbage collection of internal Qt object. self._window = window def show_source(self, index): if not self.sources: return self.stacked_widget.setCurrentIndex(index) self.change_value(self.edit.text()) def _resize_view(self): """Set the QWebView's minimum height based on its current contents. """ div = self.view.page().mainFrame().findFirstElement('.output') scrollbar_width = QApplication.style().pixelMetric( QStyle.PM_ScrollBarExtent) self.view.setMaximumHeight( div.geometry().height() + scrollbar_width + 16) def make_source(self, name): self.compiler_view.addItem(name) self.compiler_view.setCurrentRow(0) scrollbar_width = QApplication.style().pixelMetric( QStyle.PM_ScrollBarExtent) self.compiler_view.setMaximumWidth( self.compiler_view.sizeHintForColumn(0) + scrollbar_width + 16) page = QWidget() QHBoxLayout(page) page.layout().setContentsMargins(*(0,) * 4) source = QTextEdit() source.setStyleSheet('min-width: 0; min-height: 0') source.setReadOnly(True) QVBoxLayout(source) button = QPushButton('Copy') button.clicked.connect(functools.partial(self.set_clipboard, source)) page.layout().addWidget(source) source.layout().addWidget(button, 0, Qt.AlignRight | Qt.AlignBottom) self.stacked_widget.addWidget(page) return source def run_script(self, js): self.view.page().mainFrame().evaluateJavaScript(js) def set_source(self, widget, source_factory): if widget.isVisible(): widget.setPlainText(source_factory()) def set_clipboard_image(self): """Export the formatted output to an image and store it in the clipboard. The image stored in the clipboard is a PNG file with alpha transparency. """ div = self.view.page().mainFrame().findFirstElement('.output') images = {} for background in (Qt.transparent, Qt.white): image = QImage(div.geometry().size(), QImage.Format_ARGB32_Premultiplied) image.fill(background) painter = QPainter(image) div.render(painter) painter.end() images[background] = image # Windows needs this buffer hack to get alpha transparency in # the copied PNG. buffer_ = QBuffer() buffer_.open(QIODevice.WriteOnly) images[Qt.transparent].save(buffer_, 'PNG') buffer_.close() data = QMimeData() data.setData('PNG', buffer_.data()) data.setImageData(images[Qt.white]) QApplication.clipboard().setMimeData(data) def set_clipboard_word(self): """Store the formatted output in the clipboard in a Microsoft Word friendly format. Microsoft Word interprets the clipboard contents as an equation. Other programs will see it as plain text containing XML. """ QApplication.clipboard().setText(generic.word_equation_from_mathml( self.view.page().mainFrame().evaluateJavaScript(generic.MML_JS))) def set_clipboard_html(self): """Place the HTML displayed in the HTML view widget into the system clipboard. """ data = QMimeData() data.setText(self.plain) data.setHtml(self.html) QApplication.clipboard().setMimeData(data) def set_clipboard(self, source): """Place the text displayed in the given source widget into the system clipboard. """ QApplication.clipboard().setText(source.toPlainText())