def test_undo_redo(inspector): """ :type inspector: qt_style_sheet_inspector.StyleSheetInspector """ # keyClick only works if window is shown inspector.show() style_sheets = [qApp.styleSheet()] # Undo before changes doesn't have any effect inspector.widget.onUndo() assert inspector.widget.style_text_edit.toPlainText() == style_sheets[-1] # Undo after changes inspector.widget.style_text_edit.setPlainText(qApp.styleSheet() + """\ QLabel { font-size: 14px; } """) inspector.widget.apply_button.click() current = qApp.styleSheet() assert inspector.widget.style_text_edit.toPlainText() == current assert current != style_sheets[-1] style_sheets.append(current) inspector.widget.onUndo() assert inspector.widget.style_text_edit.toPlainText() == style_sheets[-2] # Redo inspector.widget.onRedo() assert inspector.widget.style_text_edit.toPlainText() == style_sheets[-1] # Redo again, won't have any effect inspector.widget.onRedo() assert inspector.widget.style_text_edit.toPlainText() == style_sheets[-1] # Undo, change again then try to redo, won't have any effect, as state # tape has been updated inspector.widget.onUndo() inspector.widget.style_text_edit.setPlainText(qApp.styleSheet() + """\ QPushButton { background-color: #dcdddf; } """) inspector.widget.apply_button.click() current = qApp.styleSheet() assert inspector.widget.style_text_edit.toPlainText() == current assert current != style_sheets[-1] style_sheets.append(current) inspector.widget.onRedo() assert inspector.widget.style_text_edit.toPlainText() == style_sheets[-1]
def test_apply(inspector): """ :type inspector: qt_style_sheet_inspector.StyleSheetInspector """ assert not inspector.widget.apply_button.isEnabled() inspector.widget.style_text_edit.setPlainText(qApp.styleSheet() + """\ QLabel { font-size: 14px; } """) assert inspector.widget.apply_button.isEnabled() inspector.widget.apply_button.click() assert inspector.widget.style_text_edit.toPlainText() == qApp.styleSheet() assert not inspector.widget.apply_button.isEnabled()
def __init__(self, parent=None): """Initialize the components of the main window.""" super(Template, self).__init__(parent) self.resize(1024, 768) self.setWindowTitle('Template') window_icon = pkg_resources.resource_filename( 'demo-qt-inspector.images', 'ic_insert_drive_file_black_48dp_1x.png') self.setWindowIcon(QIcon(window_icon)) self.initUI() self.widget = QWidget() self.layout = QHBoxLayout(self.widget) print(qApp.styleSheet()) with open("theme.qss", mode="r") as theme_file: qApp.setStyleSheet(theme_file.read()) self.menu_bar = self.menuBar() self.about_dialog = AboutDialog() self.status_bar = self.statusBar() self.status_bar.showMessage('Ready') self.file_menu() self.help_menu()
def loadStyleSheet(self): """ Load app style sheet and displays its text in inspector widget. """ style_sheet = self.style_sheet = qApp.styleSheet() self.tape.append(style_sheet) self.tape_pos = 0 self.style_text_edit.setPlainText(style_sheet) self.apply_button.setEnabled(False)
def test_load_style_sheet(inspector): """ :type inspector: qt_style_sheet_inspector.StyleSheetInspector """ assert inspector.widget.style_text_edit.toPlainText() == qApp.styleSheet()