Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新组件提议:InputDialog(已实现完整功能) #862

Closed
abcdesteve opened this issue May 2, 2024 · 1 comment
Closed

新组件提议:InputDialog(已实现完整功能) #862

abcdesteve opened this issue May 2, 2024 · 1 comment

Comments

@abcdesteve
Copy link

没用过PR就不直接提交了
先放效果
image
image
应该还算符合fluent design
下面使用了EditableComboBox,可以手动传参,决定是否允许自行填写
实现代码

class InputDialog(MaskDialogBase, Ui_Input_dialog):
    def __init__(self):
        pass

    def run(self, parent, title: str, content: str, options: list[str] = [], editable: bool = True) -> str:
        '''
        Receive an optional argv `options` which will be shown in the `ComboBox`\n
        Return input txt
        '''
        super().__init__(parent)
        self.setupUi(self.widget)
        self.widget.setFixedSize(360, 220)
        FluentStyleSheet.DIALOG.apply(self)
        self.setWindowFlag(Qt.WindowType.WindowStaysOnTopHint, True)

        self.btn_cancel.setShortcut('Alt+N')
        self.btn_ok.setShortcut('Alt+Y')
        self.btn_cancel.clicked.connect(self.cancel)
        self.btn_ok.clicked.connect(self.ok)
        self.title.setText(title)
        self.content.setText(content)
        # 这是一个自用的工具集, 在最下面贴出了最小代码
        sltk.unique_add_items(self.comboBox, options, format_item=False)
        self.comboBox.setReadOnly(not editable)
        # self.show()
        self.exec()
        return self.comboBox.currentText() if self.status else None

    def cancel(self):
        self.status = False
        self.close()

    def ok(self):
        self.status = True
        self.close()


class sltk():
    def unique_add_items(widget: QComboBox | ComboBox | QListWidget | ListWidget, *items: str | list[str], format_item: bool = True):
        '''为ComboBox不重复地添加一个或多个item,同时格式化路径(如果可以)'''
        previous_items = [(widget.itemText(i) if type(widget) in [
                           QComboBox, ComboBox]else widget.item(i).text()) for i in range(widget.count())]
        if type(items[0]) == list:
            items = items[0]
        for i in items:
            if format_item:
                i = os.path.realpath(i)
            if i not in previous_items:
                widget.addItem(i)

ui文件
input_dialog.zip

@abcdesteve abcdesteve changed the title 新组建提议:InputDialog(已实现完整功能) 新组件提议:InputDialog(已实现完整功能) May 2, 2024
@rainzee
Copy link
Contributor

rainzee commented May 3, 2024

感觉这个还是用 MessageBox Base 让用户自己来实现比较好,WinUI 组件库中也只提供 ContentDialog

@zhiyiYo zhiyiYo closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants