示例#1
0
class QToolboxRun(QWidget):
    def __init__(self, parent=QWidget):
        super(QWidget, self).__init__()
        self.layoutMainHor = QHBoxLayout()
        self.elements = []
        self.requested_size, _ = parent.get_toolbar_size()
        self.initUI()
        # self.setAttribute(QtCore.Qt.WA_StyledBackground, True)

    def add_element(self, name):
        button = QPushButton(name)
        button.setSizePolicy(
            QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding))
        button.setStyleSheet(
            "background-color: #4e4e4e; color: #fafafa; font-size: 15px; border: 1px solid white"
        )
        self.layoutMainHor.addWidget(button)
        self.elements.append([name, button])

    def initUI(self):
        self.setMinimumSize(1, 30)
        self.setMaximumHeight(self.requested_size)
        for i in range(1):
            self.add_element("6. The cave")
        self.layoutMainHor.setDirection(QBoxLayout.LeftToRight)
        self.setContentsMargins(0, 0, 0, 0)
        self.layoutMainHor.setSpacing(0)
        self.layoutMainHor.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.layoutMainHor)
示例#2
0
class TreatyElementView(QWidget):
    WIDTH = 1600
    HEIGHT = 50

    def __init__(self, delivery_date, delivery_condition, payment_condition, culture_name, organization_name,
                 requisites, email, head, post_address, legal_address, site):
        super().__init__()
        self.delivery_date = delivery_date
        self.delivery_condition = delivery_condition
        self.payment_condition = payment_condition
        self.culture_name = culture_name
        self.organization_name = organization_name
        self.requisites = requisites
        self.email = email
        self.head = head
        self.post_address = post_address
        self.legal_address = legal_address
        self.site = site
        self.h_layout = QHBoxLayout()
        self.init_gui()
        self.init_main_layout()
        self.add_labels()

    def init_main_layout(self):
        self.h_layout.setAlignment(Qt.AlignTop)
        self.h_layout.setContentsMargins(0, 0, 0, 0)
        self.h_layout.setSpacing(0)
        self.h_layout.setDirection(QHBoxLayout.LeftToRight)

    def init_gui(self):
        self.setGeometry(0, 0, self.WIDTH, self.HEIGHT)
        self.setLayout(self.h_layout)
        self.setStyleSheet("background-color: #424A52;"
                           "color:#FFFFFF;"
                           "text-align:center;"
                           "border: 1px outset #000000;")

    def add_labels(self):
        self.add_label(str(self.delivery_date))
        self.add_label(self.delivery_condition)
        self.add_label(self.payment_condition)
        self.add_label(self.culture_name)
        self.add_label(self.organization_name)
        self.add_label(self.requisites)
        self.add_label(self.email)
        self.add_label(self.head)
        self.add_label(self.post_address)
        self.add_label(self.legal_address)
        self.add_label(self.site)

    def add_label(self, str):
        label = QLabel(str)
        label.setAlignment(Qt.AlignCenter)
        label.setMinimumHeight(self.HEIGHT)
        self.h_layout.addWidget(label)
示例#3
0
 def __init__(self, combo, operation, icon=None):
     hbox = QHBoxLayout(combo)
     hbox.setDirection(hbox.RightToLeft)
     combo.setLayout(hbox)
     hbox.addStretch()
     btnOperation = QPushButton(combo)
     btnOperation.setObjectName('combo_button')
     if icon:
         btnOperation.setIcon(QIcon(icon))
         btnOperation.setIconSize(QSize(16, 16))
     hbox.addWidget(btnOperation)
     btnOperation.clicked.connect(operation)
示例#4
0
def get_lbl_hbox(text, otherWidget):  ## GENERATE AN HBOX WITH A LABEL
    lbl = QLabel()
    lbl.setText(text)
    hbox = QHBoxLayout()
    hbox.addStretch()
    hbox.setDirection(1)  ## PLACES TO THE LEFT
    hbox.addWidget(lbl)
    if isinstance(otherWidget, QLineEdit):
        otherWidget.setFixedWidth(100)
    hbox.addWidget(otherWidget)

    return hbox
示例#5
0
 def __init__(self, combo, operation, icon=None):
     hbox = QHBoxLayout(combo)
     hbox.setDirection(hbox.RightToLeft)
     hbox.setSpacing(0)#hbox.setMargin(0)
     combo.setLayout(hbox)
     hbox.addStretch()
     btnOperation = QPushButton(combo)
     btnOperation.setObjectName('combo_button')
     if icon:
         btnOperation.setIcon(QIcon(icon))
     hbox.addWidget(btnOperation)
     btnOperation.clicked.connect(operation)
示例#6
0
    def __init__(self, name: str, parent: QWidget):
        super(Group, self).__init__(parent)
        # self.setFrameShape(QFrame.NoFrame)
        # self.setLineWidth(0)
        self.setContentsMargins(0, 0, 0, 0)
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)

        seperator_layout = QHBoxLayout(self)
        seperator_layout.setContentsMargins(0, 0, 0, 0)
        seperator_layout.setSpacing(0)
        seperator_layout.setDirection(QBoxLayout.LeftToRight)
        self.setLayout(seperator_layout)

        outer_layout = QVBoxLayout()
        outer_layout.setContentsMargins(0, 0, 0, 0)
        outer_layout.setSpacing(0)
        outer_layout.setDirection(QBoxLayout.TopToBottom)
        seperator_layout.addLayout(outer_layout)
        seperator_layout.addWidget(self.create_separator())

        inner_frame = QFrame(self)
        inner_frame.setFrameShape(QFrame.NoFrame)
        inner_frame.setLineWidth(0)
        inner_frame.setContentsMargins(0, 0, 0, 0)
        inner_frame.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)

        self.inner_layout = QHBoxLayout(inner_frame)
        self.inner_layout.setContentsMargins(2, 4, 2, 0)
        self.inner_layout.setSpacing(4)
        self.inner_layout.setDirection(QBoxLayout.LeftToRight)
        inner_frame.setLayout(self.inner_layout)

        outer_layout.addWidget(inner_frame)

        self.group_name = QLabel(name, self)
        self.group_name.setProperty("TTGroupName", QtCore.QVariant(True))
        self.group_name.setSizePolicy(QSizePolicy.Preferred,
                                      QSizePolicy.Maximum)
        self.group_name.setAlignment(QtCore.Qt.AlignHCenter
                                     | QtCore.Qt.AlignVCenter  # type: ignore
                                     )
        self.group_name.adjustSize()
        outer_layout.addWidget(self.group_name)

        parent_tabtoolbar = tabtoolbar.find_tabtoolbar(self)
        if not parent_tabtoolbar:
            raise Exception("Could not find Parent Tabtoolbar")

        group_maxheight = parent_tabtoolbar.group_maxheight
        rowcount = parent_tabtoolbar.rowcount()
        height = group_maxheight + self.group_name.height() + rowcount - 1
        self.setMinimumHeight(height)
        self.setMaximumHeight(height)
示例#7
0
class RigElementView(QWidget):
    WIDTH = 1600
    HEIGHT = 50

    def __init__(self, time_work, name, production_date, capital_date, next_repair, width, height):
        super().__init__()
        self.time_work = time_work
        self.name = name
        self.production_date = production_date
        self.capital_date = capital_date
        self.next_repair = next_repair
        self.width = width
        self.height = height
        self.h_layout = QHBoxLayout()
        self.init_main_layout()
        self.init_gui()
        self.show_labels()

    def init_main_layout(self):
        self.h_layout.setAlignment(Qt.AlignTop)
        self.h_layout.setContentsMargins(0, 0, 0, 0)
        self.h_layout.setSpacing(0)
        self.h_layout.setDirection(QHBoxLayout.LeftToRight)

    def init_gui(self):
        self.setGeometry(0, 0, self.WIDTH, self.HEIGHT)
        self.setLayout(self.h_layout)
        self.setStyleSheet("background-color: #424A52;"
                           "color:#FFFFFF;"
                           "text-align:center;"
                           "border: 1px outset #000000;")

    def show_labels(self):
        self.add_label(str(self.time_work))
        self.add_label(self.name)
        self.add_label(str(self.production_date))
        self.add_label(str(self.capital_date))
        self.add_label(str(self.next_repair))
        self.add_label(str(self.width))
        self.add_label(str(self.height))

    def add_label(self, str):
        label = QLabel(str)
        label.setAlignment(Qt.AlignCenter)
        label.setMinimumHeight(self.HEIGHT)
        self.h_layout.addWidget(label)
