def __init__(self, rgbColors, parent=None, windowTitle="Palette Editor", **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(4, 4, 4, 4) hbox = gui.hBox(self, "Information") gui.widgetLabel( hbox, '<p align="center">You can reorder colors in the list using the' "<br/>buttons on the right or by dragging and dropping the items." "<br/>To change a specific color double click the item in the " "list.</p>", ) hbox = gui.hBox(self, box=True) self.discListbox = gui.listBox(hbox, self, enableDragDrop=1) vbox = gui.vBox(hbox) buttonUPAttr = gui.button(vbox, self, "", callback=self.moveAttrUP, tooltip="Move selected colors up") buttonDOWNAttr = gui.button( vbox, self, "", callback=self.moveAttrDOWN, tooltip="Move selected colors down", ) buttonUPAttr.setIcon(QIcon(gui.resource_filename("icons/Dlg_up3.png"))) buttonUPAttr.setSizePolicy( QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)) buttonUPAttr.setMaximumWidth(30) buttonDOWNAttr.setIcon( QIcon(gui.resource_filename("icons/Dlg_down3.png"))) buttonDOWNAttr.setSizePolicy( QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)) buttonDOWNAttr.setMaximumWidth(30) self.discListbox.itemDoubleClicked.connect(self.changeDiscreteColor) box = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, accepted=self.accept, rejected=self.reject, ) self.layout().addWidget(box) self.discListbox.setIconSize(QSize(25, 25)) for ind, (r, g, b) in enumerate(rgbColors): item = QListWidgetItem(ColorPixmap(QColor(r, g, b), 25), "Color %d" % (ind + 1)) item.rgbColor = (r, g, b) self.discListbox.addItem(item) self.resize(300, 300)
def __init__(self, widget, parent=None, name=None): OWPlot.__init__(self, parent, name, axes=[], widget=widget) ScaleData.__init__(self) self.update_antialiasing(False) self.widget = widget self.last_selected_curve = None self.enableGridXB(0) self.enableGridYL(0) self.domain_contingencies = None self.auto_update_axes = 1 self.old_legend_keys = [] self.selection_conditions = {} self.attributes = [] self.visualized_mid_labels = [] self.attribute_indices = [] self.valid_data = [] self.groups = {} self.colors = None self.selected_examples = [] self.unselected_examples = [] self.bottom_pixmap = QPixmap( gui.resource_filename("icons/upgreenarrow.png")) self.top_pixmap = QPixmap( gui.resource_filename("icons/downgreenarrow.png"))
def __init__(self, widget, parent=None, name=None): OWPlot.__init__(self, parent, name, axes=[], widget=widget) ScaleData.__init__(self) self.update_antialiasing(False) self.widget = widget self.last_selected_curve = None self.enableGridXB(0) self.enableGridYL(0) self.domain_contingencies = None self.auto_update_axes = 1 self.old_legend_keys = [] self.selection_conditions = {} self.attributes = [] self.visualized_mid_labels = [] self.attribute_indices = [] self.valid_data = [] self.groups = {} self.colors = None self.selected_examples = [] self.unselected_examples = [] self.bottom_pixmap = QPixmap(gui.resource_filename("icons/upgreenarrow.png")) self.top_pixmap = QPixmap(gui.resource_filename("icons/downgreenarrow.png"))
def getWidgetStateIcons(cls): if not hasattr(cls, "_cached__widget_state_icons"): info = QPixmap(gui.resource_filename("icons/information.png")) warning = QPixmap(gui.resource_filename("icons/warning.png")) error = QPixmap(gui.resource_filename("icons/error.png")) cls._cached__widget_state_icons = \ {"Info": info, "Warning": warning, "Error": error} return cls._cached__widget_state_icons
def getWidgetStateIcons(cls): """Return a (potentially cached) dictionary with icons for info (key `Info`), warning (`Warning`) and error (`Error`) """ if not hasattr(cls, "_cached__widget_state_icons"): info = QPixmap(gui.resource_filename("icons/information.png")) warning = QPixmap(gui.resource_filename("icons/warning.png")) error = QPixmap(gui.resource_filename("icons/error.png")) cls._cached__widget_state_icons = \ {"Info": info, "Warning": warning, "Error": error} return cls._cached__widget_state_icons
def setup_notifications(): settings = QSettings() # If run for the fifth time, prompt short survey show_survey = settings.value("startup/show-short-survey", True, type=bool) and \ settings.value("startup/launch-count", 0, type=int) >= 5 if show_survey: surveyDialogButtons = NotificationWidget.Ok | NotificationWidget.Close surveyDialog = NotificationWidget( icon=QIcon(gui.resource_filename("icons/information.png")), title="Survey", text="We want to understand our users better.\n" "Would you like to take a short survey?", standardButtons=surveyDialogButtons) def handle_survey_response(button): if surveyDialog.buttonRole( button) == NotificationWidget.AcceptRole: success = QDesktopServices.openUrl( QUrl("https://orange.biolab.si/survey/short.html")) settings.setValue("startup/show-short-survey", not success) elif surveyDialog.buttonRole( button) == NotificationWidget.RejectRole: settings.setValue("startup/show-short-survey", False) surveyDialog.clicked.connect(handle_survey_response) NotificationOverlay.registerNotification(surveyDialog) # data collection permission if not settings.value( "error-reporting/permission-requested", False, type=bool): permDialogButtons = NotificationWidget.Ok | NotificationWidget.Close permDialog = NotificationWidget( icon=QIcon(gui.resource_filename("../../distribute/icon-48.png")), title="Anonymous Usage Statistics", text="Do you wish to opt-in to sharing " "statistics about how you use Orange?\n" "All data is anonymized and used " "exclusively for understanding how users " "interact with Orange.", standardButtons=permDialogButtons) btnOK = permDialog.button(NotificationWidget.AcceptRole) btnOK.setText("Allow") def handle_permission_response(button): if permDialog.buttonRole(button) != permDialog.DismissRole: settings.setValue("error-reporting/permission-requested", True) if permDialog.buttonRole(button) == permDialog.AcceptRole: UsageStatistics.set_enabled(True) settings.setValue("error-reporting/send-statistics", True) permDialog.clicked.connect(handle_permission_response) NotificationOverlay.registerNotification(permDialog)
def widgetStateToHtml(self, info=True, warning=True, error=True): iconpaths = { "Info": gui.resource_filename("icons/information.png"), "Warning": gui.resource_filename("icons/warning.png"), "Error": gui.resource_filename("icons/error.png") } items = [] for show, what in [(info, "Info"), (warning, "Warning"), (error, "Error")]: if show and self.widgetState[what]: items.append('<img src="%s" style="float: left;"> %s' % (iconpaths[what], "\n".join(self.widgetState[what].values()))) return "<br>".join(items)
class Information(MessageGroup): """Base class for groups of information messages in widgets""" severity = 1 icon_path = gui.resource_filename("icons/information.png") bar_background = "#ceceff" bar_icon = QStyle.SP_MessageBoxInformation
class Error(MessageGroup): """Base class for groups of error messages in widgets""" severity = 3 icon_path = gui.resource_filename("icons/error.png") bar_background = "#ffc6c6" bar_icon = QStyle.SP_MessageBoxCritical
def compare_versions(latest): version = pkg_resources.parse_version skipped = settings.value('startup/latest-skipped-version', "", type=str) if version(latest) <= version(current) or \ latest == skipped: return questionButtons = NotificationWidget.Ok | NotificationWidget.Close question = NotificationWidget( icon=QIcon(gui.resource_filename('icons/Dlg_down3.png')), title='Orange Update Available', text='Current version: <b>{}</b><br>' 'Latest version: <b>{}</b>'.format(current, latest), textFormat=Qt.RichText, standardButtons=questionButtons, acceptLabel="Download", rejectLabel="Skip this Version") def handle_click(b): if question.buttonRole(b) == question.RejectRole: settings.setValue('startup/latest-skipped-version', latest) if question.buttonRole(b) == question.AcceptRole: QDesktopServices.openUrl( QUrl("https://orange.biolab.si/download/")) question.clicked.connect(handle_click) NotificationOverlay.registerNotification(question)
class Warning(MessageGroup): """Base class for groups of warning messages in widgets""" severity = 2 icon_path = gui.resource_filename("icons/warning.png") bar_background = "#ffffc9" bar_icon = QStyle.SP_MessageBoxWarning
def __init__(self, rgbColors, parent=None, windowTitle="Palette Editor", **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(4, 4, 4, 4) hbox = gui.hBox(self, "Information") gui.widgetLabel( hbox, '<p align="center">You can reorder colors in the list using the' '<br/>buttons on the right or by dragging and dropping the items.' '<br/>To change a specific color double click the item in the ' 'list.</p>') hbox = gui.hBox(self, box=True) self.discListbox = gui.listBox(hbox, self, enableDragDrop=1) vbox = gui.vBox(hbox) buttonUPAttr = gui.button(vbox, self, "", callback=self.moveAttrUP, tooltip="Move selected colors up") buttonDOWNAttr = gui.button(vbox, self, "", callback=self.moveAttrDOWN, tooltip="Move selected colors down") buttonUPAttr.setIcon(QIcon(gui.resource_filename("icons/Dlg_up3.png"))) buttonUPAttr.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)) buttonUPAttr.setMaximumWidth(30) buttonDOWNAttr.setIcon(QIcon(gui.resource_filename("icons/Dlg_down3.png"))) buttonDOWNAttr.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)) buttonDOWNAttr.setMaximumWidth(30) self.discListbox.itemDoubleClicked.connect(self.changeDiscreteColor) box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, accepted=self.accept, rejected=self.reject) self.layout().addWidget(box) self.discListbox.setIconSize(QSize(25, 25)) for ind, (r, g, b) in enumerate(rgbColors): item = QListWidgetItem(ColorPixmap(QColor(r, g, b), 25), "Color %d" % (ind + 1)) item.rgbColor = (r, g, b) self.discListbox.addItem(item) self.resize(300, 300)
def insertLayout(self): def createPixmapWidget(self, parent, iconName): w = QLabel(parent) parent.layout().addWidget(w) w.setFixedSize(16, 16) w.hide() if os.path.exists(iconName): w.setPixmap(QPixmap(iconName)) return w self.setLayout(QVBoxLayout()) self.layout().setMargin(2) self.warning_bar = gui.widgetBox(self, orientation="horizontal", margin=0, spacing=0) self.warning_icon = gui.widgetLabel(self.warning_bar, "") self.warning_label = gui.widgetLabel(self.warning_bar, "") self.warning_label.setStyleSheet("padding-top: 5px") self.warning_bar.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Maximum) gui.rubber(self.warning_bar) self.warning_bar.setVisible(False) self.topWidgetPart = gui.widgetBox(self, orientation="horizontal", margin=0) self.leftWidgetPart = gui.widgetBox(self.topWidgetPart, orientation="vertical", margin=0) if self.want_main_area: self.leftWidgetPart.setSizePolicy( QSizePolicy(QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)) self.leftWidgetPart.updateGeometry() self.mainArea = gui.widgetBox(self.topWidgetPart, orientation="vertical", sizePolicy=QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding), margin=0) self.mainArea.layout().setMargin(4) self.mainArea.updateGeometry() if self.want_control_area: self.controlArea = gui.widgetBox(self.leftWidgetPart, orientation="vertical", margin=4) if self.want_graph and self.show_save_graph: graphButtonBackground = gui.widgetBox(self.leftWidgetPart, orientation="horizontal", margin=4) self.graphButton = gui.button(graphButtonBackground, self, "&Save Graph") self.graphButton.setAutoDefault(0) if self.want_status_bar: self.widgetStatusArea = QFrame(self) self.statusBarIconArea = QFrame(self) self.widgetStatusBar = QStatusBar(self) self.layout().addWidget(self.widgetStatusArea) self.widgetStatusArea.setLayout(QHBoxLayout(self.widgetStatusArea)) self.widgetStatusArea.layout().addWidget(self.statusBarIconArea) self.widgetStatusArea.layout().addWidget(self.widgetStatusBar) self.widgetStatusArea.layout().setMargin(0) self.widgetStatusArea.setFrameShape(QFrame.StyledPanel) self.statusBarIconArea.setLayout(QHBoxLayout()) self.widgetStatusBar.setSizeGripEnabled(0) self.statusBarIconArea.hide() self._warningWidget = createPixmapWidget( self.statusBarIconArea, gui.resource_filename("icons/triangle-orange.png")) self._errorWidget = createPixmapWidget( self.statusBarIconArea, gui.resource_filename("icons/triangle-red.png")) if not self.resizing_enabled: self.layout().setSizeConstraint(QVBoxLayout.SetFixedSize)
def set_basic_layout(self): """Provide the basic widget layout Which parts are created is regulated by class attributes `want_main_area`, `want_control_area`, `want_message_bar` and `buttons_area_orientation`, the presence of method `send_report` and attribute `graph_name`. """ self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(2, 2, 2, 2) if not self.resizing_enabled: self.layout().setSizeConstraint(QVBoxLayout.SetFixedSize) self.want_main_area = self.want_main_area or self.graph_name self._create_default_buttons() self._insert_splitter() if self.want_control_area: self._insert_control_area() if self.want_main_area: self._insert_main_area() if self.want_message_bar: # Use a OverlayWidget for status bar positioning. c = OverlayWidget(self, alignment=Qt.AlignBottom) c.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) c.setWidget(self) c.setLayout(QVBoxLayout()) c.layout().setContentsMargins(0, 0, 0, 0) sb = QStatusBar() sb.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Maximum) sb.setSizeGripEnabled(self.resizing_enabled) c.layout().addWidget(sb) help = self.__help_action icon = QIcon(gui.resource_filename("icons/help.svg")) icon.addFile(gui.resource_filename("icons/help-hover.svg"), mode=QIcon.Active) help_button = SimpleButton( icon=icon, toolTip="Show widget help", visible=help.isVisible(), ) @help.changed.connect def _(): help_button.setVisible(help.isVisible()) help_button.setEnabled(help.isEnabled()) help_button.clicked.connect(help.trigger) sb.addWidget(help_button) if self.graph_name is not None: icon = QIcon(gui.resource_filename("icons/chart.svg")) icon.addFile(gui.resource_filename("icons/chart-hover.svg"), mode=QIcon.Active) b = SimpleButton( icon=icon, toolTip="Save Image", ) b.clicked.connect(self.save_graph) sb.addWidget(b) if hasattr(self, "send_report"): icon = QIcon(gui.resource_filename("icons/report.svg")) icon.addFile(gui.resource_filename("icons/report-hover.svg"), mode=QIcon.Active) b = SimpleButton(icon=icon, toolTip="Report") b.clicked.connect(self.show_report) sb.addWidget(b) self.message_bar = MessagesWidget(self) self.message_bar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) pb = QProgressBar(maximumWidth=120, minimum=0, maximum=100) pb.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Ignored) pb.setAttribute(Qt.WA_LayoutUsesWidgetRect) pb.setAttribute(Qt.WA_MacMiniSize) pb.hide() sb.addPermanentWidget(pb) sb.addPermanentWidget(self.message_bar) def statechanged(): pb.setVisible(bool(self.processingState) or self.isBlocking()) if self.isBlocking() and not self.processingState: pb.setRange(0, 0) # indeterminate pb elif self.processingState: pb.setRange(0, 100) # determinate pb self.processingStateChanged.connect(statechanged) self.blockingStateChanged.connect(statechanged) @self.progressBarValueChanged.connect def _(val): pb.setValue(int(val)) # Reserve the bottom margins for the status bar margins = self.layout().contentsMargins() margins.setBottom(sb.sizeHint().height()) self.setContentsMargins(margins)
import os from PyQt4.QtGui import QListWidget, QIcon, QSizePolicy from Orange.widgets import gui from Orange.widgets.settings import ContextSetting from Orange.widgets.widget import OWWidget from Orange.widgets.utils import vartype ICON_UP = gui.resource_filename("icons/Dlg_up3.png") ICON_DOWN = gui.resource_filename("icons/Dlg_down3.png") class OWVisWidget(OWWidget): _shown_attributes = ContextSetting(default=[], required=ContextSetting.REQUIRED, selected='selected_shown', reservoir="_hidden_attributes") # Setting above will override these fields _hidden_attributes = () selected_shown = () selected_hidden = () @property def shown_attributes(self): return [a[0] for a in self._shown_attributes] @shown_attributes.setter def shown_attributes(self, value): shown = [] hidden = [] domain = self.get_data_domain()
SPACE = 0 ZOOM = 1 PAN = 2 SELECT = 3 RECTANGLE = 4 POLYGON = 5 REMOVE_LAST = 6 REMOVE_ALL = 7 SEND_SELECTION = 8 ZOOM_EXTENT = 9 ZOOM_SELECTION = 10 # attr name used to store toolbars on a widget TOOLBARS_STORE = "__toolbars" dlg_zoom = gui.resource_filename("icons/Dlg_zoom.png") dlg_zoom_selection = gui.resource_filename("icons/Dlg_zoom_selection.png") dlg_pan = gui.resource_filename("icons/Dlg_pan_hand.png") dlg_select = gui.resource_filename("icons/Dlg_arrow.png") dlg_rect = gui.resource_filename("icons/Dlg_rect.png") dlg_poly = gui.resource_filename("icons/Dlg_poly.png") dlg_zoom_extent = gui.resource_filename("icons/Dlg_zoom_extent.png") dlg_undo = gui.resource_filename("icons/Dlg_undo.png") dlg_clear = gui.resource_filename("icons/Dlg_clear.png") dlg_send = gui.resource_filename("icons/Dlg_send.png") dlg_browseRectangle = gui.resource_filename("icons/Dlg_browseRectangle.png") dlg_browseCircle = gui.resource_filename("icons/Dlg_browseCircle.png") class ToolbarButton: def __init__(self,
import os from AnyQt.QtWidgets import QListWidget from Orange.widgets import gui from Orange.widgets.settings import ContextSetting from Orange.widgets.widget import OWWidget from Orange.widgets.utils import vartype ICON_UP = gui.resource_filename("icons/Dlg_up3.png") ICON_DOWN = gui.resource_filename("icons/Dlg_down3.png") class OWVisWidget(OWWidget): _shown_attributes = ContextSetting(default=[], required=ContextSetting.REQUIRED, selected='selected_shown', reservoir="_hidden_attributes") # Setting above will override these fields _hidden_attributes = () selected_shown = () selected_hidden = () @property def shown_attributes(self): return [a[0] for a in self._shown_attributes] @shown_attributes.setter def shown_attributes(self, value): shown = [] hidden = []
SPACE = 0 ZOOM = 1 PAN = 2 SELECT = 3 RECTANGLE = 4 POLYGON = 5 REMOVE_LAST = 6 REMOVE_ALL = 7 SEND_SELECTION = 8 ZOOM_EXTENT = 9 ZOOM_SELECTION = 10 # attr name used to store toolbars on a widget TOOLBARS_STORE = "__toolbars" dlg_zoom = gui.resource_filename("icons/Dlg_zoom.png") dlg_zoom_selection = gui.resource_filename("icons/Dlg_zoom_selection.png") dlg_pan = gui.resource_filename("icons/Dlg_pan_hand.png") dlg_select = gui.resource_filename("icons/Dlg_arrow.png") dlg_rect = gui.resource_filename("icons/Dlg_rect.png") dlg_poly = gui.resource_filename("icons/Dlg_poly.png") dlg_zoom_extent = gui.resource_filename("icons/Dlg_zoom_extent.png") dlg_undo = gui.resource_filename("icons/Dlg_undo.png") dlg_clear = gui.resource_filename("icons/Dlg_clear.png") dlg_send = gui.resource_filename("icons/Dlg_send.png") dlg_browseRectangle = gui.resource_filename("icons/Dlg_browseRectangle.png") dlg_browseCircle = gui.resource_filename("icons/Dlg_browseCircle.png") class ToolbarButton: def __init__(self, text, attr_name, ext_attr_name,
def insertLayout(self): def createPixmapWidget(self, parent, iconName): w = QLabel(parent) parent.layout().addWidget(w) w.setFixedSize(16, 16) w.hide() if os.path.exists(iconName): w.setPixmap(QPixmap(iconName)) return w self.setLayout(QVBoxLayout()) self.layout().setMargin(2) self.warning_bar = gui.widgetBox(self, orientation="horizontal", margin=0, spacing=0) self.warning_icon = gui.widgetLabel(self.warning_bar, "") self.warning_label = gui.widgetLabel(self.warning_bar, "") self.warning_label.setStyleSheet("padding-top: 5px") self.warning_bar.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Maximum) gui.rubber(self.warning_bar) self.warning_bar.setVisible(False) self.want_main_area = self.graph_name is not None or self.want_main_area splitter = self.Splitter(Qt.Horizontal, self) self.layout().addWidget(splitter) if self.want_control_area: self.controlArea = gui.widgetBox(splitter, orientation="vertical", margin=0) splitter.setSizes([1]) # Results in smallest size allowed by policy if self.graph_name is not None or hasattr(self, "send_report"): leftSide = self.controlArea self.controlArea = gui.widgetBox(leftSide, margin=0) if self.graph_name is not None: self.graphButton = gui.button(leftSide, None, "&Save Graph") self.graphButton.clicked.connect(self.save_graph) self.graphButton.setAutoDefault(0) if hasattr(self, "send_report"): self.report_button = gui.button(leftSide, None, "&Report", callback=self.show_report) self.report_button.setAutoDefault(0) if self.want_main_area: self.controlArea.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.MinimumExpanding) self.controlArea.layout().setContentsMargins(4, 4, 0 if self.want_main_area else 4, 4) if self.want_main_area: self.mainArea = gui.widgetBox(splitter, orientation="vertical", margin=4, sizePolicy=QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) splitter.setCollapsible(1, False) self.mainArea.layout().setContentsMargins(0 if self.want_control_area else 4, 4, 4, 4) if self.want_status_bar: self.widgetStatusArea = QFrame(self) self.statusBarIconArea = QFrame(self) self.widgetStatusBar = QStatusBar(self) self.layout().addWidget(self.widgetStatusArea) self.widgetStatusArea.setLayout(QHBoxLayout(self.widgetStatusArea)) self.widgetStatusArea.layout().addWidget(self.statusBarIconArea) self.widgetStatusArea.layout().addWidget(self.widgetStatusBar) self.widgetStatusArea.layout().setMargin(0) self.widgetStatusArea.setFrameShape(QFrame.StyledPanel) self.statusBarIconArea.setLayout(QHBoxLayout()) self.widgetStatusBar.setSizeGripEnabled(0) self.statusBarIconArea.hide() self._warningWidget = createPixmapWidget( self.statusBarIconArea, gui.resource_filename("icons/triangle-orange.png")) self._errorWidget = createPixmapWidget( self.statusBarIconArea, gui.resource_filename("icons/triangle-red.png")) if not self.resizing_enabled: self.layout().setSizeConstraint(QVBoxLayout.SetFixedSize)
def insertLayout(self): def createPixmapWidget(self, parent, iconName): w = QLabel(parent) parent.layout().addWidget(w) w.setFixedSize(16, 16) w.hide() if os.path.exists(iconName): w.setPixmap(QPixmap(iconName)) return w self.setLayout(QVBoxLayout()) self.layout().setMargin(2) self.warning_bar = gui.widgetBox(self, orientation="horizontal", margin=0, spacing=0) self.warning_icon = gui.widgetLabel(self.warning_bar, "") self.warning_label = gui.widgetLabel(self.warning_bar, "") self.warning_label.setStyleSheet("padding-top: 5px") self.warning_bar.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Maximum) gui.rubber(self.warning_bar) self.warning_bar.setVisible(False) self.topWidgetPart = gui.widgetBox(self, orientation="horizontal", margin=0) self.leftWidgetPart = gui.widgetBox(self.topWidgetPart, orientation="vertical", margin=0) if self.want_main_area: self.leftWidgetPart.setSizePolicy( QSizePolicy(QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)) self.leftWidgetPart.updateGeometry() self.mainArea = gui.widgetBox(self.topWidgetPart, orientation="vertical", sizePolicy=QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding), margin=0) self.mainArea.layout().setMargin(4) self.mainArea.updateGeometry() if self.want_control_area: self.controlArea = gui.widgetBox(self.leftWidgetPart, orientation="vertical", margin=4) if self.want_graph and self.show_save_graph: graphButtonBackground = gui.widgetBox(self.leftWidgetPart, orientation="horizontal", margin=4) self.graphButton = gui.button(graphButtonBackground, self, "&Save Graph") self.graphButton.setAutoDefault(0) if self.want_status_bar: self.widgetStatusArea = QFrame(self) self.statusBarIconArea = QFrame(self) self.widgetStatusBar = QStatusBar(self) self.layout().addWidget(self.widgetStatusArea) self.widgetStatusArea.setLayout(QHBoxLayout(self.widgetStatusArea)) self.widgetStatusArea.layout().addWidget(self.statusBarIconArea) self.widgetStatusArea.layout().addWidget(self.widgetStatusBar) self.widgetStatusArea.layout().setMargin(0) self.widgetStatusArea.setFrameShape(QFrame.StyledPanel) self.statusBarIconArea.setLayout(QHBoxLayout()) self.widgetStatusBar.setSizeGripEnabled(0) self.statusBarIconArea.hide() self._warningWidget = createPixmapWidget( self.statusBarIconArea, gui.resource_filename("icons/triangle-orange.png")) self._errorWidget = createPixmapWidget( self.statusBarIconArea, gui.resource_filename("icons/triangle-red.png")) if not self.resizing_enabled: self.layout().setSizeConstraint(QVBoxLayout.SetFixedSize)
def set_basic_layout(self): """Provide the basic widget layout Which parts are created is regulated by class attributes `want_main_area`, `want_control_area`, `want_message_bar` and `buttons_area_orientation`, the presence of method `send_report` and attribute `graph_name`. """ self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(2, 2, 2, 2) if not self.resizing_enabled: self.layout().setSizeConstraint(QVBoxLayout.SetFixedSize) self.want_main_area = self.want_main_area or self.graph_name self._create_default_buttons() self._insert_splitter() if self.want_control_area: self._insert_control_area() if self.want_main_area: self._insert_main_area() if self.want_message_bar: # Use a OverlayWidget for status bar positioning. c = OverlayWidget(self, alignment=Qt.AlignBottom) c.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) c.setWidget(self) c.setLayout(QVBoxLayout()) c.layout().setContentsMargins(0, 0, 0, 0) sb = QStatusBar() sb.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Maximum) sb.setSizeGripEnabled(self.resizing_enabled) c.layout().addWidget(sb) help = self.__help_action help_button = SimpleButton( icon=QIcon(gui.resource_filename("icons/help.svg")), toolTip="Show widget help", visible=help.isVisible(), ) @help.changed.connect def _(): help_button.setVisible(help.isVisible()) help_button.setEnabled(help.isEnabled()) help_button.clicked.connect(help.trigger) sb.addWidget(help_button) if self.graph_name is not None: b = SimpleButton( icon=QIcon(gui.resource_filename("icons/chart.svg")), toolTip="Save Image", ) b.clicked.connect(self.save_graph) sb.addWidget(b) if hasattr(self, "send_report"): b = SimpleButton( icon=QIcon(gui.resource_filename("icons/report.svg")), toolTip="Report" ) b.clicked.connect(self.show_report) sb.addWidget(b) self.message_bar = MessagesWidget(self) self.message_bar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) pb = QProgressBar(maximumWidth=120, minimum=0, maximum=100) pb.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Ignored) pb.setAttribute(Qt.WA_LayoutUsesWidgetRect) pb.setAttribute(Qt.WA_MacMiniSize) pb.hide() sb.addPermanentWidget(pb) sb.addPermanentWidget(self.message_bar) def statechanged(): pb.setVisible(bool(self.processingState) or self.isBlocking()) if self.isBlocking() and not self.processingState: pb.setRange(0, 0) # indeterminate pb elif self.processingState: pb.setRange(0, 100) # determinate pb self.processingStateChanged.connect(statechanged) self.blockingStateChanged.connect(statechanged) @self.progressBarValueChanged.connect def _(val): pb.setValue(int(val)) # Reserve the bottom margins for the status bar margins = self.layout().contentsMargins() margins.setBottom(sb.sizeHint().height()) self.setContentsMargins(margins)