コード例 #1
0
class RadioButtonGroup(QWidget):
    """创建QButtonGroup,要求传入dict或者tuple"""
    valueChanged = pyqtSignal(int, int)

    def __init__(self, parent=None, datas=None, value=0, textkey="text", valuekey="value", **kwargs):
        super().__init__(parent, **kwargs)
        if datas is not None:
            self.datas = datas
        else:
            self.datas = []
        self.value = value
        self.textkey = textkey
        self.valuekey = valuekey

        self.bg = QButtonGroup(self)
        self.mainLayout = HBoxLayout(self)

        self.bg.buttonClicked[int].connect(self.buttonClicked)

        self._addRadioButtons(self.datas)

    def buttonClicked(self, value):
        oldvalue = self.value
        self.value = value  # self.bg.checkedId()也可以获得value
        if oldvalue != value:
            self.valueChanged.emit(value, oldvalue)

    def _getDataText(self, data):
        if isinstance(data, tuple):
            return data[1]
        elif isinstance(data, dict):
            return data.get(self.textkey)
        else:
            raise Exception("need dict or tuple")

    def _getDataValue(self, data):
        if isinstance(data, tuple):
            return data[0]
        elif isinstance(data, dict):
            return data.get(self.valuekey)
        else:
            raise Exception("need dict or tuple")

    def _addRadioButtons(self, datas):
        if not datas:
            return

        for data in datas:
            text = self._getDataText(data)
            value = self._getDataValue(data)
            rb = QRadioButton(text)
            self.bg.addButton(rb, value)
            if self.value == value:
                rb.setChecked(True)
            self.mainLayout.addWidget(rb)
        self.mainLayout.addStretch(1)
コード例 #2
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.hexIn = 10
        self.hexInList = [{
            'value': 2,
            'text': '2进制'
        }, {
            'value': 8,
            'text': '8进制'
        }, {
            'value': 10,
            'text': '10进制'
        }, {
            'value': 16,
            'text': '16进制'
        }]
        self.hexOutList = [{
            'value': 2,
            'text': '2进制'
        }, {
            'value': 8,
            'text': '8进制'
        }, {
            'value': 10,
            'text': '10进制'
        }, {
            'value': 16,
            'text': '16进制'
        }]

        self.mainLayout = VBoxLayout(self.frame)
        self.mainLayout.setContentsMargins(20, 10, 0, 0)
        self.mainLayout.setSpacing(10)

        self.inRadioLayout = self.getInRadioLayout()
        self.mainLayout.addLayout(self.inRadioLayout)

        self.inputLayout = HBoxLayout()
        self.inputLayout.setSpacing(10)
        self.input = QLineEdit(self)
        self.input.setMinimumWidth(240)
        self.inputLayout.addWidget(self.input)
        self.transformSubmitButton = QPushButton("转换")
        self.inputLayout.addWidget(self.transformSubmitButton)
        self.inputLayout.addStretch(1)

        self.mainLayout.addLayout(self.inputLayout)

        self.resultTable = self.getResultTable()
        self.mainLayout.addWidget(self.resultTable)

        self.mainLayout.addStretch(1)

        self.transformSubmitButton.clicked.connect(self.transform)
コード例 #3
0
    def __init__(self, parent=None, datas=None, value=0, textkey="text", valuekey="value", **kwargs):
        super().__init__(parent, **kwargs)
        if datas is not None:
            self.datas = datas
        else:
            self.datas = []
        self.value = value
        self.textkey = textkey
        self.valuekey = valuekey

        self.bg = QButtonGroup(self)
        self.mainLayout = HBoxLayout(self)

        self.bg.buttonClicked[int].connect(self.buttonClicked)

        self._addRadioButtons(self.datas)