示例#8
0
class CropRotationView(QWidget):
    WIDTH = 1600
    HEIGHT = 50

    def __init__(self, length, width, name_seed, amount_seed,
                 amount_collected):
        super().__init__()
        self.length = length
        self.width = width
        self.name_seed = name_seed
        self.amount_seed = amount_seed
        self.amount_collected = amount_collected
        self.h_layout = QHBoxLayout()
        self.init_gui()
        self.init_main_layout()
        self.add_labels()

    def init_main_layout(self):
        self.h_layout.setAlignment(Qt.AlignTop)
        self.h_layout.setContentsMargins(0, 0, 0, 0)
        self.h_layout.setSpacing(0)
        self.h_layout.setDirection(QHBoxLayout.LeftToRight)

    def init_gui(self):
        self.setGeometry(0, 0, self.WIDTH, self.HEIGHT)
        self.setLayout(self.h_layout)
        self.setStyleSheet("background-color: #424A52;"
                           "color:#FFFFFF;"
                           "text-align:center;"
                           "border: 1px outset #000000;")

    def add_labels(self):
        self.add_label(str(self.length))
        self.add_label(str(self.width))
        self.add_label(self.name_seed)
        self.add_label(str(self.amount_seed))
        self.add_label(str(self.amount_collected))

    def add_label(self, str):
        label = QLabel(str)
        label.setAlignment(Qt.AlignCenter)
        label.setMinimumHeight(self.HEIGHT)
        self.h_layout.addWidget(label)
示例#9
0
 def construct_innerframe(self, spacing: int) -> QFrame:
     parent_toolbar = tabtoolbar.find_tabtoolbar(self)
     if not parent_toolbar:
         raise Exception("Could not find Parent Tabtoolbar")
     group_maxheight = parent_toolbar.group_maxheight
     rowcount = parent_toolbar.rowcount()
     frame = QFrame(self)
     frame.setFrameShape(QFrame.NoFrame)
     frame.setLineWidth(0)
     frame.setContentsMargins(0, 0, 0, 0)
     policy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred)
     policy.setHorizontalStretch(0)
     policy.setVerticalStretch(1)
     frame.setSizePolicy(policy)
     frame.setMaximumHeight(group_maxheight / rowcount)
     llayout = QHBoxLayout(frame)
     # layout.setMargin(0)
     llayout.setContentsMargins(0, 0, 0, 0)
     llayout.setSpacing(spacing)
     llayout.setDirection(QBoxLayout.LeftToRight)
     frame.setLayout(llayout)
     spacer = QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding)
     llayout.addItem(spacer)
     return frame
    def __init__(self):
        super().__init__()

        self.setGeometry(500, 500, 520, 500)

        self.setStyleSheet('''
            QPushButton::selected, QPushButton::hover {
                background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                stop: 0 #fafafa, stop: 0.4 #f4f4f4,
                                stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);
                }
            QPushButton {
                border: 2px solid #8f8f91;
                border-radius: 6px;
                background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
                                stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
                }
            
            QListWidget::item {
                text-align:center;
                padding: 5 10px;
            }
        ''')

        vertical_layout = QVBoxLayout()

        self.setLayout(vertical_layout)

        self.colorInput = QLineEdit()
        self.colorInput.setAlignment(QtCore.Qt.AlignCenter)

        # adding reptead color sizes
        hlayout = QHBoxLayout()

        self.size_repeating_btn = QPushButton('اضافة')
        self.size_repeating_btn.clicked.connect(self.add_size_repeater_unit)

        self.repeated_size_input = QLineEdit()
        self.repeated_size_input.setPlaceholderText('المقاس')
        self.repeated_size_input.setAlignment(QtCore.Qt.AlignHCenter)
        self.repeated_size_input.setValidator(QtGui.QIntValidator())

        self.repeated_size_counter = QLineEdit()
        self.repeated_size_counter.setPlaceholderText('العدد')
        self.repeated_size_counter.setAlignment(QtCore.Qt.AlignHCenter)
        self.repeated_size_counter.setValidator(QtGui.QIntValidator())

        hlayout.addWidget(self.size_repeating_btn)
        hlayout.addWidget(self.repeated_size_input)

        hlayout.addWidget(self.repeated_size_counter)
        hlayout.setDirection(QHBoxLayout.RightToLeft)

        self.repeated_sizes_preview = QLineEdit()
        self.repeated_sizes_preview.setEnabled(False)

        self.repeated_sizes = {}
        # end

        vertical_layout.addWidget(QLabel('اللون'))
        vertical_layout.addWidget(self.colorInput)

        vertical_layout.addLayout(hlayout)
        vertical_layout.addWidget(self.repeated_sizes_preview)

        self.sizes_list = QListWidget()

        self.sizes_list.setLayoutDirection(QtCore.Qt.RightToLeft)

        for i in range(1, 60):
            self.sizes_list.addItem(str(i))

        self.sizes_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.sizes_list.setWrapping(True)
        self.sizes_list.setFlow(self.sizes_list.LeftToRight)
        self.sizes_list.setResizeMode(self.sizes_list.Adjust)
        self.selected_color_sizes = []

        self.done_button = QPushButton('تم')
        self.done_button.clicked.connect(self.doneBtnClicked)

        vertical_layout.addWidget(self.sizes_list)

        vertical_layout.addWidget(self.done_button)
示例#11
0
class LineEdit(QLineEdit):
    inactiveText  = QtDynamicProperty('inactiveText',  unicode)
    widgetSpacing = QtDynamicProperty('widgetSpacing', int)

    def __init__(self, parent=None, contents=u""):
        super(LineEdit, self).__init__(contents, parent)
        box_direction = QBoxLayout.RightToLeft if self.isRightToLeft() else QBoxLayout.LeftToRight
        self.inactiveText = u""
        self.left_widget = SideWidget(self)
        self.left_widget.resize(0, 0)
        self.left_layout = QHBoxLayout(self.left_widget)
        self.left_layout.setContentsMargins(0, 0, 0, 0)
        self.left_layout.setDirection(box_direction)
        self.left_layout.setSizeConstraint(QLayout.SetFixedSize)
        self.right_widget = SideWidget(self)
        self.right_widget.resize(0, 0)
        self.right_layout = QHBoxLayout(self.right_widget)
        self.right_layout.setContentsMargins(0, 0, 0, 0)
        self.right_layout.setDirection(box_direction)
        self.right_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum))
        self.widgetSpacing = 2
        self.left_widget.sizeHintChanged.connect(self._update_text_margins)
        self.right_widget.sizeHintChanged.connect(self._update_text_margins)

    @property
    def left_margin(self):
        return self.left_widget.sizeHint().width() + 2*self.left_layout.spacing()

    @property
    def right_margin(self):
        return self.right_widget.sizeHint().width() + 2*self.right_layout.spacing()

    def _update_text_margins(self):
        self.setTextMargins(self.left_margin, 0, self.right_margin, 0)
        self._update_side_widget_locations()

    def _update_side_widget_locations(self):
        option = QStyleOptionFrame()
        self.initStyleOption(option)
        spacing = self.right_layout.spacing()
        text_rect = self.style().subElementRect(QStyle.SE_LineEditContents, option, self)
        text_rect.adjust(spacing, 0, -spacing, 0)
        mid_height = text_rect.center().y() + 1 - (text_rect.height() % 2)  # need -1 correction for odd heights -Dan
        if self.left_layout.count() > 0:
            left_height = mid_height - self.left_widget.height()/2
            left_width = self.left_widget.width()
            if left_width == 0:
                left_height = mid_height - self.left_widget.sizeHint().height()/2
            self.left_widget.move(text_rect.x(), left_height)
        text_rect.setX(self.left_margin)
        text_rect.setY(mid_height - self.right_widget.sizeHint().height()/2.0)
        text_rect.setHeight(self.right_widget.sizeHint().height())
        self.right_widget.setGeometry(text_rect)

    def event(self, event):
        event_type = event.type()
        if event_type == QEvent.LayoutDirectionChange:
            box_direction = QBoxLayout.RightToLeft if self.isRightToLeft() else QBoxLayout.LeftToRight
            self.left_layout.setDirection(box_direction)
            self.right_layout.setDirection(box_direction)
        elif event_type == QEvent.DynamicPropertyChange:
            property_name = event.propertyName()
            if property_name == 'widgetSpacing':
                self.left_layout.setSpacing(self.widgetSpacing)
                self.right_layout.setSpacing(self.widgetSpacing)
                self._update_text_margins()
            elif property_name == 'inactiveText':
                self.update()
        return QLineEdit.event(self, event)

    def resizeEvent(self, event):
        self._update_side_widget_locations()
        QLineEdit.resizeEvent(self, event)

    def paintEvent(self, event):
        QLineEdit.paintEvent(self, event)
        if not self.hasFocus() and not self.text() and self.inactiveText:
            options = QStyleOptionFrame()
            self.initStyleOption(options)
            text_rect = self.style().subElementRect(QStyle.SE_LineEditContents, options, self)
            text_rect.adjust(self.left_margin+2, 0, -self.right_margin, 0)
            painter = QPainter(self)
            painter.setPen(self.palette().brush(QPalette.Disabled, QPalette.Text).color())
            painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter, self.inactiveText)

    def addHeadWidget(self, widget):
        if self.isRightToLeft():
            self.right_layout.insertWidget(1, widget)
        else:
            self.left_layout.addWidget(widget)

    def addTailWidget(self, widget):
        if self.isRightToLeft():
            self.left_layout.addWidget(widget)
        else:
            self.right_layout.insertWidget(1, widget)

    def removeWidget(self, widget):
        self.left_layout.removeWidget(widget)
        self.right_layout.removeWidget(widget)
        widget.hide()
