def __init__(self, master): QWidget.__init__(self) gui.OWComponent.__init__(self, master) self.master = master # Title bar. title_holder = QWidget() title_holder.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) title_holder.setStyleSheet(""" .QWidget { background: qlineargradient( x1:0 y1:0, x2:0 y2:1, stop:0 #F8F8F8, stop:1 #C8C8C8); border-bottom: 1px solid #B3B3B3; } """) self.titleArea = QHBoxLayout() self.titleArea.setContentsMargins(10, 5, 10, 5) self.titleArea.setSpacing(0) title_holder.setLayout(self.titleArea) self.title_label = QLabel(self.title) self.title_label.mouseDoubleClickEvent = self.on_toggle self.title_label.setStyleSheet( 'font-size: 12px; border: 2px solid red;') self.titleArea.addWidget(self.title_label) self.off_label = QLabel('[disabled]') self.off_label.setStyleSheet('color: #B0B0B0; margin-left: 5px;') self.titleArea.addWidget(self.off_label) self.off_label.hide() self.titleArea.addStretch() # Root. self.rootArea = QVBoxLayout() self.rootArea.setContentsMargins(0, 0, 0, 0) self.rootArea.setSpacing(0) self.setLayout(self.rootArea) self.rootArea.addWidget(title_holder) self.contents = QWidget() contentArea = QVBoxLayout() contentArea.setContentsMargins(15, 10, 15, 10) self.contents.setLayout(contentArea) self.rootArea.addWidget(self.contents) self.method_layout = self.Layout() self.setup_method_layout() self.contents.layout().addLayout(self.method_layout) if self.toggle_enabled: self.on_off_button = OnOffButton(enabled=self.enabled) self.on_off_button.stateChanged.connect(self.on_toggle) self.on_off_button.setContentsMargins(0, 0, 0, 0) self.titleArea.addWidget(self.on_off_button) self.display_widget()
def setupUi(self): self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.__mainLayout = QVBoxLayout() self.__mainLayout.setContentsMargins(0, 40, 0, 40) self.__mainLayout.setSpacing(65) self.layout().addLayout(self.__mainLayout) self.setStyleSheet(WELCOME_WIDGET_BUTTON_STYLE) bottom_bar = QWidget(objectName="bottom-bar") bottom_bar_layout = QHBoxLayout() bottom_bar_layout.setContentsMargins(20, 10, 20, 10) bottom_bar.setLayout(bottom_bar_layout) bottom_bar.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum) check = QCheckBox(self.tr("Show at startup"), bottom_bar) check.setChecked(False) self.__showAtStartupCheck = check bottom_bar_layout.addWidget(check, alignment=Qt.AlignVCenter | \ Qt.AlignLeft) self.layout().addWidget(bottom_bar, alignment=Qt.AlignBottom, stretch=1) self.setSizeGripEnabled(False) self.setFixedSize(620, 390)
def test_dock_standalone(self): widget = QWidget() layout = QHBoxLayout() widget.setLayout(layout) layout.addStretch(1) widget.show() dock = CollapsibleDockWidget() layout.addWidget(dock) list_view = QListView() list_view.setModel(QStringListModel(["a", "b"], list_view)) label = QLabel("A label. ") label.setWordWrap(True) dock.setExpandedWidget(label) dock.setCollapsedWidget(list_view) dock.setExpanded(True) dock.setExpanded(False) timer = QTimer(dock, interval=50) timer.timeout.connect(lambda: dock.setExpanded(not dock.expanded())) timer.start() self.qWait() timer.stop()
def __init__(self, obas, parent): super(OBAControlUI, self).__init__() self.title = 'OnBoard Air Control UI' self.setLayout(QVBoxLayout(self)) self.obas = obas self.parent = parent # Init logger self.logger = Logger('obaControl', "UI : OBAControl") # Dynamically generate controls _keyStrings = [] for _i, _oba in enumerate(self.obas): _ctrl = OBAControl(_oba.name, momentary=_oba.momentary, parent=self) exec("self._%s = _ctrl" % _i) _ctrl.setIcon(QIcon(Config.icon('oba', _oba.icon)['path'])) if _oba.active: _ctrl.setChecked(True) _keyStrings.append('_%s' % _i) _oList = Tools.group(Config.obaColumns, _keyStrings) del _keyStrings # Dynamically generate panel layout using grouped tuples for oTuple in _oList: _panel = QWidget(self) _panel.setLayout(QHBoxLayout(_panel)) for oWidget in oTuple: _panel.layout().addWidget(eval('self.%s' % oWidget)) self.layout().addWidget(_panel) del _panel
def test_dock_standalone(self): widget = QWidget() layout = QHBoxLayout() widget.setLayout(layout) layout.addStretch(1) widget.show() dock = CollapsibleDockWidget() layout.addWidget(dock) list_view = QListView() list_view.setModel(QStringListModel(["a", "b"], list_view)) label = QLabel("A label. ") label.setWordWrap(True) dock.setExpandedWidget(label) dock.setCollapsedWidget(list_view) dock.setExpanded(True) self.app.processEvents() def toogle(): dock.setExpanded(not dock.expanded()) self.singleShot(2000, toogle) toogle() self.app.exec_()
def set_graph(self, graph, relayout=True): assert not graph or isinstance(graph, nx.Graph) self.graph = graph if not graph: self.clear() return large_graph = IS_LARGE_GRAPH(graph) very_large_graph = IS_VERY_LARGE_GRAPH(graph) self.setViewport( QtOpenGL.QGLWidget() # FIXME: Try reenable the following test after Qt5 port if large_graph and HAVE_OPENGL else QWidget()) self.setRenderHints(QtGui.QPainter.RenderHint( ) if very_large_graph else (QtGui.QPainter.Antialiasing | QtGui.QPainter.TextAntialiasing)) self.clear() nodes = {} for v in sorted(graph.nodes()): node = Node(v, view=self) self.addNode(node) nodes[v] = node for u, v in graph.edges(): self.addEdge(Edge(nodes[u], nodes[v], view=self)) self.selectionChanged.emit() if relayout: self.relayout()
def __init__(self): super().__init__() box = gui.widgetBox(self.controlArea, "Map grid") form = QWidget() formlayout = QFormLayout() form.setLayout(formlayout) box.layout().addWidget(form) self.le1 = lineEditIntOrNone(box, self, "xpoints", callback=self.le1_changed) formlayout.addRow("X dimension", self.le1) self.le3 = lineEditIntOrNone(box, self, "ypoints", callback=self.le3_changed) formlayout.addRow("Y dimension", self.le3) self.data = None self.set_data(self.data) # show warning gui.auto_commit(self.controlArea, self, "autocommit", "Send Data")
def __init__(self, tracs, parent): super(TracControlUI, self).__init__() self.title = 'Light Configuration' self.setLayout(QVBoxLayout(self)) self.tracs = tracs self.parent = parent # Init logger self.logger = Logger('tracControl', "UI : TracControl") # Dynamically generate controls _keyStrings = [] for _i, _trac in enumerate(self.tracs): _ctrl = TracControl(_trac.name, parent=self) exec("self._%s = _ctrl" % _i) _ctrl.setParent(self) _ctrl.setIcon(QIcon( Config.icon('tracControl', _trac.icon)['path'])) if _trac.active: _ctrl.setChecked(True) _keyStrings.append('_%s' % _i) oList = Tools.group(Config.tracColumns, _keyStrings) del _keyStrings # Dynamically generate panel layout using grouped tuples for oTuple in oList: _panel = QWidget(self) _panel.setLayout(QHBoxLayout(_panel)) for oWidget in oTuple: _panel.layout().addWidget(eval('self.%s' % oWidget)) self.layout().addWidget(_panel) del _panel
def test_toolbox(self): w = QWidget() layout = QHBoxLayout() reg = registry_tests.small_testing_registry() qt_reg = QtWidgetRegistry(reg) triggered_actions = [] model = qt_reg.model() one_action = qt_reg.action_for_widget("one") box = WidgetToolBox() box.setModel(model) box.triggered.connect(triggered_actions.append) layout.addWidget(box) box.setButtonSize(QSize(50, 80)) w.setLayout(layout) w.show() one_action.trigger() box.setButtonSize(QSize(60, 80)) box.setIconSize(QSize(35, 35)) box.setTabButtonHeight(40) box.setTabIconSize(QSize(30, 30)) self.app.exec_()
def test_overlay_message(self): container = QWidget() overlay = MessageOverlayWidget(parent=container) overlay.setWidget(container) overlay.setIcon(QStyle.SP_MessageBoxInformation) container.show() QTest.qWaitForWindowExposed(container) self.assertTrue(overlay.isVisible()) overlay.setText("Hello world! It's so nice here") QApplication.sendPostedEvents(overlay, QEvent.LayoutRequest) self.assertTrue(overlay.geometry().isValid()) button_ok = overlay.addButton(MessageOverlayWidget.Ok) button_close = overlay.addButton(MessageOverlayWidget.Close) button_help = overlay.addButton(MessageOverlayWidget.Help) self.assertTrue(all([button_ok, button_close, button_help])) self.assertIs(overlay.button(MessageOverlayWidget.Ok), button_ok) self.assertIs(overlay.button(MessageOverlayWidget.Close), button_close) self.assertIs(overlay.button(MessageOverlayWidget.Help), button_help) button = overlay.addButton("Click Me!", MessageOverlayWidget.AcceptRole) self.assertIsNot(button, None) self.assertTrue(overlay.buttonRole(button), MessageOverlayWidget.AcceptRole) mock = unittest.mock.MagicMock() overlay.accepted.connect(mock) QTest.mouseClick(button, Qt.LeftButton) self.assertFalse(overlay.isVisible()) mock.assert_called_once_with()
def __init__(self, oba, parent): super(EditOBAUI, self).__init__() self.parent = parent self.oba = oba self.setLayout(QVBoxLayout(self)) self.layout().setAlignment(Qt.AlignCenter) # Init Name text control self._nameControl = LineEdit('Name', self) self._nameControl.setText(self.oba.name) self._nameControl.kb.connect(self.showOSK) # Init Output Pin dropdown control self._outputPinControlLabel = QLabel('Output Pin', self) self._outputPinControl = QComboBox(self) for _pin in self.parent.availablePins(): self._outputPinControl.addItem(str(_pin)) for _i in range(self._outputPinControl.count()): if self._outputPinControl.itemText(_i) == str(self.oba.outputPin): self._outputPinControl.setCurrentIndex(_i) break # Init Momentary checkbox control and set value self._momentaryControl = QCheckBox('Momentary', self) self._momentaryControl.setChecked(self.oba.momentary) # Init Enabled checkbox control and set value self._enabledControl = QCheckBox('Enabled', self) self._enabledControl.setChecked(self.oba.enabled) # Init Icon dropdown control self._iconControlLabel = QLabel('Icon Path', self) self._iconControl = QComboBox(self) for _key in Config.icons['oba'].keys(): icon = Config.icon('oba', _key) self._iconControl.addItem(icon['name'], _key) self._iconControl.setItemIcon(self._iconControl.count() - 1, QIcon(icon['path'])) for _i in range(self._iconControl.count()): # Set current index if matching icon attribute if self.oba.icon is not None and self._iconControl.itemData( _i) == self.oba.icon: self._iconControl.setCurrentIndex(_i) break # Init Save button self._saveBtn = QPushButton('Save', self) self._saveBtn.clicked.connect(self.__saveBtnAction) # Init cancel button self._cancelBtn = QPushButton('Cancel', self) self._cancelBtn.clicked.connect(self.__cancel) # Assign control layout _layout = [['_nameControl'], ['_outputPinControlLabel', '_outputPinControl'], ['_momentaryControl', '_enabledControl'], ['_iconControlLabel', '_iconControl'], ['_saveBtn', '_cancelBtn']] for _list in _layout: _panel = QWidget(self) _panel.setLayout(QHBoxLayout(_panel)) _panel.layout().setAlignment(Qt.AlignCenter) _panel.layout().setSpacing(20) for _control in _list: _panel.layout().addWidget(eval('self.%s' % _control)) self.layout().addWidget(_panel)
def test1(self): class FT(QToolBar): def paintEvent(self, e): pass w = QMainWindow() ftt, ftb = FT(), FT() ftt.setFixedHeight(15) ftb.setFixedHeight(15) w.addToolBar(Qt.TopToolBarArea, ftt) w.addToolBar(Qt.BottomToolBarArea, ftb) f = dropshadow.DropShadowFrame() te = QTextEdit() c = QWidget() c.setLayout(QVBoxLayout()) c.layout().setContentsMargins(20, 0, 20, 0) c.layout().addWidget(te) w.setCentralWidget(c) f.setWidget(te) f.radius = 15 f.color = QColor(Qt.blue) w.show() self.singleShot(3000, lambda: f.setColor(Qt.red)) self.singleShot(4000, lambda: f.setRadius(30)) self.singleShot(5000, lambda: f.setRadius(40)) self.app.exec_()
def __init__(self): super().__init__() self.graph = None self.items = None # items set by Items signal self.items_graph = None # items set by graph.items by Network signal self.items_analysis = None # items to output and merge with analysis result self.known = {} self.running_jobs = {} # Indicates that node level statistics have changed or are pending to self._nodelevel_invalidated = False self.controlArea = QWidget(self.controlArea) self.layout().addWidget(self.controlArea) layout = QGridLayout() self.controlArea.setLayout(layout) layout.setContentsMargins(4, 4, 4, 4) tabs = gui.tabWidget(self.controlArea) tabs.setMinimumWidth(450) graph_indices = gui.createTabPage(tabs, "Graph-level indices", orientation=Qt.Horizontal) node_indices = gui.createTabPage(tabs, "Node-level indices", orientation=Qt.Horizontal) graph_methods = gui.vBox(graph_indices) gui.rubber(graph_indices) graph_labels = gui.vBox(graph_indices) node_methods = gui.vBox(node_indices) gui.rubber(node_indices) node_labels = gui.vBox(node_indices) graph_labels.layout().setAlignment(Qt.AlignRight) self.method_cbs = {} for method in METHODS.values(): if method.level == INTERNAL: continue setattr(self, method.name, method.name in self.enabled_methods) setattr(self, "lbl_" + method.name, "") methods = node_methods if method.level == NODELEVEL else graph_methods labels = node_labels if method.level == NODELEVEL else graph_labels cb = gui.checkBox( methods, self, method.name, method.label, callback=lambda attr=method.name: self.method_clicked(attr)) self.method_cbs[method.name] = cb lbl = gui.label(labels, self, f"%(lbl_{method.name})s") labels.layout().setAlignment(lbl, Qt.AlignRight) setattr(self, "tool_" + method.name, lbl) # todo: is this accessible through controls? graph_indices.layout().addStretch(1) node_indices.layout().addStretch(1)
def init_form(self): self._form = QWidget() layout = QVBoxLayout() if _api.USED_API == _api.QT_API_PYQT5: layout.setContentsMargins(0, 0, 0, 0) elif _api.USED_API == _api.QT_API_PYQT4: layout.setMargin(0) self._form.setLayout(layout) self._app = vv.use('pyqt5') self._app.Create() self._first = True Figure = self._app.GetFigureClass() self._fig = Figure(self._form) vv.figure(self._fig.nr) policy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) widget = self._fig._widget widget.setSizePolicy(policy) widget.setMinimumSize(100, 100) layout.addWidget(widget) self._colorMap = vv.CM_AUTUMN self._colors_limits = None super(ControlVisVisVolume, self).init_form()
def test_two_overlays(self): container2 = QWidget() overlay2 = NotificationOverlay(container2) self.server.newNotification.connect(overlay2.addNotification) self.server.nextNotification.connect(overlay2.nextWidget) mock = unittest.mock.MagicMock() self.notif.accepted.connect(mock) self.server.registerNotification(self.notif) self.container.show() container2.show() w1 = self.overlay.currentWidget() w2 = overlay2.currentWidget() self.assertTrue(w1.isVisible()) self.assertTrue(w2.isVisible()) button = w2.button(NotificationWidget.Ok) QTest.mouseClick(button, Qt.LeftButton) mock.assert_called_once_with() self.assertFalse(w1.isVisible()) self.assertFalse(w2.isVisible())
def main(argv=None): # pragma: no cover from AnyQt.QtWidgets import QVBoxLayout, QCheckBox, QStatusBar app = QApplication(list(argv) if argv else []) l1 = QVBoxLayout() l1.setContentsMargins(0, 0, 0, 0) blayout = QVBoxLayout() l1.addLayout(blayout) sb = QStatusBar() w = QWidget() w.setLayout(l1) messages = [ Message( Severity.Error, text="Encountered a HCF", detailedText="<em>AAA! It burns.</em>", textFormat=Qt.RichText, ), Message( Severity.Warning, text="ACHTUNG!", detailedText=('<div style="color: red">DAS KOMPUTERMASCHINE IST ' "NICHT FÜR DER GEFINGERPOKEN</div>"), textFormat=Qt.RichText, ), Message( Severity.Information, text="The rain in spain falls mostly on the plain", informativeText=( '<a href="https://www.google.si/search?q=' 'Average+Yearly+Precipitation+in+Spain">Link</a>'), textFormat=Qt.RichText, ), Message( Severity.Error, text="I did not do this!", informativeText="The computer made suggestions...", detailedText="... and the default options was yes.", ), Message(), ] mw = MessagesWidget(openExternalLinks=True) for i, m in enumerate(messages): cb = QCheckBox(m.text) def toogled(state, i=i, m=m): if state: mw.setMessage(i, m) else: mw.removeMessage(i) cb.toggled[bool].connect(toogled) blayout.addWidget(cb) sb.addWidget(mw) w.layout().addWidget(sb, 0) w.show() return app.exec_()
def generateDrawSpecs(self, p): axis_spec, tick_specs, text_specs = super().generateDrawSpecs(p) bounds = self.mapRectFromParent(self.geometry()) max_width = int(0.9 * bounds.width() / (len(text_specs) or 1)) elide = QFontMetrics(QWidget().font()).elidedText text_specs = [(rect, flags, elide(text, Qt.ElideRight, max_width)) for rect, flags, text in text_specs] return axis_spec, tick_specs, text_specs
def setUp(self): self.data = Table("iris") self.model = model = VariableItemModel() model.set_data(self.data) widget = OWCreateInstance() self.delegate = VariableDelegate(widget) self.parent = QWidget() self.opt = QStyleOptionViewItem()
def new_inbox(): nonlocal row, col, inbox inbox = QWidget() layout = QGridLayout() inbox.setLayout(layout) layout.setContentsMargins(0, 0, 0, 0) box.layout().addWidget(inbox) row = col = 0
def box_spacing(self, widget): if isinstance(widget.layout(), QGridLayout): widget = widget.layout() if isinstance(widget, QGridLayout): space = QWidget() space.setFixedSize(12, 12) widget.addWidget(space, widget.rowCount(), 0) else: gui.separator(widget)
def __init__(self, parent=None, windowTitle="Color Palette List", **kwargs): super().__init__(parent, windowTitle=windowTitle, **kwargs) self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) sa = QScrollArea(horizontalScrollBarPolicy=Qt.ScrollBarAlwaysOff, verticalScrollBarPolicy=Qt.ScrollBarAlwaysOn) sa.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) sa.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.layout().addWidget(sa) space = QWidget(self) space.setLayout(QVBoxLayout()) sa.setWidget(space) sa.setWidgetResizable(True) self.buttons = [] self.setMinimumWidth(400) box = gui.vBox(space, "Information", addSpace=True) gui.widgetLabel( box, '<p align="center">This dialog shows a list of predefined ' 'color palettes <br>from colorbrewer.org that can be used ' 'in Orange.<br/>You can select a palette by clicking on it.</p>') box = gui.vBox(space, "Default Palette", addSpace=True) butt = _ColorButton(DefaultRGBColors, flat=True, toolTip="Default color palette", clicked=self._buttonClicked) box.layout().addWidget(butt) self.buttons.append(butt) for type in [ "Qualitative", "Spectral", "Diverging", "Sequential", "Pastels" ]: colorGroup = colorbrewer.colorSchemes.get(type.lower(), {}) if colorGroup: box = gui.vBox(space, type + " Palettes", addSpace=True) items = sorted(colorGroup.items()) for key, colors in items: butt = _ColorButton(colors, self, toolTip=key, flat=True, clicked=self._buttonClicked) box.layout().addWidget(butt) self.buttons.append(butt) buttons = QDialogButtonBox(QDialogButtonBox.Cancel, rejected=self.reject) self.layout().addWidget(buttons) self.selectedColors = None
def _fullscreen_to_maximized(geometry): """Don't restore windows into full screen mode because it loses decorations and can't be de-fullscreened at least on some platforms. Use Maximized state insted.""" w = QWidget(visible=False) w.restoreGeometry(QByteArray(geometry)) if w.isFullScreen(): w.setWindowState(w.windowState() & ~Qt.WindowFullScreen | Qt.WindowMaximized) return w.saveGeometry()
def setUp(self) -> None: self.container = QWidget() stdb = NotificationWidget.Ok | NotificationWidget.Close self.overlay = NotificationOverlay(self.container) self.notif = NotificationWidget(title="lol", text="hihi", standardButtons=stdb) self.container.show() QTest.qWaitForWindowExposed(self.container) self.overlay.show() QTest.qWaitForWindowExposed(self.overlay)
def add_main_layout(self): main_widget = QWidget() layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) main_widget.setLayout(layout) self.controlArea.layout().addWidget(main_widget) left = gui.vBox(main_widget).layout() right = gui.vBox(main_widget).layout() self._add_algorithm_to_layout(left) self._add_regularization_to_layout(left) self._add_learning_params_to_layout(right)
def test_popup_position(self): popup = CategoryPopupMenu() screen = popup.screen() screen_geom = screen.availableGeometry() popup.setMinimumHeight(screen_geom.height() + 20) w = QWidget() w.setGeometry(screen_geom.left() + 100, screen_geom.top() + 100, 20, 20) pos = popup_position_from_source(popup, w) self.assertTrue(screen_geom.contains(pos)) pos = QPoint(screen_geom.top() - 100, screen_geom.left() - 100) geom = widget_popup_geometry(pos, popup) self.assertEqual(screen_geom.intersected(geom), geom)
def setUp(self) -> None: self.container = QWidget() self.overlay = NotificationOverlay(self.container) self.server = NotificationServer() self.server.newNotification.connect(self.overlay.addNotification) self.server.nextNotification.connect(self.overlay.nextWidget) self.notif = Notification( title="Hello world!", text="Welcome to the testing grounds – this is where your resolve" "and stability will be tried and tested.", accept_button_label="Ok")
def __init__(self): super().__init__() # data self.dataA = None self.dataB = None # GUI w = QWidget(self) self.controlArea.layout().addWidget(w) grid = QGridLayout() grid.setContentsMargins(0, 0, 0, 0) w.setLayout(grid) # attribute A selection boxAttrA = gui.vBox(self, self.tr("Attribute A"), addToLayout=False) grid.addWidget(boxAttrA, 0, 0) self.attrViewA = gui.comboBox(boxAttrA, self, 'attr_a', orientation=Qt.Horizontal, sendSelectedValue=True, callback=self._invalidate) self.attrModelA = itemmodels.VariableListModel() self.attrViewA.setModel(self.attrModelA) # attribute B selection boxAttrB = gui.vBox(self, self.tr("Attribute B"), addToLayout=False) grid.addWidget(boxAttrB, 0, 1) self.attrViewB = gui.comboBox(boxAttrB, self, 'attr_b', orientation=Qt.Horizontal, sendSelectedValue=True, callback=self._invalidate) self.attrModelB = itemmodels.VariableListModel() self.attrViewB.setModel(self.attrModelB) # info A boxDataA = gui.vBox(self, self.tr("Data A Input"), addToLayout=False) grid.addWidget(boxDataA, 1, 0) self.infoBoxDataA = gui.widgetLabel(boxDataA, self.dataInfoText(None)) # info B boxDataB = gui.vBox(self, self.tr("Data B Input"), addToLayout=False) grid.addWidget(boxDataB, 1, 1) self.infoBoxDataB = gui.widgetLabel(boxDataB, self.dataInfoText(None)) gui.rubber(self)
def __init__(self, rWidget=None): super(OSK, self).__init__() self.showFullScreen() self._rWidget = rWidget self.layout = QVBoxLayout(self) self.currentText = QLabel(self) self.currentText.setAlignment(Qt.AlignCenter) if rWidget is not None: self.currentText.setText(rWidget.text()) self.layout.addWidget(self.currentText) keyLayout = [['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-'], ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'], ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'], ['z', 'x', 'c', 'v', 'b', 'n', 'm']] for l in keyLayout: panel = QWidget(self) panel.layout = QHBoxLayout(panel) for key in l: button = OSKKey(key, self, parent=self) panel.layout.addWidget(button) self.layout.addWidget(panel) contolPanel = QWidget(self) contolPanel.layout = QHBoxLayout(contolPanel) self._shift = QPushButton('Shift', self) self._shift.setCheckable(True) self._shift.setFixedWidth(150) contolPanel.layout.addWidget(self._shift) spaceBar = OSKKey('space', self, parent=self) spaceBar.rKey = ' ' spaceBar.setFixedWidth(2 * self.window().geometry().width() / 3) contolPanel.layout.addWidget(spaceBar) bkspc = OSKKey('delete', self, parent=self) bkspc.rKey = '<<' contolPanel.layout.addWidget(bkspc) self.layout.addWidget(contolPanel) self.closeButton = QPushButton("OK", self) self.closeButton.clicked.connect(self.__closeButtonAction) self.layout.addWidget(self.closeButton)
def test_layout(self): container = QWidget() container.setLayout(QHBoxLayout()) container1 = QWidget() container.layout().addWidget(container1) container.show() QTest.qWaitForWindowExposed(container) container.resize(600, 600) overlay = OverlayWidget(parent=container) overlay.setWidget(container) overlay.resize(20, 20) overlay.show() center = overlay.geometry().center() self.assertTrue(290 < center.x() < 310) self.assertTrue(290 < center.y() < 310) overlay.setAlignment(Qt.AlignTop | Qt.AlignHCenter) geom = overlay.geometry() self.assertEqual(geom.top(), 0) self.assertTrue(290 < geom.center().x() < 310) overlay.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) geom = overlay.geometry() self.assertEqual(geom.left(), 0) self.assertTrue(290 < geom.center().y() < 310) overlay.setAlignment(Qt.AlignBottom | Qt.AlignRight) geom = overlay.geometry() self.assertEqual(geom.right(), 600 - 1) self.assertEqual(geom.bottom(), 600 - 1) overlay.setWidget(container1) geom = overlay.geometry() self.assertEqual(geom.right(), container1.geometry().right()) self.assertEqual(geom.bottom(), container1.geometry().bottom())
def test_show_tip(self): w = QWidget() show_tip(w, QPoint(100, 100), "Ha Ha") app = QApplication.instance() windows = app.topLevelWidgets() label = [tl for tl in windows if tl.parent() is w and tl.objectName() == "tip-label"][0] self.assertTrue(label.isVisible()) self.assertTrue(label.text() == "Ha Ha") show_tip(w, QPoint(100, 100), "Ha") self.assertTrue(label.text() == "Ha") show_tip(w, QPoint(100, 100), "") self.assertFalse(label.isVisible())