コード例 #4
0
ファイル: SqlJavaCodeWidget.py プロジェクト: lukoou3/Toolbox
    def __init__(self, parent=None):
        super().__init__(parent)

        self.sqlInTextEdit = QPlainTextEdit()
        self.javaInTextEdit = QPlainTextEdit()
        self.tableNameLineEdit = QLineEdit(minimumWidth=240)
        self.tableNameLineEdit.setText("table_name")
        self.dataNameLineEdit = QLineEdit(minimumWidth=240)
        self.dataNameLineEdit.setText("data")
        self.paramNameLineEdit = QLineEdit(minimumWidth=240)
        self.paramNameLineEdit.setText("param")
        self.outSqlTypeRadioGroup = RadioButtonGroup(datas=[{
            "value": 1,
            "text": "jdbc"
        }, {
            "value": 2,
            "text": "mybatis"
        }],
                                                     value=1,
                                                     maximumWidth=200)
        self.execButton = QPushButton("execute(执行)", maximumWidth=100)
        self.resultTextEdit = LineTextEdit()

        mainLayout = QVBoxLayout(self)
        mainLayout.addLayout(
            HBoxLayout(
                widgets=[QLabel("sql:"), QLabel("java:")]))
        mainLayout.addLayout(
            HBoxLayout(widgets=[self.sqlInTextEdit, self.javaInTextEdit]), 2)
        mainLayout.addLayout(
            HBoxLayout(widgets=[
                QLabel("tableName:"), self.tableNameLineEdit,
                LayStretch(1),
                QLabel("dataName:"), self.dataNameLineEdit,
                LayStretch(1),
                QLabel("paramName:"), self.paramNameLineEdit,
                LayStretch(1)
            ]))
        mainLayout.addLayout(
            HBoxLayout(widgets=[
                QLabel("输出sql类型:"), self.outSqlTypeRadioGroup,
                LayStretch(1)
            ]))
        mainLayout.addWidget(self.execButton)
        mainLayout.addWidget(self.resultTextEdit, 7)

        self.registerSignalConnect()
コード例 #5
0
    def getInRadioLayout(self):
        inRadioLayout = HBoxLayout()
        inRadioLayout.setSpacing(10)

        bg1 = QButtonGroup(self)
        for item in self.hexInList:
            rb11 = QRadioButton(item['text'])
            bg1.addButton(rb11, item['value'])
            if self.hexIn == item['value']:
                rb11.setChecked(True)
            inRadioLayout.addWidget(rb11)
        inRadioLayout.addStretch(1)
        """
        buttonClicked(self, QAbstractButton) [signal]
        buttonClicked(self, int) [signal]
        """
        bg1.buttonClicked[int].connect(lambda x: setattr(self, 'hexIn', x))
        # 也能获得选中的值
        # print(bg1.checkedId())

        return inRadioLayout
コード例 #6
0
ファイル: FileRenameWidget.py プロジェクト: lukoou3/Toolbox
    def __init__(self, parent=None, **kwargs):
        super().__init__(parent, **kwargs)
        self.fileDir = ""
        self.fileDragList = []
        self.fileList = []
        self.filterRe = ""
        self.dirDeepSearch = False
        self.filterUseRe = False
        self.replaceUseRe = False

        self.fileDirLineEdit = FileOpenDirLineEdit()
        self.dirDeepSearchCheckBox = QCheckBox("递归搜素目录")
        self.filterReLineEdit = QLineEdit(minimumWidth=240)
        self.filterUseReCheckBox = QCheckBox("使用re")
        self.replaceTmpBtn = QPushButton("模板")#"<span style='color:blue'>模板</span>"
        self.replaceOldLineEdit = QLineEdit(minimumWidth=240)
        self.replaceNewLineEdit = QLineEdit(minimumWidth=240)
        self.replaceUseReCheckBox = QCheckBox("使用re")
        self.execButton = QPushButton("execute(执行)", maximumWidth=100)
        self.replacePromptLabel = QLabel()
        self.fileListText = DragLineTextEdit()

        gridLayout = GridLayout(self, contentsMargins=(10, 10, 10, 10), spacing=10)
        replaceLayout = HBoxLayout(contentsMargins=(0, 10, 10, 10), spacing=10,
                            widgets=[self.replaceOldLineEdit, QLabel("替换成"), self.replaceNewLineEdit,
                                     self.replaceUseReCheckBox, self.replaceTmpBtn,LayStretch(1)])
        glWidgets = [
            [GLItem(QLabel("目录:"), 1, 2), GLItem(self.fileDirLineEdit, 1, 4), GLItem(self.dirDeepSearchCheckBox, 1, 2),GLItem(QWidget(), 1, -1)],
            [GLItem(QLabel("过滤字符串:"), 1, 2), GLItem(self.filterReLineEdit, 1, 3), GLItem(self.filterUseReCheckBox, 1, 2),GLItem(QWidget(), 1, 3)],
            [GLItem(QLabel("替换:"), 1, 2),GLItem(replaceLayout, 1, -1)],
            [GLItem(self.execButton, 1, 2), GLItem(self.replacePromptLabel, 1, -1)],
            [GLItem(self.fileListText, 1, -1)]
        ]
        gridLayout.addWidgets(glWidgets)

        self.replaceTmpWidget = QListWidget(self)
        self.replaceTmpList = [{"text":"添加后缀","name":"add_suffix"}]
        self.replaceTmpWidget.addItems(replaceTmp['text'] for replaceTmp in self.replaceTmpList)
        self.replaceTmpWidget.resize(100, 300)
        self.replaceTmpWidget.hide()

        # 注册事件
        self.registerSignalConnect()
