当前位置: 首页>>代码示例>>Python>>正文


Python QBoxLayout.addLayout方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QBoxLayout.addLayout方法的典型用法代码示例。如果您正苦于以下问题:Python QBoxLayout.addLayout方法的具体用法?Python QBoxLayout.addLayout怎么用?Python QBoxLayout.addLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QBoxLayout的用法示例。


在下文中一共展示了QBoxLayout.addLayout方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AddConfigurationDialog

# 需要导入模块: from PyQt5.QtWidgets import QBoxLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import addLayout [as 别名]
class AddConfigurationDialog(QDialog):
    def __init__(self, parent=None):
        super(AddConfigurationDialog, self).__init__(parent)
        self._layout = QBoxLayout(QBoxLayout.TopToBottom)
        self.setLayout(self._layout)
        self.setWindowTitle('Add configuration')

        self._nameField = QLineEdit()
        name_form_layout = QFormLayout()
        name_form_layout.addRow('Name:', self._nameField)
        self._layout.addLayout(name_form_layout)
        self._layout.addWidget(QLabel("You won't be able to change this name later."))
        self._cancelButton = QPushButton("Cancel")
        self._saveButton = QPushButton("Create")
        button_layout = QBoxLayout(QBoxLayout.LeftToRight)
        button_layout.addWidget(self._cancelButton)
        button_layout.addWidget(self._saveButton)
        self._layout.addLayout(button_layout)
        
        self._configuration = None
        
        self._cancelButton.clicked.connect(self.reject)
        self._saveButton.clicked.connect(self._saved)
        
    def _saved(self):
        name = self._nameField.text()
        self._configuration = Configuration(name)
        data = DataStorage()
        data.add_configuration(self._configuration)
        data.persist()
        self.accept()
        
    def get_configuration(self):
        """
        Returns the created configuration if called after executing the dialog or None otherwise.
        :rtype: Configuration
        """
        return self._configuration
开发者ID:frmwrk123,项目名称:oeprint,代码行数:40,代码来源:add_configuration_dialog.py

示例2: E5SideBar

# 需要导入模块: from PyQt5.QtWidgets import QBoxLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import addLayout [as 别名]
class E5SideBar(QWidget):
    """
    Class implementing a sidebar with a widget area, that is hidden or shown,
    if the current tab is clicked again.
    """
    Version = 1
    
    North = 0
    East = 1
    South = 2
    West = 3
    
    def __init__(self, orientation=None, delay=200, parent=None):
        """
        Constructor
        
        @param orientation orientation of the sidebar widget (North, East,
            South, West)
        @param delay value for the expand/shrink delay in milliseconds
            (integer)
        @param parent parent widget (QWidget)
        """
        super(E5SideBar, self).__init__(parent)
        
        self.__tabBar = QTabBar()
        self.__tabBar.setDrawBase(True)
        self.__tabBar.setShape(QTabBar.RoundedNorth)
        self.__tabBar.setUsesScrollButtons(True)
        self.__tabBar.setDrawBase(False)
        self.__stackedWidget = QStackedWidget(self)
        self.__stackedWidget.setContentsMargins(0, 0, 0, 0)
        self.__autoHideButton = QToolButton()
        self.__autoHideButton.setCheckable(True)
        self.__autoHideButton.setIcon(
            UI.PixmapCache.getIcon("autoHideOff.png"))
        self.__autoHideButton.setChecked(True)
        self.__autoHideButton.setToolTip(
            self.tr("Deselect to activate automatic collapsing"))
        self.barLayout = QBoxLayout(QBoxLayout.LeftToRight)
        self.barLayout.setContentsMargins(0, 0, 0, 0)
        self.layout = QBoxLayout(QBoxLayout.TopToBottom)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(0)
        self.barLayout.addWidget(self.__autoHideButton)
        self.barLayout.addWidget(self.__tabBar)
        self.layout.addLayout(self.barLayout)
        self.layout.addWidget(self.__stackedWidget)
        self.setLayout(self.layout)
        
        # initialize the delay timer
        self.__actionMethod = None
        self.__delayTimer = QTimer(self)
        self.__delayTimer.setSingleShot(True)
        self.__delayTimer.setInterval(delay)
        self.__delayTimer.timeout.connect(self.__delayedAction)
        
        self.__minimized = False
        self.__minSize = 0
        self.__maxSize = 0
        self.__bigSize = QSize()
        
        self.splitter = None
        self.splitterSizes = []
        
        self.__hasFocus = False
        # flag storing if this widget or any child has the focus
        self.__autoHide = False
        
        self.__tabBar.installEventFilter(self)
        
        self.__orientation = E5SideBar.North
        if orientation is None:
            orientation = E5SideBar.North
        self.setOrientation(orientation)
        
        self.__tabBar.currentChanged[int].connect(
            self.__stackedWidget.setCurrentIndex)
        e5App().focusChanged[QWidget, QWidget].connect(self.__appFocusChanged)
        self.__autoHideButton.toggled[bool].connect(self.__autoHideToggled)
    
    def setSplitter(self, splitter):
        """
        Public method to set the splitter managing the sidebar.
        
        @param splitter reference to the splitter (QSplitter)
        """
        self.splitter = splitter
        self.splitter.splitterMoved.connect(self.__splitterMoved)
        self.splitter.setChildrenCollapsible(False)
        index = self.splitter.indexOf(self)
        self.splitter.setCollapsible(index, False)
    
    def __splitterMoved(self, pos, index):
        """
        Private slot to react on splitter moves.
        
        @param pos new position of the splitter handle (integer)
        @param index index of the splitter handle (integer)
        """
        if self.splitter:
