Beispiel #1
0
 def setIconModes(self):
     icon1 = QIcon("icon.png")
     label1 = QLabel("sample", self)
     pixmap1 = icon1.pixmap(100, 100, QIcon.Active, QIcon.On)
     label1.setPixmap(pixmap1)
     label2 = QLabel("sample", self)
     pixmap2 = icon1.pixmap(100, 100, QIcon.Disabled, QIcon.Off)
     label2.setPixmap(pixmap2)
     label2.move(100, 0)
     label3 = QLabel("sample", self)
     pixmap3 = icon1.pixmap(100, 100, QIcon.Selected, QIcon.On)
     label3.setPixmap(pixmap3)
     label3.move(200, 0)
Beispiel #2
0
    def __init__(self, scripts_list_widget, script):
        super(ScriptsList_ScriptWidget, self).__init__()

        self.script = script
        self.scripts_list_widget = scripts_list_widget

        self.ignore_name_line_edit_signal = False

        # UI
        main_layout = QHBoxLayout()

        # create icon via label
        script_icon = QIcon('resources/pics/script_picture.png')
        icon_label = QLabel()
        icon_label.setFixedSize(20, 20)
        icon_label.setStyleSheet('border:none;')
        icon_label.setPixmap(script_icon.pixmap(20, 20))
        main_layout.addWidget(icon_label)

        # create name and data_type line edits
        self.name_line_edit = ListWidget_NameLineEdit(script.name, self)
        self.name_line_edit.setPlaceholderText('name')
        self.name_line_edit.setEnabled(False)
        self.name_line_edit.editingFinished.connect(
            self.name_line_edit_editing_finished)
        self.name_line_edit.unfocused.connect(
            self.name_line_edit_editing_finished)

        name_type_layout = QVBoxLayout()
        name_type_layout.addWidget(self.name_line_edit)
        main_layout.addLayout(name_type_layout)

        self.setLayout(main_layout)
Beispiel #3
0
    def __init__(self, vars_list_widget, variables_hander, var):
        super(VarsList_VarWidget, self).__init__()

        self.variables_handler = variables_hander
        self.var = var
        self.vars_list_widget = vars_list_widget

        self.ignore_name_line_edit_signal = False

        # UI
        main_layout = QHBoxLayout()

        # create icon via label
        variable_icon = QIcon('resources/pics/variable_picture.png')
        icon_label = QLabel()
        icon_label.setFixedSize(15, 15)
        icon_label.setStyleSheet('border:none;')
        icon_label.setPixmap(variable_icon.pixmap(15, 15))
        main_layout.addWidget(icon_label)

        # create name and data_type line edits
        self.name_line_edit = ListWidget_NameLineEdit(var.name, self)
        self.name_line_edit.setPlaceholderText('name')
        self.name_line_edit.setEnabled(False)
        self.name_line_edit.editingFinished.connect(
            self.name_line_edit_editing_finished)
        self.name_line_edit.unfocused.connect(
            self.name_line_edit_editing_finished)

        name_type_layout = QVBoxLayout()
        name_type_layout.addWidget(self.name_line_edit)
        main_layout.addLayout(name_type_layout)

        self.setLayout(main_layout)
Beispiel #4
0
 def __init__(self, configurationManager: ConfigurationManager):
     super(ToolBar, self).__init__()
     self.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
     self.configurationManager = configurationManager
     self.setStyleSheet(
         "background-color: #2D2D30; color: white; font-weight: 500")
     self.setMovable(False)
     self.setWindowTitle("Toolbar")
     self.compile = QAction(
         QIcon(main.resource_path("resources/compile.png")), "Compile",
         self)
     self.compile.setShortcut(QKeySequence("Ctrl+Shift+B"))
     self.debug = QAction(QIcon(main.resource_path("resources/debug.png")),
                          "Debug", self)
     self.debug.setShortcut(QKeySequence("Ctrl+F5"))
     self.run = QAction(QIcon(main.resource_path("resources/run.png")),
                        "Run", self)
     self.label = QLabel("Select current project")
     self.label.setStyleSheet("padding-left: 5px;")
     icon = QIcon(main.resource_path("resources/current_folder.png"))
     self.currentIcon = QLabel()
     self.currentIcon.setPixmap(icon.pixmap(QSize(20, 20)))
     self.projectComboBox = ProjectComboBox(self.configurationManager)
     self.projectComboBox.setMinimumWidth(250)
     self.run.setShortcut(QKeySequence("F5"))
     self.addAction(self.compile)
     self.addAction(self.debug)
     self.addAction(self.run)
     self.addSeparator()
     self.addWidget(self.currentIcon)
     self.addWidget(self.label)
     self.addWidget(self.projectComboBox)