コード例 #7
0
    def __init__(self, parent=None, **kwargs):
        super().__init__(parent, **kwargs)
        self.displayParam = DisplayParam()

        pageSizeCombobox = ComboBox(
            self, datas=map(str, [10, 20, 50, 100, 200]),
            maximumWidth=60)  # maximumWidth=300, minimumWidth=200
        self.pageSizeCombobox = pageSizeCombobox

        preButton = QPushButton(toolTip="pre")
        #preButton.setToolTip("1111")
        preButton.setFixedSize(26, 26)
        preButton.setStyleSheet(
            "QPushButton{border-image: url(icon/page_pre.png)}")
        self.preButton = preButton

        nextButton = QPushButton(toolTip="next")
        nextButton.setFixedSize(26, 26)
        nextButton.setStyleSheet(
            "QPushButton{border-image: url(icon/page_next.png)}")
        self.nextButton = nextButton

        pageInput = QLineEdit(maximumWidth=35)
        self.pageInput = pageInput

        pageJumpBtn = QPushButton("确定")
        self.pageJumpBtn = pageJumpBtn

        descLabel = QLabel("")
        self.descLabel = descLabel

        pageButtons = []
        self.pageButtons = pageButtons
        for i in range(1, 10):
            pageButton = QPushButton(str(i))
            pageButton.setObjectName("page_{}".format(i))
            #可以通过ObjectName找到元素
            # print(self.findChild(QPushButton, "page_1").text())
            pageButton.setFixedSize(26, 26)
            pageButton.hide()
            pageButtons.append(pageButton)

        mainLayout = HBoxLayout(self,
                                contentsMargins=(10, 5, 10, 5),
                                spacing=10)
        mainLayout.addWidget(pageSizeCombobox)
        mainLayout.addWidget(preButton)
        mainLayout.addWidgets(pageButtons)
        mainLayout.addWidget(nextButton)
        mainLayout.addText("到")
        mainLayout.addWidget(pageInput)
        mainLayout.addText("页")
        mainLayout.addWidget(pageJumpBtn)
        mainLayout.addStretch(1)
        mainLayout.addWidget(descLabel)
        mainLayout.addSpacing(30)

        self.registerSignal()
        #通过下面的方式防止初始化Combobox参数时触发信号
        pageSizeCombobox.blockSignals(True)
        pageSizeCombobox.setCurrentText(str(self.displayParam.pageSize))
        pageSizeCombobox.blockSignals(False)