#.........这里部分代码省略.........
开发者ID:pycom,项目名称:EricShort,代码行数:103,代码来源:E5SideBar.py

示例3: SlidersGroup

# 需要导入模块: from PyQt5.QtWidgets import QBoxLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import addLayout [as 别名]
class SlidersGroup(QGroupBox):

    valueChanged = pyqtSignal(int)

    def __init__(self, commandBox, parent=None):
        super(SlidersGroup, self).__init__("", parent)
        self.slidersLayout = QBoxLayout(QBoxLayout.LeftToRight)
        self.commandBox = commandBox

        self.sliders = []
#        self.spinBoxes = []
        self.labels = []
        if len(screen_data) == 1:
            self.slidersLayout.addStretch()
        for i, (name, value) in enumerate(screen_data):
            self.createBrightnessCtrl(name, value, i)

        if len(screen_data) > 1:
            self.createBrightnessCtrl("All", 100, None)
            self.sliders[-1].valueChanged.connect(self.setAllValues)

        self.setLayout(self.slidersLayout)

        self.refreshCurrentValues()

    def createBrightnessCtrl(self, name, value, i):
        sl = QSlider(Qt.Vertical)
        sl.setFocusPolicy(Qt.StrongFocus)
        sl.setTickPosition(QSlider.TicksBothSides)
        sl.setTickInterval(10)
        sl.setSingleStep(1)
        sl.setMinimum(5)
        sl.setMaximum(100)
        sl.setValue(value)

        sb = QSpinBox()
        sb.setRange(5, 100)
        sb.setSingleStep(10)
        sb.setValue(value)

        sl.valueChanged.connect(sb.setValue)
        sb.valueChanged.connect(sl.setValue)
        if i != None:
            sl.valueChanged.connect(self.setValuePartial(i))
            sb.valueChanged.connect(self.setValuePartial(i))

        boxLayout = QBoxLayout(QBoxLayout.LeftToRight)
        lbl = QLabel(name)
        boxLayout.addWidget(lbl)
        boxLayout.addWidget(sb)

        boxLayout.addWidget(sl)

        self.slidersLayout.addLayout(boxLayout)
        # stretch is between (label, spinner, slider) groups
        if i != None:
            self.slidersLayout.addStretch()

        self.sliders.append(sl)