Beispiel #5
0
    def initRadioButtons(self):

        width = self.width()
        height = self.height()

        self.deterministicRadio = QRadioButton('Deterministic Queue', self)
        self.deterministicRadio.setFont(QFont('Sanserif', 18))
        self.deterministicRadio.setStyleSheet('QRadioButton{color:maroon}')
        self.deterministicRadio.adjustSize()
        self.deterministicRadio.move(100, 100)
        self.deterministicRadio.clicked.connect(self.deterministicRadioClicked)

        self.stochasticRadio = QRadioButton('Stochastic Queue', self)
        self.stochasticRadio.setFont(QFont('Sanserif', 18))
        self.stochasticRadio.setStyleSheet('QRadioButton{color:darkslategray}')
        self.stochasticRadio.adjustSize()
        self.stochasticRadio.move((width / 2) + 50, 100)
        self.stochasticRadio.clicked.connect(self.stochasticRadioClicked)

        self.deterministicRadio = QRadioButton('WhatEver Queue', self)
        self.deterministicRadio.setFont(QFont('Sanserif', 18))
        self.deterministicRadio.setStyleSheet('QRadioButton{color:steelblue}')
        self.deterministicRadio.adjustSize()
        self.deterministicRadio.move(300, 200)

        icon1 = QIcon('line.png')
        label1 = QLabel('Sample', self)
        pixmap1 = icon1.pixmap(100, 100, QIcon.Active, QIcon.On)
        label1.setPixmap(pixmap1)
        label1.move((width / 2) - 50, 300)
        label1.adjustSize()
Beispiel #6
0
    def __init__(self, title: str, icon: QtGui.QIcon, parent: QtWidgets.QDockWidget):
        """
        Initialize the widget.
        """
        super().__init__(parent)
        # CREATE TITLEBAR ICON AND TITLE
        self.imageLabel = QtWidgets.QLabel(self)
        self.imageLabel.setPixmap(icon.pixmap(18))
        self.imageLabel.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
        self.imageLabel.setContentsMargins(0, 0, 0, 0)
        self.imageLabel.setFixedSize(18, 18)
        self.titleLabel = QtWidgets.QLabel(title, self)
        self.titleLabel.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
        self.titleLabel.setContentsMargins(4, 0, 0, 0)
        self.titleLabel.setMinimumWidth(1)

        # CREATE STANDARD BUTTONS
        close = QtWidgets.QPushButton(self)
        close.setIcon(ctx.closeDockIcon)
        close.setFixedSize(18, 18)
        close.clicked.connect(parent.close)
        self.buttons = [close]

        # CONFIGURE LAYOUT
        self.mainLayout = QtWidgets.QHBoxLayout(self)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.mainLayout.setSpacing(0)
        self.setContentsMargins(6, 4, 6, 4)
        self.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)
        # self.setMinimumWidth(self.imageLabel.width())
        self.updateLayout()
Beispiel #7
0
    def definir_imagens(self):
        appIcon = QIcon("/home/juliandev/projects/SYSCAD/v3/images/fav_icon.png")
        img_login = QIcon("/home/juliandev/projects/SYSCAD/v3/images/icon_login.png")
        img_base = QIcon("/home/juliandev/projects/SYSCAD/v3/images/icon_login_base.png")

        pixmap_login = img_login.pixmap(191,191)
        pixmap_base = img_base.pixmap(400,220)

        lbl_login = QLabel('login', self)
        lbl_login.setPixmap(pixmap_login)
        lbl_login.move(100,10)

        lbl_base = QLabel('Base', self)
        lbl_base.setPixmap(pixmap_base)
        lbl_base.setGeometry(0,440, 411, 161)

        self.setWindowIcon(appIcon)