コード例 #8
0
class HexConvertWidget(ScrollArea):
    """https://tool.lu/hexconvert"""
    def __init__(self, parent=None):
        super().__init__(parent)
        self.hexIn = 10
        self.hexInList = [{
            'value': 2,
            'text': '2进制'
        }, {
            'value': 8,
            'text': '8进制'
        }, {
            'value': 10,
            'text': '10进制'
        }, {
            'value': 16,
            'text': '16进制'
        }]
        self.hexOutList = [{
            'value': 2,
            'text': '2进制'
        }, {
            'value': 8,
            'text': '8进制'
        }, {
            'value': 10,
            'text': '10进制'
        }, {
            'value': 16,
            'text': '16进制'
        }]

        self.mainLayout = VBoxLayout(self.frame)
        self.mainLayout.setContentsMargins(20, 10, 0, 0)
        self.mainLayout.setSpacing(10)

        self.inRadioLayout = self.getInRadioLayout()
        self.mainLayout.addLayout(self.inRadioLayout)

        self.inputLayout = HBoxLayout()
        self.inputLayout.setSpacing(10)
        self.input = QLineEdit(self)
        self.input.setMinimumWidth(240)
        self.inputLayout.addWidget(self.input)
        self.transformSubmitButton = QPushButton("转换")
        self.inputLayout.addWidget(self.transformSubmitButton)
        self.inputLayout.addStretch(1)

        self.mainLayout.addLayout(self.inputLayout)

        self.resultTable = self.getResultTable()
        self.mainLayout.addWidget(self.resultTable)

        self.mainLayout.addStretch(1)

        self.transformSubmitButton.clicked.connect(self.transform)

    def getInRadioLayout(self):
        inRadioLayout = HBoxLayout()
        inRadioLayout.setSpacing(10)

        bg1 = QButtonGroup(self)
        for item in self.hexInList:
            rb11 = QRadioButton(item['text'])
            bg1.addButton(rb11, item['value'])
            if self.hexIn == item['value']:
                rb11.setChecked(True)
            inRadioLayout.addWidget(rb11)
        inRadioLayout.addStretch(1)
        """
        buttonClicked(self, QAbstractButton) [signal]
        buttonClicked(self, int) [signal]
        """
        bg1.buttonClicked[int].connect(lambda x: setattr(self, 'hexIn', x))
        # 也能获得选中的值
        # print(bg1.checkedId())

        return inRadioLayout

    def getResultTable(self):
        resultTable = QTableWidget()
        resultTable.setMaximumWidth(600)
        resultTable.setMinimumHeight(200)
        # resultTable.horizontalHeader().setStyleSheet("QHeaderView::section{background:#F3F3F3;}")
        self.setStyleSheet("QTableWidget{border:0 none;//最外层边框}")
        resultTable.verticalHeader().setVisible(False)  # 隐藏行号
        resultTable.setAlternatingRowColors(True)
        resultTable.setColumnCount(2)
        # 注意必须在初始化行列之后进行,否则,没有效果
        resultTable.setHorizontalHeaderLabels(['进制', '结果'])
        # 设置可以自适应宽度
        resultTable.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        # 设置可以自定义宽度
        resultTable.horizontalHeader().setSectionResizeMode(
            0, QHeaderView.Interactive)
        # QTableWidget的一些配置“https://blog.csdn.net/vah101/article/details/6215066”
        resultTable.setEditTriggers(QTableView.NoEditTriggers)  # 不可编辑
        resultTable.setSelectionMode(QAbstractItemView.NoSelection)  # 设置不能选中
        # resultTable.setSelectionBehavior(QAbstractItemView.SelectItems)  # 设置只能选中单元格
        # resultTable.setSelectionMode(QAbstractItemView.SingleSelection)  # 设置只能选中一行
        # resultTable.setSelectionBehavior(QAbstractItemView.SelectRows)  # 设置只有行选中
        resultTable.setColumnWidth(0, 50)

        # 可以设置tableview所有列的默认行高
        resultTable.verticalHeader().setDefaultSectionSize(40)

        resultTable.setRowCount(4)
        for i, data in enumerate(self.hexOutList):
            item = QTableWidgetItem(str(data['value']))
            resultTable.setItem(i, 0, item)
            lineEdit = QLineEdit()
            lineEdit.setContentsMargins(5, 5, 30, 5)
            lineEdit.setObjectName("rst_text_hex{}".format(data['value']))
            resultTable.setCellWidget(i, 1, lineEdit)

        return resultTable

    def transform(self):
        hexIn = self.hexIn
        text = self.input.text()
        num = int(text, hexIn)

        for data in self.hexOutList:
            hexOut = data['value']
            if hexOut == 2:
                rst = bin(num)[2:]
            elif hexOut == 8:
                rst = oct(num)[2:]
            elif hexOut == 10:
                rst = str(num)
            elif hexOut == 16:
                rst = hex(num)[2:]
            else:
                rst = util.hex_convert(num, hexOut)
            self.resultTable.findChild(
                QLineEdit, "rst_text_hex{}".format(hexOut)).setText(rst)