示例#12
0
class E5LineEdit(QLineEdit):
    """
    Class implementing a line edit widget showing some inactive text.
    """
    LeftSide = 0
    RightSide = 1

    def __init__(self, parent=None, inactiveText=""):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        @param inactiveText text to be shown on inactivity (string)
        """
        super(E5LineEdit, self).__init__(parent)

        self.setMinimumHeight(22)

        self.setPlaceholderText(inactiveText)

        self.__mainLayout = QHBoxLayout(self)
        self.__mainLayout.setContentsMargins(0, 0, 0, 0)
        self.__mainLayout.setSpacing(0)

        self.__leftMargin = 0
        self.__leftWidget = E5LineEditSideWidget(self)
        self.__leftWidget.resize(0, 0)
        self.__leftLayout = QHBoxLayout(self.__leftWidget)
        self.__leftLayout.setContentsMargins(0, 0, 2, 0)
        if QApplication.isRightToLeft():
            self.__leftLayout.setDirection(QBoxLayout.RightToLeft)
        else:
            self.__leftLayout.setDirection(QBoxLayout.LeftToRight)
        self.__leftLayout.setSizeConstraint(QLayout.SetFixedSize)

        self.__rightWidget = E5LineEditSideWidget(self)
        self.__rightWidget.resize(0, 0)
        self.__rightLayout = QHBoxLayout(self.__rightWidget)
        self.__rightLayout.setContentsMargins(0, 0, 2, 0)
        if self.isRightToLeft():
            self.__rightLayout.setDirection(QBoxLayout.RightToLeft)
        else:
            self.__rightLayout.setDirection(QBoxLayout.LeftToRight)

        horizontalSpacer = QSpacerItem(0, 0, QSizePolicy.Expanding,
                                       QSizePolicy.Minimum)
        self.__mainLayout.addWidget(self.__leftWidget, 0,
                                    Qt.AlignVCenter | Qt.AlignLeft)
        self.__mainLayout.addItem(horizontalSpacer)
        self.__mainLayout.addWidget(self.__rightWidget, 0,
                                    Qt.AlignVCenter | Qt.AlignRight)
        if self.isRightToLeft():
            self.__mainLayout.setDirection(QBoxLayout.RightToLeft)
        else:
            self.__mainLayout.setDirection(QBoxLayout.LeftToRight)

        self.setWidgetSpacing(3)
        self.__leftWidget.sizeHintChanged.connect(self._updateTextMargins)
        self.__rightWidget.sizeHintChanged.connect(self._updateTextMargins)

    def setLeftMargin(self, margin):
        """
        Public method to set the left margin.
        
        @param margin left margin in pixel (integer)
        """
        self.__leftMargin = margin

    def leftMargin(self):
        """
        Public method to get the size of the left margin.
        
        @return left margin in pixel (integer)
        """
        return self.__leftMargin

    def event(self, evt):
        """
        Public method to handle events.
        
        @param evt reference to the event (QEvent)
        @return flag indicating, whether the event was recognized (boolean)
        """
        if evt.type() == QEvent.LayoutDirectionChange:
            if self.isRightToLeft():
                self.__mainLayout.setDirection(QBoxLayout.RightToLeft)
                self.__leftLayout.setDirection(QBoxLayout.RightToLeft)
                self.__rightLayout.setDirection(QBoxLayout.RightToLeft)
            else:
                self.__mainLayout.setDirection(QBoxLayout.LeftToRight)
                self.__leftLayout.setDirection(QBoxLayout.LeftToRight)
                self.__rightLayout.setDirection(QBoxLayout.LeftToRight)
        return QLineEdit.event(self, evt)

    def paintEvent(self, evt):
        """
        Protected method handling a paint event.
        
        @param evt reference to the paint event (QPaintEvent)
        """
        super(E5LineEdit, self).paintEvent(evt)

    def _updateTextMargins(self):
        """
        Protected slot to update the text margins.
        """
        if self.__leftMargin == 0:
            left = self.__leftWidget.sizeHint().width()
        else:
            left = self.__leftMargin
        right = self.__rightWidget.sizeHint().width()
        top = 0
        bottom = 0
        self.setTextMargins(left, top, right, bottom)

    def addWidget(self, widget, position):
        """
        Public method to add a widget to a side.
        
        @param widget reference to the widget to add (QWidget)
        @param position position to add to (E5LineEdit.LeftSide,
            E5LineEdit.RightSide)
        """
        if widget is None:
            return

        if self.isRightToLeft():
            if position == self.LeftSide:
                position = self.RightSide
            else:
                position = self.LeftSide
        if position == self.LeftSide:
            self.__leftLayout.addWidget(widget)
        else:
            self.__rightLayout.insertWidget(1, widget)

    def removeWidget(self, widget):
        """
        Public method to remove a widget from a side.
        
        @param widget reference to the widget to remove (QWidget)
        """
        if widget is None:
            return

        self.__leftLayout.removeWidget(widget)
        self.__rightLayout.removeWidget(widget)
        widget.hide()

    def widgetSpacing(self):
        """
        Public method to get the side widget spacing.
        
        @return side widget spacing (integer)
        """
        return self.__leftLayout.spacing()

    def setWidgetSpacing(self, spacing):
        """
        Public method to set the side widget spacing.
        
        @param spacing side widget spacing (integer)
        """
        self.__leftLayout.setSpacing(spacing)
        self.__rightLayout.setSpacing(spacing)
        self._updateTextMargins()

    def textMargin(self, position):
        """
        Public method to get the text margin for a side.
        
        @param position side to get margin for (E5LineEdit.LeftSide,
            E5LineEdit.RightSide)
        @return text margin (integer)
        """
        spacing = self.__rightLayout.spacing()
        w = 0
        if position == self.LeftSide:
            w = self.__leftWidget.sizeHint().width()
        else:
            w = self.__rightWidget.sizeHint().width()
        if w == 0:
            return 0
        return w + spacing * 2

    def inactiveText(self):
        """
        Public method to get the inactive text.
        
        @return inactive text (string)
        """
        if qVersionTuple() < (4, 7, 0):
            return self.__inactiveText
        else:
            return self.placeholderText()

    def setInactiveText(self, inactiveText):
        """
        Public method to set the inactive text.
        
        @param inactiveText text to be shown on inactivity (string)
        """

        self.setPlaceholderText(inactiveText)
示例#13
0
class CEditorContent ( QWidget ):

	def __init__ ( self, editor ):
		super ().__init__ ()
		self.editor = editor
		self.toolBarAreaManager = CToolBarAreaManager ( editor )

		self.mainLayout = QVBoxLayout ()
		self.mainLayout.setContentsMargins ( 0, 0, 0, 0 )
		self.mainLayout.setSpacing ( 0 )
		self.contentLayout = QHBoxLayout ()
		self.contentLayout.setContentsMargins ( 0, 0, 0, 0 )
		self.contentLayout.setSpacing ( 0 )

		self.content = QWidget ()
		self.content.setSizePolicy ( QSizePolicy.Expanding, QSizePolicy.Expanding )

		self.editor.signalAdaptiveLayoutChanged.connect ( self.onAdaptiveLayoutChanged )

		self.setLayout ( self.mainLayout )

	def initialize ( self ):
		self.toolBarAreaManager.initialize ()

		self.mainLayout.addWidget ( self.toolBarAreaManager.getWidget ( CToolBarAreaManagerArea.Top ) )
		self.mainLayout.addLayout ( self.contentLayout )
		self.mainLayout.addWidget ( self.toolBarAreaManager.getWidget ( CToolBarAreaManagerArea.Bottom ) )

		self.contentLayout.addWidget ( self.toolBarAreaManager.getWidget ( CToolBarAreaManagerArea.Left ) )
		self.contentLayout.addWidget ( self.content )
		self.contentLayout.addWidget ( self.toolBarAreaManager.getWidget ( CToolBarAreaManagerArea.Right ) )

	def getContent ( self ):
		return self.content

	def setContent ( self, content ):
		if isinstance ( content, QWidget ):
			self.content.setSizePolicy ( QSizePolicy.Expanding, QSizePolicy.Expanding )
			self.contentLayout.replaceWidget ( self.content, content )
			self.content.setObjectName ( "CEditorContent" )
			self.content.deleteLater ()
			self.content = content
		elif isinstance ( content, QLayout ):
			contentLayout = content
			content = QWidget ()
			content.setSizePolicy ( QSizePolicy.Expanding, QSizePolicy.Expanding )
			content.setLayout ( contentLayout )
			content.setObjectName ( "CEditorContent" )
			contentLayout.setContentsMargins ( 0, 0, 0, 0 )
			contentLayout.setSpacing ( 0 )

			self.contentLayout.replaceWidget ( self.content, content )
			self.content.deleteLater ()
			self.content = content

	def customizeToolBar ( self ):
		# TODO: CToolBarCustomizeDialog
		return self.content

	def toggleToolBarLock ( self ):
		return self.toolBarAreaManager.toggleLock ()

	def addExpandingSpacer ( self ):
		return self.toolBarAreaManager.addExpandingSpacer ()

	def addFixedSpacer ( self ):
		return self.toolBarAreaManager.addFixedSpacer ()

	def getMinimumSizeForOrientation ( self, orientation ) -> QSize:
		isDefaultOrientation = orientation == self.editor.GetDefaultOrientation ()
		contentMinSize = self.content.layout ().minimumSize ()

		topArea = self.toolBarAreaManager.getWidget ( CToolBarAreaManagerArea.Top )
		bottomArea = self.toolBarAreaManager.getWidget ( CToolBarAreaManagerArea.Bottom )
		leftArea = self.toolBarAreaManager.getWidget ( CToolBarAreaManagerArea.Left )
		rightArea = self.toolBarAreaManager.getWidget ( CToolBarAreaManagerArea.Right )

		result = QSize ( 0, 0 )
		if isDefaultOrientation:
			# Take width from left and right areas if we're switching to the editor's default orientation
			result.setWidth ( result.width () + leftArea.getLargestItemMinimumSize ().width () )
			result.setWidth ( result.width () + rightArea.getLargestItemMinimumSize ().width () )

			# Use top and bottom area to calculate min height
			result.setHeight ( result.height () + leftArea.getLargestItemMinimumSize ().height () )
			result.setHeight ( result.height () + rightArea.getLargestItemMinimumSize ().height () )

			# Add content min size
			result += contentMinSize

			# Take the area layout size hints into account. Expand the current result with the toolbar area layout's size hint.
			# We use size hint rather than minimum size since toolbar area item's size policy is set to preferred.
			result = result.expandedTo ( QSize ( topArea.layout ().sizeHint ().height (), leftArea.layout ().sizeHint ().width () ) )
			result = result.expandedTo ( QSize ( bottomArea.layout ().sizeHint ().height (), rightArea.layout ().sizeHint ().width () ) )
		else:
			# If we're not switching to the default orientation, then we need to use the top and bottom toolbar areas' width
			# since these areas will be placed at the left and right of the editor content in this case of adaptive layouts
			result.setWidth ( result.width () + topArea.getLargestItemMinimumSize ().width () )
			result.setWidth ( result.width () + bottomArea.getLargestItemMinimumSize ().width () )

			# We must also flip where we get toolbar area min height from
			result.setHeight ( result.height () + leftArea.getLargestItemMinimumSize ().height () )
			result.setHeight ( result.height () + rightArea.getLargestItemMinimumSize ().height () )

			# Add flipped content min size
			result += QSize ( contentMinSize.height (), contentMinSize.width () )

			result = result.expandedTo ( QSize ( leftArea.layout ().sizeHint ().height (), topArea.layout ().sizeHint ().width () ) )
			result = result.expandedTo ( QSize ( rightArea.layout ().sizeHint ().height (), bottomArea.layout ().sizeHint ().width () ) )

		return result


	def onAdaptiveLayoutChanged ( self ):
		isDefaultOrientation = self.editor.GetOrientation () == self.editor.GetDefaultOrientation ()
		self.mainLayout.setDirection ( QBoxLayout.TopToBottom if isDefaultOrientation else QBoxLayout.LeftToRight )
		self.contentLayout.setDirection ( QBoxLayout.LeftToRight if isDefaultOrientation else QBoxLayout.TopToBottom )

	def paintEvent ( self, event ):
		styleOption = QStyleOption ()
		styleOption.initFrom ( self )
		painter = QPainter ( self )
		self.style ().drawPrimitive ( QStyle.PE_Widget, styleOption, painter, self )
示例#14
0
文件: Scroll.py 项目: CountryTk/WMS
class ScrollArea(QWidget):
    def __init__(self, parent):
        super().__init__(parent)

        self.parent = parent

        self.layout_main = QVBoxLayout()
        self.search_layout = QHBoxLayout()
        self.search_layout.addStretch()
        self.search_layout.setDirection(QBoxLayout.RightToLeft)
        self.search_layout.setSpacing(0)
        self.search_layout.setContentsMargins(0, 0, 0, 0)

        self.search_bar = QLineEdit()
        self.search_bar.setMaximumWidth(250)
        self.search_bar.setPlaceholderText("Kirjuta otsingusona siia")

        self.search_button = QPushButton("Otsi")
        self.search_button.setMaximumWidth(100)
        self.edasi = QPushButton("Järgmine")
        self.edasi.setMaximumWidth(100)
        self.edasi.clicked.connect(self.jargmine)
        self.search_button.clicked.connect(self.search)
        self.index = 0
        self.search_layout.addWidget(self.edasi)
        self.search_layout.addWidget(self.search_button)
        self.search_layout.addWidget(self.search_bar)
        # self.layout_main.addLayout(self.search_layout)

        self.value_tuple = ()
        self.scroll_area = QScrollArea()
        self.scroll_area.setWidgetResizable(True)
        self.container_widget = QWidget()

        self.scroll_area.setWidget(self.container_widget)
        self.container_layout = QVBoxLayout(self.container_widget)
        self.container_layout.setContentsMargins(0, 30, 0, 30)

        self.layout_main.addWidget(self.scroll_area)
        self.setLayout(self.layout_main)

    def find_all(self, a_str, sub):
        start = 0
        while True:
            start = a_str.find(sub, start)
            if start == -1:
                return
            yield start
            start += len(sub)  # use start += 1 to find overlapping matches

    def search(self):

        text = self.search_bar.text()
        self.lmao_list = []
        a = 0
        # print(self.container_layout.itemAt(0).widget.geometry())
        self.margin = self.scroll_area.verticalScrollBar().maximum() // 33
        self.indexes = []
        li = list(set(self.parent.names))
        # li.sort()
        for l in li:

            result = list(self.find_all(l, text))

            self.lmao_list.append(result)

        for index, a in enumerate(self.lmao_list):
            if a != []:
                self.indexes.append(index)

    def jargmine(self):
        try:
            # self.scroll_area.verticalScrollBar().setValue(self.margin * self.indexes[self.index])
            x = self.parent.kohalik.container_layout.itemAt(
                self.indexes[self.index + 1]).widget()
            print(x.toode)
            x.toode = "<b>{}</b>".format(x.toode)
            from widgets.Item import Item
            oh = Item(x.tootja, x.toode, x.jalanumber, x.kogus, x.hind, False)
            print(oh.toode)
            self.parent.kohalik.container_layout.removeWidget(
                self.parent.kohalik.container_layout.itemAt(
                    self.indexes[self.index + 1]).widget())
            self.parent.kohalik.container_layout.insertWidget(
                self.indexes[self.index + 1], oh)
        except IndexError:
            self.index = 0
        self.index += 1
示例#15
0
class TabToolbar(QToolBar):
    """[summary]

    Args:
        _TabToolbar ([type]): [description]

    Returns:
        [type]: [description]
    """

    Minimized = QtCore.pyqtSignal()
    Maximized = QtCore.pyqtSignal()
    SpecialTabClicked = QtCore.pyqtSignal()
    StyleChanged = QtCore.pyqtSignal()

    def __init__(self,
                 parent: QWidget = None,
                 group_maxheight: int = 75,
                 group_rowcount: int = 3):
        super(TabToolbar, self).__init__(parent)
        style.register_default_styles()
        self.group_rowcount = group_rowcount
        self.group_maxheight = group_maxheight
        self.has_specialtab = False
        self.current_index = 0
        self.ignore_styleevent = False
        self.is_shown = True
        self._is_minimized = False
        self.maxheight = QtWidgets.QWIDGETSIZE_MAX
        self._style = style.StyleParams()
        self.setObjectName("TabToolbar")

        # self.tempShowTimer = QtCore.QTimer()
        # self.tempShowTimer.setSingleShot(True)
        # self.tempShowTimer.setInterval(QApplication.doubleClickInterval())

        self.setProperty("TabToolbar", QtCore.QVariant(True))
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.layout().setSpacing(0)
        self.setContentsMargins(0, 0, 0, 0)
        self.setFloatable(False)
        self.setMovable(False)
        self.setAllowedAreas(QtCore.Qt.TopToolBarArea)
        self.tabBar = QTabWidget(self)

        self.tabBar.setProperty("TTWidget", QtCore.QVariant(True))
        self.tabBar.tabBar().setProperty("TTTab", QtCore.QVariant(True))
        self.tabBarHandle = self.addWidget(self.tabBar)
        self.tabBar.setUsesScrollButtons(True)

        self.cornerActions = QFrame(self)
        self.cornerActions.setFrameShape(QFrame.NoFrame)
        self.cornerActions.setLineWidth(0)
        self.cornerActions.setContentsMargins(0, 0, 0, 0)
        self.cornerActions.setSizePolicy(QSizePolicy.Preferred,
                                         QSizePolicy.Minimum)
        self.cornerLayout = QHBoxLayout(self.cornerActions)

        self.cornerLayout.setContentsMargins(0, 0, 0, 0)
        self.cornerLayout.setSpacing(0)
        self.cornerLayout.setDirection(QBoxLayout.LeftToRight)
        self.cornerActions.setLayout(self.cornerLayout)

        self.hideAction = QAction(self)
        self.hideAction.setCheckable(True)
        self.hideAction.setText("▲")
        self.hideButton = QToolButton(self.tabBar)
        self.hideButton.setProperty("TTHide", QtCore.QVariant(True))
        self.hideButton.setToolButtonStyle(QtCore.Qt.ToolButtonTextOnly)
        self.hideButton.setDefaultAction(self.hideAction)
        self.hideButton.setAutoRaise(True)
        self.hideButton.setSizePolicy(QSizePolicy.Expanding,
                                      QSizePolicy.Expanding)

        self.hideAction.triggered.connect(self._hideaction)
        self.tabBar.tabBarDoubleClicked.connect(self.hideAction.trigger)
        self.tabBar.tabBarClicked.connect(self.current_tabchanged)
        self.tabBar.currentChanged.connect(self.focus_changed)
        self.cornerLayout.addWidget(self.hideButton)
        self.tabBar.setCornerWidget(self.cornerActions)
        self.set_style(style.get_defaultstyle())

    def _hideaction(self):
        # self.tempShowTimer.start()
        self._is_minimized = self.hideAction.isChecked()
        self.hideAction.setText("▼" if self._is_minimized else "▲")
        self.hide_at(self.tabBar.currentIndex())
        if self._is_minimized:
            self.Minimized.emit()
        else:
            self.Maximized.emit()

    def event(self, event: QtCore.QEvent):
        if event.type(
        ) == QtCore.QEvent.StyleChange and not self.ignore_styleevent:
            # TODO: Validatre if we need a timer
            stylename = (self._style.objectName()
                         if self._style else style.get_defaultstyle())
            self.set_style(stylename)
        return super(TabToolbar, self).event(event)

    def focus_changed(self, old: QWidget = None, now: QWidget = None):
        if now and now != self:
            if self.isMinimized() and self.is_shown:
                parent = now
                while parent:
                    parent = parent.parent()
                    if parent == self:
                        return
                self.hide_at(self.current_index)

    def rowcount(self):
        return self.group_rowcount

    def group_maxheight(self):
        return self.group_maxheight * style.get_scalefactor(self)

    def set_style(self, stylename: str):
        self.ignore_styleevent = True
        self._style = style.create_style(stylename)
        stylesheet = style.get_stylesheet(self._style)
        self.setStyleSheet(stylesheet)
        self.ignore_styleevent = False
        self.StyleChanged.emit()

    def get_style(self) -> str:
        if self._style:
            return self._style.objectName()
        return ""

    def add_corneraction(self, action: QAction):
        action_button = QToolButton(self.tabBar)
        action_button.setProperty("TTInternal", QtCore.QVariant(True))
        action_button.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        action_button.setDefaultAction(action)
        action_button.setAutoRaise(True)
        action_button.setSizePolicy(QSizePolicy.Expanding,
                                    QSizePolicy.Expanding)
        self.cornerActions.layout().addWidget(action_button)

    def set_specialtabenabled(self, enabled: bool):
        self.has_specialtab = enabled
        self.tabBar.tabBar().setProperty("TTSpecial", QtCore.QVariant(enabled))
        if enabled and self.tabBar.count() > 0:
            self.tabBar.setCurrentIndex(1)

    def hide_action(self) -> QAction:
        return self.hideAction

    def tab_clicked(self, index: int):
        if self.tempShowTimer.isActive() or (index == 0
                                             and self.has_specialtab):
            return
        if self._is_minimized:
            if self.is_shown and index != self.current_index:
                return
            self._is_minimized = self.is_shown
            self.hide_at(index)
            self._is_minimized = True

    def current_tabchanged(self, index: int):
        QtCore.QSignalBlocker(self.tabBar)
        if index == 0 and self.has_specialtab:
            self.tabBar.setCurrentIndex(self.current_index)
            self.SpecialTabClicked.emit()
        else:
            self.current_index = index

    @property
    def current_tab(self) -> int:
        return self.current_index

    def set_currenttab(self, index: int):
        self.tabBar.setCurrentIndex(index)

    def hide_at(self, index: int):
        if self._is_minimized:
            minheight = self.tabBar.tabBar().height() + 2
            self.tabBar.setMaximumHeight(minheight)
            self.tabBar.setMinimumHeight(minheight)
            self.setMaximumHeight(minheight)
            self.setMinimumHeight(minheight)
            self.is_shown = False
        else:
            self.tabBar.setCurrentIndex(index)
            if not self.is_shown:
                self.tabBar.setMaximumHeight(self.maxheight)
                self.tabBar.setMinimumHeight(self.maxheight)
                self.setMaximumHeight(self.maxheight)
                self.setMinimumHeight(self.maxheight)
                self.tabBar.adjustSize()
            self.setFocus()
            self.is_shown = True

    def hide_tab(self, index: int):
        page = self.sender()
        QtCore.QSignalBlocker(page)
        for i in range(self.tabBar.count()):
            if self.tabBar.widget(i) == page:
                self.tabBar.removeTab(i)
                return
        self.current_index = self.tabBar.currentIndex()

    @QtCore.pyqtSlot(int)
    def _adjustverticalsize(self, vsize: int):
        self.maxheight = vsize + self.tabBar.tabBar().height() + 6
        self.setMaximumHeight(self.maxheight)
        self.setMinimumHeight(self.maxheight)

    def adjust_verticalsize(self, vsize: int):
        QtCore.QTimer.singleShot(0, lambda: self._adjustverticalsize(vsize)
                                 )  # type: ignore[attr-defined]
        # self._AdjustVerticleSize(vSize)

    def show_tab(self, index: int):
        tab_page = self.sender()
        QtCore.QSignalBlocker(tab_page)
        self.tabBar.insertTab(index, tab_page, tab_page.objectName())
        self.current_index = self.tabBar.currentIndex()

    def add_page(self, page_name: str) -> page.Page:
        tab_page = page.Page(self.tabBar.count(), page_name)
        QtCore.QSignalBlocker(tab_page)
        tab_page.Hiding.connect(self.hide_tab)
        tab_page.Showing.connect(self.show_tab)
        self.tabBar.addTab(tab_page, page_name)
        return tab_page
示例#16
0
class Layouter:
    """This class solves itself placing widget
    similarly as tkinter geometry manager does."""
    def __init__(self, kind=None):
        self.kind = None
        self.layout = None
        self.top = None
        self.bottom = None
        self.left = None
        self.right = None
        self.widget_found = False  # Ending recursion faster...

        self.inited = False

        if kind is None:
            return

        self._manual_init(kind)

    def _manual_init(self, kind, other_args={}):
        self.kind = kind

        if kind == PACK:
            self._init_pack(other_args)
        elif kind == GRID:
            self._init_grid(other_args)
        # Place omited.

        self.inited = True

    def _init_pack(self, other_args={}):
        """
        If pack strategy is used, initiation differs according to child widgets
        packed side. If child is packed on left side, QHBoxLayout (horizontal)
        is initiated and gradually filled with:
        1) QHBoxLayout (for left packed child),
        2) QHBoxLayout with QVBoxLayout (for top packed child) and QVBoxLayout
        with reverse order (for bottom packed child)
        3) QHBoxLayout with reverse order (for right packed child)
        as for three columns with middle column having top and bottom part.

        If child is packed on any other side then left, QVBoxLayout (vertical)
        is initiated and gradually filled with:
        1) QVBoxLayout (for top packed child),
        2) QVBoxLayout with QHBoxLayout (for left packed child) and QHBoxLayout
        with reverse order (for right packed child),
        3) QVBoxLayout with reverse order (for bottom packed child),
        as for three rows with middle row having left and right part.

        These two strategies for packing proved as most similar solution
        to the Packer from Tkinter and also the best looking one since
        packing first widget as bottom or right did not really made sense.
        """

        side = other_args.get('-side', TOP)

        # Init vertical layouts
        self.top = QVBoxLayout()
        self.bottom = QVBoxLayout()
        self.bottom.setDirection(QBoxLayout.BottomToTop)

        # Init horizontal layouts
        self.left = QHBoxLayout()
        self.right = QHBoxLayout()
        self.right.setDirection(QBoxLayout.RightToLeft)

        if side == LEFT:
            # Init top level layout
            self.layout = QHBoxLayout()

            # Init middle column layout and add vertical layouts
            self.column_layout = QHBoxLayout()
            self.column_layout.addLayout(self.top)
            self.column_layout.addLayout(self.bottom)

            # Compose layout
            self.layout.addLayout(self.left)
            self.layout.addLayout(self.column_layout)
            self.layout.addLayout(self.right)
        else:  # Supports only left and top - Gonna say this means top.
            # Init top level layout
            self.layout = QVBoxLayout()

            # Init middle row layout and add horizontal layouts
            self.row_layout = QHBoxLayout()
            self.row_layout.addLayout(self.left)
            self.row_layout.addLayout(self.right)

            # Compose layout
            self.layout.addLayout(self.top)
            self.layout.addLayout(self.row_layout)
            self.layout.addLayout(self.bottom)

    def _init_grid(self, other_args={}):
        """Initiates QGridLayout."""
        self.layout = QGridLayout()

    def _get_layout_for_side(self, side=TOP):
        side_switch = {
            TOP: self.top,
            LEFT: self.left,
            RIGHT: self.right,
        }

        return side_switch.get(side, self.bottom)

    def pack_widget(self, widget, other_args={}):
        side = other_args.get('-side', "top")
        # TODO: Other args

        self._get_layout_for_side(side).addWidget(widget)

    def grid_find_widget(self, layout, widget):
        if self.widget_found:
            return None, -1

        # There is no better way then recursion?!
        idx = layout.indexOf(widget)
        if idx == -1:
            for children in layout.children():
                self.grid_find_widget(self, widget, children)

            return None, -1

        return layout, idx

    def grid_widget(self, widget, other_args):
        row, column = 0, 0
        rows, cols = 1, 1

        layout, found_index = self.grid_find_widget(self.layout, widget)
        if found_index != -1:
            row, column, rows, cols = layout.getItemPosition(found_index)

        row_new = other_args.get('-row', row)
        column_new = other_args.get('-column', column)
        rows_new = other_args.get('-rowspan', rows)
        columns_new = other_args.get('-columnspan', cols)

        if '-sticky' not in other_args and found_index != -1:
            self.layout.addWidget(widget, row_new, column_new, rows_new,
                                  columns_new)
        else:
            sticky = translate_align(other_args.get('-sticky', ''))
            self.layout.addWidget(widget,
                                  row_new,
                                  column_new,
                                  rows_new,
                                  columns_new,
                                  alignment=sticky)

        return

    def add_widget(self, widget, kind="pack", other_args={}):
        """Adds widget to the layout, checks layout kind
        and accepts other arguments as "-side" for pack
        or "-columnspan" for grid."""

        if not self.inited:
            self._manual_init(kind, other_args)

        if kind != self.kind:
            raise MixedLayouts

        if kind == PACK:
            self.pack_widget(widget, other_args)
        elif kind == GRID:
            self.grid_widget(widget, other_args)
示例#17
0
class MenuView(QWidget):
    HEIGHT = 1080
    WIDTH = 1600
    isLogin = True
    name = "kostya05983"

    stacked_widgets = None

    def __init__(self):
        super().__init__()
        self.h_layout = QHBoxLayout(self)
        self.controller = MenuController(self)
        self.init_gui()
        self.setLayout(self.h_layout)
        self.h_layout.setAlignment(Qt.AlignLeft)
        self.init_buttons()
        self.left_menu_layout = None

    def init_gui(self):
        self.h_layout.setDirection(QHBoxLayout.LeftToRight)
        self.h_layout.setContentsMargins(0, 0, 0, 0)
        self.setGeometry(0, 0, self.WIDTH, self.HEIGHT)
        widget = QWidget()
        widget.setFixedSize(QSize(self.WIDTH, self.HEIGHT))
        widget.setStyleSheet("background-color: #000000")
        self.add_block()

    def add_block(self):
        widget = QWidget()
        widget.setBaseSize(QSize(600, self.HEIGHT))
        widget.setMinimumWidth(400)
        v_layout = QVBoxLayout()
        v_layout.setDirection(QVBoxLayout.TopToBottom)
        widget.setLayout(v_layout)
        widget.setStyleSheet("background-color: #424A52;")
        self.h_layout.addWidget(widget)
        self.left_menu_layout = v_layout
        self.left_menu_layout.setSpacing(0)
        self.left_menu_layout.setContentsMargins(0, 0, 0, 0)
        self.left_menu_layout.setAlignment(Qt.AlignTop)

    def init_buttons(self):
        if self.isLogin:
            self.init_header_login()
            self.init_product_button()
            self.init_plan_button()
            self.init_graph_button()
            self.init_deal_button()
            self.init_technique_button()
            self.init_rig_button()
        else:
            self.init_product_button()

    def init_header_login(self):
        label = QLabel("Вы вошли как " + self.name)
        label.setStyleSheet("color: #FFFFFF;"
                            "font-size: 20px;"
                            "margin-left:10px;"
                            "margin-top:20px")
        self.left_menu_layout.addWidget(label, 0, Qt.AlignTop)

    def init_product_button(self):
        qwidget = QWidget()
        layout = QHBoxLayout()
        qwidget.setLayout(layout)

        qwidget.setStyleSheet("margin-left:15px")

        wheat_icon = QIcon(os.getcwd() + "/icons/wheat.png")
        wheat_button = QPushButton(wheat_icon, "")
        wheat_button.setIconSize(QSize(40, 40))
        wheat_button.setFlat(True)

        label = QLabel("Продукты")
        label.setStyleSheet("color:#FFFFFF;"
                            "font-size:18px;"
                            "margin-left:5px")
        layout.addWidget(wheat_button)
        layout.addWidget(label)
        self.left_menu_layout.addWidget(qwidget, 0, Qt.AlignLeft)
        qwidget.mouseReleaseEvent = self.controller.show_shop_view

    def init_plan_button(self):
        qwidget = QWidget()
        layout = QHBoxLayout()
        qwidget.setLayout(layout)

        qwidget.setStyleSheet("margin-left:15px")

        plan_icon = QIcon(os.getcwd() + "/icons/plan.png")
        plan_button = QPushButton(plan_icon, "")
        plan_button.setIconSize(QSize(30, 30))
        plan_button.setFlat(True)

        label = QLabel("План Севооборота")
        label.setStyleSheet("color: #FFFFFF;"
                            "font-size:18px;"
                            "margin-left:14px")
        layout.addWidget(plan_button)
        layout.addWidget(label)
        self.left_menu_layout.addWidget(qwidget, 0, Qt.AlignLeft)
        qwidget.mouseReleaseEvent = self.controller.show_plan_crop_rotation_view

    def init_graph_button(self):
        qwidget = QWidget()
        layout = QHBoxLayout()
        qwidget.setLayout(layout)
        qwidget.setStyleSheet("margin-left:15px")

        graph_icon = QIcon(os.getcwd() + "/icons/graph.png")
        graph_button = QPushButton(graph_icon, "")
        graph_button.setIconSize(QSize(30, 30))
        graph_button.setFlat(True)

        label = QLabel("График урожайности")
        label.setStyleSheet("color:#FFFFFF;"
                            "font-size:18px;"
                            "margin-left:15px")
        layout.addWidget(graph_button)
        layout.addWidget(label)
        self.left_menu_layout.addWidget(qwidget, 0, Qt.AlignLeft)
        qwidget.mouseReleaseEvent = self.controller.show_graph_yield_view

    def init_deal_button(self):
        qwidget = QWidget()
        layout = QHBoxLayout()
        qwidget.setLayout(layout)
        qwidget.setStyleSheet("margin-left:15px")

        deal_icon = QIcon(os.getcwd() + "/icons/document.png")
        deal_button = QPushButton(deal_icon, "")
        deal_button.setIconSize(QSize(40, 40))
        deal_button.setFlat(True)

        label = QLabel("Договор на поставку")
        label.setStyleSheet("color:#FFFFFF;"
                            "font-size: 18px;"
                            "margin-left:5px")

        layout.addWidget(deal_button)
        layout.addWidget(label)
        self.left_menu_layout.addWidget(qwidget, 0, Qt.AlignLeft)
        qwidget.mouseReleaseEvent = self.controller.show_treaty_view

    def init_technique_button(self):
        qwidget = QWidget()
        layout = QHBoxLayout()
        qwidget.setLayout(layout)
        qwidget.setStyleSheet("margin-left:15px")

        technique_icon = QIcon(os.getcwd() + "/icons/combine.png")
        technique_button = QPushButton(technique_icon, "")
        technique_button.setIconSize(QSize(30, 30))
        technique_button.setFlat(True)

        label = QLabel("Техника на ремонте")
        label.setStyleSheet("color:#FFFFFF;"
                            "font-size:18px;"
                            "margin-left:15px")

        layout.addWidget(technique_button)
        layout.addWidget(label)
        qwidget.mouseReleaseEvent = self.controller.show_technique_view
        self.left_menu_layout.addWidget(qwidget, 0, Qt.AlignLeft)

    def init_rig_button(self):
        qwidget = QWidget()
        layout = QHBoxLayout()
        qwidget.setLayout(layout)
        qwidget.setStyleSheet("margin-left:15px")

        rig_icon = QIcon(os.getcwd() + "/icons/time.png")
        rig_button = QPushButton(rig_icon, "")
        rig_button.setIconSize(QSize(30, 30))
        rig_button.setFlat(True)

        label = QLabel("Наряды")
        label.setStyleSheet("color: #FFFFFF;"
                            "font-size:18px;"
                            "margin-left:15px")

        layout.addWidget(rig_button)
        layout.addWidget(label)
        self.left_menu_layout.addWidget(qwidget, 0, Qt.AlignLeft)
        qwidget.mouseReleaseEvent = self.controller.show_rig_view

    def show_another_view(self, number):
        self.stacked_widgets.widget(1).hide()
        self.stacked_widgets.widget(number).show()
        self.stacked_widgets.setWindowTitle(self.get_title(number))

    def get_title(self, number):
        return {
            0: "Магазин",
            1: "Меню",
            2: "Техника",
            3: "График урожайности",
            4: "Севооборот",
            5: "Договора",
            6: "Наряды"
        }.get(number, 1)
示例#18
0
    def _create_form_layout(self):
        grid = QGridLayout()

        layers_menu = QGridLayout()
        fid_menu = QGridLayout()

        layers_menu.addWidget(self.layers, 1, 1, 1, 2)
        layers_menu.addWidget(self.ok_button, 1, 3)
        layers_menu.addWidget(self.change_button, 1, 4)

        fid_menu.addWidget(self.fid_input, 1, 1)
        fid_menu.addWidget(self.go_to_fid_button, 1, 2)

        fid_label = QHBoxLayout()
        fid_label.addStretch(1)
        fid_label.addWidget(self.count)
        fid_label.addStretch(1)

        fio_form = QFormLayout()
        fio_form.addRow(QLabel('Фамилия'), self.surname)
        fio_form.addRow(QLabel('Имя'), self.name)
        fio_form.addRow(QLabel('Отчество'), self.middlename)

        dtc_grid = QGridLayout()
        # first row
        dtc_grid.addWidget(QLabel('Дата рождения'), 1, 1)
        dtc_grid.addWidget(self.birth, 1, 2)
        dtc_grid.addWidget(QLabel('Дата смерти'), 1, 3)
        dtc_grid.addWidget(self.death, 1, 4)
        # second row
        dtc_grid.addWidget(QLabel('Тип захоронения'), 2, 1)
        dtc_grid.addWidget(self.gravetype, 2, 2)
        dtc_grid.addWidget(QLabel('Состояние'), 2, 3)
        dtc_grid.addWidget(self.condition, 2, 4)

        buttons = QHBoxLayout()
        buttons.setDirection(QBoxLayout.RightToLeft)
        buttons.addStretch(1)
        buttons.addWidget(self.next, 2)
        buttons.addStretch(1)
        buttons.addWidget(self.previous, 2)
        buttons.addStretch(1)

        stat_grid = QGridLayout()
        stat_grid.addWidget(QLabel('Возраст'), 1, 1)
        stat_grid.addWidget(self.age, 1, 2)
        stat_grid.addWidget(QLabel('Примечания'), 2, 1)
        stat_grid.addWidget(self.comment, 2, 2)

        grid.addLayout(layers_menu, 1, 1)
        grid.addLayout(fid_menu, 2, 1)
        grid.addLayout(fid_label, 3 ,1)
        grid.addLayout(fio_form, 4, 1)
        grid.addWidget(QLabel(), 5, 1)
        grid.addLayout(dtc_grid, 6, 1)
        grid.addWidget(QLabel(), 7, 1)
        grid.addWidget(QLabel(), 8, 1)
        grid.addLayout(buttons, 9, 1)
        grid.addWidget(QLabel(), 10, 1)
        grid.addLayout(stat_grid, 11, 1)
        set_spacing(fio_form, dtc_grid, stat_grid, h=25, v=30)
        grid.setContentsMargins(int(self.width() * 0.05), 0, int(self.width() * 0.05), 10)
        return grid
示例#19
0
class LineEdit(QLineEdit):
    inactiveText = QtDynamicProperty('inactiveText', str)
    widgetSpacing = QtDynamicProperty('widgetSpacing', int)

    def __init__(self, parent=None, contents=""):
        super(LineEdit, self).__init__(contents, parent)
        box_direction = QBoxLayout.RightToLeft if self.isRightToLeft(
        ) else QBoxLayout.LeftToRight
        self.inactiveText = ""
        self.left_widget = SideWidget(self)
        self.left_widget.resize(0, 0)
        self.left_layout = QHBoxLayout(self.left_widget)
        self.left_layout.setContentsMargins(0, 0, 0, 0)
        self.left_layout.setDirection(box_direction)
        self.left_layout.setSizeConstraint(QLayout.SetFixedSize)
        self.right_widget = SideWidget(self)
        self.right_widget.resize(0, 0)
        self.right_layout = QHBoxLayout(self.right_widget)
        self.right_layout.setContentsMargins(0, 0, 0, 0)
        self.right_layout.setDirection(box_direction)
        self.right_layout.addItem(
            QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum))
        self.widgetSpacing = 2
        self.left_widget.sizeHintChanged.connect(self._update_text_margins)
        self.right_widget.sizeHintChanged.connect(self._update_text_margins)

    @property
    def left_margin(self):
        return self.left_widget.sizeHint().width(
        ) + 2 * self.left_layout.spacing()

    @property
    def right_margin(self):
        return self.right_widget.sizeHint().width(
        ) + 2 * self.right_layout.spacing()

    def _update_text_margins(self):
        self.setTextMargins(self.left_margin, 0, self.right_margin, 0)
        self._update_side_widget_locations()

    def _update_side_widget_locations(self):
        option = QStyleOptionFrame()
        self.initStyleOption(option)
        spacing = self.right_layout.spacing()
        text_rect = self.style().subElementRect(QStyle.SE_LineEditContents,
                                                option, self)
        text_rect.adjust(spacing, 0, -spacing, 0)
        mid_height = text_rect.center().y() + 1 - (
            text_rect.height() % 2)  # need -1 correction for odd heights -Dan
        if self.left_layout.count() > 0:
            left_height = int(mid_height - self.left_widget.height() / 2)
            left_width = self.left_widget.width()
            if left_width == 0:
                left_height = int(mid_height -
                                  self.left_widget.sizeHint().height() / 2)
            self.left_widget.move(text_rect.x(), left_height)
        text_rect.setX(self.left_margin)
        text_rect.setY(
            int(mid_height - self.right_widget.sizeHint().height() / 2.0))
        text_rect.setHeight(self.right_widget.sizeHint().height())
        self.right_widget.setGeometry(text_rect)

    def event(self, event):
        event_type = event.type()
        if event_type == QEvent.LayoutDirectionChange:
            box_direction = QBoxLayout.RightToLeft if self.isRightToLeft(
            ) else QBoxLayout.LeftToRight
            self.left_layout.setDirection(box_direction)
            self.right_layout.setDirection(box_direction)
        elif event_type == QEvent.DynamicPropertyChange:
            property_name = event.propertyName()
            if property_name == 'widgetSpacing':
                self.left_layout.setSpacing(self.widgetSpacing)
                self.right_layout.setSpacing(self.widgetSpacing)
                self._update_text_margins()
            elif property_name == 'inactiveText':
                self.update()
        return QLineEdit.event(self, event)

    def resizeEvent(self, event):
        self._update_side_widget_locations()
        QLineEdit.resizeEvent(self, event)

    def paintEvent(self, event):
        QLineEdit.paintEvent(self, event)
        if not self.hasFocus() and not self.text() and self.inactiveText:
            options = QStyleOptionFrame()
            self.initStyleOption(options)
            text_rect = self.style().subElementRect(QStyle.SE_LineEditContents,
                                                    options, self)
            text_rect.adjust(self.left_margin + 2, 0, -self.right_margin, 0)
            painter = QPainter(self)
            painter.setPen(self.palette().brush(QPalette.Disabled,
                                                QPalette.Text).color())
            painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter,
                             self.inactiveText)

    def addHeadWidget(self, widget):
        if self.isRightToLeft():
            self.right_layout.insertWidget(1, widget)
        else:
            self.left_layout.addWidget(widget)

    def addTailWidget(self, widget):
        if self.isRightToLeft():
            self.left_layout.addWidget(widget)
        else:
            self.right_layout.insertWidget(1, widget)

    def removeWidget(self, widget):
        self.left_layout.removeWidget(widget)
        self.right_layout.removeWidget(widget)
        widget.hide()
示例#20
0
class E5LineEdit(QLineEdit):
    """
    Class implementing a line edit widget showing some inactive text.
    """
    LeftSide = 0
    RightSide = 1
    
    def __init__(self, parent=None, inactiveText=""):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        @param inactiveText text to be shown on inactivity (string)
        """
        super(E5LineEdit, self).__init__(parent)
        
        self.setMinimumHeight(22)
        
        if qVersion() < "4.7.0":
            self.__inactiveText = inactiveText
        else:
            self.setPlaceholderText(inactiveText)
        
        self.__mainLayout = QHBoxLayout(self)
        self.__mainLayout.setContentsMargins(0, 0, 0, 0)
        self.__mainLayout.setSpacing(0)
        
        self.__leftMargin = 0
        self.__leftWidget = E5LineEditSideWidget(self)
        self.__leftWidget.resize(0, 0)
        self.__leftLayout = QHBoxLayout(self.__leftWidget)
        self.__leftLayout.setContentsMargins(0, 0, 2, 0)
        if QApplication.isRightToLeft():
            self.__leftLayout.setDirection(QBoxLayout.RightToLeft)
        else:
            self.__leftLayout.setDirection(QBoxLayout.LeftToRight)
        self.__leftLayout.setSizeConstraint(QLayout.SetFixedSize)
        
        self.__rightWidget = E5LineEditSideWidget(self)
        self.__rightWidget.resize(0, 0)
        self.__rightLayout = QHBoxLayout(self.__rightWidget)
        self.__rightLayout.setContentsMargins(0, 0, 2, 0)
        if self.isRightToLeft():
            self.__rightLayout.setDirection(QBoxLayout.RightToLeft)
        else:
            self.__rightLayout.setDirection(QBoxLayout.LeftToRight)
        
        horizontalSpacer = QSpacerItem(
            0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.__mainLayout.addWidget(
            self.__leftWidget, 0, Qt.AlignVCenter | Qt.AlignLeft)
        self.__mainLayout.addItem(horizontalSpacer)
        self.__mainLayout.addWidget(
            self.__rightWidget, 0, Qt.AlignVCenter | Qt.AlignRight)
        if self.isRightToLeft():
            self.__mainLayout.setDirection(QBoxLayout.RightToLeft)
        else:
            self.__mainLayout.setDirection(QBoxLayout.LeftToRight)
        
        self.setWidgetSpacing(3)
        self.__leftWidget.sizeHintChanged.connect(self._updateTextMargins)
        self.__rightWidget.sizeHintChanged.connect(self._updateTextMargins)
    
    def setLeftMargin(self, margin):
        """
        Public method to set the left margin.
        
        @param margin left margin in pixel (integer)
        """
        self.__leftMargin = margin
    
    def leftMargin(self):
        """
        Public method to get the size of the left margin.
        
        @return left margin in pixel (integer)
        """
        return self.__leftMargin
    
    def event(self, evt):
        """
        Public method to handle events.
        
        @param evt reference to the event (QEvent)
        @return flag indicating, whether the event was recognized (boolean)
        """
        if evt.type() == QEvent.LayoutDirectionChange:
            if self.isRightToLeft():
                self.__mainLayout.setDirection(QBoxLayout.RightToLeft)
                self.__leftLayout.setDirection(QBoxLayout.RightToLeft)
                self.__rightLayout.setDirection(QBoxLayout.RightToLeft)
            else:
                self.__mainLayout.setDirection(QBoxLayout.LeftToRight)
                self.__leftLayout.setDirection(QBoxLayout.LeftToRight)
                self.__rightLayout.setDirection(QBoxLayout.LeftToRight)
        return QLineEdit.event(self, evt)
    
    def paintEvent(self, evt):
        """
        Protected method handling a paint event.
        
        @param evt reference to the paint event (QPaintEvent)
        """
        super(E5LineEdit, self).paintEvent(evt)
        
        if qVersion() < "4.7.0":
            if not self.text() and \
               self.__inactiveText and \
               not self.hasFocus():
                panel = QStyleOptionFrame()
                self.initStyleOption(panel)
                textRect = self.style().subElementRect(
                    QStyle.SE_LineEditContents, panel, self)
                textRect.adjust(2, 0, 0, 0)
                left = self.textMargin(self.LeftSide)
                right = self.textMargin(self.RightSide)
                textRect.adjust(left, 0, -right, 0)
                painter = QPainter(self)
                painter.setPen(self.palette().brush(
                    QPalette.Disabled, QPalette.Text).color())
                painter.drawText(
                    textRect, Qt.AlignLeft | Qt.AlignVCenter,
                    self.__inactiveText)
    
    def _updateTextMargins(self):
        """
        Protected slot to update the text margins.
        """
        if self.__leftMargin == 0:
            left = self.__leftWidget.sizeHint().width()
        else:
            left = self.__leftMargin
        right = self.__rightWidget.sizeHint().width()
        top = 0
        bottom = 0
        self.setTextMargins(left, top, right, bottom)
    
    def addWidget(self, widget, position):
        """
        Public method to add a widget to a side.
        
        @param widget reference to the widget to add (QWidget)
        @param position position to add to (E5LineEdit.LeftSide,
            E5LineEdit.RightSide)
        """
        if widget is None:
            return
        
        if self.isRightToLeft():
            if position == self.LeftSide:
                position = self.RightSide
            else:
                position = self.LeftSide
        if position == self.LeftSide:
            self.__leftLayout.addWidget(widget)
        else:
            self.__rightLayout.insertWidget(1, widget)
    
    def removeWidget(self, widget):
        """
        Public method to remove a widget from a side.
        
        @param widget reference to the widget to remove (QWidget)
        """
        if widget is None:
            return
        
        self.__leftLayout.removeWidget(widget)
        self.__rightLayout.removeWidget(widget)
        widget.hide()
    
    def widgetSpacing(self):
        """
        Public method to get the side widget spacing.
        
        @return side widget spacing (integer)
        """
        return self.__leftLayout.spacing()
    
    def setWidgetSpacing(self, spacing):
        """
        Public method to set the side widget spacing.
        
        @param spacing side widget spacing (integer)
        """
        self.__leftLayout.setSpacing(spacing)
        self.__rightLayout.setSpacing(spacing)
        self._updateTextMargins()
    
    def textMargin(self, position):
        """
        Public method to get the text margin for a side.
        
        @param position side to get margin for (E5LineEdit.LeftSide,
            E5LineEdit.RightSide)
        @return text margin (integer)
        """
        spacing = self.__rightLayout.spacing()
        w = 0
        if position == self.LeftSide:
            w = self.__leftWidget.sizeHint().width()
        else:
            w = self.__rightWidget.sizeHint().width()
        if w == 0:
            return 0
        return w + spacing * 2
    
    def inactiveText(self):
        """
        Public method to get the inactive text.
        
        @return inactive text (string)
        """
        if qVersion() < "4.7.0":
            return self.__inactiveText
        else:
            return self.placeholderText()
    
    def setInactiveText(self, inactiveText):
        """
        Public method to set the inactive text.
        
        @param inactiveText text to be shown on inactivity (string)
        """
        if qVersion() < "4.7.0":
            self.__inactiveText = inactiveText
            self.update()
        else:
            self.setPlaceholderText(inactiveText)
示例#21
0
class Group(QFrame):
    def __init__(self, name: str, parent: QWidget):
        super(Group, self).__init__(parent)
        # self.setFrameShape(QFrame.NoFrame)
        # self.setLineWidth(0)
        self.setContentsMargins(0, 0, 0, 0)
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)

        seperator_layout = QHBoxLayout(self)
        seperator_layout.setContentsMargins(0, 0, 0, 0)
        seperator_layout.setSpacing(0)
        seperator_layout.setDirection(QBoxLayout.LeftToRight)
        self.setLayout(seperator_layout)

        outer_layout = QVBoxLayout()
        outer_layout.setContentsMargins(0, 0, 0, 0)
        outer_layout.setSpacing(0)
        outer_layout.setDirection(QBoxLayout.TopToBottom)
        seperator_layout.addLayout(outer_layout)
        seperator_layout.addWidget(self.create_separator())

        inner_frame = QFrame(self)
        inner_frame.setFrameShape(QFrame.NoFrame)
        inner_frame.setLineWidth(0)
        inner_frame.setContentsMargins(0, 0, 0, 0)
        inner_frame.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)

        self.inner_layout = QHBoxLayout(inner_frame)
        self.inner_layout.setContentsMargins(2, 4, 2, 0)
        self.inner_layout.setSpacing(4)
        self.inner_layout.setDirection(QBoxLayout.LeftToRight)
        inner_frame.setLayout(self.inner_layout)

        outer_layout.addWidget(inner_frame)

        self.group_name = QLabel(name, self)
        self.group_name.setProperty("TTGroupName", QtCore.QVariant(True))
        self.group_name.setSizePolicy(QSizePolicy.Preferred,
                                      QSizePolicy.Maximum)
        self.group_name.setAlignment(QtCore.Qt.AlignHCenter
                                     | QtCore.Qt.AlignVCenter  # type: ignore
                                     )
        self.group_name.adjustSize()
        outer_layout.addWidget(self.group_name)

        parent_tabtoolbar = tabtoolbar.find_tabtoolbar(self)
        if not parent_tabtoolbar:
            raise Exception("Could not find Parent Tabtoolbar")

        group_maxheight = parent_tabtoolbar.group_maxheight
        rowcount = parent_tabtoolbar.rowcount()
        height = group_maxheight + self.group_name.height() + rowcount - 1
        self.setMinimumHeight(height)
        self.setMaximumHeight(height)

    def add_subgroup(self, align: subgroup.Align) -> subgroup.SubGroup:
        sgrp = subgroup.SubGroup(align, self)
        self.inner_layout.addWidget(sgrp)
        return sgrp

    def create_separator(self) -> QFrame:
        separator = QFrame(self)
        separator.setProperty("TTSeparator", QtCore.QVariant(True))
        separator.setAutoFillBackground(False)
        separator.setFrameShadow(QFrame.Plain)
        separator.setLineWidth(1)
        separator.setMidLineWidth(0)
        separator.setFrameShape(QFrame.VLine)
        return separator

    def add_separator(self):
        self.inner_layout.addWidget(self.create_separator())

    def add_action(self, type: QToolButton.ToolButtonPopupMode,
                   action: QAction, menu: QMenu):
        if type == QToolButton.MenuButtonPopup:
            self.inner_layout.addWidget(_CompactToolButton(action, menu, self))
        else:
            icon_size = int(
                style.get_pixelmetric(QStyle.PM_LargeIconSize) *
                style.get_scalefactor(self))

            btn = QToolButton(self)
            btn.setProperty("TTInternal", QtCore.QVariant(True))
            btn.setAutoRaise(True)
            btn.setDefaultAction(action)
            btn.setIconSize(QtCore.QSize(icon_size, icon_size))
            btn.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred)
            btn.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
            btn.setPopupMode(type)
            btn.setStyle(style.TTToolButtonStyle())
            if menu:
                btn.setMenu(menu)
            self.inner_layout.addWidget(btn)

    def add_widget(self, widget: QWidget):
        widget.setParent(self)
        widget.setProperty("TTInternal", QtCore.QVariant(True))
        self.inner_layout.addWidget(widget)