Beispiel #8
0
 def createBackArrow(self):
     icon1 = QIcon('arrow_back.png')
     label1 = QLabel('Sample', self)
     pixmap1 = icon1.pixmap(20, 20, QIcon.Active, QIcon.On)
     label1.setPixmap(pixmap1)
     label1.move(25, 25)
     label1.adjustSize()
     label1.mousePressEvent = self.arrowbackClicked
Beispiel #9
0
def Icon(icon="ascii", width=32, height=32, *args, **kwargs):
    if icon.startswith("/"):
        ico = QIcon(icon)
    else:
        ico = QIcon.fromTheme(icon)
    lab = QLabel(*args, **kwargs)
    lab.setGeometry(0, 0, width, height)
    lab.setPixmap(ico.pixmap(width, height))
    return lab
 def PixmapFromIcon(icon: QtGui.QIcon):
     pixmap = icon.pixmap(16, 16)
     pix_of_ic = QtGui.QPixmap(pixmap)
     ItemTypeIcon = QtWidgets.QLabel()
     ItemTypeIcon.setPixmap(pix_of_ic)
     ItemTypeIcon.setStyleSheet(""" 
         background-color: transparent;
         """)
     ItemTypeIcon.setAlignment(QtCore.Qt.AlignLeft)
     return ItemTypeIcon
    def setIconModes(self):
        icon1 = QIcon("icon.png")
        label1 = QLabel('Sample', self)
        pixmap1 = icon1.pixmap(100, 100, QIcon.Active, QIcon.On)
        label1.setPixmap(pixmap1)
        label1.setToolTip("Active Icon")

        icon2 = QIcon("icon.png")
        label2 = QLabel('Sample', self)
        pixmap2 = icon2.pixmap(100, 100, QIcon.Disabled, QIcon.Off)
        label2.setPixmap(pixmap2)
        label2.move(100, 0)
        label2.setToolTip("Disabled Icon")

        icon3 = QIcon("icon.png")
        label3 = QLabel('Sample', self)
        pixmap3 = icon3.pixmap(100, 100, QIcon.Selected, QIcon.On)
        label3.setPixmap(pixmap3)
        label3.move(200, 0)
        label3.setToolTip("Selected Icon")
    def setIconModes(self):
        # inabled icon
        icon1 = QIcon("Screenshot from 2019-10-15 09-33-25.png")
        label1 = QLabel("Sample", self)
        pixmap1 = icon1.pixmap(100, 100, QIcon.Active, QIcon.On)
        label1.setPixmap(pixmap1)

        # this one is disabled icon
        icon2 = QIcon("Screenshot from 2019-10-15 09-33-25.png")
        label2 = QLabel("sample", self)
        pixmap2 = icon2.pixmap(100, 100, QIcon.Disabled, QIcon.Off)
        label2.setPixmap(pixmap2)
        label2.move(100, 0)

        # third
        icon3 = QIcon("Screenshot from 2019-10-15 09-33-25.png")
        label3 = QLabel("sample", self)
        pixmap3 = icon3.pixmap(100, 100, QIcon.Selected, QIcon.On)
        label3.setPixmap(pixmap3)
        label3.move(200, 0)
Beispiel #13
0
    def set_img(self):
        #icone 1
        icone1 = QIcon('imagens/icon_check.png')
        label1 = QLabel('Palavra', self)
        pixmap1 = icone1.pixmap(100, 100, QIcon.Active)

        # label1.setPixmap(pixmap1)

        #icone 2
        icone2 = QIcon('imagens/icon_check.png')
        label2 = QLabel('Palavra', self)
        label2.move(100, 0)
        pixmap2 = icone2.pixmap(100, 100, QIcon.Disabled)

        # label2.setPixmap(pixmap2)

        #icone 3
        icone3 = QIcon('imagens/icon_check.png')
        label3 = QLabel('Palavra', self)
        label3.move(200, 0)
        pixmap3 = icone3.pixmap(100, 100, QIcon.Selected)
