def qtapi(qtbot): from pyvmmonitor_qt.qt_app import obtain_qapp from pyvmmonitor_qt.qt_collect import start_collect_only_in_ui_thread obtain_qapp() # Will make sure that the default stylesheet is also applied start_collect_only_in_ui_thread( ) # Make sure we'll only collect items in the main thread def d(self, make_visible=True): widget_and_visibility = [] for weak_widget in _list_widgets(self): widget = weak_widget() if widget is not None: widget_and_visibility.append((widget, widget.isVisible())) if make_visible: for w in widget_and_visibility: w[0].setVisible(True) from pyvmmonitor_qt.qt.QtWidgets import QApplication QApplication.instance().exec_() for widget, visible in widget_and_visibility: widget.setVisible(visible) qtbot.d = types.MethodType(d, qtbot) yield qtbot for w in _list_widgets(qtbot): w = w() if hasattr(w, 'set_data'): w.set_data(None) if hasattr(w, 'clear_cycles'): w.clear_cycles() from pyvmmonitor_qt.qt_event_loop import process_events process_events(collect=True)
def qtapi(qtbot): from pyvmmonitor_qt.qt_app import obtain_qapp from pyvmmonitor_qt.qt_collect import start_collect_only_in_ui_thread obtain_qapp() # Will make sure that the default stylesheet is also applied start_collect_only_in_ui_thread() # Make sure we'll only collect items in the main thread def d(self, make_visible=True): widget_and_visibility = [] for weak_widget in _list_widgets(self): widget = weak_widget() if widget is not None: widget_and_visibility.append((widget, widget.isVisible())) if make_visible: for w in widget_and_visibility: w[0].setVisible(True) from pyvmmonitor_qt.qt.QtWidgets import QApplication QApplication.instance().exec_() for widget, visible in widget_and_visibility: widget.setVisible(visible) qtbot.d = types.MethodType(d, qtbot) yield qtbot for w in _list_widgets(qtbot): w = w() if hasattr(w, 'set_data'): w.set_data(None) if hasattr(w, 'clear_cycles'): w.clear_cycles() from pyvmmonitor_qt.qt_event_loop import process_events process_events(collect=True)
def _create_children(self, pythonic_tree, node): if node is None: from pyvmmonitor_qt.qt_app import obtain_qapp if self._roots is None: top_level_widgets = obtain_qapp().topLevelWidgets() else: top_level_widgets = self._roots for widget in top_level_widgets: self._create_node(pythonic_tree, widget, '', self._widget_id_to_attr_name) else: parent_obj_id = node.obj_id widget = self._id_to_widget[parent_obj_id] if widget is not None: print('%s - children: %s' % (widget, widget.children())) for child in widget.children(): self._create_node(pythonic_tree, child, parent_obj_id, self._widget_id_to_attr_name) else: print('None widget:', parent_obj_id, widget)
def show_message( message, detailed_message='', title='Error', parent=None, icon=None): ''' :param icon: QMessageBox.NoIcon QMessageBox.Question QMessageBox.Information QMessageBox.Warning QMessageBox.Critical ''' from pyvmmonitor_qt.qt.QtWidgets import QMessageBox if icon is None: icon = QMessageBox.Critical if isinstance(icon, compat.bytes): icon = icon.decode('utf-8', 'replace') if isinstance(icon, compat.unicode): icon = icon.lower() if icon == 'error': icon = QMessageBox.Critical elif icon in ('warning', 'warn'): icon = QMessageBox.Warning elif icon in ('information', 'info'): icon = QMessageBox.Information elif icon == 'question': icon = QMessageBox.Question else: logger.warn('Invalid icon: %s' % (icon,)) icon = QMessageBox.NoIcon if not is_in_main_thread(): # Important: if we're not in the main thread, we have to schedule to run it later # (in the UI thread). def func(): show_message(message, detailed_message, title, parent, icon) from pyvmmonitor_qt.qt_event_loop import execute_on_next_event_loop execute_on_next_event_loop(func) return if parent is None: parent = get_main_window() from pyvmmonitor_qt.qt_app import obtain_qapp get_icon = obtain_qapp().style().standardIcon from pyvmmonitor_qt.qt.QtWidgets import QStyle if icon == QMessageBox.Information: icon = get_icon(QStyle.SP_MessageBoxInformation) elif icon == QMessageBox.Critical: icon = get_icon(QStyle.SP_MessageBoxCritical) elif icon == QMessageBox.Warning: icon = get_icon(QStyle.SP_MessageBoxWarning) elif icon == QMessageBox.Question: icon = get_icon(QStyle.SP_MessageBoxQuestion) else: from pyvmmonitor_qt.qt.QtGui import QIcon icon = QIcon() return __show_dialog_and_exec(parent, title, message, detailed_message, icon)
self._hsv_widget = widget_builder.add_widget(HSVWidget(widget_builder.widget, model)) self._hsv_widget = widget_builder.add_widget(_OpacityWidget(widget_builder.widget, model)) self._tab_widget.addTab(widget_builder.widget, 'RGB, HSV') widget_builder = WidgetBuilder() widget_builder.create_widget(self._tab_widget) self._cmyk_widget = widget_builder.add_widget(_CMYKWidget(self._tab_widget, model)) widget_builder.create_spacer() self._tab_widget.addTab(widget_builder.widget, 'CMYK') layout = QGridLayout(self) self.setLayout(layout) layout.addWidget(self._selected_color_widget, 0, 0) layout.addWidget(self._tab_widget, 0, 1, 2) @property def model(self): return self._model @property def color_wheel_widget(self): return self._color_wheel_widget if __name__ == '__main__': qapp = obtain_qapp() w = _SelectedColorWidget() w.show() qapp.exec_()
on_text_value_changed(initial_text) while True: ret = input_dialog.exec_() if not ret: return None txt = input_dialog.textValue() if not get_input_error(txt): return txt # If the user accepted and the value is invalid, show it again (keep in while True). if __name__ == '__main__': from pyvmmonitor_qt.qt_app import obtain_qapp obtain_qapp() def get_input_error(txt): if txt == 'foo': return '' return 'The name must be "foo".' print( ask_text_input('Enter title', 'Enter message', 'initial', 'OkFoo', 'CFoo', get_input_error=get_input_error)) # print(ask_yes_no_cancel(
""" # Create a QApplication instance if no instance currently exists # (e.g. if the module is used directly from the interpreter) if QApplication.startingUp(): _app = QApplication([]) dialog = FormDialog(data, title, comment, icon, parent, apply, restore) if dialog.exec_(): return dialog.get() if __name__ == "__main__": from pyvmmonitor_qt.qt_app import obtain_qapp obtain_qapp() # I.e.: this is our way of testing :) # Comment to see things. def exec_(self): self.accept() return True FormDialog.exec_ = exec_ # Emulating the Filename with a CustomDataEditor... def on_create_field(parent): return QFilenameLayout(Filename('c:/temp/b.txt'), parent) def on_extract_value(field): return Filename(field.text())
_OpacityWidget(widget_builder.widget, model)) self._tab_widget.addTab(widget_builder.widget, 'RGB, HSV') widget_builder = WidgetBuilder() widget_builder.create_widget(self._tab_widget) self._cmyk_widget = widget_builder.add_widget( _CMYKWidget(self._tab_widget, model)) widget_builder.create_spacer() self._tab_widget.addTab(widget_builder.widget, 'CMYK') layout = QGridLayout(self) self.setLayout(layout) layout.addWidget(self._selected_color_widget, 0, 0) layout.addWidget(self._tab_widget, 0, 1, 2, 1) @property def model(self): return self._model @property def color_wheel_widget(self): return self._color_wheel_widget if __name__ == '__main__': qapp = obtain_qapp() w = _SelectedColorWidget() w.show() qapp.exec_()
def get_background(self): st = obtain_qapp().style() return st.standardPalette().color(QPalette.Base)
def get_foreground(self): st = obtain_qapp().style() return st.standardPalette().color(QPalette.Text)