def test_visual_settings(self, timeout=DEFAULT_TIMEOUT): graph = self.widget.graph font = QFont() font.setItalic(True) font.setFamily("Helvetica") self.send_signal(self.widget.Inputs.data, self.data) self.wait_until_finished(timeout=timeout) key, value = ("Fonts", "Font family", "Font family"), "Helvetica" self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Title", "Font size"), 20 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Title", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(20) self.assertFontEqual(graph.parameter_setter.title_item.item.font(), font) key, value = ("Fonts", "Label", "Font size"), 10 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Label", "Italic"), True self.widget.set_visual_settings(key, value) simulate.combobox_activate_item(self.widget.controls.attr_label, self.data.domain[0].name) font.setPointSize(10) self.assertFontEqual(graph.labels[0].textItem.font(), font) key, value = ("Fonts", "Categorical legend", "Font size"), 14 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Categorical legend", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(14) legend_item = list(graph.parameter_setter.cat_legend_items)[0] self.assertFontEqual(legend_item[1].item.font(), font) key, value = ("Fonts", "Numerical legend", "Font size"), 12 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Numerical legend", "Italic"), True self.widget.set_visual_settings(key, value) simulate.combobox_activate_item(self.widget.controls.attr_color, self.data.domain[0].name) variables = self.data.domain.variables + self.data.domain.metas discrete_var = next( (x for x in variables if isinstance(x, DiscreteVariable)), None) if discrete_var: # activate item only when discrete variable available simulate.combobox_activate_item(self.widget.controls.attr_shape, discrete_var.name) font.setPointSize(12) self.assertFontEqual( graph.parameter_setter.num_legend.items[0][0].font, font) key, value = ("Annotations", "Title", "Title"), "Foo" self.widget.set_visual_settings(key, value) self.assertEqual(graph.parameter_setter.title_item.item.toPlainText(), "Foo") self.assertEqual(graph.parameter_setter.title_item.text, "Foo")
def test_visual_settings(self): graph = self.widget.graph font = QFont() font.setItalic(True) font.setFamily("Helvetica") self.send_signal(self.widget.Inputs.data, self.data) key, value = ("Fonts", "Font family", "Font family"), "Helvetica" self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Title", "Font size"), 20 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Title", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(20) self.assertFontEqual(graph.parameter_setter.title_item.item.font(), font) key, value = ("Fonts", "Axis title", "Font size"), 16 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Axis title", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(16) for item in graph.parameter_setter.axis_items: self.assertFontEqual(item.label.font(), font) key, value = ("Fonts", "Axis ticks", "Font size"), 15 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Axis ticks", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(15) for item in graph.parameter_setter.axis_items: self.assertFontEqual(item.style["tickFont"], font) key, value = ("Fonts", "Legend", "Font size"), 14 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Legend", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(14) legend_item = list(graph.parameter_setter.legend_items)[0] self.assertFontEqual(legend_item[1].item.font(), font) key, value = ("Annotations", "Title", "Title"), "Foo" self.widget.set_visual_settings(key, value) self.assertEqual(graph.parameter_setter.title_item.item.toPlainText(), "Foo") self.assertEqual(graph.parameter_setter.title_item.text, "Foo") key, value = ("Figure", "Gridlines", "Show"), False self.assertTrue(graph.getAxis("left").grid) self.widget.set_visual_settings(key, value) self.assertFalse(graph.getAxis("left").grid) key, value = ("Figure", "Bottom axis", "Vertical tick text"), False self.assertTrue(graph.getAxis("bottom").style["rotateTicks"]) self.widget.set_visual_settings(key, value) self.assertFalse(graph.getAxis("bottom").style["rotateTicks"])
def font_from_dict(font_dict, font=None): if font is None: font = QFont() else: font = QFont(font) if "family" in font_dict: font.setFamily(font_dict["family"]) if "size" in font_dict: font.setPixelSize(font_dict["size"]) return font
def test_visual_settings(self, timeout=DEFAULT_TIMEOUT): graph = self.widget.graph font = QFont() font.setItalic(True) font.setFamily("Helvetica") self.send_signal(self.widget.Inputs.data, self.data) self.wait_until_finished(timeout=timeout) key, value = ("Fonts", "Font family", "Font family"), "Helvetica" self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Title", "Font size"), 20 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Title", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(20) self.assertFontEqual(graph.title_item.item.font(), font) key, value = ("Fonts", "Label", "Font size"), 10 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Label", "Italic"), True self.widget.set_visual_settings(key, value) simulate.combobox_activate_item(self.widget.controls.attr_label, self.data.domain[0].name) font.setPointSize(10) self.assertFontEqual(graph.labels[0].textItem.font(), font) key, value = ("Fonts", "Categorical legend", "Font size"), 14 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Categorical legend", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(14) legend_item = list(graph.cat_legend_items)[0] self.assertFontEqual(legend_item[1].item.font(), font) key, value = ("Fonts", "Numerical legend", "Font size"), 12 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Numerical legend", "Italic"), True self.widget.set_visual_settings(key, value) simulate.combobox_activate_item(self.widget.controls.attr_color, self.data.domain[0].name) simulate.combobox_activate_item(self.widget.controls.attr_shape, self.data.domain[4].name) font.setPointSize(12) self.assertFontEqual(graph.num_legend.items[0][0].font, font) key, value = ("Annotations", "Title", "Title"), "Foo" self.widget.set_visual_settings(key, value) self.assertEqual(graph.title_item.item.toPlainText(), "Foo") self.assertEqual(graph.title_item.text, "Foo")
def change_font(font: QFont, settings: _SettingType) -> QFont: assert all(s in (Updater.FONT_FAMILY_LABEL, Updater.SIZE_LABEL, Updater.IS_ITALIC_LABEL) for s in settings), settings family = settings.get(Updater.FONT_FAMILY_LABEL) if family is not None: font.setFamily(family) size = settings.get(Updater.SIZE_LABEL) if size is not None: font.setPointSize(size) italic = settings.get(Updater.IS_ITALIC_LABEL) if italic is not None: font.setItalic(italic) return font
def font_from_dict(font_dict, font=None): # type: (dict, Optional[QFont]) -> QFont if font is None: font = QFont() else: font = QFont(font) if "family" in font_dict: font.setFamily(font_dict["family"]) if "size" in font_dict: font.setPixelSize(font_dict["size"]) return font
def test_visual_settings(self, timeout=DEFAULT_TIMEOUT): super().test_visual_settings(timeout) graph = self.widget.graph font = QFont() font.setItalic(True) font.setFamily("Helvetica") key, value = ("Fonts", "Anchor", "Font size"), 10 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Anchor", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(10) for item in graph.anchor_items: if isinstance(item, AnchorItem): item = item._label self.assertFontEqual(item.textItem.font(), font)
def test_visual_settings(self): font = QFont() font.setItalic(True) font.setFamily("Helvetica") self.send_signal(self.widget.Inputs.data, self.iris) self.send_signal(self.widget.Inputs.model, self.rf_cls) self.wait_until_finished() setter = self.widget.plot.parameter_setter key, value = ("Fonts", "Font family", "Font family"), "Helvetica" self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Axis title", "Font size"), 14 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Axis title", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(14) for axis in setter.axis_items: self.assertFontEqual(axis.label.font(), font) key, value = ('Fonts', 'Axis ticks', 'Font size'), 15 self.widget.set_visual_settings(key, value) key, value = ('Fonts', 'Axis ticks', 'Italic'), True self.widget.set_visual_settings(key, value) font.setPointSize(15) for axis in setter.axis_items: self.assertFontEqual(axis.style["tickFont"], font) key, value = ("Fonts", "Variable name", "Font size"), 19 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Variable name", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(19) self.assertFontEqual(setter.labels[0].item.items[0].font(), font) key, value = ("Fonts", "Variable value", "Font size"), 10 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Variable value", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(10) self.assertFontEqual(setter.labels[0].item.items[1].font(), font) key, value = ("Figure", "Label length", "Label length"), 50 self.widget.set_visual_settings(key, value) self.assertLessEqual(setter.labels[0].item.boundingRect().width(), 50)
def test_visual_settings(self): super().test_visual_settings() graph = self.widget.graph font = QFont() font.setItalic(True) font.setFamily("Helvetica") key, value = ('Fonts', 'Axis title', 'Font size'), 16 self.widget.set_visual_settings(key, value) key, value = ('Fonts', 'Axis title', 'Italic'), True self.widget.set_visual_settings(key, value) font.setPointSize(16) for item in graph.parameter_setter.axis_items: self.assertFontEqual(item.label.font(), font) key, value = ('Fonts', 'Axis ticks', 'Font size'), 15 self.widget.set_visual_settings(key, value) key, value = ('Fonts', 'Axis ticks', 'Italic'), True self.widget.set_visual_settings(key, value) font.setPointSize(15) for item in graph.parameter_setter.axis_items: self.assertFontEqual(item.style["tickFont"], font) self.widget.graph.controls.show_reg_line.setChecked(True) self.assertGreater(len(graph.parameter_setter.reg_line_label_items), 0) key, value = ('Fonts', 'Line label', 'Font size'), 16 self.widget.set_visual_settings(key, value) key, value = ('Fonts', 'Line label', 'Italic'), True self.widget.set_visual_settings(key, value) font.setPointSize(16) for label in graph.parameter_setter.reg_line_label_items: self.assertFontEqual(label.textItem.font(), font) key, value = ('Figure', 'Lines', 'Width'), 10 self.widget.set_visual_settings(key, value) for item in graph.reg_line_items: self.assertEqual(item.pen.width(), 10)
def test_visual_settings(self): super().test_visual_settings() graph = self.widget.graph font = QFont() font.setItalic(True) font.setFamily("Helvetica") key, value = ('Fonts', 'Axis title', 'Font size'), 16 self.widget.set_visual_settings(key, value) key, value = ('Fonts', 'Axis title', 'Italic'), True self.widget.set_visual_settings(key, value) font.setPointSize(16) for item in graph.axis_items: self.assertFontEqual(item.label.font(), font) key, value = ('Fonts', 'Axis ticks', 'Font size'), 15 self.widget.set_visual_settings(key, value) key, value = ('Fonts', 'Axis ticks', 'Italic'), True self.widget.set_visual_settings(key, value) font.setPointSize(15) for item in graph.axis_items: self.assertFontEqual(item.style["tickFont"], font)
def test_visual_settings(self, timeout=DEFAULT_TIMEOUT): graph = self.widget.graph font = QFont() font.setItalic(True) font.setFamily("Helvetica") self.send_signal(self.widget.Inputs.data, self.data) self.wait_until_finished(timeout=timeout) key, value = ("Fonts", "Font family", "Font family"), "Helvetica" self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Title", "Font size"), 20 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Title", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(20) self.assertFontEqual(graph.parameter_setter.title_item.item.font(), font) key, value = ("Fonts", "Axis title", "Font size"), 14 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Axis title", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(14) for ax in ["bottom", "left"]: axis = graph.parameter_setter.getAxis(ax) self.assertFontEqual(axis.label.font(), font) key, value = ('Fonts', 'Axis ticks', 'Font size'), 15 self.widget.set_visual_settings(key, value) key, value = ('Fonts', 'Axis ticks', 'Italic'), True self.widget.set_visual_settings(key, value) font.setPointSize(15) for ax in ["bottom", "left"]: axis = graph.parameter_setter.getAxis(ax) self.assertFontEqual(axis.style["tickFont"], font) key, value = ("Fonts", "Legend", "Font size"), 16 self.widget.set_visual_settings(key, value) key, value = ("Fonts", "Legend", "Italic"), True self.widget.set_visual_settings(key, value) font.setPointSize(16) legend_item = list(graph.parameter_setter.legend_items)[0] self.assertFontEqual(legend_item[1].item.font(), font) key, value = ("Annotations", "Title", "Title"), "Foo" self.widget.set_visual_settings(key, value) self.assertEqual(graph.parameter_setter.title_item.item.toPlainText(), "Foo") self.assertEqual(graph.parameter_setter.title_item.text, "Foo") key, value = ("Annotations", "x-axis title", "Title"), "Foo2" self.widget.set_visual_settings(key, value) axis = graph.parameter_setter.getAxis("bottom") self.assertEqual(axis.label.toPlainText().strip(), "Foo2") self.assertEqual(axis.labelText, "Foo2") key, value = ("Annotations", "y-axis title", "Title"), "Foo3" self.widget.set_visual_settings(key, value) axis = graph.parameter_setter.getAxis("left") self.assertEqual(axis.label.toPlainText().strip(), "Foo3") self.assertEqual(axis.labelText, "Foo3")
def _load_code_editor_settings(self): """ Load settings on the code editor like, font style, margins, scroll, etc. Based on the example from http://eli.thegreenplace.net/2011/04/01/sample-using-qscintilla-with-pyqt/ """ item = self.form.font_size.currentText() size = int(item) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(size) self._code_editor.setFont(font) self._code_editor.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(font) self._code_editor.setMarginsFont(font) self._code_editor.setMarginWidth(0, fontmetrics.width("00000") + 6) self._code_editor.setMarginLineNumbers(0, True) self._code_editor.setMarginsBackgroundColor(QColor("#cccccc")) # Clickable margin 1 for showing markers self._code_editor.setMarginSensitivity(1, True) self._code_editor.marginClicked.connect(self.on_margin_clicked) self._code_editor.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self._code_editor.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) # Detect changes to text self._code_editor.modificationChanged.connect( self.on_modification_changed) # Brace matching: enable for a brace immediately before or after the current position self._code_editor.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self._code_editor.setCaretLineVisible(True) self._code_editor.setCaretLineBackgroundColor(QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width Courier. lexer = self.lexer() lexer.setDefaultFont(font) self._code_editor.setLexer(lexer) self._code_editor.setIndentationWidth(4) # self._code_editor.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') self._code_editor.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1) # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented here: http://www.scintilla.org/ScintillaDoc.html) self._code_editor.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self._lexer_obj = lexer self.qsci_api = QsciAPIs(self._lexer_obj) ## Add autocompletion strings self.qsci_api.add("aLongString") self.qsci_api.add("aLongerString") self.qsci_api.add("aDifferentString") self.qsci_api.add("sOmethingElse") ## Compile the api for use in the lexer self.qsci_api.prepare() self._code_editor.setAutoCompletionThreshold(1) self._code_editor.setAutoCompletionSource(QsciScintilla.AcsAll)