Beispiel #14
0
 def _update_online_state(self, online: bool):
     """
     Updates online status icon
     """
     if not isinstance(online, bool):
         raise TypeError(f"{online} not in (True, False)")
     self.online = online
     if online:
         icon = QIcon("resources/img/icon_tick.png")
     else:
         icon = QIcon("resources/img/icon_cross.png")
     pixmap = icon.pixmap(QSize(32, 32))
     self._onlineLabel.setPixmap(pixmap)
Beispiel #15
0
    def backGroundcolorChanger(self):
        icon1=QIcon('colors.png')
        label1=QLabel('ColorPalette',self)
        pixmap1=icon1.pixmap(30,30,QIcon.Active,QIcon.On)
        label1.setPixmap(pixmap1)
        label1.setToolTip('go to Previous Screen')
        label1.mousePressEvent=self.getBackgroundColor

        self.namesLabel=QLabel('Designed by:\n\tAbd-ElRahman Abd-ElFattah Habib.\n\tMohammed Ahmed Mekkawy.\n\tElSayed Abd-ElMohaymen ElSayed.\n',self)
        self.namesLabel.width=300
        width=self.width()
        height=self.height()

        label1.move(width-40,height-40)
        self.namesLabel.move(10,height-60)
        self.namesLabel.adjustSize()
Beispiel #16
0
    def __init__(self, scripts_list_widget, script):
        super(ScriptsList_ScriptWidget, self).__init__()

        self.script = script
        self.scripts_list_widget = scripts_list_widget

        self.ignore_name_line_edit_signal = False

        # UI
        main_layout = QHBoxLayout()

        # create icon via label
        script_icon = QIcon('stuff/pics/script_picture.png')
        icon_label = QLabel()
        icon_label.setFixedSize(20, 20)
        icon_label.setStyleSheet('border:none;')
        icon_label.setPixmap(script_icon.pixmap(20, 20))
        main_layout.addWidget(icon_label)

        # create name and data_type line edits
        self.name_line_edit = ListWidget_NameLineEdit(script.name, self)
        self.name_line_edit.setPlaceholderText('name')
        # TODO create variable name and dt-type stylesheets
        #  (with small border/paddin/margin - this didn't work so far at all - I don't know why)
        #  Also the double click event on a line edit only get's catched correctly when clicking in the middle
        self.name_line_edit.setEnabled(False)
        self.name_line_edit.editingFinished.connect(
            self.name_line_edit_editing_finished)
        self.name_line_edit.unfocused.connect(
            self.name_line_edit_editing_finished)
        # TODO handle the variable name-and dt-line_edit's 'editing finished' the right way.
        #  It doesn't work when just clicking to somewhere else after starting to edit (it stays editable)

        name_type_layout = QVBoxLayout()
        name_type_layout.addWidget(self.name_line_edit)
        main_layout.addLayout(name_type_layout)

        # TODO create buttons (del, maybe: move up, move down etc.)

        # add whole layout to the main widget and save in widgets array
        self.setLayout(main_layout)
Beispiel #17
0
    def createLayout(self):

        icon1=QIcon('line.png')
        label1=QLabel('Sample',self)
        pixmap1=icon1.pixmap(200,200,QIcon.Active,QIcon.On)
        label1.setPixmap(pixmap1)

        self.submitButton=QPushButton('Continue',self)
        self.submitButton.setFont(QFont('Sanserif',18))
        self.submitButton.setStyleSheet('background-color: blueviolet;color:white;border: 1px solid; border-radius:15px')
        self.submitButton.clicked.connect(self.handleSubmitClick)

        vbox=QVBoxLayout()
        vbox.setAlignment(Qt.AlignCenter)
        vbox.setContentsMargins(10,30,10,30)

        vbox.addWidget(label1)
        vbox.setSpacing(50)
        vbox.addWidget(self.submitButton)

        self.setLayout(vbox)
