class ToolBar(QToolBar): def __init__(self, *, model): self._toolBar = QToolBar(parent=self) prevImage = self._toolBar.addAction('prev') prevImage.triggered.connect(model.moveToPrevImage) nextImage = self._toolBar.addAction('next') nextImage.triggered.connect(self.moveToNextImage)
def testReference(self): toolbar = QToolBar() for i in xrange(20): toolbar.addAction(QAction("Action %d" % i, None)) buttons = toolbar.findChildren(QToolButton, "") toolbar.clear() for b in buttons: self.assertRaises(RuntimeError, b.objectName)
def testReference(self): toolbar = QToolBar() for i in xrange(20): toolbar.addAction(QAction("Action %d" % i, None)) buttons = toolbar.findChildren(QToolButton, "") toolbar.clear() for b in buttons: self.assertRaises(RuntimeError, b.objectName)
def _initUI(self): # Variables self._widgets = {} tbl_model = self._LimitTableModel() # Widgets self._cb_limit = QComboBox() self._cb_limit.setModel(self._LimitComboBoxModel()) btn_limit_add = QPushButton() btn_limit_add.setIcon(getIcon("list-add")) self._tbl_limit = QTableView() self._tbl_limit.setModel(tbl_model) self._tbl_limit.setItemDelegate(self._LimitTableDelegate()) header = self._tbl_limit.horizontalHeader() header.setResizeMode(QHeaderView.Stretch) header.hide() policy = self._tbl_limit.sizePolicy() policy.setVerticalStretch(True) self._tbl_limit.setSizePolicy(policy) tlb_limit = QToolBar() spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) tlb_limit.addWidget(spacer) act_remove = tlb_limit.addAction(getIcon("list-remove"), "Remove limit") act_clear = tlb_limit.addAction(getIcon("edit-clear"), "Clear") # Layouts layout = _ExpandableOptionsWizardPage._initUI(self) sublayout = QHBoxLayout() sublayout.addWidget(self._cb_limit, 1) sublayout.addWidget(btn_limit_add) layout.addRow("Select", sublayout) layout.addRow(self._tbl_limit) layout.addRow(tlb_limit) # Signals btn_limit_add.released.connect(self._onLimitAdd) act_remove.triggered.connect(self._onLimitRemove) act_clear.triggered.connect(self._onLimitClear) self._tbl_limit.doubleClicked.connect(self._onLimitDoubleClicked) tbl_model.dataChanged.connect(self.valueChanged) tbl_model.rowsInserted.connect(self.valueChanged) tbl_model.rowsRemoved.connect(self.valueChanged) return layout
def testAddActionWithIcon(self): bar = QToolBar() self._called = False icon = QIcon() a = bar.addAction(icon, "act1", self.callback) a.trigger() self.assert_(self._called)
def testAddActionWithIcon(self): bar = QToolBar() self._called = False icon = QIcon() a = bar.addAction(icon, "act1", self.callback) a.trigger() self.assert_(self._called)
def qtoolbar(self): toolbar = QToolBar(self.name, self.window) for action in self.actions: if isinstance(action, ToolbarSplitter): toolbar.addSeparator() else: if action.icon is not None: act = QAction(action.icon, action.name, toolbar) else: act = QAction(action.name, toolbar) if action.triggered is not None: act.triggered.connect(action.triggered) if action.tooltip: act.setToolTip(action.tooltip) toolbar.addAction(act) return toolbar
def _initUI(self): # Widgets self._cb_model_type = QComboBox() self._cb_model_type.setModel(self._ModelTypeComboBoxModel()) self._cb_model = QComboBox() self._cb_model.setModel(self._ModelComboBoxModel()) self._cb_model.setMaxVisibleItems(10) btn_model_add = QPushButton() btn_model_add.setIcon(getIcon("list-add")) self._tbl_model = ModelTableWidget() tlb_model = QToolBar() spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) tlb_model.addWidget(spacer) act_remove = tlb_model.addAction(getIcon("list-remove"), "Remove model") act_clear = tlb_model.addAction(getIcon("edit-clear"), "Clear") # Layouts layout = _ExpandableOptionsWizardPage._initUI(self) sublayout = QHBoxLayout() sublayout.addWidget(self._cb_model_type, 1) sublayout.addWidget(self._cb_model, 1) sublayout.addWidget(btn_model_add) layout.addRow("Select", sublayout) layout.addRow(self._tbl_model) layout.addRow(tlb_model) # Signals btn_model_add.released.connect(self._onModelAdd) act_remove.triggered.connect(self._onModelRemove) act_clear.triggered.connect(self._onModelClear) self._cb_model_type.currentIndexChanged.connect(self._onModelTypeChanged) self._tbl_model.dataChanged.connect(self.valueChanged) return layout
def testToolBar(self): self._actionDestroyed = False w = QWidget() toolBar = QToolBar(w) act = toolBar.addAction("MENU") _ref = weakref.ref(act, self.actionDestroyed) act = None self.assertFalse(self._actionDestroyed) toolBar.clear() self.assertTrue(self._actionDestroyed)
def testToolBar(self): self._actionDestroyed = False w = QWidget() toolBar = QToolBar(w) act = toolBar.addAction("MENU") _ref = weakref.ref(act, self.actionDestroyed) act = None self.assertFalse(self._actionDestroyed) toolBar.clear() self.assertTrue(self._actionDestroyed)
class LayerListWithToolBar(QWidget): def __init__(self): super(LayerListWithToolBar, self).__init__() layout = QVBoxLayout() self.setLayout(layout) self.list = LayerList() self.toolbar = QToolBar() add_action = self.toolbar.addAction( QIcon.fromTheme('list-add'), 'add', ).triggered.connect(self._add) remove_action = self.toolbar.addAction( QIcon.fromTheme('list-remove'), 'remove', ).triggered.connect(self._remove) self.layout().addWidget(self.toolbar) self.layout().addWidget(self.list) def _add(self): dialog = QFileDialog(self) dialog.setFileMode(QFileDialog.ExistingFiles) dialog.setViewMode(QFileDialog.Detail) fileNames = dialog.selectedFiles() if dialog.exec_() else [] for fileName in fileNames: layer = Layer() layer.load_file(fileName, None) self.list.add_layer(layer) def _remove(self): rows = sorted({index.row() for index in self.list.selectedIndexes()}) for row in reversed(rows): self.list.remove_layer(row) def add_layer(self, layer): self.list.add_layer(layer) def __iter__(self): return self.list.__iter__() def multiplyOrientation(self, quat): self.list.multiplyOrientation(quat)
def create(self, window: QtGui.QMainWindow, parent: QtGui.QToolBar): if self.disabled: return if callable(self.method_name): method = self.method_name else: method = getattr(window, self.method_name) if self.sep: parent.addSeparator() if self.icon: action = QtGui.QAction(get_icon(self.icon), self.verbose_name, p(window)) else: action = QtGui.QAction(self.verbose_name, p(window)) # noinspection PyUnresolvedReferences action.triggered.connect(method) parent.addAction(action) if self.shortcut: action.setShortcut(self.shortcut) if self.help_text: action.setStatusTip(self.help_text)
class AbstractContext(QWidget): def __init__(self, parent, labels): super(AbstractContext, self).__init__(parent) self.add = QAction(QIcon(":/img/add.png"), self.tr("Add"), self) self.delete = QAction(QIcon(":/img/delete.png"), self.tr("Delete"), self) self.edit = QAction(QIcon(":/img/edit.png"), self.tr("Edit"), self) self.print_ = QAction(QIcon(":/img/print.png"), self.tr("Print"), self) self.toolbar = QToolBar(self.tr("Controls"), self) self.toolbar.addAction(self.add) self.toolbar.addAction(self.delete) self.toolbar.addAction(self.edit) self.toolbar.addAction(self.print_) self.entries = QTreeWidget(self) self.entries.setHeaderLabels(labels) self.search = QLineEdit(self) self.search_by = QComboBox(self) self.search_by.insertItems(len(labels), labels) layout = QGridLayout(self) layout.addWidget(self.toolbar, 0, 0) layout.addWidget(self.entries, 1, 0, 1, 8) layout.addWidget(QLabel(self.tr("Search for:"), self), 2, 0) layout.addWidget(self.search, 2, 1) layout.addWidget(QLabel(self.tr("by"), self), 2, 2) layout.addWidget(self.search_by, 2, 3) def add_entry(self, entry): pass def delete_entry(self, entry): index = self.entries.indexOfTopLevelItem(entry) self.entries.takeTopLevelItem(index) def edit_entry(self, entry, new_data): for column, data in new_data: entry.setText(column, data) def confirm_deletion(self, what): return True
class AddActionText(UsesQApplication): '''Test case for calling QToolbar.addAction passing a text''' def setUp(self): #Acquire resources super(AddActionText, self).setUp() self.window = QMainWindow() self.toolbar = QToolBar() self.window.addToolBar(self.toolbar) def tearDown(self): #Release resources super(AddActionText, self).tearDown() del self.toolbar del self.window def testText(self): #QToolBar.addAction(text) - add a QToolButton self.toolbar.addAction('aaaa') self.assertEqual(len(self.toolbar.actions()), 1) action = self.toolbar.actions()[0] self.assert_(isinstance(action, QAction)) self.assertEqual(action.text(), 'aaaa')
class AddActionText(UsesQApplication): '''Test case for calling QToolbar.addAction passing a text''' def setUp(self): #Acquire resources super(AddActionText, self).setUp() self.window = QMainWindow() self.toolbar = QToolBar() self.window.addToolBar(self.toolbar) def tearDown(self): #Release resources super(AddActionText, self).tearDown() del self.toolbar del self.window def testText(self): #QToolBar.addAction(text) - add a QToolButton self.toolbar.addAction('aaaa') self.assertEqual(len(self.toolbar.actions()), 1) action = self.toolbar.actions()[0] self.assert_(isinstance(action, QAction)) self.assertEqual(action.text(), 'aaaa')
def __init__(self, U, plot, length=1, title=None): super(PlotMainWindow, self).__init__() layout = QVBoxLayout() if title: title = QLabel('<b>' + title + '</b>') title.setAlignment(Qt.AlignHCenter) layout.addWidget(title) layout.addWidget(plot) plot.set(U, 0) if length > 1: hlayout = QHBoxLayout() self.slider = QSlider(Qt.Horizontal) self.slider.setMinimum(0) self.slider.setMaximum(length - 1) self.slider.setTickPosition(QSlider.TicksBelow) hlayout.addWidget(self.slider) lcd = QLCDNumber(m.ceil(m.log10(length))) lcd.setDecMode() lcd.setSegmentStyle(QLCDNumber.Flat) hlayout.addWidget(lcd) layout.addLayout(hlayout) hlayout = QHBoxLayout() toolbar = QToolBar() self.a_play = QAction(self.style().standardIcon(QStyle.SP_MediaPlay), 'Play', self) self.a_play.setCheckable(True) self.a_rewind = QAction(self.style().standardIcon(QStyle.SP_MediaSeekBackward), 'Rewind', self) self.a_toend = QAction(self.style().standardIcon(QStyle.SP_MediaSeekForward), 'End', self) self.a_step_backward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipBackward), 'Step Back', self) self.a_step_forward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipForward), 'Step', self) self.a_loop = QAction(self.style().standardIcon(QStyle.SP_BrowserReload), 'Loop', self) self.a_loop.setCheckable(True) toolbar.addAction(self.a_play) toolbar.addAction(self.a_rewind) toolbar.addAction(self.a_toend) toolbar.addAction(self.a_step_backward) toolbar.addAction(self.a_step_forward) toolbar.addAction(self.a_loop) if hasattr(self, 'save'): self.a_save = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self) toolbar.addAction(self.a_save) self.a_save.triggered.connect(self.save) hlayout.addWidget(toolbar) self.speed = QSlider(Qt.Horizontal) self.speed.setMinimum(0) self.speed.setMaximum(100) hlayout.addWidget(QLabel('Speed:')) hlayout.addWidget(self.speed) layout.addLayout(hlayout) self.timer = QTimer() self.timer.timeout.connect(self.update_solution) self.slider.valueChanged.connect(self.slider_changed) self.slider.valueChanged.connect(lcd.display) self.speed.valueChanged.connect(self.speed_changed) self.a_play.toggled.connect(self.toggle_play) self.a_rewind.triggered.connect(self.rewind) self.a_toend.triggered.connect(self.to_end) self.a_step_forward.triggered.connect(self.step_forward) self.a_step_backward.triggered.connect(self.step_backward) self.speed.setValue(50) elif hasattr(self, 'save'): hlayout = QHBoxLayout() toolbar = QToolBar() self.a_save = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self) toolbar.addAction(self.a_save) hlayout.addWidget(toolbar) layout.addLayout(hlayout) self.a_save.triggered.connect(self.save) self.setLayout(layout) self.plot = plot self.U = U self.length = length
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])
def testAddAction(self): bar = QToolBar() self._called = False a = bar.addAction("act1", self.callback) a.trigger() self.assert_(self._called)
class MainWindow(QDialog): """monkey_linux UI""" def __init__(self,parent=None): super(MainWindow, self).__init__() self.init_conf() self.setParent(parent) common.Log.info("set up ui") self.setup_ui() self.findDeviceAction.triggered.connect(self.get_device_status) self.deleteDeviceAction.triggered.connect(self.del_device) # self.storeButton.clicked.connect(self.set_conf) self.startButton.clicked.connect(self.start) self.stopButton.clicked.connect(self.stop) self.checkLogButton.clicked.connect(self.check) self.monkeyButton.clicked.connect(self.checkMonkeyLog) self.exportButton.clicked.connect(self.exportConf) self.importButton.clicked.connect(self.importConf) self.setAbout.triggered.connect(self.about) self.startTime = datetime.datetime.now() self.secsTime = float(1) * 60 * 60 def setup_ui(self): # main window width hand height # self.setMinimumWidth(600) self.setMaximumWidth(800) self.setMinimumHeight(600) # main window title self.setWindowTitle(static.title) # file menu bar self.menuBar = QMenuBar() self.menuBar.setMaximumHeight(23) # self.menuFile = self.menuBar.addMenu(static.menuFile) # self.importAction = QAction(QIcon(static.importPNG), static.importFile, self) # self.exportAction = QAction(QIcon(static.exportPNG), static.exportFile, self) # self.menuFile.addAction(self.importAction) # self.menuFile.addAction(self.exportAction) self.setEnvActioin = QAction(QIcon(static.setPNG), static.pcSet, self) self.menuSet = self.menuBar.addMenu(static.menuSet) self.menuSet.addAction(self.setEnvActioin) self.setAbout = QAction(QIcon(static.setPNG), static.menuAbout, self) self.setAbout.setStatusTip('About') # 状态栏提示 self.menuHelp = self.menuBar.addMenu(static.menuHelp) self.menuHelp.addAction(self.setAbout) # set all layout self.hbox = QHBoxLayout(self) # device ======== self.topLeft = QFrame(self) self.topLeft.setMaximumSize(218, 300) self.topLeft.setMinimumSize(218, 200) self.topLeft.setFrameShape(QFrame.StyledPanel) self.topLeftLayout = QVBoxLayout(self.topLeft) self.toolBar = QToolBar() # self.androidDeviceAction = QRadioButton('Android', self) # self.androidDeviceAction.setFocusPolicy(Qt.NoFocus) # self.ipDeviceAction = QRadioButton('IP', self) # self.ipDeviceAction.setFocusPolicy(Qt.NoFocus) # self.ipDeviceAction.move(10, 10) # self.ipDeviceAction.toggle() self.findDeviceAction = QAction(QIcon(static.findDevice), static.findDeviceButton, self) self.deleteDeviceAction = QAction(QIcon(static.deleteDevice), static.deleteDeviceButton, self) # self.toolBar.addWidget(self.androidDeviceAction) # self.toolBar.addWidget(self.ipDeviceAction) self.toolBar.addAction(self.findDeviceAction) self.toolBar.addAction(self.deleteDeviceAction) self.deviceLab = QLabel(static.deviceName, self) self.device = QTableWidget(1, 2) self.device.setHorizontalHeaderLabels(['name', 'status']) self.device.setColumnWidth(0, 100) self.device.setColumnWidth(1, 80) self.topLeftLayout.addWidget(self.deviceLab) self.topLeftLayout.addWidget(self.toolBar) self.topLeftLayout.addWidget(self.device) # set button or other for running monkey or not and status of device and log ======== self.topRight = QFrame(self) self.topRight.setFrameShape(QFrame.StyledPanel) self.topRight.setMaximumHeight(40) self.startButton = QPushButton(QIcon(static.startPNG), "") self.stopButton = QPushButton(QIcon(static.stopPNG), "") self.status = QLabel(static.status) self.statusEdit = QLineEdit(self) self.statusEdit.setReadOnly(True) self.statusEdit.setMaximumWidth(80) self.statusEdit.setMinimumWidth(80) self.statusEdit.setText("") # check log self.checkLogButton = QPushButton(static.checkLog) self.checkLogButton.setMaximumHeight(20) self.checkLogButton.setMinimumHeight(20) self.checkLogButton.setMaximumWidth(60) self.selectLog = QLabel(static.selectlog) self.logfile = QComboBox() self.dirlist = os.listdir(os.path.join(DIR, "Result")) for d in self.dirlist: if d != "AutoMonkey.log": self.logfile.insertItem(0, d) self.logfile.setMaximumWidth(150) self.logfile.setMaximumHeight(20) self.logfile.setMinimumHeight(20) self.topLayout = QHBoxLayout(self.topRight) self.topLayout.addWidget(self.startButton) self.topLayout.addWidget(self.stopButton) self.topLayout.addWidget(self.status) self.topLayout.addWidget(self.statusEdit) self.topLayout.addWidget(self.selectLog) self.topLayout.addWidget(self.logfile) self.topLayout.addWidget(self.checkLogButton) # set parameter for monkey ======= self.midRight = QFrame(self) self.midRight.setMaximumSize(555, 200) self.midRight.setMinimumSize(555, 200) self.midRight.setFrameShape(QFrame.StyledPanel) self.midRightLayout = QVBoxLayout(self.midRight) self.subLayout0 = QVBoxLayout() self.subLayout1 = QVBoxLayout() self.subLayout2 = QHBoxLayout() self.subLayout3 = QVBoxLayout() self.subLayout4 = QVBoxLayout() self.subLayout5 = QHBoxLayout() self.subLayout6 = QHBoxLayout() self.toolBar = QToolBar() # self.storeAction = QAction(QIcon(static.storePNG), static.storeButton, self) self.startAction = QAction(QIcon(static.startPNG), static.startButton, self) self.stopAction = QAction(QIcon(static.stopPNG), static.stopButton, self) # self.toolBar.addAction(self.storeAction) self.toolBar.addAction(self.startAction) self.toolBar.addAction(self.stopAction) self.timeLongLbl = QLabel(static.timeString, self) self.timeLong = QLineEdit(self) self.timeLong.setMaximumWidth(100) self.timeLong.setMinimumWidth(100) self.timeLong.setPlaceholderText(static.timeLong) self.timeLongUnit = QLabel("H") self.etSetLbl = QLabel(static.eventTypeSet) self.etSet = QTableWidget(2, 2) self.etSet.setMaximumHeight(150) self.etSet.setHorizontalHeaderLabels(['option', 'value']) self.etSet.horizontalHeader().setStretchLastSection(True) self.etSet.setItem(0, 0, QTableWidgetItem("--throttle")) self.etSet.setItem(0, 1, QTableWidgetItem(str(static.eventType["--throttle"]))) # set event type percent self.etPercentLbl = QLabel(static.eventTpyePercent, self) self.etPercent = QTableWidget(2, 2) self.etPercent.setMaximumHeight(150) self.etPercent.setHorizontalHeaderLabels(['option', 'value']) self.etPercent.horizontalHeader().setStretchLastSection(True) self.etPercent.setItem(0, 0, QTableWidgetItem("--pct-touch")) self.etPercent.setItem(0, 1, QTableWidgetItem(str(static.eventPercent["--pct-touch"]))) self.etPercent.setItem(1, 0, QTableWidgetItem("--pct-motion")) self.etPercent.setItem(1, 1, QTableWidgetItem(str(static.eventPercent["--pct-motion"]))) # self.storeButton = QPushButton(QIcon(static.storePNG), static.storeButton) # self.storeButton.setToolTip(static.storeButton) self.exportButton = QPushButton(QIcon(static.exportPNG), static.exportFile) self.exportButton.setToolTip(static.exportFile) self.importButton = QPushButton(QIcon(static.importPNG), static.importFile) self.importButton.setToolTip(static.importFile) self.subLayout2.addWidget(self.timeLongLbl) self.subLayout2.addWidget(self.timeLong) self.subLayout2.addWidget(self.timeLongUnit) self.subLayout2.addWidget(QLabel(" " * 300)) # self.subLayout2.addWidget(self.storeButton) self.subLayout2.addWidget(self.exportButton) self.subLayout2.addWidget(self.importButton) self.subLayout0.addLayout(self.subLayout2) self.subLayout3.addWidget(self.etSetLbl) self.subLayout3.addWidget(self.etSet) self.subLayout4.addWidget(self.etPercentLbl) self.subLayout4.addWidget(self.etPercent) self.subLayout5.addLayout(self.subLayout0) self.subLayout6.addLayout(self.subLayout3) self.subLayout6.addLayout(self.subLayout4) self.midRightLayout.addLayout(self.subLayout5) self.midRightLayout.addLayout(self.subLayout6) # log ======== self.bottom = QFrame(self) self.bottom.setFrameShape(QFrame.StyledPanel) # log information self.logInfo = QLabel(static.logInfo) # information filter self.logFilter = QLabel(static.logFilter) self.monkeyButton = QPushButton(static.openMonkeyLog) self.combo = QComboBox() for i in range(len(static.logLevel)): self.combo.addItem(static.logLevel[i]) self.combo.setMaximumWidth(55) self.combo.setMaximumHeight(20) self.combo.setMinimumHeight(20) # information details self.bottomLayout = QVBoxLayout(self.bottom) self.subLayout = QHBoxLayout() self.subLayout.addWidget(self.logInfo) for i in range(10): self.subLayout.addWidget(QLabel("")) self.subLayout.addWidget(self.monkeyButton) self.subLayout.addWidget(self.logFilter) self.subLayout.addWidget(self.combo) self.bottomLayout.addLayout(self.subLayout) self.tabwidget = TabWidget() self.tabwidget.setMinimumHeight(100) self.bottomLayout.addWidget(self.tabwidget) # splitter mainWindow ++++++++++++++++++++++++++++++++++++ self.splitter2 = QSplitter(Qt.Vertical) self.splitter2.addWidget(self.topRight) self.splitter2.addWidget(self.midRight) self.splitter0 = QSplitter(Qt.Horizontal) self.splitter0.addWidget(self.topLeft) self.splitter0.addWidget(self.splitter2) self.splitter1 = QSplitter(Qt.Vertical) self.splitter1.addWidget(self.menuBar) self.splitter1.addWidget(self.splitter0) self.splitter1.addWidget(self.bottom) self.hbox.addWidget(self.splitter1) self.setLayout(self.hbox) self.show() def about(self): common.showDialog(static.menuAbout, static.dialogAbout) def init_conf(self): common.Log.info("init monkey conf") with open(monkeyConfFile, "w") as f: f.write("deviceList = []" + "\n") f.write("times = " + static.times + "\n") f.write("--throttle = " + static.eventType["--throttle"] + "\n") f.write("--pct-touch = " + static.eventPercent["--pct-touch"] + "\n") f.write("--pct-motion = " + static.eventPercent["--pct-motion"] + "\n") def setup_env(self): pass def _set_eventType(self, confFile): try: option = self.etSet.item(0, 0).text() value = self.etSet.item(0, 1).text() if value > "0": with open(confFile, 'a+') as f: f.write(option + " = " + value + "\n") except AttributeError, e: pass
class PenelopeMaterialDialog(_MaterialDialog): def __init__(self, parent=None): _MaterialDialog.__init__(self, parent) self.setWindowTitle('Material') self.setMinimumWidth(1000) def _initUI(self): # Variables model_forcing = _InteractionForcingTableModel() # Actions act_add_forcing = QAction(getIcon("list-add"), "Add interaction forcing", self) act_remove_forcing = QAction(getIcon("list-remove"), "Remove interaction forcing", self) # Widgets self._lbl_elastic_scattering_c1 = QLabel('C1') self._lbl_elastic_scattering_c1.setStyleSheet("color: blue") self._txt_elastic_scattering_c1 = MultiNumericalLineEdit() self._txt_elastic_scattering_c1.setValidator(_ElasticScatteringValidator()) self._txt_elastic_scattering_c1.setValues([0.0]) self._lbl_elastic_scattering_c2 = QLabel('C2') self._lbl_elastic_scattering_c2.setStyleSheet("color: blue") self._txt_elastic_scattering_c2 = MultiNumericalLineEdit() self._txt_elastic_scattering_c2.setValidator(_ElasticScatteringValidator()) self._txt_elastic_scattering_c2.setValues([0.0]) self._lbl_cutoff_energy_inelastic = QLabel('Inelastic collisions') self._lbl_cutoff_energy_inelastic.setStyleSheet("color: blue") self._txt_cutoff_energy_inelastic = MultiNumericalLineEdit() self._txt_cutoff_energy_inelastic.setValidator(_CutoffEnergyValidator()) self._txt_cutoff_energy_inelastic.setValues([50.0]) self._cb_cutoff_energy_inelastic = UnitComboBox('eV') self._lbl_cutoff_energy_bremsstrahlung = QLabel('Bremsstrahlung emission') self._lbl_cutoff_energy_bremsstrahlung.setStyleSheet("color: blue") self._txt_cutoff_energy_bremsstrahlung = MultiNumericalLineEdit() self._txt_cutoff_energy_bremsstrahlung.setValidator(_CutoffEnergyValidator()) self._txt_cutoff_energy_bremsstrahlung.setValues([50.0]) self._cb_cutoff_energy_bremsstrahlung = UnitComboBox('eV') self._lbl_maximum_step_length = QLabel('Maximum step length') self._lbl_maximum_step_length.setStyleSheet("color: blue") self._txt_maximum_step_length = MultiNumericalLineEdit() self._txt_maximum_step_length.setValidator(_MaximumStepLengthValidator()) self._txt_maximum_step_length.setValues([1e15]) self._cb_maximum_step_length_unit = UnitComboBox('m') self._tbl_forcing = QTableView() self._tbl_forcing.setModel(model_forcing) self._tbl_forcing.setItemDelegate(_InteractionForcingDelegate()) header = self._tbl_forcing.horizontalHeader() header.setResizeMode(QHeaderView.Stretch) self._tlb_forcing = QToolBar() spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._tlb_forcing.addWidget(spacer) self._tlb_forcing.addAction(act_add_forcing) self._tlb_forcing.addAction(act_remove_forcing) # Layouts layout = QHBoxLayout() layout.addLayout(_MaterialDialog._initUI(self), 1) frame = QFrame() frame.setFrameShape(QFrame.VLine) frame.setFrameShadow(QFrame.Sunken) layout.addWidget(frame) sublayout = QVBoxLayout() box_elastic_scattering = QGroupBox("Elastic scattering") boxlayout = QFormLayout() boxlayout.addRow(self._lbl_elastic_scattering_c1, self._txt_elastic_scattering_c1) boxlayout.addRow(self._lbl_elastic_scattering_c2, self._txt_elastic_scattering_c2) box_elastic_scattering.setLayout(boxlayout) sublayout.addWidget(box_elastic_scattering) box_cutoff_energy = QGroupBox("Cutoff energy") boxlayout = QFormLayout() boxsublayout = QHBoxLayout() boxsublayout.addWidget(self._txt_cutoff_energy_inelastic, 1) boxsublayout.addWidget(self._cb_cutoff_energy_inelastic) boxlayout.addRow(self._lbl_cutoff_energy_inelastic, boxsublayout) boxsublayout = QHBoxLayout() boxsublayout.addWidget(self._txt_cutoff_energy_bremsstrahlung, 1) boxsublayout.addWidget(self._cb_cutoff_energy_bremsstrahlung) boxlayout.addRow(self._lbl_cutoff_energy_bremsstrahlung, boxsublayout) box_cutoff_energy.setLayout(boxlayout) sublayout.addWidget(box_cutoff_energy) subsublayout = QFormLayout() subsubsublayout = QHBoxLayout() subsubsublayout.addWidget(self._txt_maximum_step_length, 1) subsubsublayout.addWidget(self._cb_maximum_step_length_unit) subsublayout.addRow(self._lbl_maximum_step_length, subsubsublayout) sublayout.addLayout(subsublayout) box_forcing = QGroupBox('Interaction forcing') boxlayout = QVBoxLayout() boxlayout.addWidget(self._tbl_forcing) boxlayout.addWidget(self._tlb_forcing) box_forcing.setLayout(boxlayout) sublayout.addWidget(box_forcing) sublayout.addStretch() layout.addLayout(sublayout, 1) # Signals self._txt_elastic_scattering_c1.textChanged.connect(self._onElasticScatteringC1Changed) self._txt_elastic_scattering_c2.textChanged.connect(self._onElasticScatteringC2Changed) self._txt_cutoff_energy_inelastic.textChanged.connect(self._onCutoffEnergyInelasticChanged) self._txt_cutoff_energy_bremsstrahlung.textChanged.connect(self._onCutoffEnergyBremsstrahlungChanged) self._txt_maximum_step_length.textChanged.connect(self._onMaximumStepLengthChanged) act_add_forcing.triggered.connect(self._onForcingAdd) act_remove_forcing.triggered.connect(self._onForcingRemove) return layout def _onElasticScatteringC1Changed(self): if self._txt_elastic_scattering_c1.hasAcceptableInput(): self._txt_elastic_scattering_c1.setStyleSheet('background: none') else: self._txt_elastic_scattering_c1.setStyleSheet('background: pink') def _onElasticScatteringC2Changed(self): if self._txt_elastic_scattering_c2.hasAcceptableInput(): self._txt_elastic_scattering_c2.setStyleSheet('background: none') else: self._txt_elastic_scattering_c2.setStyleSheet('background: pink') def _onCutoffEnergyInelasticChanged(self): if self._txt_cutoff_energy_inelastic.hasAcceptableInput(): self._txt_cutoff_energy_inelastic.setStyleSheet('background: none') else: self._txt_cutoff_energy_inelastic.setStyleSheet('background: pink') def _onCutoffEnergyBremsstrahlungChanged(self): if self._txt_cutoff_energy_bremsstrahlung.hasAcceptableInput(): self._txt_cutoff_energy_bremsstrahlung.setStyleSheet('background: none') else: self._txt_cutoff_energy_bremsstrahlung.setStyleSheet('background: pink') def _onMaximumStepLengthChanged(self): if self._txt_maximum_step_length.hasAcceptableInput(): self._txt_maximum_step_length.setStyleSheet('background: none') else: self._txt_maximum_step_length.setStyleSheet('background: pink') def _onForcingAdd(self): index = self._tbl_forcing.selectionModel().currentIndex() model = self._tbl_forcing.model() model.insertRows(index.row() + 1) def _onForcingRemove(self): selection = self._tbl_forcing.selectionModel().selection().indexes() if len(selection) == 0: QMessageBox.warning(self, "Interaction forcing", "Select a row") return model = self._tbl_forcing.model() for row in sorted(map(methodcaller('row'), selection), reverse=True): model.removeRow(row) def _getParametersDict(self): params = _MaterialDialog._getParametersDict(self) params['c1'] = self._txt_elastic_scattering_c1.values().tolist() params['c2'] = self._txt_elastic_scattering_c2.values().tolist() wcc = self._txt_cutoff_energy_inelastic.values() * self._cb_cutoff_energy_inelastic.factor() params['wcc'] = wcc.tolist() wcr = self._txt_cutoff_energy_bremsstrahlung.values() * self._cb_cutoff_energy_bremsstrahlung.factor() params['wcr'] = wcr.tolist() dsmax = self._txt_maximum_step_length.values() * self._cb_maximum_step_length_unit.factor() params['dsmax'] = dsmax.tolist() params['forcings'] = \ self._tbl_forcing.model().interaction_forcings() return params def _generateName(self, parameters, varied): name = parameters.pop('name') if name is None: name = PenelopeMaterial.generate_name(parameters['composition']) parts = [name] for key in varied: if key == 'composition': continue elif key == 'forcings': forcing = parameters[key][0] forcer = forcing.forcer wlow = forcing.weight[0] whigh = forcing.weight[1] parts.append('forcings={0:n}_{1:n}_{2:n}'.format(forcer, wlow, whigh)) else: parts.append('{0:s}={1:n}'.format(key, parameters[key])) return '+'.join(parts) def _createMaterial(self, parameters, varied): mat = _MaterialDialog._createMaterial(self, parameters, varied) c1 = parameters['c1'] c2 = parameters['c2'] wcc = parameters['wcc'] wcr = parameters['wcr'] dsmax = parameters['dsmax'] forcings = parameters['forcings'] return PenelopeMaterial(mat.composition, mat.name, mat.density_kg_m3, mat.absorption_energy_eV, elastic_scattering=(c1, c2), cutoff_energy_inelastic_eV=wcc, cutoff_energy_bremsstrahlung_eV=wcr, interaction_forcings=forcings, maximum_step_length_m=dsmax) def setValue(self, material): _MaterialDialog.setValue(self, material) # Elastic scattering c1, c2 = material.elastic_scattering self._txt_elastic_scattering_c1.setValues(c1) self._txt_elastic_scattering_c2.setValues(c2) # Cutoff energy self._txt_cutoff_energy_inelastic.setValues(material.cutoff_energy_inelastic_eV) self._cb_cutoff_energy_inelastic.setUnit('eV') self._txt_cutoff_energy_bremsstrahlung.setValues(material.cutoff_energy_bremsstrahlung_eV) self._cb_cutoff_energy_bremsstrahlung.setUnit('eV') # Maximum step length self._txt_maximum_step_length.setValues(material.maximum_step_length_m) self._cb_maximum_step_length_unit.setUnit('m') # Interaction forcings forcings = material.interaction_forcings model = self._tbl_forcing.model() model.removeRows(0, model.rowCount()) model.insertRows(1, len(forcings)) for row, forcing in enumerate(forcings): model.setData(model.index(row, 0), forcing.particle) model.setData(model.index(row, 1), forcing.collision) model.setData(model.index(row, 2), forcing.forcer) model.setData(model.index(row, 3), forcing.weight[0]) model.setData(model.index(row, 4), forcing.weight[1]) def setReadOnly(self, state): _MaterialDialog.setReadOnly(self, state) style = 'color: none' if state else 'color: blue' self._lbl_elastic_scattering_c1.setStyleSheet(style) self._txt_elastic_scattering_c1.setReadOnly(state) self._lbl_elastic_scattering_c2.setStyleSheet(style) self._txt_elastic_scattering_c2.setReadOnly(state) self._lbl_cutoff_energy_inelastic.setStyleSheet(style) self._txt_cutoff_energy_inelastic.setReadOnly(state) self._cb_cutoff_energy_inelastic.setEnabled(not state) self._lbl_cutoff_energy_bremsstrahlung.setStyleSheet(style) self._txt_cutoff_energy_bremsstrahlung.setReadOnly(state) self._cb_cutoff_energy_bremsstrahlung.setEnabled(not state) self._lbl_maximum_step_length.setStyleSheet(style) self._txt_maximum_step_length.setReadOnly(state) self._cb_maximum_step_length_unit.setEnabled(not state) self._tbl_forcing.setEnabled(not state) self._tlb_forcing.setVisible(not state) def isReadOnly(self): return _MaterialDialog.isReadOnly(self) and \ self._txt_elastic_scattering_c1.isReadOnly() and \ self._txt_elastic_scattering_c2.isReadOnly() and \ self._txt_cutoff_energy_inelastic.isReadOnly() and \ self._txt_cutoff_energy_bremsstrahlung.isReadOnly() and \ self._txt_maximum_step_length.isReadOnly() and \ not self._tbl_forcing.isEnabled() and \ not self._tlb_forcing.isVisible()
class LayerListWidget(_ParameterWidget): def __init__(self, parameter, parent=None): _ParameterWidget.__init__(self, parameter, parent) # Variables model = _LayerModel() self._material_class = Material # Actions act_add = QAction(getIcon("list-add"), "Add layer", self) act_remove = QAction(getIcon("list-remove"), "Remove layer", self) act_clean = QAction(getIcon('edit-clear'), "Clear", self) # Widgets self._cb_unit = UnitComboBox('m') self._cb_unit.setUnit('um') self._tbl_layers = QTableView() self._tbl_layers.setModel(model) self._tbl_layers.setItemDelegate(_LayerDelegate()) header = self._tbl_layers.horizontalHeader() header.setResizeMode(QHeaderView.Stretch) header.setStyleSheet('color: blue') self._tlb_layers = QToolBar() spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._tlb_layers.addWidget(spacer) self._tlb_layers.addAction(act_add) self._tlb_layers.addAction(act_remove) self._tlb_layers.addAction(act_clean) # Layouts layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) sublayout = QHBoxLayout() sublayout.addStretch() sublayout.addWidget(QLabel('Thickness unit')) sublayout.addWidget(self._cb_unit) layout.addLayout(sublayout) layout.addWidget(self._tbl_layers) layout.addWidget(self._tlb_layers) self.setLayout(layout) # Signals self.valuesChanged.connect(self._onChanged) self.validationRequested.connect(self._onChanged) act_add.triggered.connect(self._onAdd) act_remove.triggered.connect(self._onRemove) act_clean.triggered.connect(self._onClear) self._tbl_layers.doubleClicked.connect(self._onDoubleClicked) model.dataChanged.connect(self.valuesChanged) model.rowsInserted.connect(self.valuesChanged) model.rowsRemoved.connect(self.valuesChanged) self.validationRequested.emit() def _onChanged(self): if self.hasAcceptableInput(): self._tbl_layers.setStyleSheet("background: none") else: self._tbl_layers.setStyleSheet("background: pink") def _onDoubleClicked(self, index): if index.column() != 0: return model = self._tbl_layers.model() materials = model.materials(index) if len(materials) == 0: dialog = get_material_dialog_class(self._material_class)() elif len(materials) == 1: dialog = get_material_dialog_class(self._material_class)() dialog.setValue(materials[0]) else: dialog = MaterialListDialog() dialog.setMaterialClass(self._material_class) dialog.setValues(materials) dialog.setReadOnly(self.isReadOnly()) if not dialog.exec_(): return model.setData(index, dialog.values()) def _onAdd(self): index = self._tbl_layers.selectionModel().currentIndex() model = self._tbl_layers.model() model.insertRows(index.row() + 1) # Show material dialog right away index = model.createIndex(index.row() + 1, 0) self._onDoubleClicked(index) def _onRemove(self): selection = self._tbl_layers.selectionModel().selection().indexes() if len(selection) == 0: QMessageBox.warning(self, "Layer", "Select a row") return model = self._tbl_layers.model() for row in sorted(map(methodcaller('row'), selection), reverse=True): model.removeRow(row) def _onClear(self): model = self._tbl_layers.model() for row in reversed(range(model.rowCount())): model.removeRow(row) def values(self): factor = self._cb_unit.factor() layers = [] for material, thickness in self._tbl_layers.model().layers(): if not material or not thickness: continue thickness_m = np.array(thickness, ndmin=1) * factor layers.append(_MockLayer(material, thickness_m)) return layers def setValues(self, layers): layers = np.array(layers, ndmin=1) factor = self._cb_unit.factor() model = self._tbl_layers.model() model.removeRows(0, model.rowCount()) model.insertRows(0, len(layers)) for i, layer in enumerate(layers): model.setData(model.index(i, 0), layer.material) model.setData(model.index(i, 1), layer.thickness_m / factor) def isReadOnly(self): return not self._cb_unit.isEnabled() and \ not self._tlb_layers.isVisible() def setReadOnly(self, state): self._cb_unit.setEnabled(not state) self._tlb_layers.setVisible(not state) style = 'color: none' if state else 'color: blue' self._tbl_layers.horizontalHeader().setStyleSheet(style) self._tbl_layers.itemDelegate().setReadOnly(state) def setMaterialClass(self, clasz): self._material_class = clasz
def __init__(self, parent=None): QDialog.__init__(self, parent) self.setWindowTitle('Runner') self.setMinimumWidth(750) # Runner self._runner = None self._running_timer = QTimer() self._running_timer.setInterval(500) # Widgets self._dlg_progress = QProgressDialog() self._dlg_progress.setRange(0, 100) self._dlg_progress.setModal(True) self._dlg_progress.hide() lbl_outputdir = QLabel("Output directory") self._txt_outputdir = DirBrowseWidget() max_workers = cpu_count() #@UndefinedVariable lbl_workers = QLabel('Number of workers') self._spn_workers = QSpinBox() self._spn_workers.setRange(1, max_workers) self._spn_workers.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) lbl_max_workers = QLabel('(max: %i)' % max_workers) self._chk_overwrite = QCheckBox("Overwrite existing results in output directory") self._chk_overwrite.setChecked(True) self._lbl_available = QLabel('Available') self._lst_available = QListView() self._lst_available.setModel(_AvailableOptionsListModel()) self._lst_available.setSelectionMode(QListView.SelectionMode.MultiSelection) tlb_available = QToolBar() spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) tlb_available.addWidget(spacer) act_open = tlb_available.addAction(getIcon("document-open"), "Open") act_open.setShortcut(QKeySequence.Open) tlb_available.addSeparator() act_remove = tlb_available.addAction(getIcon("list-remove"), "Remove") act_clear = tlb_available.addAction(getIcon("edit-clear"), "Clear") self._btn_addtoqueue = QPushButton(getIcon("go-next"), "") self._btn_addtoqueue.setToolTip("Add to queue") self._btn_addtoqueue.setEnabled(False) self._btn_addalltoqueue = QPushButton(getIcon("go-last"), "") self._btn_addalltoqueue.setToolTip("Add all to queue") self._btn_addalltoqueue.setEnabled(False) self._lbl_options = QLabel('Queued/Running/Completed') self._tbl_options = QTableView() self._tbl_options.setModel(_StateOptionsTableModel()) self._tbl_options.setItemDelegate(_StateOptionsItemDelegate()) self._tbl_options.setSelectionMode(QListView.SelectionMode.NoSelection) self._tbl_options.setColumnWidth(1, 60) self._tbl_options.setColumnWidth(2, 80) header = self._tbl_options.horizontalHeader() header.setResizeMode(0, QHeaderView.Interactive) header.setResizeMode(1, QHeaderView.Fixed) header.setResizeMode(2, QHeaderView.Fixed) header.setResizeMode(3, QHeaderView.Stretch) self._btn_start = QPushButton(getIcon("media-playback-start"), "Start") self._btn_cancel = QPushButton("Cancel") self._btn_cancel.setEnabled(False) self._btn_close = QPushButton("Close") self._btn_import = QPushButton("Import") self._btn_import.setEnabled(False) # Layouts layout = QVBoxLayout() sublayout = QGridLayout() sublayout.addWidget(lbl_outputdir, 0, 0) sublayout.addWidget(self._txt_outputdir, 0, 1) sublayout.addWidget(lbl_workers, 1, 0) subsublayout = QHBoxLayout() subsublayout.addWidget(self._spn_workers) subsublayout.addWidget(lbl_max_workers) sublayout.addLayout(subsublayout, 1, 1) layout.addLayout(sublayout) sublayout.addWidget(self._chk_overwrite, 2, 0, 1, 3) sublayout = QGridLayout() sublayout.setColumnStretch(0, 1) sublayout.setColumnStretch(2, 3) sublayout.addWidget(self._lbl_available, 0, 0) sublayout.addWidget(self._lst_available, 1, 0) sublayout.addWidget(tlb_available, 2, 0) subsublayout = QVBoxLayout() subsublayout.addStretch() subsublayout.addWidget(self._btn_addtoqueue) subsublayout.addWidget(self._btn_addalltoqueue) subsublayout.addStretch() sublayout.addLayout(subsublayout, 1, 1) sublayout.addWidget(self._lbl_options, 0, 2) sublayout.addWidget(self._tbl_options, 1, 2) layout.addLayout(sublayout) sublayout = QHBoxLayout() sublayout.addStretch() sublayout.addWidget(self._btn_import) sublayout.addWidget(self._btn_start) sublayout.addWidget(self._btn_cancel) sublayout.addWidget(self._btn_close) layout.addLayout(sublayout) self.setLayout(layout) # Signal self._running_timer.timeout.connect(self._onRunningTimer) act_open.triggered.connect(self._onOpen) act_remove.triggered.connect(self._onRemove) act_clear.triggered.connect(self._onClear) self._btn_addtoqueue.released.connect(self._onAddToQueue) self._btn_addalltoqueue.released.connect(self._onAddAllToQueue) self._btn_start.released.connect(self._onStart) self._btn_cancel.released.connect(self._onCancel) self._btn_close.released.connect(self._onClose) self._btn_import.released.connect(self._onImport) self.options_added.connect(self._onOptionsAdded) self.options_running.connect(self._onOptionsRunning) self.options_simulated.connect(self._onOptionsSimulated) self.options_error.connect(self._onOptionsError) self.results_error.connect(self._onResultsError) # Defaults settings = get_settings() section = settings.add_section('gui') if hasattr(section, 'outputdir'): self._txt_outputdir.setPath(section.outputdir) if hasattr(section, 'maxworkers'): self._spn_workers.setValue(int(section.maxworkers)) if hasattr(section, 'overwrite'): state = True if section.overwrite.lower() == 'true' else False self._chk_overwrite.setChecked(state)
class FilterBoxFrame(ModuleFrame): """ModuleFrame for handling filtering operations. """ def __init__(self, parent, parent_frame = None, title = None): """Constructor for FilterBoxFrame.""" super(FilterBoxFrame, self).__init__(parent, parent_frame, title) self.allowDocks(True) def createView(self): """Creates the module-specific view for the FilterBox module.""" view = QWidget() layout = QGridLayout() self.filter_label = QLabel("") layout.addWidget(self.filter_label, 0, 0, 1, 1) view.setLayout(layout) view.resize(20, 20) return view # Not currently in use # Toolbars are too big. Someday this may be done with a prettier label. def createToolBar(self): if isinstance(self.parent(), BFDockWidget): self.toolbar = BFDragToolBar('Filter Tools', self, self.parent()) else: self.toolbar = QToolBar('Filter Tools', parent = self) if isinstance(self.parent(), BFDockWidget): dragAction = QAction(QIcon(":/filterbox_move.png"), \ "Drag to Change Parent", self) self.toolbar.addAction(dragAction) createChildAction = QAction(QIcon(":/filterbox_new.png"), \ "New Filterbox", self) createChildAction.triggered.connect(self.createChildWindow) self.toolbar.addAction(createChildAction) self.addToolBar(self.toolbar) # No functionality currently # Demonstration of changing Drag & Drop behavior for window unique data # May not be necessary for other modules. def dropEvent(self, event): # Dropped Filter if isinstance(event.mimeData(), FilterMime): myfilter = event.mimeData().getFilter() # Do something with it. event.accept() else: super(FilterBoxFrame, self).dropEvent(event) @Slot(Clause) def editFilter(self, clause): """Given a Clause object, passes it to the Agent to associate a fiter based on that Clause with this module. Updates the ModuleFrame to show the filter. """ self.agent.createSimpleFilter(clause) self.filter_label.setText("Filter: " + str(clause)) def buildTabDialog(self): """Appends the FilterBox specific filter-building GUI to the tab dialog for this module. """ super(FilterBoxFrame, self).buildTabDialog() self.filter_tab = FilterTab(self.tab_dialog, self, self.agent.filters) self.filter_tab.applySignal.connect(self.editFilter) self.tab_dialog.addTab(self.filter_tab, "Filters")
def __init__(self, grid, U): assert isinstance(U, Communicable) super(MainWindow, self).__init__() U = U.data layout = QVBoxLayout() plotBox = QHBoxLayout() plot = GlumpyPatchWidget(self, grid, vmin=np.min(U), vmax=np.max(U), bounding_box=bounding_box, codim=codim) bar = ColorBarWidget(self, vmin=np.min(U), vmax=np.max(U)) plotBox.addWidget(plot) plotBox.addWidget(bar) layout.addLayout(plotBox) if len(U) == 1: plot.set(U.ravel()) else: plot.set(U[0]) hlayout = QHBoxLayout() self.slider = QSlider(Qt.Horizontal) self.slider.setMinimum(0) self.slider.setMaximum(len(U) - 1) self.slider.setTickPosition(QSlider.TicksBelow) hlayout.addWidget(self.slider) lcd = QLCDNumber(m.ceil(m.log10(len(U)))) lcd.setDecMode() lcd.setSegmentStyle(QLCDNumber.Flat) hlayout.addWidget(lcd) layout.addLayout(hlayout) hlayout = QHBoxLayout() toolbar = QToolBar() self.a_play = QAction(self.style().standardIcon(QStyle.SP_MediaPlay), 'Play', self) self.a_play.setCheckable(True) self.a_rewind = QAction(self.style().standardIcon(QStyle.SP_MediaSeekBackward), 'Rewind', self) self.a_toend = QAction(self.style().standardIcon(QStyle.SP_MediaSeekForward), 'End', self) self.a_step_backward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipBackward), 'Step Back', self) self.a_step_forward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipForward), 'Step', self) self.a_loop = QAction(self.style().standardIcon(QStyle.SP_BrowserReload), 'Loop', self) self.a_loop.setCheckable(True) toolbar.addAction(self.a_play) toolbar.addAction(self.a_rewind) toolbar.addAction(self.a_toend) toolbar.addAction(self.a_step_backward) toolbar.addAction(self.a_step_forward) toolbar.addAction(self.a_loop) hlayout.addWidget(toolbar) self.speed = QSlider(Qt.Horizontal) self.speed.setMinimum(0) self.speed.setMaximum(100) hlayout.addWidget(QLabel('Speed:')) hlayout.addWidget(self.speed) layout.addLayout(hlayout) self.timer = QTimer() self.timer.timeout.connect(self.update_solution) self.slider.valueChanged.connect(self.slider_changed) self.slider.valueChanged.connect(lcd.display) self.speed.valueChanged.connect(self.speed_changed) self.a_play.toggled.connect(self.toggle_play) self.a_rewind.triggered.connect(self.rewind) self.a_toend.triggered.connect(self.to_end) self.a_step_forward.triggered.connect(self.step_forward) self.a_step_backward.triggered.connect(self.step_backward) self.speed.setValue(50) self.setLayout(layout) self.plot = plot self.U = U
def _initUI(self): # Variables self._parameter_getters = {} def _program_getter(options): programs = list(options.programs) if len(programs) == 1: return programs[0] else: return list(programs) self._parameter_getters['program'] = _program_getter options = self.options() for name, getter in iter_getters(options): values = np.array(getter(options), ndmin=1) if len(values) < 2: continue self._parameter_getters[name] = getter # Actions act_add_series = QAction(getIcon("list-add"), "Add series", self) act_remove_series = QAction(getIcon("list-remove"), "Remove series", self) act_clear_series = QAction(getIcon("edit-clear"), "Clear", self) # Widgets self._cb_result_key = QComboBox() self._cb_x_parameter = QComboBox() self._cb_x_parameter.addItems(list(self._parameter_getters.keys())) self._lst_series = QListView() self._lst_series.setModel(_SeriesModel()) tlb_series = QToolBar() spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) tlb_series.addWidget(spacer) tlb_series.addAction(act_add_series) tlb_series.addAction(act_remove_series) tlb_series.addAction(act_clear_series) self._chk_normalize = QCheckBox('Normalize series') # Layouts layout = _ResultsToolItem._initUI(self) layout.addRow("Result", self._cb_result_key) layout.addRow("X parameter", self._cb_x_parameter) layout.addRow("Series", self._lst_series) layout.addRow(tlb_series) layout.addRow(self._chk_normalize) # Signals act_add_series.triggered.connect(self._onAddSeries) act_remove_series.triggered.connect(self._onRemoveSeries) act_clear_series.triggered.connect(self._onClearSeries) self._lst_series.doubleClicked.connect(self._onSeriesDoubleClicked) self._cb_result_key.currentIndexChanged.connect(self._onResultKeyChanged) self._chk_normalize.stateChanged.connect(self.stateChanged) # Defaults keys = set() for container in self.results(): for key, result in container.items(): if not isinstance(result, _SummarizableResult): continue keys.add(key) self._cb_result_key.addItems(sorted(keys)) return layout
def __init__(self): QWidget.__init__(self) self.book = None self.toc = None self.current = None layout = QVBoxLayout(self) toolbar = QToolBar() toolbar.addAction('Open', self.openClicked) toolbar.addAction('Cover', self.coverClicked) toolbar.addAction('ToC', self.tocClicked) toolbar.addAction('Back', self.goBackClicked) toolbar.addAction('Forward', self.goForwardClicked) toolbar.addAction('Quit', self.quitClicked) layout.addWidget(toolbar) self.view = QWebView(self) layout.addWidget(self.view) self.setLayout(layout)
def __init__(self, U, plot, length=1, title=None): super().__init__() layout = QVBoxLayout() if title: title = QLabel('<b>' + title + '</b>') title.setAlignment(Qt.AlignHCenter) layout.addWidget(title) layout.addWidget(plot) plot.set(U, 0) if length > 1: hlayout = QHBoxLayout() self.slider = QSlider(Qt.Horizontal) self.slider.setMinimum(0) self.slider.setMaximum(length - 1) self.slider.setTickPosition(QSlider.TicksBelow) hlayout.addWidget(self.slider) lcd = QLCDNumber(m.ceil(m.log10(length))) lcd.setDecMode() lcd.setSegmentStyle(QLCDNumber.Flat) hlayout.addWidget(lcd) layout.addLayout(hlayout) hlayout = QHBoxLayout() toolbar = QToolBar() self.a_play = QAction( self.style().standardIcon(QStyle.SP_MediaPlay), 'Play', self) self.a_play.setCheckable(True) self.a_rewind = QAction( self.style().standardIcon(QStyle.SP_MediaSeekBackward), 'Rewind', self) self.a_toend = QAction( self.style().standardIcon(QStyle.SP_MediaSeekForward), 'End', self) self.a_step_backward = QAction( self.style().standardIcon(QStyle.SP_MediaSkipBackward), 'Step Back', self) self.a_step_forward = QAction( self.style().standardIcon(QStyle.SP_MediaSkipForward), 'Step', self) self.a_loop = QAction( self.style().standardIcon(QStyle.SP_BrowserReload), 'Loop', self) self.a_loop.setCheckable(True) toolbar.addAction(self.a_play) toolbar.addAction(self.a_rewind) toolbar.addAction(self.a_toend) toolbar.addAction(self.a_step_backward) toolbar.addAction(self.a_step_forward) toolbar.addAction(self.a_loop) if hasattr(self, 'save'): self.a_save = QAction( self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self) toolbar.addAction(self.a_save) self.a_save.triggered.connect(self.save) hlayout.addWidget(toolbar) self.speed = QSlider(Qt.Horizontal) self.speed.setMinimum(0) self.speed.setMaximum(100) hlayout.addWidget(QLabel('Speed:')) hlayout.addWidget(self.speed) layout.addLayout(hlayout) self.timer = QTimer() self.timer.timeout.connect(self.update_solution) self.slider.valueChanged.connect(self.slider_changed) self.slider.valueChanged.connect(lcd.display) self.speed.valueChanged.connect(self.speed_changed) self.a_play.toggled.connect(self.toggle_play) self.a_rewind.triggered.connect(self.rewind) self.a_toend.triggered.connect(self.to_end) self.a_step_forward.triggered.connect(self.step_forward) self.a_step_backward.triggered.connect(self.step_backward) self.speed.setValue(50) elif hasattr(self, 'save'): hlayout = QHBoxLayout() toolbar = QToolBar() self.a_save = QAction( self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self) toolbar.addAction(self.a_save) hlayout.addWidget(toolbar) layout.addLayout(hlayout) self.a_save.triggered.connect(self.save) self.setLayout(layout) self.plot = plot self.U = U self.length = length
def testAddAction(self): bar = QToolBar() self._called = False a = bar.addAction("act1", self.callback) a.trigger() self.assert_(self._called)