#        self.spinBoxes.append(sl)
        self.labels.append(lbl)

    def setValue(self, i, value):
        global screen_data
        screen_data[i] = (screen_data[i][0], value)
        self.refreshCommandBox()

    def setValuePartial(self, i):
        s = self.setValue
        return lambda value: s(i, value)

    def setAllValues(self, value):
        for sl in self.sliders:
            sl.setValue(value)

    def refreshCurrentValues(self):
        for i in range(len(screen_data)):
            lbl = self.labels[i]
            name, value = screen_data[i]
            if i == primary and len(screen_data) > 1:
                name += " (primary) "
            lbl.setText(name + " (" + str(value) + ")")
        self.refreshCommandBox()

    def refreshCommandBox(self):
        self.commandBox.document().setPlainText("# apply changes")
        for command in get_apply_commands():
            self.commandBox.appendPlainText(command)
开发者ID:VelizarHristov,项目名称:xrandr-dimmer,代码行数:90,代码来源:__init__.py

示例4: PrintView

# 需要导入模块: from PyQt5.QtWidgets import QBoxLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import addLayout [as 别名]
class PrintView(QWidget):
    """
    Displays the print view.
    """
    def __init__(self, parent=None):
        super(PrintView, self).__init__(parent)
        self._layout = QBoxLayout(QBoxLayout.TopToBottom)
        self.setLayout(self._layout)
        # initialize
        config = Config()
        self._printerSelection = QComboBox()
        self._printerSelection.addItems(config.get("Data", "printers").split(","))
        self._printerSelection.setEditable(True)
        self._printButton = QPushButton("Print")

        form_layout = QFormLayout()
        form_layout.addRow("Printer:", self._printerSelection)
        self._layout.addLayout(form_layout)
        self._layout.addWidget(self._printButton)
        self._model = None # type: QTreeWidget

        # initialize event listener
        self._printButton.clicked.connect(self._print)

    def set_parent_model(self, model):
        self._model = model

    def _print(self):
        """
        Prints the selected materials.
        """
        print_amounts = self._calculate_print_amounts(self._model.invisibleRootItem())
        printer = self._printerSelection.currentText()
        ssh_input = SSHInput(self.parent())
        connection = Connection(ssh_input)
        self._printButton.setText("Printing...")
        self._printButton.setDown(True)
        result = connection.send_print_data(print_amounts, printer)
        if not result:
            error = connection.get_error_object()
            if error.output is not None:
                show_error_alert(error.output)
            else:
                show_error_alert("Something went wrong")
        self._printButton.setText("Print")
        self._printButton.setDown(False)

    def _calculate_print_amounts(self, root_item):
        """
        :param root_item:
        :type root_item: QTreeWidgetItem
        :rtype: dict
        """
        print_amounts = {}
        if root_item.childCount() > 0:
            for child_index in range(root_item.childCount()):
                child = root_item.child(child_index)
                if is_checked_tree(child):
                    print_amounts[child.text(0)] = int(child.text(1))
                else:
                    child_print_amounts = self._calculate_print_amounts(child)
                    print_amounts.update(child_print_amounts)

        elif is_checked_tree(root_item):
            print_amounts[root_item.text(0)] = int(root_item.text(1))

        return print_amounts
开发者ID:frmwrk123,项目名称:oeprint,代码行数:69,代码来源:print_view.py

示例5: EditView