Beispiel #18
0
def IconRoundPixmap(icon: QtGui.QIcon, extend: int) -> QtGui.QPixmap:
    if not icon:
        pixmap = QtGui.QPixmap(extend, extend)
        pixmap.fill(QtGui.QColor("grey"))
    else:
        pixmap: QtGui.QPixmap = icon.pixmap(extend)

    pixmap2 = pixmap.scaled(extend, extend,
                            QtCore.Qt.KeepAspectRatioByExpanding,
                            QtCore.Qt.SmoothTransformation)

    pixmap.fill(QtCore.Qt.transparent)
    painter = QtGui.QPainter(pixmap)
    painter.setRenderHints(QtGui.QPainter.Antialiasing
                           | QtGui.QPainter.HighQualityAntialiasing
                           | QtGui.QPainter.SmoothPixmapTransform)

    path = QtGui.QPainterPath()
    path.addRoundedRect(0, 0, extend, extend, extend / 2, extend / 2)
    painter.setClipPath(path)
    painter.drawPixmap(0, 0, pixmap2)
    painter.end()
    return pixmap
Beispiel #19
0
    def __init__(self, parent: QWidget, model: Model) -> None:
        super().__init__(parent)

        logger.add(self.log)

        self.mainlayout = QVBoxLayout()
        self.setLayout(self.mainlayout)

        self.splitter = QSplitter(Qt.Vertical)

        self.stack = QStackedWidget()
        self.splitter.addWidget(self.stack)

        # mod list widget

        self.modlistwidget = QWidget()
        self.modlistlayout = QVBoxLayout()
        self.modlistlayout.setContentsMargins(0, 0, 0, 0)
        self.modlistwidget.setLayout(self.modlistlayout)
        self.stack.addWidget(self.modlistwidget)

        # search bar

        self.searchbar = QLineEdit()
        self.searchbar.setPlaceholderText('Search...')
        self.modlistlayout.addWidget(self.searchbar)

        # mod list

        self.modlist = ModList(self, model)
        self.modlistlayout.addWidget(self.modlist)

        self.searchbar.textChanged.connect(lambda e: self.modlist.setFilter(e))

        # welcome message

        welcomelayout = QVBoxLayout()
        welcomelayout.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        welcomewidget = QWidget()
        welcomewidget.setLayout(welcomelayout)
        welcomewidget.dragEnterEvent = self.modlist.dragEnterEvent  # type: ignore
        welcomewidget.dragMoveEvent = self.modlist.dragMoveEvent  # type: ignore
        welcomewidget.dragLeaveEvent = self.modlist.dragLeaveEvent  # type: ignore
        welcomewidget.dropEvent = self.modlist.dropEvent  # type: ignore
        welcomewidget.setAcceptDrops(True)

        icon = QIcon(str(getRuntimePath('resources/icons/open-folder.ico')))
        iconpixmap = icon.pixmap(32, 32)
        icon = QLabel()
        icon.setPixmap(iconpixmap)
        icon.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        icon.setContentsMargins(4, 4, 4, 4)
        welcomelayout.addWidget(icon)

        welcome = QLabel('''<p><font>
            No mod installed yet.
            Drag a mod into this area to get started!
            </font></p>''')
        welcome.setAttribute(Qt.WA_TransparentForMouseEvents)
        welcome.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        welcomelayout.addWidget(welcome)

        self.stack.addWidget(welcomewidget)

        # output log

        self.output = QTextEdit(self)
        self.output.setTextInteractionFlags(Qt.NoTextInteraction)
        self.output.setReadOnly(True)
        self.output.setContextMenuPolicy(Qt.NoContextMenu)
        self.output.setPlaceholderText('Program output...')
        self.splitter.addWidget(self.output)

        # TODO: enhancement: add a launch game icon
        # TODO: enhancement: show indicator if scripts have to be merged

        self.splitter.setStretchFactor(0, 1)
        self.splitter.setStretchFactor(1, 0)
        self.mainlayout.addWidget(self.splitter)

        if len(model):
            self.stack.setCurrentIndex(0)
            self.splitter.setSizes([self.splitter.size().height(), 50])
        else:
            self.stack.setCurrentIndex(1)
            self.splitter.setSizes([self.splitter.size().height(), 0])
        model.updateCallbacks.append(self.modelUpdateEvent)
