def main():
    'Application entry point'

    if args.scale != 1:
        os.environ['QT_SCALE_FACTOR'] = str(args.scale)
    else:
        os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1'
    if args.style != 'native':
        style = QtWidgets.QStyleFactory.create(args.style)
        QtWidgets.QApplication.setStyle(style)
    logging.basicConfig(level=logging.DEBUG)
    app = QtWidgets.QApplication(sys.argv[:1] + unknown)
    window = QtWidgets.QMainWindow()

    # use the default font size
    font = app.font()
    if args.font_size > 0:
        font.setPointSizeF(args.font_size)
    if args.font_family:
        font.setFamily(args.font_family)
    app.setFont(font)

    # setup ui
    ui = Ui()
    ui.setup(window)
    ui.bt_delay_popup.addActions([ui.actionAction, ui.actionAction_C])
    ui.bt_instant_popup.addActions([ui.actionAction, ui.actionAction_C])
    ui.bt_menu_button_popup.addActions([ui.actionAction, ui.actionAction_C])
    window.setWindowTitle('Sample BreezeStyleSheets application.')

    # Add event triggers
    ui.actionAction.triggered.connect(ui.about)
    ui.actionAction_C.triggered.connect(ui.critical)

    # tabify dock widgets to show bug #6
    window.tabifyDockWidget(ui.dockWidget1, ui.dockWidget2)

    # setup stylesheet
    if args.stylesheet != 'native':
        file = QtCore.QFile(stylesheet)
        file.open(ReadOnly | Text)
        stream = QtCore.QTextStream(file)
        app.setStyleSheet(stream.readAll())

    # run
    window.show()
    if args.pyqt6:
        return app.exec()
    else:
        return app.exec_()
Beispiel #2
0
def test(args, qtargv, test_widget):
    '''Test a single widget.'''

    app = QtWidgets.QApplication(qtargv)

    # use the default font size
    font = app.font()
    if args.font_size > 0:
        font.setPointSizeF(args.font_size)
    if args.font_family:
        font.setFamily(args.font_family)
    app.setFont(font)

    # setup stylesheet
    if args.stylesheet != 'native':
        file = QtCore.QFile(stylesheet)
        file.open(ReadOnly | Text)
        stream = QtCore.QTextStream(file)
        app.setStyleSheet(stream.readAll())

    # Setup the main window.
    window = QtWidgets.QMainWindow()
    window.setWindowTitle('Sample single widget application.')
    window.resize(args.width, args.height)
    widget = QtWidgets.QWidget()
    scroll = QtWidgets.QScrollArea()
    scroll.setHorizontalScrollBarPolicy(ScrollBarAsNeeded)
    scroll.setVerticalScrollBarPolicy(ScrollBarAsNeeded)
    scroll.setWidgetResizable(True)

    # Get the correct parameters for our test widget.
    try:
        function = globals()[f'test_{test_widget}']
    except KeyError:
        raise NotImplementedError(f'test for {test_widget} not implemented')
    result = function(widget, window, font, args.width, args.height, app)
    child = []
    layout_type = 'vertical'
    show_window = True
    quit = False
    if result and isinstance(result, list):
        # Have a single value passed as a list
        child = result
    elif isinstance(result, tuple):
        child = result[0]
    else:
        child = result
    if isinstance(result, tuple) and len(result) >= 2:
        layout_type = result[1]
    if isinstance(result, tuple) and len(result) >= 3:
        show_window = result[2]
    if isinstance(result, tuple) and len(result) >= 4:
        quit = result[3]

    # Add the widgets to the layout.
    if layout_type is not None and child is not None:
        widget_layout = layout[layout_type]()
        if args.compress:
            widget_layout.addStretch(1)
            add_widgets(widget_layout, child)
            widget_layout.addStretch(1)
        else:
            add_widgets(widget_layout, child)
        if args.alignment is not None:
            widget_layout.setAlignment(alignment[args.alignment])
        widget.setLayout(widget_layout)
    scroll.setWidget(widget)
    window.setCentralWidget(scroll)

    # run
    if show_window:
        window.show()
    if quit:
        return app.quit()
    if args.pyqt6:
        return app.exec()
    else:
        return app.exec_()
Beispiel #3
0
def main():
    'Application entry point'

    if args.scale != 1:
        os.environ['QT_SCALE_FACTOR'] = str(args.scale)
    else:
        os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1'
    if args.style != 'native':
        style = QtWidgets.QStyleFactory.create(args.style)
        QtWidgets.QApplication.setStyle(style)

    app = QtWidgets.QApplication(sys.argv[:1] + unknown)
    window = QtWidgets.QMainWindow()

    # use the default font size
    font = app.font()
    if args.font_size > 0:
        font.setPointSizeF(args.font_size)
    if args.font_family:
        font.setFamily(args.font_family)
    app.setFont(font)

    # setup stylesheet
    if args.stylesheet != 'native':
        file = QtCore.QFile(stylesheet)
        file.open(ReadOnly | Text)
        stream = QtCore.QTextStream(file)
        app.setStyleSheet(stream.readAll())

    # setup the dock manager
    window.setObjectName('MainWindow')
    window.resize(1068, 824)
    widget = QtWidgets.QWidget(window)
    window.setCentralWidget(widget)
    dock_manager = QtAds.CDockManager(window)

    # add widgets to the dock manager
    label_widget = QtAds.CDockWidget('Dock')
    label = QtWidgets.QLabel('Some label')
    label_widget.setWidget(label)
    dock_area = dock_manager.setCentralWidget(label_widget)
    dock_area.setAllowedAreas(QtAds.DockWidgetArea.OuterDockAreas)

    list_widget = QtAds.CDockWidget('List')
    lst = QtWidgets.QListWidget()
    for index in range(10):
        lst.addItem(QtWidgets.QListWidgetItem(f'Item {index + 1}'))
    list_widget.setWidget(lst)
    list_widget.setMinimumSizeHintMode(
        QtAds.CDockWidget.MinimumSizeHintFromDockWidget)
    dock_manager.addDockWidget(QtAds.DockWidgetArea.LeftDockWidgetArea,
                               list_widget, dock_area)

    table_widget = QtAds.CDockWidget('Table')
    table = QtWidgets.QTableWidget()
    # make sure we have both scroll areas active.
    table.setColumnCount(40)
    table.setRowCount(40)
    table_widget.setWidget(table)
    table_widget.setMinimumSizeHintMode(
        QtAds.CDockWidget.MinimumSizeHintFromDockWidget)
    dock_manager.addDockWidget(QtAds.DockWidgetArea.RightDockWidgetArea,
                               table_widget, dock_area)

    if not args.use_internal:
        dock_manager.setStyleSheet('')

    # run
    window.setWindowState(WindowMaximized)
    window.show()
    if args.pyqt6:
        return app.exec()
    else:
        return app.exec_()