def __init__(self, parent, host, text): UIWidget.__init__(self, host) QtWidgets.QWidget.__init__(self, parent) self._palette = None self.update_colors() self._drag_diff = None self.moved_by_hand = False self.top_row_layout = QtWidgets.QHBoxLayout() #close_button = QtWidgets.QPushButton("x") close_button = PanelButton(pixmap=qt_prefs.close_icon, tooltip='Close', parent=self, size=12, color_key='content1') close_button.setMaximumWidth(16) self.ui_manager.connect_element_to_action(close_button, 'close_embed') self.top_row_layout.addWidget(close_button) self.top_row_layout.setAlignment(QtCore.Qt.AlignLeft) self.top_row_layout.addSpacing(8) self.top_title = QtWidgets.QLabel(text) self.top_row_layout.addWidget(self.top_title) self.assumed_width = 300 self.assumed_height = 100 self._magnet = QtCore.QPoint(0, 0), 1 # Effect will be disabled if QTextEdit is used. self.setAutoFillBackground(True) self.setBackgroundRole(QtGui.QPalette.Window) self.hide()
def icon_button(ui_manager, parent, layout, icon=None, text='', action='', x=-1, y=-1, checkable=False, size=20, color_key='accent8', tooltip_suffix='', align=None): """ :param ui_manager: :param layout: :param parent: :param text: :param action: :param x :param y :param checkable :param size :param color_key :param tooltip_suffix :param align :return: """ button = PanelButton(pixmap=icon, tooltip=text, parent=parent, size=size, color_key=color_key) button.setCheckable(checkable) if action: ui_manager.connect_element_to_action(button, action, tooltip_suffix=tooltip_suffix) if x != -1: layout.addWidget(button, y, x) elif align is not None: layout.addWidget(button, 1, align) else: layout.addWidget(button) return button
def __init__(self, text_options, ui_key, parent=None): UIWidget.__init__(self, ui_key=ui_key) PanelButton.__init__(self, None, text_options[0], size=24, parent=parent) self.setCheckable(True) self.text_options = text_options font = QtGui.QFont(qt_prefs.fonts[g.UI_FONT]) font.setPointSize(font.pointSize() * 1.2) fm = QtGui.QFontMetrics(font) mw = max([fm.width(text) for text in text_options]) self.setFlat(True) self.setMinimumWidth(mw + 12) self.setMinimumHeight(24) ctrl.add_watcher(self, 'ui_font_changed')
def __init__(self, name, default_position='bottom', parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main :param ui_manager: pass a dictionary where buttons from this panel will be added """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.setMinimumHeight(40) inner.setMaximumHeight(50) inner.preferred_size = QtCore.QSize(220, 40) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) selector = SelectionBox(self) self.selector = selector for key, item in []: selector.addItem('%s (%s)' % (key, item.shortcut), key) self.ui_manager.connect_element_to_action(selector, 'set_visualization') hlayout.addWidget(selector) self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap, tooltip='Visualization settings', parent=self, size=20) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action(self.toggle_options, 'toggle_panel_%s' % g.VIS_OPTIONS) hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) inner.setLayout(layout) self.watchlist = ['forest_changed'] self.preferred_size = inner.preferred_size self.setWidget(inner) self.widget().setAutoFillBackground(True) self.finish_init()
def __init__(self, text_options, ui_key, parent=None, icon=None): UIWidget.__init__(self, ui_key=ui_key) self.negated_icon = None PanelButton.__init__(self, icon, text_options[0], size=24, parent=parent) self.setCheckable(True) self.text_options = text_options font = QtGui.QFont(qt_prefs.fonts[g.UI_FONT]) font.setPointSize(font.pointSize() * 1.2) fm = QtGui.QFontMetrics(font) mw = max([fm.width(text) for text in text_options]) self.setFlat(True) self.setMinimumWidth(mw + 12) self.setMinimumHeight(24) ctrl.add_watcher(self, 'ui_font_changed')
def mini_icon_button(ui_manager, parent, layout, icon=None, text='', action='', x=-1, y=-1, checkable=False, max_width=16): """ :param ui_manager: :param layout: :param parent: :param text: :param action: :param x: :param y: :param checkable: :param max_width: :return: """ button = PanelButton(pixmap=icon, tooltip=text, parent=parent, size=12) button.setMaximumWidth(max_width) button.setCheckable(checkable) ui_manager.connect_element_to_action(button, action) if x != -1: layout.addWidget(button, y, x) else: layout.addWidget(button) return button
def __init__(self, name, default_position="bottom", parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main :param ui_manager: pass a dictionary where buttons from this panel will be added """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.setMinimumHeight(40) inner.setMaximumHeight(50) inner.preferred_size = QtCore.QSize(220, 40) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) selector = SelectionBox(self) self.selector = selector for key, item in []: selector.addItem("%s (%s)" % (key, item.shortcut), key) self.ui_manager.connect_element_to_action(selector, "set_visualization") hlayout.addWidget(selector) self.toggle_options = PanelButton( pixmap=qt_prefs.settings_pixmap, tooltip="Visualization settings", parent=self, size=20 ) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action(self.toggle_options, "toggle_panel_%s" % g.VIS_OPTIONS) hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) inner.setLayout(layout) self.watchlist = ["forest_changed"] self.preferred_size = inner.preferred_size self.setWidget(inner) self.widget().setAutoFillBackground(True) self.finish_init()
class VisualizationPanel(Panel): """ Switch visualizations and adjust their settings """ def __init__(self, name, default_position='right', parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.preferred_size = QtCore.QSize(200, 70) inner.setMaximumWidth(220) inner.setMaximumHeight(80) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() self.selector = SelectionBox(self) self.selector.add_items([('%s (%s)' % (key, item.shortcut), key) for key, item in VISUALIZATIONS.items()]) self.ui_manager.connect_element_to_action(self.selector, 'set_visualization') hlayout.addWidget(self.selector) self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap, parent=self, size=20) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action(self.toggle_options, 'toggle_panel_VisualizationOptionsPanel') hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) hlayout = QtWidgets.QHBoxLayout() w = 36 b1 = PanelButton(pixmap=qt_prefs.shape_icon_plain, parent=self, size=24) b1.setFixedWidth(w) b1.setCheckable(True) ctrl.ui.connect_element_to_action(b1, 'set_no_frame_node_shape') hlayout.addWidget(b1) b2 = PanelButton(pixmap=qt_prefs.shape_icon_scope, parent=self, size=24) b2.setFixedWidth(w) b2.setCheckable(True) ctrl.ui.connect_element_to_action(b2, 'set_scopebox_node_shape') hlayout.addWidget(b2) b3 = PanelButton(pixmap=qt_prefs.shape_icon_brackets, parent=self, size=24) b3.setFixedWidth(w) b3.setCheckable(True) ctrl.ui.connect_element_to_action(b3, 'set_bracketed_node_shape') hlayout.addWidget(b3) b4 = PanelButton(pixmap=qt_prefs.shape_icon_box, parent=self, size=24) b4.setFixedWidth(w) b4.setCheckable(True) ctrl.ui.connect_element_to_action(b4, 'set_box_node_shape') hlayout.addWidget(b4) b5 = PanelButton(pixmap=qt_prefs.shape_icon_card, parent=self, size=24) b5.setFixedWidth(w) b5.setCheckable(True) ctrl.ui.connect_element_to_action(b5, 'set_card_node_shape') hlayout.addWidget(b5) layout.addLayout(hlayout) #layout.setContentsMargins(0, 0, 0, 0) inner.setLayout(layout) self.watchlist = ['visualization'] self.preferred_size = inner.preferred_size self.setWidget(inner) inner.setAutoFillBackground(True) self.finish_init() def showEvent(self, event): """ Panel may have missed signals to update its contents when it was hidden: update all that signals would update. :param event: :return: """ # ?? super().showEvent(event) def watch_alerted(self, obj, signal, field_name, value): """ Receives alerts from signals that this object has chosen to listen. These signals are declared in 'self.watchlist'. This method will try to sort out the received signals and act accordingly. :param obj: the object causing the alarm :param signal: identifier for type of the alarm :param field_name: name of the field of the object causing the alarm :param value: value given to the field :return: """ if signal == 'visualization': if value and 'name' in value: index = list(VISUALIZATIONS.keys()).index(value['name']) self.selector.setCurrentIndex(index) def sizeHint(self): #print("VisualizationPanel asking for sizeHint, ", self.preferred_size) return self.preferred_size
class VisualizationPanel(Panel): """ Switch visualizations and adjust their settings """ def __init__(self, name, default_position='right', parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.preferred_size = QtCore.QSize(200, 70) inner.setMaximumWidth(220) inner.setMaximumHeight(80) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() self.selector = SelectionBox(self) self.selector.add_items([('%s (%s)' % (key, item.shortcut), key) for key, item in VISUALIZATIONS.items()]) self.ui_manager.connect_element_to_action(self.selector, 'set_visualization') hlayout.addWidget(self.selector) self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap, parent=self, size=20) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action( self.toggle_options, 'toggle_panel_VisualizationOptionsPanel') hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) hlayout = QtWidgets.QHBoxLayout() w = 36 b1 = PanelButton(pixmap=qt_prefs.shape_icon_plain, parent=self, size=24) b1.setFixedWidth(w) b1.setCheckable(True) ctrl.ui.connect_element_to_action(b1, 'set_no_frame_node_shape') hlayout.addWidget(b1) b2 = PanelButton(pixmap=qt_prefs.shape_icon_scope, parent=self, size=24) b2.setFixedWidth(w) b2.setCheckable(True) ctrl.ui.connect_element_to_action(b2, 'set_scopebox_node_shape') hlayout.addWidget(b2) b3 = PanelButton(pixmap=qt_prefs.shape_icon_brackets, parent=self, size=24) b3.setFixedWidth(w) b3.setCheckable(True) ctrl.ui.connect_element_to_action(b3, 'set_bracketed_node_shape') hlayout.addWidget(b3) b4 = PanelButton(pixmap=qt_prefs.shape_icon_box, parent=self, size=24) b4.setFixedWidth(w) b4.setCheckable(True) ctrl.ui.connect_element_to_action(b4, 'set_box_node_shape') hlayout.addWidget(b4) b5 = PanelButton(pixmap=qt_prefs.shape_icon_card, parent=self, size=24) b5.setFixedWidth(w) b5.setCheckable(True) ctrl.ui.connect_element_to_action(b5, 'set_card_node_shape') hlayout.addWidget(b5) layout.addLayout(hlayout) #layout.setContentsMargins(0, 0, 0, 0) inner.setLayout(layout) self.watchlist = ['visualization'] self.preferred_size = inner.preferred_size self.setWidget(inner) inner.setAutoFillBackground(True) self.finish_init() def showEvent(self, event): """ Panel may have missed signals to update its contents when it was hidden: update all that signals would update. :param event: :return: """ # ?? super().showEvent(event) def watch_alerted(self, obj, signal, field_name, value): """ Receives alerts from signals that this object has chosen to listen. These signals are declared in 'self.watchlist'. This method will try to sort out the received signals and act accordingly. :param obj: the object causing the alarm :param signal: identifier for type of the alarm :param field_name: name of the field of the object causing the alarm :param value: value given to the field :return: """ if signal == 'visualization': if value and 'name' in value: index = list(VISUALIZATIONS.keys()).index(value['name']) self.selector.setCurrentIndex(index) def sizeHint(self): #print("VisualizationPanel asking for sizeHint, ", self.preferred_size) return self.preferred_size
def __init__(self, name, default_position='right', parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.preferred_size = QtCore.QSize(200, 70) inner.setMaximumWidth(220) inner.setMaximumHeight(80) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() self.selector = SelectionBox(self) self.selector.add_items([('%s (%s)' % (key, item.shortcut), key) for key, item in VISUALIZATIONS.items()]) self.ui_manager.connect_element_to_action(self.selector, 'set_visualization') hlayout.addWidget(self.selector) self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap, parent=self, size=20) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action( self.toggle_options, 'toggle_panel_VisualizationOptionsPanel') hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) hlayout = QtWidgets.QHBoxLayout() w = 36 b1 = PanelButton(pixmap=qt_prefs.shape_icon_plain, parent=self, size=24) b1.setFixedWidth(w) b1.setCheckable(True) ctrl.ui.connect_element_to_action(b1, 'set_no_frame_node_shape') hlayout.addWidget(b1) b2 = PanelButton(pixmap=qt_prefs.shape_icon_scope, parent=self, size=24) b2.setFixedWidth(w) b2.setCheckable(True) ctrl.ui.connect_element_to_action(b2, 'set_scopebox_node_shape') hlayout.addWidget(b2) b3 = PanelButton(pixmap=qt_prefs.shape_icon_brackets, parent=self, size=24) b3.setFixedWidth(w) b3.setCheckable(True) ctrl.ui.connect_element_to_action(b3, 'set_bracketed_node_shape') hlayout.addWidget(b3) b4 = PanelButton(pixmap=qt_prefs.shape_icon_box, parent=self, size=24) b4.setFixedWidth(w) b4.setCheckable(True) ctrl.ui.connect_element_to_action(b4, 'set_box_node_shape') hlayout.addWidget(b4) b5 = PanelButton(pixmap=qt_prefs.shape_icon_card, parent=self, size=24) b5.setFixedWidth(w) b5.setCheckable(True) ctrl.ui.connect_element_to_action(b5, 'set_card_node_shape') hlayout.addWidget(b5) layout.addLayout(hlayout) #layout.setContentsMargins(0, 0, 0, 0) inner.setLayout(layout) self.watchlist = ['visualization'] self.preferred_size = inner.preferred_size self.setWidget(inner) inner.setAutoFillBackground(True) self.finish_init()
class SyntaxPanel(Panel): """ Switch between trees or derivation steps """ def __init__(self, name, default_position="bottom", parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main :param ui_manager: pass a dictionary where buttons from this panel will be added """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.setMinimumHeight(40) inner.setMaximumHeight(50) inner.preferred_size = QtCore.QSize(220, 40) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) selector = SelectionBox(self) self.selector = selector for key, item in []: selector.addItem("%s (%s)" % (key, item.shortcut), key) self.ui_manager.connect_element_to_action(selector, "set_visualization") hlayout.addWidget(selector) self.toggle_options = PanelButton( pixmap=qt_prefs.settings_pixmap, tooltip="Visualization settings", parent=self, size=20 ) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action(self.toggle_options, "toggle_panel_%s" % g.VIS_OPTIONS) hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) inner.setLayout(layout) self.watchlist = ["forest_changed"] self.preferred_size = inner.preferred_size self.setWidget(inner) self.widget().setAutoFillBackground(True) self.finish_init() def watch_alerted(self, obj, signal, field_name, value): """ Receives alerts from signals that this object has chosen to listen. These signals are declared in 'self.watchlist'. This method will try to sort out the received signals and act accordingly. :param obj: the object causing the alarm :param signal: identifier for type of the alarm :param field_name: name of the field of the object causing the alarm :param value: value given to the field :return: """ if signal == "forest_changed": keeper = ctrl.main.forest_keeper if keeper is not None: display_index = keeper.current_index + 1 max_index = len(keeper.forests) self.treeset_counter.setText("%s/%s" % (display_index, max_index))
def __init__(self, key, tt): self.checked_icon = None self.hover_icon = None PanelButton.__init__(self, qt_prefs.eye_icon, size=24, tooltip=tt) self._hover = False self.setCheckable(True)
class SyntaxPanel(Panel): """ Switch between trees or derivation steps """ def __init__(self, name, default_position='bottom', parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main :param ui_manager: pass a dictionary where buttons from this panel will be added """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.setMinimumHeight(40) inner.setMaximumHeight(50) inner.preferred_size = QtCore.QSize(220, 40) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) selector = SelectionBox(self) self.selector = selector for key, item in []: selector.addItem('%s (%s)' % (key, item.shortcut), key) self.ui_manager.connect_element_to_action(selector, 'set_visualization') hlayout.addWidget(selector) self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap, tooltip='Visualization settings', parent=self, size=20) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action(self.toggle_options, 'toggle_panel_%s' % g.VIS_OPTIONS) hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) inner.setLayout(layout) self.watchlist = ['forest_changed'] self.preferred_size = inner.preferred_size self.setWidget(inner) self.widget().setAutoFillBackground(True) self.finish_init() def watch_alerted(self, obj, signal, field_name, value): """ Receives alerts from signals that this object has chosen to listen. These signals are declared in 'self.watchlist'. This method will try to sort out the received signals and act accordingly. :param obj: the object causing the alarm :param signal: identifier for type of the alarm :param field_name: name of the field of the object causing the alarm :param value: value given to the field :return: """ if signal == 'forest_changed': keeper = ctrl.main.forest_keeper if keeper is not None: display_index = keeper.current_index + 1 max_index = len(keeper.forests) self.treeset_counter.setText('%s/%s' % (display_index, max_index))
def __init__(self, name, default_position='right', parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.preferred_size = QtCore.QSize(200, 70) inner.setMaximumWidth(220) inner.setMaximumHeight(80) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() self.selector = SelectionBox(self) self.selector.add_items([('%s (%s)' % (key, item.shortcut), key) for key, item in VISUALIZATIONS.items()]) self.ui_manager.connect_element_to_action(self.selector, 'set_visualization') hlayout.addWidget(self.selector) self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap, parent=self, size=20) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action(self.toggle_options, 'toggle_panel_VisualizationOptionsPanel') hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) hlayout = QtWidgets.QHBoxLayout() w = 36 b1 = PanelButton(pixmap=qt_prefs.shape_icon_plain, parent=self, size=24) b1.setFixedWidth(w) b1.setCheckable(True) ctrl.ui.connect_element_to_action(b1, 'set_no_frame_node_shape') hlayout.addWidget(b1) b2 = PanelButton(pixmap=qt_prefs.shape_icon_scope, parent=self, size=24) b2.setFixedWidth(w) b2.setCheckable(True) ctrl.ui.connect_element_to_action(b2, 'set_scopebox_node_shape') hlayout.addWidget(b2) b3 = PanelButton(pixmap=qt_prefs.shape_icon_brackets, parent=self, size=24) b3.setFixedWidth(w) b3.setCheckable(True) ctrl.ui.connect_element_to_action(b3, 'set_bracketed_node_shape') hlayout.addWidget(b3) b4 = PanelButton(pixmap=qt_prefs.shape_icon_box, parent=self, size=24) b4.setFixedWidth(w) b4.setCheckable(True) ctrl.ui.connect_element_to_action(b4, 'set_box_node_shape') hlayout.addWidget(b4) b5 = PanelButton(pixmap=qt_prefs.shape_icon_card, parent=self, size=24) b5.setFixedWidth(w) b5.setCheckable(True) ctrl.ui.connect_element_to_action(b5, 'set_card_node_shape') hlayout.addWidget(b5) layout.addLayout(hlayout) #layout.setContentsMargins(0, 0, 0, 0) inner.setLayout(layout) self.watchlist = ['visualization'] self.preferred_size = inner.preferred_size self.setWidget(inner) inner.setAutoFillBackground(True) self.finish_init()