class HeaderInput(QGroupBox):
    def __init__(self, parent, header, value, common_values):
        super().__init__(parent)
        self.header = header
        self.valid = not self.header["not_null"]

        self.setStyleSheet(styles.header_input_groupbox_dark)

        # LAYOUTS
        self.grid = QGridLayout()
        self.v_layout = QVBoxLayout()

        # FIELDS
        self.header_label = QLabel(f'{self.header["name"]} : ', self)
        self.header_label.setFixedWidth(WIDTH * 0.08)

        self.info_label = QLabel('')
        self.info_label.hide()

        self.type_label = QLabel('')
        self.type_label.hide()

        self.pixmap_label = QLabel()
        self.pixmap_label.setFixedWidth(16)

        pal = QPalette()
        pal.setColor(QPalette.Base, Qt.white)
        self.input = QLineEdit(self)
        self.input.setMaxLength(self.header["data_type"]["max_value"])
        self.input.textEdited.connect(self.check_input)
        self.input.editingFinished.connect(self.finish_editing)
        self.setPalette(pal)
        if value is None or not value or len(value) == 0:
            self.input.setPlaceholderText("Some examples : " +
                                          str(common_values).replace("'", '').
                                          replace('[', '').replace(']', ''))
        else:
            self.input.setText(value)

        self.validator = None
        if self.header["data_type"]["type"] == 'int':
            self.validator = TypeValidInt(self.valid, self.header,
                                          self.info_label, self.type_label)

        if self.header["data_type"]["type"] == 'str':
            self.validator = HeaderValidator(self.valid, self.header,
                                             self.info_label, self.type_label)

        if self.header["data_type"]["type"] == 'date':
            self.validator = TypeValidDate(self.valid, self.header,
                                           self.info_label, self.type_label)

        # SET UP

        self.icon = None
        if self.header["not_null"]:
            self.set_invalid()
            self.header_label.setFont(BOLD)

        if self.header["is_primary"]:
            self.icon = QIcon(PRIMARY_KEY_ICON)

        if self.header["is_foreign_key"]:
            self.icon = QIcon(FOREIGN_KEY_ICON)

        if self.header["is_primary"] and self.header["is_foreign_key"]:
            self.icon = QIcon(PRIMARY_FOREIGN_KEY)

        self.v_layout.addWidget(self.input)
        self.v_layout.addWidget(self.info_label)
        self.v_layout.addWidget(self.type_label)

        if self.icon is not None:
            self.pixmap_label.setPixmap(self.icon.pixmap(16, 16))

        self.grid.addWidget(self.pixmap_label, 0, 0)
        self.grid.addWidget(self.header_label, 0, 1)
        self.grid.addLayout(self.v_layout, 0, 2)

        self.setLayout(self.grid)

    def check_input(self, txt):
        self.set_valid() if self.validator.validate(
            txt) else self.set_invalid()

    def set_valid(self):
        self.valid = True
        self.input.setStyleSheet(styles.input_valid)

    def set_invalid(self):
        self.valid = False
        self.input.setStyleSheet(styles.input_invalid)

    def finish_editing(self):
        self.info_label.hide()
        self.type_label.hide()
        if not self.header["not_null"] and self.valid:
            self.set_valid()

    def get_value(self):
        return {
            "is_valid": self.valid,
            "name": self.header["name"],
            "value": self.input.text()
        }

    def clear(self):
        self.input.setText('')
        self.valid = not self.header["not_null"]
        self.set_valid() if self.valid else self.set_invalid()

    def set_value(self, value):
        self.check_input(value)
        self.input.setText(value)
Beispiel #21
0
 def testQIconCtorWithNone(self):
     icon = QIcon(None)
     pixmap = icon.pixmap(48, 48)
     self.app.exec_()
