class WorkspaceStatus(BaseWorkspace): def setupWorkspace(self): self.pile = QStackedWidget(self) self.wLayout.addWidget(self.pile) self.dlgs = weakref.WeakValueDictionary() self.pile.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding) self.push(DefaultStatusWidget(), 'default') def push(self, widget, name): idx = self.pile.addWidget(widget) self.pile.setCurrentIndex(idx) self.dlgs[name] = widget return idx, widget def clear(self, name): if name in self.dlgs: w = self.dlgs[name] idx = self.pile.indexOf(w) if idx: self.pile.removeWidget(w) def pushProgress(self, name): return self.push(DefaultProgressDialog(), name) async def pushRunDialog(self, dialog, name): dialog.setEnabled(True) idx, w = self.push(dialog, name) await runDialogAsync(dialog)
def layout_param(self, i_param): fd = self._submodel._dict name = fd[(i_param, "name")] name_label = QLabel(name) myFont = QtGui.QFont()#QtGui.QFont() myFont.setWeight(QtGui.QFont.ExtraBold) name_label.setFont(myFont) self._layout.addWidget(name_label, i_param, 0, 1, 1) # Adds a check-box for default if fd[(i_param, "has_def")]: is_default = self._widgets[(i_param, "is_def")] = QCheckBox()#"(default)", self) # is_default.setFont(QtGui.QFont("Times", italic=True)) is_default.setChecked(fd[(i_param, "is_def")]) is_default.stateChanged.connect(functools.partial( self.on_user_mod, (i_param, "is_def"), is_default.isChecked)) self._layout.addWidget(is_default, i_param, 1, 1, 1) # Handles Union types qs = QStackedWidget()# MinimizedStackedWidget() qs.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) n_uargs = fd[(i_param, "n_types")] if n_uargs == 0: utype = fd[(i_param, 0, "type")] print("utype", utype) utype_label = QLabel(type_name(utype)) self._layout.addWidget(utype_label, i_param, 2, 1, 1) self.layout_uarg(qs, i_param, 0) else: utypes = [fd[(i_param, utype, "type")] for utype in range(n_uargs)] utypes_combo = self._widgets[(i_param, "type_sel")] = QComboBox() self._widgets[(i_param, 'qs_type_sel')] = utypes_combo utypes_combo.addItems(type_name(t) for t in utypes) utypes_combo.setCurrentIndex(fd[(i_param, "type_sel")]) utypes_combo.activated.connect(functools.partial( self.on_user_mod, (i_param, "type_sel"), utypes_combo.currentIndex)) # Connect to the QS utypes_combo.currentIndexChanged[int].connect(qs.setCurrentIndex) # utypes_combo.activated.connect(qs.setCurrentIndex) self._layout.addWidget(utypes_combo, i_param, 2, 1, 1) for utype in range(n_uargs): self.layout_uarg(qs, i_param, utype) # The displayed item of the union is denoted by "type_sel" : # self.layout_uarg(qs, i_param, fd[(i_param, "type_sel")]) qs.setCurrentIndex(fd[(i_param, "type_sel")]) self._layout.addWidget(qs, i_param, 3, 1, 1) self._layout.setRowStretch(i_param, 0) # label = QGroupBox()#self) # label.add # label.setTitle("Hello World") # label.setAttribute(Qt.WA_TranslucentBackground) # self._layout.addWidget(label, 2*i_param, 0, 1, 3) # adds a spacer at bottom self._layout.setRowStretch(i_param + 1, 1) pass
class CorpusGeneralWidget(QWidget): def __init__(self, parent): super(CorpusGeneralWidget, self).__init__(parent) self.setLayout(QVBoxLayout()) self.layout().addWidget(QLabel("Corpus Information", self)) self.w_corpus = QFrame(self) self.w_corpus.setWindowTitle("Corpus Information") self.w_corpus.setLayout(QVBoxLayout()) self.layout().addWidget(self.w_corpus) self.lt_actions = QHBoxLayout(self) self.layout().addWidget(QLabel("Template", self)) self.layout().addItem(self.lt_actions) self.layout().addWidget(QLabel("Project Information", self)) self.w_movie = CorpusMovieWidget(self) self.layout().addWidget(self.w_movie) self.w_name = QWidget(self) self.w_name.setLayout(QHBoxLayout()) self.w_name.layout().addWidget(QLabel("Corpus Name")) self.textEdit_Name = QLineEdit(self.w_name) self.textEdit_Name.editingFinished.connect(self.on_name_changed) self.w_name.layout().addWidget(self.textEdit_Name) self.w_corpus.layout().addWidget(self.w_name) self.templateStack = QStackedWidget(self) self.templateStack.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) self.lt_actions.addWidget(self.templateStack) self.template_widget_manage = QWidget(self.templateStack) self.template_widget_edit = QWidget(self.templateStack) self.templateStack.addWidget(self.template_widget_manage) self.templateStack.addWidget(self.template_widget_edit) self.template_widget_manage.setLayout(QGridLayout()) self.template_widget_edit.setLayout(QGridLayout()) self.btn_EditTemplate = QPushButton("Edit Template", self) self.template_widget_manage.layout().addWidget(self.btn_EditTemplate, 0, 0) self.btn_ImportTemplate = QPushButton("Import Template", self) self.template_widget_manage.layout().addWidget(self.btn_ImportTemplate, 0, 1) self.btn_SaveTemplate = QPushButton("Save Template", self) self.template_widget_edit.layout().addWidget(self.btn_SaveTemplate, 0, 0) self.btn_CloseTemplate = QPushButton("Close Template", self) self.template_widget_edit.layout().addWidget(self.btn_CloseTemplate, 0, 1) self.layout().addItem( QSpacerItem(1, 1, QSizePolicy.Preferred, QSizePolicy.Expanding)) self.corpus = None self.setEnabled(False) def on_corpus_loaded(self, corpus): self.corpus = corpus if self.corpus is not None: self.textEdit_Name.setText(self.corpus.name) self.setEnabled(True) else: self.setEnabled(False) def on_name_changed(self): if self.corpus is not None: if self.textEdit_Name.text() != "": self.corpus.name = self.textEdit_Name.text() self.corpus.save() def on_project_changed(self, project): self.w_movie.set_project(project)
class AboutDialog(QDialog): """ Display an About window """ def __init__(self, parent=None) -> None: super().__init__(parent) self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint) self.setObjectName('AboutDialog') self.setStyleSheet( 'QDialog#AboutDialog {background-image: url(:/splashscreen.png);}') pixmap = QPixmap(':/splashscreen.png') try: ratio = pixmap.devicePixelRatioF() except AttributeError: ratio = pixmap.devicePixelRatio() if ratio > 1.0: size = QSize(pixmap.width() / ratio, pixmap.height() / ratio) else: size = pixmap.size() self.setFixedSize(size) # These values are derived from the splash screen image contents. # If the image changes, so should these white_box_height = 80 title_bottom = 45 left_margin = 16 transparency = "rgba(0, 0, 0, 130)" # Standard About view msg = """Copyright © 2007-2020 Damon Lynch.<br><br> <a href="http://www.damonlynch.net/rapid" %(link_style)s> www.damonlynch.net/rapid</a><br><br> This program comes with absolutely no warranty.<br> See the <a href="http://www.gnu.org/copyleft/gpl.html" %(link_style)s>GNU General Public License, version 3 or later</a> for details. """ % dict(link_style='style="color: white;"') details = QLabel(msg) details_style_sheet = """QLabel { color: white; background-color: %(transparency)s; margin-left: 0px; padding-left: %(left_margin)dpx; padding-top: 6px; padding-right: 6px; padding-bottom: 6px; }""" % dict(left_margin=left_margin, transparency=transparency) details.setStyleSheet(details_style_sheet) details.setOpenExternalLinks(True) details.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) font = self.font() # type: QFont font_size = font.pointSize() - 2 font.setPointSize(font_size) details.setFont(font) aboutLayout = QVBoxLayout() aboutLayout.setContentsMargins(0, 0, 0, 0) aboutLayout.addSpacing(150) detailsLayout = QHBoxLayout() detailsLayout.setContentsMargins(0, 0, 0, 0) detailsLayout.addWidget(details) detailsLayout.addStretch(10) aboutLayout.addLayout(detailsLayout) aboutLayout.addStretch(10) about = QWidget() about.setLayout(aboutLayout) # Credits view credits_text = """ Copyright © 2007-2020 Damon Lynch. Portions copyright © 2008-2015 Canonical Ltd. Portions copyright © 2013 Bernard Baeyens. Portions copyright © 2012-2015 Jim Easterbrook. Portions copyright © 2012 Sven Marnach. Portions copyright © 2015 Dmitry Shachnev. Photo %(photolink)s copyright © 2014-2018 Damon Lynch, all rights reserved. Camera icon courtesy %(artlink1)s. Video camera icon courtesy %(artlink2)s. Home icon courtesy %(artlink3)s. Speech bubble courtesy %(artlink4)s. Lightbulb icon courtesy %(artlink5)s. Unlink icon courtesy %(artlink6)s. Clock icon courtesy %(artlink7)s. """ credits_text = credits_text.replace('\n', '<br>\n') credits_text = credits_text % dict( photolink= """<a href="https://500px.com/photo/246096445/afghan-men-pulling-heavy-load- by-damon-lynch" style="color: white;">Afghan Men Pulling Heavy Load</a>""", artlink1= '<a href="http://www.webalys.com" style="color: white;">Vincent Le Moign</a>', artlink2= """<a href="https://www.iconfinder.com/bluewolfski" style="color: white;">The Pictographers</a>""", artlink3= '<a href="https://www.iconfinder.com/Enesdal" style="color: white;">Enes' ' Dal</a>', artlink4= '<a href="http://www.iconsolid.com/" style="color: white;">Icons Solid</a>', artlink5= '<a href="https://sellfy.com/designcoon" style="color: white;">Icon Coon</a>', artlink6= '<a href="https://www.iconfinder.com/icons/1608708/unlink_icon" style="color: ' 'white;">Dave Gandy</a>', artlink7= '<a href="https://www.flaticon.com/authors/pixel-perfect" style="color: ' 'white;">Pixel perfect</a>') label_style_sheet = """QLabel { background-color: rgba(0, 0, 0, 0); color: white; padding-left: %(left_margin)dpx; padding-top: 6px; padding-right: 6px; padding-bottom: 6px; }""" % dict(left_margin=left_margin) creditsLabel = QLabel(credits_text) creditsLabel.setFont(font) creditsLabel.setStyleSheet(label_style_sheet) creditsLabel.setOpenExternalLinks(True) credits = QScrollArea() credits.setWidget(creditsLabel) scroll_area_style_sheet = """QScrollArea { background-color: %(transparency)s; border: 0px; } """ % dict(transparency=transparency) credits.setStyleSheet(scroll_area_style_sheet) # Translators view translators_text = """ <b>Algerian</b> Algent Albrahimi <*****@*****.**> <b>Belarusian</b> Ilya Tsimokhin <*****@*****.**> <b>Brazilian Portuguese</b> Ney Walens de Mesquita <*****@*****.**> Rubens Stuginski Jr <*****@*****.**> <b>Catalan</b> Adolfo Jayme Barrientos <*****@*****.**> <b>Czech</b> Pavel Borecki <*****@*****.**> <b>Danish</b> Torben Gundtofte-Bruun <*****@*****.**> <b>Dutch</b> Alain J. Baudrez <*****@*****.**> <b>Estonian</b> Tauno Erik <*****@*****.**> <b>Finnish</b> Mikko Ruohola <*****@*****.**> <b>French</b> Jean-Marc Lartigue <*****@*****.**> <b>Greek</b> Dimitris Xenakis <*****@*****.**> <b>Hungarian</b> László <*****@*****.**> András Lőrincz <*****@*****.**> <b>Italian</b> Matteo Carotta <*****@*****.**> Milo Casagrande <*****@*****.**> <b>Japanese</b> Koji Yokota <*****@*****.**> <b>Kabyle</b> Mohammed Belkacem <*****@*****.**> <b>Norwegian Bokmal</b> Harlad H <*****@*****.**> Rudolf Maurer <*****@*****.**> <b>Norwegian Nynorsk</b> Kevin Brubeck Unhammer <*****@*****.**> Harlad H <*****@*****.**> <b>Polish</b> Michal Predotka <*****@*****.**> <b>Russian</b> Evgeny Kozlov <*****@*****.**> <b>Serbian</b> Мирослав Николић <*****@*****.**> <b>Slovak</b> Robert Valik <*****@*****.**> <b>Spanish</b> Adolfo Jayme Barrientos <*****@*****.**> Jose Luis Tirado <*****@*****.**> <b>Swedish</b> Joachim Johansson <*****@*****.**> <b>Turkish</b> Ilker Alp <*****@*****.**> <b>Previous translators</b> Anton Alyab'ev <*****@*****.**> Michel Ange <*****@*****.**> Tobias Bannert <*****@*****.**> Bert <*****@*****.**> Martin Dahl Moe Marco de Freitas <*****@*****.**> Martin Egger <*****@*****.**> Sergiy Gavrylov <*****@*****.**> Emanuele Grande <*****@*****.**> Toni Lähdekorpi <*****@*****.**> Miroslav Matejaš <*****@*****.**> Erik M Frederik Müller <*****@*****.**> Jose Luis Navarro <*****@*****.**> Tomas Novak <*****@*****.**> Abel O'Rian <*****@*****.**> Balazs Oveges <*****@*****.**> Daniel Paessler <*****@*****.**> Miloš Popović <*****@*****.**> Ye Qing <*****@*****.**> Luca Reverberi <*****@*****.**> Ahmed Shubbar <*****@*****.**> Sergei Sedov <*****@*****.**> Marco Solari <*****@*****.**> Ulf Urdén <*****@*****.**> Julien Valroff <*****@*****.**> Aron Xu <*****@*****.**> Nicolás M. Zahlut <*****@*****.**> 梁其学 <*****@*****.**> """ # Replace < and > in email addresses translators_text = re.sub(r'<(.+)@(.+)>', r'<\1@\2>', translators_text, flags=re.MULTILINE) translators_text = translators_text.replace('\n', '<br>\n') translatorsLabel = QLabel(translators_text) translatorsLabel.setFont(font) translatorsLabel.setStyleSheet(label_style_sheet) translators = QScrollArea() translators.setWidget(translatorsLabel) translators.setStyleSheet(scroll_area_style_sheet) mainLayout = QVBoxLayout() self.stack = QStackedWidget() self.stack.addWidget(about) self.stack.addWidget(credits) self.stack.addWidget(translators) self.stack.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) buttonBox = QDialogButtonBox() closeButton = buttonBox.addButton( QDialogButtonBox.Close) # type: QPushButton translateDialogBoxButtons(buttonBox) self.creditsButton = buttonBox.addButton( _('Credits'), QDialogButtonBox.HelpRole) # type: QPushButton self.creditsButton.setDefault(False) self.creditsButton.setCheckable(True) self.translatorsButton = buttonBox.addButton( _('Translators'), QDialogButtonBox.ResetRole) # type: QPushButton self.translatorsButton.setDefault(False) self.translatorsButton.setCheckable(True) closeButton.setDefault(True) buttonLayout = QVBoxLayout() buttonLayout.addWidget(buttonBox) buttonLayout.setContentsMargins(left_margin, left_margin, left_margin, left_margin) mainLayout.setContentsMargins(0, 0, 0, 0) version = QLabel(__about__.__version__) version.setFixedHeight(white_box_height - title_bottom) version_style_sheet = """QLabel { padding-left: %(left_margin)dpx; }""" % dict(left_margin=left_margin) version.setStyleSheet(version_style_sheet) mainLayout.addSpacing(title_bottom) mainLayout.addWidget(version) mainLayout.addWidget(self.stack) mainLayout.addLayout(buttonLayout) self.setLayout(mainLayout) buttonBox.rejected.connect(self.reject) self.creditsButton.clicked.connect(self.creditsButtonClicked) self.translatorsButton.clicked.connect(self.translatorsButtonClicked) closeButton.setFocus() @pyqtSlot() def creditsButtonClicked(self) -> None: self.translatorsButton.setChecked(False) self.showStackItem() @pyqtSlot() def translatorsButtonClicked(self) -> None: self.creditsButton.setChecked(False) self.showStackItem() @pyqtSlot() def showStackItem(self) -> None: if self.creditsButton.isChecked(): self.stack.setCurrentIndex(1) elif self.translatorsButton.isChecked(): self.stack.setCurrentIndex(2) self.creditsButton.setChecked(False) else: self.stack.setCurrentIndex(0)
class CollapsibleTabWidget(QWidget): Horizontal = 0 Vertical = 1 doCollapse = pyqtSignal() def __init__(self, orientation=0, parent=None): super(CollapsibleTabWidget, self).__init__(parent=parent) self.frameLayout = None self.verticalLayout = None self.tabBar = None self.tabBarWidget = QWidget(self) self.orientation = orientation # self.orientation = self.Vertical self.splitter = None self.splitterPos = None self.splitterLower = None self.stackTitle = None self.stackWidget = None self.tabBarList = [] # local data if self.orientation == self.Horizontal: self.initHorizontalUI() self.titleBarIcon = TitleBar.down elif self.orientation == self.Vertical: self.initVerticalUI() self.titleBarIcon = TitleBar.left self.tabBarWidget.setStyleSheet('background-color: #B2B2B2;') self.stackTitle.setStyleSheet('background-color: #B2B2B2;') def initHorizontalUI(self): self.frameLayout = QVBoxLayout(self) self.tabBar = QHBoxLayout(self) self.tabBarWidget.setLayout(self.tabBar) self.tabBar.setAlignment(Qt.AlignLeft) self.verticalLayout = QVBoxLayout(self) # fill stack self.stackTitle = QStackedWidget(self) self.stackWidget = QStackedWidget(self) self.verticalLayout.addWidget(self.stackTitle) self.verticalLayout.addWidget(self.stackWidget) # finish self.frameLayout.addLayout(self.verticalLayout) self.frameLayout.addWidget(self.tabBarWidget) self.setLayout(self.frameLayout) self.tabBarWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) def initVerticalUI(self): self.frameLayout = QHBoxLayout(self) self.verticalLayout = QVBoxLayout(self) # tab bar self.tabBar = QVBoxLayout(self) self.tabBarWidget.setLayout(self.tabBar) self.tabBar.setAlignment(Qt.AlignTop) # fill stack self.stackTitle = QStackedWidget(self) self.stackWidget = QStackedWidget(self) self.verticalLayout.addWidget(self.stackTitle) self.verticalLayout.addWidget(self.stackWidget) self.stackWidget.addWidget(QLabel('asdf', self)) # finish self.frameLayout.addWidget(self.tabBarWidget) self.frameLayout.addLayout(self.verticalLayout) self.setLayout(self.frameLayout) self.tabBarWidget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Expanding) def setOrientation(self, orient): self.orientation = orient def onTabClicked(self, index): pass def addTab(self, widget: QWidget, title: str): titleBar = TitleBar(title, self) titleBar.setButtonOrient(self.titleBarIcon) titleBar.CollapseButton.clicked.connect(self.collapseStacks) self.stackTitle.addWidget(titleBar) self.stackWidget.addWidget(widget) tabButton = customPushButton(title, len(self.tabBarList), self.orientation, self) self.tabBarList.append(tabButton) tabButton.clicked.connect(self.collapseStacks) tabButton.clicked_index.connect(self.setCurStack) self.tabBar.addWidget(tabButton, 0, Qt.AlignLeft) self.stackTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.stackTitle.setFixedHeight(titleBar.Height) def collapseStacks(self): if self.stackWidget.isVisible(): self.splitterPos = self.splitter.sizes() self.stackTitle.hide() self.stackWidget.hide() if self.orientation == self.Horizontal: self.splitter.setSizes([10000, 0]) if self.orientation == self.Vertical: self.splitter.setSizes([0, 10000]) self.splitter.handle(1).setDisabled(True) else: self.splitter.setSizes(self.splitterPos) self.stackTitle.show() self.stackWidget.show() self.splitter.handle(1).setDisabled(False) self.doCollapse.emit() def setCurStack(self, index): self.stackTitle.setCurrentIndex(index) self.stackWidget.setCurrentIndex(index) def setSplitter(self, splitter: QSplitter): self.splitter = splitter self.splitter.splitterMoved.connect(self.setSplitterRate) def setSplitterRate(self, pos, index): self.splitterLower = self.splitter.sizes()[1]
class App(QDialog): def __init__(self): super().__init__() self.left = 10 self.top = 10 self.width = 800 self.height = 600 self.initUI() def initUI(self): self.setGeometry(self.left, self.top, self.width, self.height) self.createSidebar() self.createContent() self.windowLayout = QHBoxLayout(self) self.windowLayout.addWidget(self.sidebar) self.windowLayout.addWidget(self.content) self.addMenu(MenuChat()) #self.addMenu(MenuTraffic()) #self.addMenu(MenuFirewall()) self.addMenu(MenuExit()) self.content.setCurrentIndex(0) self.show() def addMenu(self, menu): menuButton = QPushButton(menu.name) menuButton.setSizePolicy( QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)) self.sidebarLayout.addWidget(menuButton) contentIndex = self.content.addWidget(menu.widget) def onClick(): self.content.setCurrentIndex(contentIndex) menu.onClick() menuButton.clicked.connect(onClick) def createSidebar(self): self.menuStack = QStackedWidget() sidebar = QWidget() sidebarLayout = QVBoxLayout() sidebar.setLayout(sidebarLayout) sidebar.setSizePolicy( QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)) #layout.setColumnStretch(1, 4) #layout.setColumnStretch(2, 4) self.sidebarLayout = sidebarLayout self.sidebar = sidebar def createContent(self): self.content = QStackedWidget() self.content.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
class EntryView(BaseTransactionView): def _setup(self): self._setupUi() self.etable = EntryTable(self.model.etable, view=self.tableView) self.efbar = EntryFilterBar(model=self.model.filter_bar, view=self.filterBar) self.bgraph = Chart(self.model.bargraph, view=self.barGraphView) self.lgraph = Chart(self.model.balgraph, view=self.lineGraphView) self._setupColumns( ) # Can only be done after the model has been connected self.reconciliationButton.clicked.connect( self.model.toggle_reconciliation_mode) def _setupUi(self): self.resize(483, 423) self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setSpacing(0) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setSpacing(0) self.filterBar = RadioBox(self) sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.filterBar.sizePolicy().hasHeightForWidth()) self.filterBar.setSizePolicy(sizePolicy) self.horizontalLayout.addWidget(self.filterBar) self.horizontalLayout.addItem(horizontalSpacer()) self.reconciliationButton = QPushButton(tr("Reconciliation")) self.reconciliationButton.setCheckable(True) self.horizontalLayout.addWidget(self.reconciliationButton) self.verticalLayout.addLayout(self.horizontalLayout) self.splitterView = QSplitter() self.splitterView.setOrientation(Qt.Vertical) self.splitterView.setChildrenCollapsible(False) self.tableView = TableView(self) self.tableView.setAcceptDrops(True) self.tableView.setEditTriggers(QAbstractItemView.DoubleClicked | QAbstractItemView.EditKeyPressed) self.tableView.setDragEnabled(True) self.tableView.setDragDropMode(QAbstractItemView.InternalMove) self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows) self.tableView.setSortingEnabled(True) self.tableView.horizontalHeader().setHighlightSections(False) self.tableView.horizontalHeader().setMinimumSectionSize(18) self.tableView.verticalHeader().setVisible(False) self.tableView.verticalHeader().setDefaultSectionSize(18) self.splitterView.addWidget(self.tableView) self.graphView = QStackedWidget(self) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.graphView.sizePolicy().hasHeightForWidth()) self.graphView.setSizePolicy(sizePolicy) self.graphView.setMinimumSize(0, 200) self.lineGraphView = LineGraphView() self.graphView.addWidget(self.lineGraphView) self.barGraphView = BarGraphView() self.graphView.addWidget(self.barGraphView) self.splitterView.addWidget(self.graphView) self.graphView.setCurrentIndex(1) self.splitterView.setStretchFactor(0, 1) self.splitterView.setStretchFactor(1, 0) self.verticalLayout.addWidget(self.splitterView) def _setupColumns(self): h = self.tableView.horizontalHeader() h.setSectionsMovable(True) # column drag & drop reorder # --- QWidget override def setFocus(self): self.etable.view.setFocus() # --- Public def fitViewsForPrint(self, viewPrinter): hidden = self.model.mainwindow.hidden_areas viewPrinter.fitTable(self.etable) if PaneArea.BottomGraph not in hidden: viewPrinter.fit(self.graphView.currentWidget(), 300, 150, expandH=True, expandV=True) def restoreSubviewsSize(self): graphHeight = self.model.graph_height_to_restore if graphHeight: splitterHeight = self.splitterView.height() sizes = [splitterHeight - graphHeight, graphHeight] self.splitterView.setSizes(sizes) # --- model --> view def refresh_reconciliation_button(self): if self.model.can_toggle_reconciliation_mode: self.reconciliationButton.setEnabled(True) self.reconciliationButton.setChecked( self.model.reconciliation_mode) else: self.reconciliationButton.setEnabled(False) self.reconciliationButton.setChecked(False) def show_bar_graph(self): self.graphView.setCurrentIndex(1) def show_line_graph(self): self.graphView.setCurrentIndex(0) def update_visibility(self): hidden = self.model.mainwindow.hidden_areas self.graphView.setHidden(PaneArea.BottomGraph in hidden)
def __setupUi(self): """Set up the UI. """ if self.__macUnified: self.tab = QToolBar() self.addToolBar(Qt.TopToolBarArea, self.tab) self.setUnifiedTitleAndToolBarOnMac(True) # This does not seem to work self.setWindowFlags(self.windowFlags() & \ ~Qt.MacWindowToolBarButtonHint) self.tab.actionTriggered[QAction].connect( self.__macOnToolBarAction) central = QStackedWidget() central.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) else: self.tab = central = QTabWidget(self) # Add a close button to the bottom of the dialog # (to satisfy GNOME 3 which shows the dialog without a title bar). container = container_widget_helper() container.layout().addWidget(central) buttonbox = QDialogButtonBox(QDialogButtonBox.Close) buttonbox.rejected.connect(self.close) container.layout().addWidget(buttonbox) self.setCentralWidget(container) self.stack = central # General Tab tab = QWidget() self.addTab(tab, self.tr("General"), toolTip=self.tr("General Options")) form = QFormLayout() tab.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) nodes = QWidget(self, objectName="nodes") nodes.setLayout(QVBoxLayout()) nodes.layout().setContentsMargins(0, 0, 0, 0) cb_anim = QCheckBox(self.tr("Enable node animations"), objectName="enable-node-animations", toolTip=self.tr( "Enable shadow and ping animations for nodes " "in the workflow.")) self.bind(cb_anim, "checked", "schemeedit/enable-node-animations") nodes.layout().addWidget(cb_anim) form.addRow(self.tr("Nodes"), nodes) links = QWidget(self, objectName="links") links.setLayout(QVBoxLayout()) links.layout().setContentsMargins(0, 0, 0, 0) cb_show = QCheckBox(self.tr("Show channel names between widgets"), objectName="show-channel-names", toolTip=self.tr( "Show source and sink channel names " "over the links.")) self.bind(cb_show, "checked", "schemeedit/show-channel-names") links.layout().addWidget(cb_show) form.addRow(self.tr("Links"), links) quickmenu = QWidget(self, objectName="quickmenu-options") quickmenu.setLayout(QVBoxLayout()) quickmenu.layout().setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("On double click"), toolTip=self.tr("Open quick menu on a double click " "on an empty spot in the canvas")) cb2 = QCheckBox(self.tr("On right click"), toolTip=self.tr("Open quick menu on a right click " "on an empty spot in the canvas")) cb3 = QCheckBox(self.tr("On space key press"), toolTip=self.tr("On Space key press while the mouse" "is hovering over the canvas.")) cb4 = QCheckBox(self.tr("On any key press"), toolTip=self.tr("On any key press while the mouse" "is hovering over the canvas.")) self.bind(cb1, "checked", "quickmenu/trigger-on-double-click") self.bind(cb2, "checked", "quickmenu/trigger-on-right-click") self.bind(cb3, "checked", "quickmenu/trigger-on-space-key") self.bind(cb4, "checked", "quickmenu/trigger-on-any-key") quickmenu.layout().addWidget(cb1) quickmenu.layout().addWidget(cb2) quickmenu.layout().addWidget(cb3) quickmenu.layout().addWidget(cb4) form.addRow(self.tr("Open quick menu on"), quickmenu) startup = QWidget(self, objectName="startup-group") startup.setLayout(QVBoxLayout()) startup.layout().setContentsMargins(0, 0, 0, 0) cb_splash = QCheckBox(self.tr("Show splash screen"), self, objectName="show-splash-screen") cb_welcome = QCheckBox(self.tr("Show welcome screen"), self, objectName="show-welcome-screen") self.bind(cb_splash, "checked", "startup/show-splash-screen") self.bind(cb_welcome, "checked", "startup/show-welcome-screen") startup.layout().addWidget(cb_splash) startup.layout().addWidget(cb_welcome) form.addRow(self.tr("On startup"), startup) toolbox = QWidget(self, objectName="toolbox-group") toolbox.setLayout(QVBoxLayout()) toolbox.layout().setContentsMargins(0, 0, 0, 0) exclusive = QCheckBox(self.tr("Only one tab can be open at a time")) self.bind(exclusive, "checked", "mainwindow/toolbox-dock-exclusive") toolbox.layout().addWidget(exclusive) form.addRow(self.tr("Tool box"), toolbox) tab.setLayout(form) # Output Tab tab = QWidget() self.addTab(tab, self.tr("Output"), toolTip="Output Redirection") form = QFormLayout() box = QWidget(self, objectName="streams") layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("Standard output")) cb2 = QCheckBox(self.tr("Standard error")) self.bind(cb1, "checked", "output/redirect-stdout") self.bind(cb2, "checked", "output/redirect-stderr") layout.addWidget(cb1) layout.addWidget(cb2) box.setLayout(layout) form.addRow(self.tr("Redirect output"), box) box = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) combo = QComboBox() combo.addItems([ self.tr("Critical"), self.tr("Error"), self.tr("Warn"), self.tr("Info"), self.tr("Debug") ]) cb = QCheckBox(self.tr("Show output on 'Error'"), objectName="focus-on-error") self.bind(combo, "currentIndex", "logging/level") self.bind(cb, "checked", "output/show-on-error") layout.addWidget(combo) layout.addWidget(cb) box.setLayout(layout) form.addRow(self.tr("Logging"), box) box = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("Stay on top"), objectName="stay-on-top") cb2 = QCheckBox(self.tr("Dockable"), objectName="output-dockable") self.bind(cb1, "checked", "output/stay-on-top") self.bind(cb2, "checked", "output/dockable") layout.addWidget(cb1) layout.addWidget(cb2) box.setLayout(layout) form.addRow(self.tr("Output window"), box) box = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("Open in external browser"), objectName="open-in-external-browser") cb2 = QCheckBox(self.tr("Stay on top"), objectName="help-stay-on-top") cb3 = QCheckBox(self.tr("Dockable"), objectName="help-dockable") self.bind(cb1, "checked", "help/open-in-external-browser") self.bind(cb2, "checked", "help/stay-on-top") self.bind(cb3, "checked", "help/dockable") layout.addWidget(cb1) layout.addWidget(cb2) layout.addWidget(cb3) box.setLayout(layout) form.addRow(self.tr("Help window"), box) tab.setLayout(form) # Categories Tab tab = QWidget() layout = QVBoxLayout() view = QListView() from .. import registry reg = registry.global_registry() model = QStandardItemModel() settings = QSettings() for cat in reg.categories(): item = QStandardItem() item.setText(cat.name) item.setCheckable(True) visible, _ = category_state(cat, settings) item.setCheckState(Qt.Checked if visible else Qt.Unchecked) model.appendRow([item]) view.setModel(model) layout.addWidget(view) tab.setLayout(layout) model.itemChanged.connect(lambda item: save_category_state( reg.category(str(item.text())), _State(item.checkState() == Qt.Checked, -1), settings)) self.addTab(tab, "Categories") if self.__macUnified: # Need some sensible size otherwise mac unified toolbar 'takes' # the space that should be used for layout of the contents self.adjustSize()
class LedWidget(QWidget): switched = pyqtSignal(str, str) # __________________________________________________________________ def __init__(self, status, size): super(LedWidget, self).__init__() self._redAsBold = False self._redAsRed = False self._defaultText = status self._defaultTextColor = "#{0:02x}{1:02x}{2:02x}".format( QGuiApplication.palette().color(QPalette.Text).red(), QGuiApplication.palette().color(QPalette.Text).green(), QGuiApplication.palette().color(QPalette.Text).blue()) self._ledImage = QStackedWidget() self._ledImage.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self._led = {} for color in [ 'black', 'blue', 'gray', 'green', 'orange', 'purple', 'red', 'yellow' ]: self._led[color] = QLabel() self._led[color].setPixmap( QIcon("./leds/led-{0}.svg".format(color)).pixmap(size)) self._led[color].setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self._ledImage.addWidget(self._led[color]) self._ledStatus = QLabel(self._defaultText) self._ledStatus.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) self._color = None main_layout = QHBoxLayout() main_layout.setContentsMargins(0, 0, 0, 0) main_layout.setSpacing(8) main_layout.addWidget(self._ledImage) main_layout.addWidget(self._ledStatus) self.setLayout(main_layout) self.switchOn('gray') # __________________________________________________________________ def close(self): self._file.close() # __________________________________________________________________ def color(self): return self._color # __________________________________________________________________ def setRedAsBold(self, yes): self._redAsBold = yes # __________________________________________________________________ def setRedAsRed(self, yes): self._redAsRed = yes @pyqtSlot(str, str) # __________________________________________________________________ def switchOn(self, color, text=""): if not text: text = self._defaultText style_color = self._defaultTextColor style_weight = "normal" if color == 'red' and self._redAsBold: style_weight = "bold" if color == 'red' and self._redAsRed: style_color = LED_COLOR_STYLE_RED for c in [ 'black', 'blue', 'gray', 'green', 'orange', 'purple', 'red', 'yellow' ]: if color == c: self._ledImage.setCurrentWidget(self._led[color]) self._color = color self._ledStatus.setStyleSheet("color: {0}; font-weight: {1}".format( style_color, style_weight)) self._ledStatus.setText(text) self.switched.emit(color, text)
class EntryView(BaseTransactionView): def _setup(self): self._setupUi() self.etable = EntryTable(self.model.etable, view=self.tableView) self.efbar = EntryFilterBar(model=self.model.filter_bar, view=self.filterBar) self.bgraph = Chart(self.model.bargraph, view=self.barGraphView) self.lgraph = Chart(self.model.balgraph, view=self.lineGraphView) self._setupColumns() # Can only be done after the model has been connected self.reconciliationButton.clicked.connect(self.model.toggle_reconciliation_mode) def _setupUi(self): self.resize(483, 423) self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setSpacing(0) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setSpacing(0) self.filterBar = RadioBox(self) sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.filterBar.sizePolicy().hasHeightForWidth()) self.filterBar.setSizePolicy(sizePolicy) self.horizontalLayout.addWidget(self.filterBar) self.horizontalLayout.addItem(horizontalSpacer()) self.reconciliationButton = QPushButton(tr("Reconciliation")) self.reconciliationButton.setCheckable(True) self.horizontalLayout.addWidget(self.reconciliationButton) self.verticalLayout.addLayout(self.horizontalLayout) self.splitterView = QSplitter() self.splitterView.setOrientation(Qt.Vertical) self.splitterView.setChildrenCollapsible(False) self.tableView = TableView(self) self.tableView.setAcceptDrops(True) self.tableView.setEditTriggers(QAbstractItemView.DoubleClicked|QAbstractItemView.EditKeyPressed) self.tableView.setDragEnabled(True) self.tableView.setDragDropMode(QAbstractItemView.InternalMove) self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows) self.tableView.setSortingEnabled(True) self.tableView.horizontalHeader().setHighlightSections(False) self.tableView.horizontalHeader().setMinimumSectionSize(18) self.tableView.verticalHeader().setVisible(False) self.tableView.verticalHeader().setDefaultSectionSize(18) self.splitterView.addWidget(self.tableView) self.graphView = QStackedWidget(self) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.graphView.sizePolicy().hasHeightForWidth()) self.graphView.setSizePolicy(sizePolicy) self.graphView.setMinimumSize(0, 200) self.lineGraphView = LineGraphView() self.graphView.addWidget(self.lineGraphView) self.barGraphView = BarGraphView() self.graphView.addWidget(self.barGraphView) self.splitterView.addWidget(self.graphView) self.graphView.setCurrentIndex(1) self.splitterView.setStretchFactor(0, 1) self.splitterView.setStretchFactor(1, 0) self.verticalLayout.addWidget(self.splitterView) def _setupColumns(self): h = self.tableView.horizontalHeader() h.setSectionsMovable(True) # column drag & drop reorder # --- QWidget override def setFocus(self): self.etable.view.setFocus() # --- Public def fitViewsForPrint(self, viewPrinter): hidden = self.model.mainwindow.hidden_areas viewPrinter.fitTable(self.etable) if PaneArea.BottomGraph not in hidden: viewPrinter.fit(self.graphView.currentWidget(), 300, 150, expandH=True, expandV=True) def restoreSubviewsSize(self): graphHeight = self.model.graph_height_to_restore if graphHeight: splitterHeight = self.splitterView.height() sizes = [splitterHeight-graphHeight, graphHeight] self.splitterView.setSizes(sizes) # --- model --> view def refresh_reconciliation_button(self): if self.model.can_toggle_reconciliation_mode: self.reconciliationButton.setEnabled(True) self.reconciliationButton.setChecked(self.model.reconciliation_mode) else: self.reconciliationButton.setEnabled(False) self.reconciliationButton.setChecked(False) def show_bar_graph(self): self.graphView.setCurrentIndex(1) def show_line_graph(self): self.graphView.setCurrentIndex(0) def update_visibility(self): hidden = self.model.mainwindow.hidden_areas self.graphView.setHidden(PaneArea.BottomGraph in hidden)
class Ui_MainWindow(object): def setupUi(self, MainWindow): self.MainWindow = MainWindow self.setupMainWindow() self.setupMenuBar() self.setupAjdustmentOptionBar() self.setupMainStack() self.shiftUi = Ui_ShiftWindow(self.shift_page) self.shiftUi.setupUi() self.perpetualUi = Ui_PerpetualWindow(self.perpetual_page) self.perpetualUi.setupUi() self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def setupMainWindow(self): self.MainWindow.setObjectName("MainWindow") self.MainWindow.resize(1500, 800) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(1) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.MainWindow.sizePolicy().hasHeightForWidth()) self.MainWindow.setSizePolicy(sizePolicy) self.MainWindow.setMinimumSize(QtCore.QSize(1500, 800)) self.centralWidget = QWidget(self.MainWindow) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(1) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.centralWidget.sizePolicy().hasHeightForWidth()) self.centralWidget.setSizePolicy(sizePolicy) self.centralWidget.setMinimumSize(QtCore.QSize(1500, 800)) self.centralWidget.setSizeIncrement(QtCore.QSize(5, 5)) self.centralWidget.setBaseSize(QtCore.QSize(5, 5)) self.centralWidget.setObjectName("centralWidget") self.MainWindow.setCentralWidget(self.centralWidget) self.statusBar = QStatusBar(self.MainWindow) self.statusBar.setObjectName("statusBar") self.MainWindow.setStatusBar(self.statusBar) self.toolBar = QToolBar(self.MainWindow) self.toolBar.setObjectName("toolBar") self.MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar) self.outer_gridLayout = QGridLayout(self.centralWidget) self.outer_gridLayout.setSizeConstraint(QLayout.SetMinimumSize) self.outer_gridLayout.setContentsMargins(11, 6, 11, 0) self.outer_gridLayout.setSpacing(6) self.outer_gridLayout.setObjectName("outer_gridLayout") def setupMenuBar(self): self.menuBar = QMenuBar(self.MainWindow) self.menuBar.setGeometry(QtCore.QRect(0, 0, 942, 21)) self.menuBar.setObjectName("menuBar") self.MainWindow.setMenuBar(self.menuBar) self.menuLog = QMenu(self.menuBar) self.menuLog.setObjectName("menuLog") self.actionLog = QAction(self.MainWindow) self.actionLog.setObjectName("actionLog") self.menuLog.addAction(self.actionLog) self.menuBar.addAction(self.menuLog.menuAction()) _translate = QtCore.QCoreApplication.translate self.menuLog.setTitle(_translate("MainWindow", "Log")) self.actionLog.setText(_translate("MainWindow", "Show Log")) self.menuAbout = QMenu(self.menuBar) self.menuAbout.setObjectName("menuAbout") self.actionHelp = QAction(self.MainWindow) self.actionHelp.setObjectName("actionHelp") self.menuAbout.addAction(self.actionHelp) self.menuBar.addAction(self.menuAbout.menuAction()) _translate = QtCore.QCoreApplication.translate self.menuAbout.setTitle(_translate("MainWindow", "About")) self.actionHelp.setText(_translate("MainWindow", "Help")) def setupAjdustmentOptionBar(self): self.verticalWidget = QWidget(self.centralWidget) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(1) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.verticalWidget.sizePolicy().hasHeightForWidth()) self.verticalWidget.setSizePolicy(sizePolicy) self.verticalWidget.setMinimumSize(QtCore.QSize(120, 0)) self.verticalWidget.setMaximumSize(QtCore.QSize(120, 16777215)) self.verticalWidget.setStyleSheet("background-color:darkgray") self.verticalWidget.setObjectName("verticalWidget") self.verticalLayout = QVBoxLayout(self.verticalWidget) self.verticalLayout.setContentsMargins(5, 65, 5, 11) self.verticalLayout.setSpacing(20) self.verticalLayout.setObjectName("verticalLayout") self.shift_button = QPushButton(self.verticalWidget) self.shift_button.setMinimumSize(QtCore.QSize(0, 100)) font = QtGui.QFont() font.setPointSize(11) font.setBold(True) font.setWeight(75) self.shift_button.setFont(font) self.shift_button.setObjectName("shift_button") self.shift_button.setCheckable(True) self.perpetual_button = QPushButton(self.verticalWidget) self.perpetual_button.setMinimumSize(QtCore.QSize(0, 100)) font = QtGui.QFont() font.setPointSize(11) font.setBold(True) font.setWeight(75) self.perpetual_button.setFont(font) self.perpetual_button.setCheckable(True) self.perpetual_button.setObjectName("perpetual_button") self.verticalLayout.addWidget(self.shift_button) self.verticalLayout.addWidget(self.perpetual_button) self.buttonGroup = QButtonGroup(self.verticalWidget) self.buttonGroup.addButton(self.shift_button) self.buttonGroup.addButton(self.perpetual_button) self.buttonGroup.setExclusive(True) spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) self.verticalLayout.addItem(spacerItem) self.outer_gridLayout.addWidget(self.verticalWidget, 0, 0, 1, 1) def setupMainStack(self): self.shift_main_stacked = QStackedWidget(self.centralWidget) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(1) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.shift_main_stacked.sizePolicy().hasHeightForWidth()) self.shift_main_stacked.setSizePolicy(sizePolicy) self.shift_main_stacked.setObjectName("shift_main_stacked") self.shift_page = QWidget() sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(1) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.shift_page.sizePolicy().hasHeightForWidth()) self.shift_page.setSizePolicy(sizePolicy) self.shift_page.setObjectName("shift_page") self.shift_main_stacked.addWidget(self.shift_page) self.perpetual_page = QWidget() sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(1) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.perpetual_page.sizePolicy().hasHeightForWidth()) self.perpetual_page.setSizePolicy(sizePolicy) self.perpetual_page.setObjectName("perpetual_page") self.shift_main_stacked.addWidget(self.perpetual_page) self.outer_gridLayout.addWidget(self.shift_main_stacked, 0, 1, 1, 1) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate self.MainWindow.setWindowTitle( _translate("MainWindow", "Continuous Contract Maker")) self.shift_button.setText( _translate("MainWindow", "Forward\n" "Backward")) self.perpetual_button.setText( _translate("MainWindow", "Perputual\n" " Series")) self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar"))