# 需要导入模块: from PyQt5.QtWidgets import QBoxLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import addLayout [as 别名]
class EditView(QDialog):
    """
    Displays the edit view
    """
    _material_model = None  # type: QTreeWidget
    _configuration_model = None  # type: QTreeWidget
    
    def __init__(self, parent=None):
        super(EditView, self).__init__(parent)
        self._layout = QBoxLayout(QBoxLayout.LeftToRight)
        self.setLayout(self._layout)
        self.setWindowTitle('Edit configuration')
        
        self._configurationTreeWidget = TreeWidget()
        self._configurationTreeWidget.setColumnCount(2)
        self._configurationTreeWidget.setHeaderLabels(["Configuration name", "Print amount"])
        self._materialTreeWidget = TreeWidget()
        self._materialTreeWidget.setColumnCount(2)
        self._materialTreeWidget.setHeaderLabels(["Material name", "Print amount"])
        self._initialize_material_model()
        
        self._currentConfiguration = None # type: Configuration
        
        config_widget = QWidget()
        self._configLayout = QBoxLayout(QBoxLayout.TopToBottom)
        self._nameField = QLineEdit()
        self._nameField.setEnabled(False)
        name_form_layout = QFormLayout()
        name_form_layout.addRow('Name:', self._nameField)
        self._configLayout.addLayout(name_form_layout)
        self._configLayout.addWidget(QLabel('List of configurations'))
        self._configLayout.addWidget(self._configurationTreeWidget)
        config_widget.setLayout(self._configLayout)
        
        self._saveButton = QPushButton("Save")
        material_widget = QWidget()
        self._materialLayout = QBoxLayout(QBoxLayout.TopToBottom)
        self._materialLayout.addWidget(self._saveButton)
        self._materialLayout.addWidget(QLabel('List of materials'))
        self._materialLayout.addWidget(self._materialTreeWidget)
        material_widget.setLayout(self._materialLayout)
        
        self._layout.addWidget(config_widget)
        self._layout.addWidget(material_widget)

        # add event listener for selection change
        self._configurationTreeWidget.setEditTriggers(self._configurationTreeWidget.NoEditTriggers)
        self._materialTreeWidget.setEditTriggers(self._materialTreeWidget.NoEditTriggers)
        self._configurationTreeWidget.itemDoubleClicked.connect(self._check_edit_configuration)
        self._materialTreeWidget.itemDoubleClicked.connect(self._check_edit_material)
        self._materialTreeWidget.expanded.connect(self._resize_columns)
        self._materialTreeWidget.collapsed.connect(self._resize_columns)
        self._materialTreeWidget.itemChecked.connect(self._on_toggle)
        self._saveButton.clicked.connect(self._save)

    @staticmethod
    def get_material_model():
        return EditView._material_model

    @staticmethod
    def get_configuration_model():
        return EditView._configuration_model
        
    def _resize_columns(self):
        self._materialTreeWidget.resizeColumnToContents(0)
        self._materialTreeWidget.resizeColumnToContents(1)
        self._configurationTreeWidget.resizeColumnToContents(0)
        self._configurationTreeWidget.resizeColumnToContents(1)
        
    def _check_edit_material(self, item, column):
        """
        Checks if the column of the item can be edited and set edit state if that is the case.
        :param item:
        :type item: QTreeWidgetItem
        :param column:
        :type column: number
        """
        if column == 1:
            self._materialTreeWidget.editItem(item, column)
            
    def _check_edit_configuration(self, item, column):
        """
        Checks if the column of the item can be edited and set edit state if that is the case.
        :param item:
        :type item: QTreeWidgetItem
        :param column:
        :type column: number
        """
        if column == 1:
            self._configurationTreeWidget.editItem(item, column)
            
    def _on_toggle(self, model_index):
        """
        Called on selecting a new item in the treeView.
        :param model_index: index of selected item
        :type model_index: QModelIndex
        """
        self._materialTreeWidget.blockSignals(True)
        selected_item = self._materialTreeWidget.itemFromIndex(model_index)  # type: QTreeWidgetItem
        parent_item = selected_item.parent()
#.........这里部分代码省略.........
开发者ID:frmwrk123,项目名称:oeprint,代码行数:103,代码来源:edit_view.py


注:本文中的PyQt5.QtWidgets.QBoxLayout.addLayout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。