class ReplaceWidget(FindWidget): def __init__(self, parent): super(FindWidget, self).__init__(parent) self.adv_code_widget = weakref.ref(parent) self.button_size = self.fontMetrics().width(u'Replace All') + 20 from pyvmmonitor_qt.qt.QtWidgets import QFormLayout form_layout = QFormLayout() form_layout.addRow('Fin&d', self._create_find_control()) form_layout.addRow('Rep&lace', self._create_replace_control()) from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout layout = QHBoxLayout() layout.addLayout(form_layout) from pyvmmonitor_qt.qt.QtWidgets import QPushButton close_button = QPushButton('Close') layout.addWidget(close_button, 1, QtCore.Qt.AlignRight) close_button.clicked.connect(self.hide) self.setLayout(layout) def _create_replace_control(self): from pyvmmonitor_qt.qt.QtWidgets import QWidget from pyvmmonitor_qt.qt.QtWidgets import QPushButton from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout from pyvmmonitor_qt.qt.QtWidgets import QLineEdit control = QWidget(self) self.replace_edit = QLineEdit() self.replace_button = QPushButton('&Replace') self.replace_button.setFixedWidth(self.button_size) self.replace_all_button = QPushButton('Replace &All') self.replace_all_button.setFixedWidth(self.button_size) layout = QHBoxLayout() layout.addWidget(self.replace_edit) layout.addWidget(self.replace_button) layout.addWidget(self.replace_all_button) layout.addStretch(2) layout.setContentsMargins(0, 0, 0, 0) control.setLayout(layout) return control
def add_tab(self, widget, label, closeable): widget.setParent(self._stack) self._widgets.append(widget) self._stack.addWidget(widget) self._tabbar.addTab(label) if closeable: bt = QPushButton(self._tabbar) bt.setFixedSize(20, 20) bt.setIcon(bt.style().standardIcon( QStyle.SP_DockWidgetCloseButton)) self._tabbar.setTabButton( len(self._widgets) - 1, QTabBar.RightSide, bt) self._buttons.append(bt) weak_bt = weakref.ref(bt) weak_tab_widget = weakref.ref(self) def on_close(): self = weak_tab_widget() bt = weak_bt() if self is None or bt is None: return if not qt_utils.is_qobject_alive( self) or not qt_utils.is_qobject_alive(bt): return i = self._buttons.index(bt) if i != -1: self.on_remove_requested(i) bt.clicked.connect(on_close) else: self._buttons.append(None)
def _create_find_control(self): from pyvmmonitor_qt.qt.QtWidgets import QWidget from pyvmmonitor_qt.qt.QtWidgets import QLineEdit from pyvmmonitor_qt.qt.QtWidgets import QPushButton from pyvmmonitor_qt.qt.QtWidgets import QMenu from pyvmmonitor_qt.qt.QtWidgets import QAction from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout control = QWidget(self) self.line_edit = QLineEdit() self.next_button = QPushButton('&Next') self.next_button.setFixedWidth(self.button_size) self.prev_button = QPushButton('&Prev') self.prev_button.setFixedWidth(self.button_size) self.options_button = QPushButton('&Options') self.options_button.setFixedWidth(self.button_size) options_menu = QMenu(self) self.case_action = QAction('Match &case', options_menu) self.case_action.setCheckable(True) self.word_action = QAction('Match words', options_menu) self.word_action.setCheckable(True) self.wrap_action = QAction('Wrap search', options_menu) self.wrap_action.setCheckable(True) self.wrap_action.setChecked(True) options_menu.addAction(self.case_action) options_menu.addAction(self.word_action) options_menu.addAction(self.wrap_action) self.options_button.setMenu(options_menu) layout = QHBoxLayout() layout.addWidget(self.line_edit) layout.addWidget(self.next_button) layout.addWidget(self.prev_button) layout.addWidget(self.options_button) layout.addStretch(2) layout.setContentsMargins(0, 0, 0, 0) control.setLayout(layout) return control
def add_tab(self, widget, label, closeable): widget.setParent(self._stack) self._widgets.append(widget) self._stack.addWidget(widget) self._tabbar.addTab(label) if closeable: bt = QPushButton(self._tabbar) bt.setFixedSize(20, 20) bt.setIcon(bt.style().standardIcon(QStyle.SP_DockWidgetCloseButton)) self._tabbar.setTabButton(len(self._widgets) - 1, QTabBar.RightSide, bt) self._buttons.append(bt) weak_bt = weakref.ref(bt) weak_tab_widget = weakref.ref(self) def on_close(): self = weak_tab_widget() bt = weak_bt() if self is None or bt is None: return if not qt_utils.is_qobject_alive(self) or not qt_utils.is_qobject_alive(bt): return i = self._buttons.index(bt) if i != -1: self.on_remove_requested(i) bt.clicked.connect(on_close) else: self._buttons.append(None)
def test_custom_widget(qtapi, tree): tree.columns = ['Caption', 'Action'] tree.tree.show() tree['a'] = ('a', '') tree['c'] = ('c', '') tree['b'] = ('b', '') from pyvmmonitor_qt.qt.QtGui import QPixmap from pyvmmonitor_qt.qt.QtWidgets import QPushButton from pyvmmonitor_qt.qt.QtCore import Qt bt = QPushButton(None) icon = QPixmap(20, 20) icon.fill(Qt.red) from pyvmmonitor_qt.qt.QtGui import QIcon bt.setIcon(QIcon(icon)) bt.setAutoFillBackground(True) # Should show a button at column 1 tree['a'].set_item_custom_widget(1, bt) assert tree['a'].item_custom_widget(1) == bt
def _create_replace_control(self): from pyvmmonitor_qt.qt.QtWidgets import QWidget from pyvmmonitor_qt.qt.QtWidgets import QPushButton from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout from pyvmmonitor_qt.qt.QtWidgets import QLineEdit control = QWidget(self) self.replace_edit = QLineEdit() self.replace_button = QPushButton('&Replace') self.replace_button.setFixedWidth(self.button_size) self.replace_all_button = QPushButton('Replace &All') self.replace_all_button.setFixedWidth(self.button_size) layout = QHBoxLayout() layout.addWidget(self.replace_edit) layout.addWidget(self.replace_button) layout.addWidget(self.replace_all_button) layout.addStretch(2) layout.setContentsMargins(0, 0, 0, 0) control.setLayout(layout) return control
def CreateStyledQPushButton(parent, icon_name, text=''): ''' :param icon_name: Name to find icon (i.e.: :appbar.page.edit.svg) or callable which provides it. ''' from pyvmmonitor_qt.qt.QtWidgets import QPushButton from pyvmmonitor_qt.qt.QtGui import QIcon ret = QPushButton(parent) if text: ret.setText(text) if callable(icon_name): ret.setIcon(QIcon(icon_name())) else: ret.setIcon(QIcon(icon_name)) _styled_qt_objects.setdefault(icon_name, WeakSet()).add(ret) return ret
def __init__(self, parent): super(FindWidget, self).__init__(parent) self.adv_code_widget = weakref.ref(parent) self.button_size = self.fontMetrics().width(u'Replace All') + 20 from pyvmmonitor_qt.qt.QtWidgets import QFormLayout form_layout = QFormLayout() form_layout.addRow('Fin&d', self._create_find_control()) form_layout.addRow('Rep&lace', self._create_replace_control()) from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout layout = QHBoxLayout() layout.addLayout(form_layout) from pyvmmonitor_qt.qt.QtWidgets import QPushButton close_button = QPushButton('Close') layout.addWidget(close_button, 1, QtCore.Qt.AlignRight) close_button.clicked.connect(self.hide) self.setLayout(layout)
class FindWidget(QWidget): def __init__(self, parent): from pyvmmonitor_qt.qt.QtWidgets import QFormLayout from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout from pyvmmonitor_qt.qt.QtWidgets import QPushButton super(FindWidget, self).__init__(parent) self.adv_code_widget = weakref.ref(parent) self.button_size = self.fontMetrics().width(u'Replace All') + 20 form_layout = QFormLayout() form_layout.addRow('Fin&d', self._create_find_control()) layout = QHBoxLayout() layout.addLayout(form_layout) close_button = QPushButton('Close') layout.addWidget(close_button, 1, QtCore.Qt.AlignRight) close_button.clicked.connect(self.hide) self.setLayout(layout) def setFocus(self): self.line_edit.setFocus() def _create_find_control(self): from pyvmmonitor_qt.qt.QtWidgets import QWidget from pyvmmonitor_qt.qt.QtWidgets import QLineEdit from pyvmmonitor_qt.qt.QtWidgets import QPushButton from pyvmmonitor_qt.qt.QtWidgets import QMenu from pyvmmonitor_qt.qt.QtWidgets import QAction from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout control = QWidget(self) self.line_edit = QLineEdit() self.next_button = QPushButton('&Next') self.next_button.setFixedWidth(self.button_size) self.prev_button = QPushButton('&Prev') self.prev_button.setFixedWidth(self.button_size) self.options_button = QPushButton('&Options') self.options_button.setFixedWidth(self.button_size) options_menu = QMenu(self) self.case_action = QAction('Match &case', options_menu) self.case_action.setCheckable(True) self.word_action = QAction('Match words', options_menu) self.word_action.setCheckable(True) self.wrap_action = QAction('Wrap search', options_menu) self.wrap_action.setCheckable(True) self.wrap_action.setChecked(True) options_menu.addAction(self.case_action) options_menu.addAction(self.word_action) options_menu.addAction(self.wrap_action) self.options_button.setMenu(options_menu) layout = QHBoxLayout() layout.addWidget(self.line_edit) layout.addWidget(self.next_button) layout.addWidget(self.prev_button) layout.addWidget(self.options_button) layout.addStretch(2) layout.setContentsMargins(0, 0, 0, 0) control.setLayout(layout) return control