Beispiel #22
0
 def testQIconCtorWithNone(self):
     icon = QIcon(None)
     pixmap = icon.pixmap(48, 48)
     self.app.exec_()
Beispiel #23
0
class MainForm(QWidget):
    def __init__(self):
        super(MainForm, self).__init__()
        self.app_icon = QIcon(r'SourceData/LabelPrint/ico/file.ico')
        self.pixmap = self.app_icon.pixmap(50, 50, QIcon.Active)
        self.lbl_title = QLabel(
            '<b><font color=blue fontWeight=20 size=20>Welcome to ZBPrintLbl</font></b>'
        )
        self.lbl_ico_title = QLabel()
        self.lbl_ico_title.setPixmap(self.pixmap)
        self.initUI()

    def initUI(self):
        # Create Layouts
        grid = QGridLayout()  # for frame_input
        vbox = QVBoxLayout()  # for MainForm
        hbox_frame_btn = QHBoxLayout()  # for frame_button
        hbox_title = QHBoxLayout()  # for frame_title

        # Create controls
        frame_title = QFrame()
        frame_input = QFrame()
        frame_button = QFrame()
        self.tbl = QTableWidget(50, n)
        self.tbl.setHorizontalHeaderLabels(FIELDS2ZH)
        self.tbl.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        self.tbl.setEditTriggers(QAbstractItemView.NoEditTriggers)

        # Binding layout for MainForm and subFrame
        self.setLayout(vbox)
        frame_title.setLayout(hbox_title)
        frame_input.setLayout(grid)
        frame_button.setLayout(hbox_frame_btn)

        # Add widgets for each layout,
        # then it can show widgets in the form which binding the matched layout
        # # set Main Form's layout
        vbox.addWidget(frame_title)
        vbox.addWidget(frame_input)
        vbox.addWidget(frame_button)
        vbox.addWidget(self.tbl)

        # # set sub frame's layout
        zh_en_btn = {
            '生成条目': self.gen_items,
            '清空': self.clear,
            '打印程序': self.print
        }
        for btn_name in zh_en_btn.keys():
            btn = QPushButton(btn_name)
            btn.clicked.connect(zh_en_btn[btn_name])
            hbox_frame_btn.addWidget(btn)
        hbox_frame_btn.addStretch(1)

        positions = [(i, j) for i in range(2) for j in range(n)]
        for control_name, pos in zip(FIELDS2ZH * 2, positions):
            if pos[0] == 0:
                control = QLabel(control_name)
            else:
                control = QLineEdit(control_name, text='100')
            grid.addWidget(control, *pos)  # main add Widget method

        hbox_title.addWidget(self.lbl_ico_title)
        hbox_title.addWidget(self.lbl_title)
        hbox_title.addStretch(1)

        self.move(300, 150)  # (top, left) is the start position
        self.setWindowIcon(self.app_icon)
        self.show()

    def gen_items(self):
        values = []
        flag = True
        for line_edit in self.findChildren(QLineEdit, ''):
            value = line_edit.text()
            if value == '':
                msg = QMessageBox()
                msg.setText('缺少必要信息!')
                msg.setWindowIcon(self.app_icon)
                msg.setWindowTitle('警告')
                msg.exec_()
                line_edit.setFocus()
                flag = False
                break
            values.append(value)
        if flag:
            info = dict(zip(FIELDS, values))
            items = create_items(info)
            print(items)
            self.tbl.setRowCount(len(items))
            row = 0
            for item in items:
                for col in range(len(item)):
                    newItem = QTableWidgetItem(str(item[col]))
                    self.tbl.setItem(row, col, newItem)
                row += 1

    def clear(self):
        for line_edit in self.findChildren(QLineEdit, ''):
            line_edit.setText(None)

    def print(self):
        pass
Beispiel #24
0
 def draw_icon(self, painter: QPainter, rect: QRect, icon: QIcon):
     r = QRect(0, 0, 20, 20)
     r.moveCenter(rect.center())
     painter.drawPixmap(r, icon.pixmap(20, 20))