コード例 #9
0
    def __init__(self, parent=None, width=500, hight=300):
        super().__init__(parent)
        self.setWindowTitle("导出")
        self.resize(width, hight)

        self.labl1 = QLabel("文件类型:")
        self.fileTypeComboBox = ComboBox(datas=[{
            "id": 1,
            "text": "csv"
        }, {
            "id": 2,
            "text": "excel"
        }],
                                         maximumWidth=200)
        self.labl2 = QLabel("文件保存路径:")
        self.pathLineEdit = FileSaveLineEdit(filter="Text files (*.csv)",
                                             maximumWidth=300)
        self.pathLineEdit.setPlaceholderText("输入或者选择路径")

        self.confirmButton = QPushButton("确定", maximumWidth=100)
        self.cancelButton = QPushButton("取消", maximumWidth=100)

        mainLayout = VBoxLayout(self,
                                contentsMargins=(10, 10, 10, 10),
                                spacing=10)

        fromlayout = QFormLayout()
        fromlayout.addRow(self.labl1, self.fileTypeComboBox)
        fromlayout.addRow(self.labl2, self.pathLineEdit)

        submitLayout = HBoxLayout(contentsMargins=(10, 10, 10, 10), spacing=10)
        submitLayout.addStretch(1)
        submitLayout.addWidget(self.confirmButton)
        submitLayout.addSpacing(20)
        submitLayout.addWidget(self.cancelButton)
        submitLayout.addStretch(1)

        fromlayout.setLayout(2, QFormLayout.SpanningRole, submitLayout)

        mainLayout.addLayout(fromlayout)

        self.fileTypeComboBox.currentIndexChanged.connect(self.fileTypeChanged)
        self.confirmButton.clicked.connect(self.accept)
        self.cancelButton.clicked.connect(self.reject)
コード例 #10
0
ファイル: DbSettingDialog.py プロジェクト: lukoou3/Toolbox
    def __init__(self,
                 parent=None,
                 width=400,
                 hight=250,
                 host="localhost",
                 port=3306,
                 user="******",
                 passwd="123456",
                 db="test",
                 charset="utf8"):
        super().__init__(parent)
        self.setWindowTitle("db设置")
        self.resize(width, hight)

        self.host = host
        self.port = port
        self.db = db
        self.user = user
        self.passwd = passwd
        self.charset = charset

        self.hostLineEdit = QLineEdit(self.host, maximumWidth=260)
        self.portLineEdit = QLineEdit(str(self.port), maximumWidth=260)
        self.dbLineEdit = QLineEdit(self.db, maximumWidth=260)
        self.userLineEdit = QLineEdit(self.user, maximumWidth=260)
        self.passwdLineEdit = QLineEdit(self.passwd, maximumWidth=260)
        self.charsetLineEdit = QLineEdit(self.charset, maximumWidth=260)
        self.confirmButton = QPushButton("确定", maximumWidth=100)
        self.cancelButton = QPushButton("取消", maximumWidth=100)

        fromlayout = QFormLayout(self)
        fromlayout.addRow("host:", self.hostLineEdit)
        fromlayout.addRow("port:", self.portLineEdit)
        fromlayout.addRow("db:", self.dbLineEdit)
        fromlayout.addRow("user:", self.userLineEdit)
        fromlayout.addRow("passwd:", self.passwdLineEdit)
        fromlayout.addRow("charset:", self.charsetLineEdit)

        submitLayout = HBoxLayout(contentsMargins=(10, 10, 10, 10), spacing=10)
        submitLayout.addStretch(1)
        submitLayout.addWidget(self.confirmButton)
        submitLayout.addSpacing(20)
        submitLayout.addWidget(self.cancelButton)
        submitLayout.addStretch(1)

        fromlayout.addRow(submitLayout)

        self.confirmButton.clicked.connect(self.accept)
        self.cancelButton.clicked.connect(self.reject)