======================== CODE SNIPPETS ======================== TITLE: Using LabelExample Widget DESCRIPTION: Demonstrates the basic application setup required to run a dayu_widgets example like LabelExample. It initializes a Qt application, creates the example widget, applies the custom Dayu theme, and displays the widget. Requires dayu_widgets.dayu_theme and dayu_widgets.qt.application. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_8 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = LabelExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Running Dayu Widgets Application - Python DESCRIPTION: This snippet demonstrates the basic application setup using `dayu_widgets.qt.application`. It initializes a specific widget (e.g., MenuExample), applies the global Dayu theme using `dayu_theme.apply()`, and shows the main widget window. This context manager ensures proper application lifecycle management. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_18 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = MenuExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Running PushButtonExample Application (Python) DESCRIPTION: Demonstrates the basic application setup using `dayu_widgets.qt.application` to run and display the `PushButtonExample` widget with the dayu theme applied. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_29 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = PushButtonExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Initializing Page Example Application - Python DESCRIPTION: Sets up and runs a basic PyQt application to display the PageExample widget, applying the dayu_widgets theme. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_24 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = PageExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Running ProgressCircleExample Application (Python) DESCRIPTION: Demonstrates the basic application setup using `dayu_widgets.qt.application` to run and display the `ProgressCircleExample` widget with the dayu theme applied. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_27 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = ProgressCircleExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Running PushButtonGroupExample Application (Python) DESCRIPTION: Demonstrates the basic application setup using `dayu_widgets.qt.application` to run and display the `PushButtonGroupExample` widget with the dayu theme applied. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_30 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = PushButtonGroupExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Running ThemeExample Application Python DESCRIPTION: Provides the standard entry point code for running the `ThemeExample` example. It initializes the Qt application using a context manager, creates an instance of the example widget, applies the `dayu_theme`, and displays the widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_47 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = ThemeExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Using ToolButton Example Widget in Python DESCRIPTION: Example showing the basic instantiation and display of the ToolButtonExample widget. It demonstrates the typical pattern for running a Dayu Widgets example: importing necessary modules, creating a QApplication instance, initializing the widget, applying the Dayu theme, and showing the widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_50 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = ToolButtonExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Initializing ItemViewSetExample UI DESCRIPTION: Initializes various MItemViewSet types (Table, List, Tree, Big, Searchable Tree) and configures their headers. It sets up buttons for search/expand/collapse and refresh, arranges them in a QVBoxLayout with dividers, and prepares data binding and initial data setup. Requires dayu_widgets.MItemViewSet, dayu_widgets.MPushButton, dayu_widgets.MDivider, and QtWidgets. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_7 LANGUAGE: Python CODE: ``` item_view_set_table = MItemViewSet(view_type=MItemViewSet.TableViewType) item_view_set_table.set_header_list(mock.header_list) item_view_set_list = MItemViewSet(view_type=MItemViewSet.ListViewType) item_view_set_list.set_header_list(mock.header_list) item_view_set_tree = MItemViewSet(view_type=MItemViewSet.TreeViewType) item_view_set_tree.set_header_list(mock.header_list) item_view_set_thumbnail = MItemViewSet(view_type=MItemViewSet.BigViewType) item_view_set_thumbnail.set_header_list(mock.header_list) item_view_set_search = MItemViewSet(view_type=MItemViewSet.TreeViewType) item_view_set_search.set_header_list(mock.header_list) item_view_set_search.searchable() expand_button = MPushButton("Expand All") expand_button.clicked.connect(item_view_set_search.item_view.expandAll) coll_button = MPushButton("Collapse All") coll_button.clicked.connect(item_view_set_search.item_view.collapseAll) item_view_set_search.insert_widget(coll_button) item_view_set_search.insert_widget(expand_button) refresh_button = MPushButton("Refresh Data") refresh_button.clicked.connect(self.slot_update_data) main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("Table View")) main_lay.addWidget(refresh_button) main_lay.addWidget(item_view_set_table) main_lay.addWidget(MDivider("List View")) main_lay.addWidget(item_view_set_list) main_lay.addWidget(MDivider("Tree View")) main_lay.addWidget(item_view_set_tree) main_lay.addWidget(MDivider("Big View")) main_lay.addWidget(item_view_set_thumbnail) main_lay.addWidget(MDivider("With Search line edit")) main_lay.addWidget(item_view_set_search) main_lay.addStretch() self.setLayout(main_lay) item_view_set_tree.setup_data(mock.tree_data_list) item_view_set_search.setup_data(mock.tree_data_list) self.view_list = [ item_view_set_table, item_view_set_list, item_view_set_thumbnail, ] self.bind( "item_view_set_example_header_state", item_view_set_table.item_view.header_view, "state", ) self.slot_update_data() ``` ---------------------------------------- TITLE: Running TableViewExample Application Python DESCRIPTION: Shows the standard boilerplate for running a `dayu_widgets` example application using the `dayu_widgets.qt.application` context manager. It initializes the QApplication, creates an instance of `TableViewExample`, applies the `dayu_theme`, and shows the main window. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_41 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets.qt import application with application() as app: test = TableViewExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Initializing Message Example Application - Python DESCRIPTION: Sets up and runs a basic PyQt application to display the MessageExample widget, applying the dayu_widgets theme. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_22 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = MessageExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Running MTabWidgetTest Application Python DESCRIPTION: Provides the standard entry point code for running the `MTabWidgetTest` example. It initializes the Qt application using a context manager, creates an instance of the example widget, applies the `dayu_theme`, and displays the widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_43 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = MTabWidgetTest() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Initializing MenuTabWidget Example Application - Python DESCRIPTION: Sets up and runs a basic PyQt application to display the MenuTabWidgetExample, applying the dayu_widgets theme for consistent styling. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_20 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = MenuTabWidgetExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Using ToolButtonGroup Example Widget in Python DESCRIPTION: Example showing the basic instantiation and display of the ToolButtonGroupExample widget. It follows the typical pattern for running a Dayu Widgets example: importing necessary modules, creating a QApplication instance, initializing the widget, applying the Dayu theme, and showing the widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_52 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = ToolButtonGroupExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Running TextEditExample Application Python DESCRIPTION: Provides the standard entry point code for running the `TextEditExample` example. It initializes the Qt application using a context manager, creates an instance of the example widget, applies the `dayu_theme`, and displays the widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_45 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = TextEditExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Running ListViewExample Application - Python DESCRIPTION: Initializes a Qt application context using dayu_widgets.qt.application, creates an instance of the ListViewExample widget, applies the dayu_theme for styling, and displays the main window. This is a typical entry point for dayu_widgets example applications. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_14 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = ListViewExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Run dayu_widgets Examples via Python DESCRIPTION: This command runs the example program for dayu_widgets directly as a Python module. It requires a Qt environment (like PySide2 or PyQt5) to be already installed in your Python environment. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` python -m dayu_widgets ``` ---------------------------------------- TITLE: Initializing SequenceFileExample UI Python DESCRIPTION: This snippet illustrates the UI setup for the `SequenceFileExample` widget. It includes adding a `MDragFileButton` to allow file selection or drag-and-drop, setting file filters, connecting a signal for file changes, and integrating a `MSequenceFile` widget into the layout. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_35 LANGUAGE: python CODE: ``` browser = MDragFileButton(text="Click or drag files") browser.set_dayu_filters([".py", "pyc", ".jpg", ".mov", "exr"]) browser.sig_file_changed.connect(self.slot_add_file) self.sequence_file_1 = MSequenceFile() main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("different size")) main_lay.addWidget(browser) main_lay.addWidget(self.sequence_file_1) main_lay.addStretch() self.setLayout(main_lay) @QtCore.Slot(str) ``` ---------------------------------------- TITLE: Running LoadingExample Application - Python (Partial) DESCRIPTION: Begins the initialization of a Qt application context using dayu_widgets.qt.application and creates an instance of the LoadingExample widget. It sets up the basic structure for applying the theme and showing the widget, although the snippet is incomplete. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_16 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = LoadingExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Install dayu_widgets Python DESCRIPTION: This command installs the dayu_widgets library using pip, the standard package installer for Python. This is the primary method to get the library into your Python environment. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` pip install dayu_widgets ``` ---------------------------------------- TITLE: Initializing ToolButton Example UI in Python DESCRIPTION: Example of how to initialize and configure the UI for a ToolButtonExample widget. It demonstrates various features of MToolButton, including different sizes, enabling/disabling, checkable state, icon-only display, and text-beside-icon display, arranging them using QVBoxLayout and QHBoxLayout. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_51 LANGUAGE: Python CODE: ``` size_lay = QtWidgets.QVBoxLayout() sub_lay1 = QtWidgets.QHBoxLayout() sub_lay1.addWidget(MToolButton().svg("left_line.svg").icon_only().huge()) sub_lay1.addWidget(MToolButton().svg("right_line.svg").icon_only().large()) sub_lay1.addWidget(MToolButton().svg("up_line.svg").icon_only()) sub_lay1.addWidget(MToolButton().svg("up_line.svg").icon_only().small()) sub_lay1.addWidget(MToolButton().svg("down_line.svg").icon_only().tiny()) custom_size = MToolButton().svg("left_line.svg").icon_only() custom_size.set_dayu_size(200) custom_size.setToolTip("Custom Size 200") sub_lay1.addStretch() size_lay.addLayout(sub_lay1) size_lay.addWidget(custom_size) button2 = MToolButton().svg("detail_line.svg").icon_only() button2.setEnabled(False) button7 = MToolButton().svg("bold.svg").icon_only() button7.setCheckable(True) state_lay = QtWidgets.QHBoxLayout() state_lay.addWidget(button2) state_lay.addWidget(button7) state_lay.addStretch() button_trash = MToolButton().svg("trash_line.svg").text_beside_icon() button_trash.setText("Delete") button_login = MToolButton().svg("user_line.svg").text_beside_icon() button_login.setText("Login") button_lay = QtWidgets.QHBoxLayout() button_lay.addWidget(button_trash) button_lay.addWidget(button_login) main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("different button_size")) main_lay.addLayout(size_lay) main_lay.addWidget(MDivider("disabled & checkable")) main_lay.addLayout(state_lay) main_lay.addWidget(MDivider("type=normal")) main_lay.addLayout(button_lay) main_lay.addStretch() self.setLayout(main_lay) ``` ---------------------------------------- TITLE: Running LineTabWidgetExample Application - Python DESCRIPTION: Initializes a Qt application context using dayu_widgets.qt.application, creates an instance of the LineTabWidgetExample widget, applies the dayu_theme for styling, and displays the main window. Follows the standard pattern for dayu_widgets examples. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_12 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = LineTabWidgetExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Initializing Toast Example UI in Python DESCRIPTION: Example of how to initialize and configure the UI for a ToastExample widget, demonstrating different message types (normal, success, warning, error, loading) using MPushButton and MToast widgets from the dayu_widgets library. It arranges buttons using QHBoxLayout and QVBoxLayout. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_49 LANGUAGE: Python CODE: ``` button3 = MPushButton(text="Normal Message").primary() button4 = MPushButton(text="Success Message").success() button5 = MPushButton(text="Warning Message").warning() button6 = MPushButton(text="Error Message").danger() button3.clicked.connect( functools.partial(self.slot_show_message, MToast.info, {"text": "好像没啥用"}) ) button4.clicked.connect( functools.partial(self.slot_show_message, MToast.success, {"text": "领取成功"}) ) button5.clicked.connect( functools.partial(self.slot_show_message, MToast.warning, {"text": "暂不支持"}) ) button6.clicked.connect( functools.partial( self.slot_show_message, MToast.error, {"text": "支付失败,请重试"} ) ) sub_lay1 = QtWidgets.QHBoxLayout() sub_lay1.addWidget(button3) sub_lay1.addWidget(button4) sub_lay1.addWidget(button5) sub_lay1.addWidget(button6) loading_button = MPushButton("Loading Toast").primary() loading_button.clicked.connect(self.slot_show_loading) main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("different type")) main_lay.addLayout(sub_lay1) main_lay.addWidget(MLabel("不同的提示状态:成功、失败、加载中。默认2秒后消失")) main_lay.addWidget(loading_button) main_lay.addStretch() self.setLayout(main_lay) ``` ---------------------------------------- TITLE: Running LineEditExample Application - Python DESCRIPTION: Initializes a Qt application context using dayu_widgets.qt.application, creates an instance of the LineEditExample widget, applies the dayu_theme for styling, and displays the main window. This is a typical entry point for dayu_widgets example applications. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_10 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = LineEditExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Using ComboBoxExample Widget DESCRIPTION: Sets up a QApplication and displays the ComboBoxExample widget from the dayu_widgets library, applying the default dayu_theme. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_1 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = ComboBoxExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Using SpinBoxExample Widget Python DESCRIPTION: This snippet shows how to run the `SpinBoxExample` widget from the `dayu_widgets` library by initializing a Qt application, applying the theme, and showing the example widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_38 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = SpinBoxExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Installing dayu_widgets with pip (Shell) DESCRIPTION: This command installs the dayu_widgets PySide UI library using the Python package installer, pip. It downloads and installs the library and its dependencies from PyPI. Requires a Python environment with pip installed. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/docs/README.md#_snippet_0 LANGUAGE: shell CODE: ``` pip install dayu_widgets ``` ---------------------------------------- TITLE: Initializing ComboBoxExample UI DESCRIPTION: Example of how to initialize and configure the UI for ComboBoxExample widget. It demonstrates creating MComboBox widgets with different sizes and data sources (using MMenu), and binding their values to fields. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_2 LANGUAGE: Python CODE: ``` cities = ["北京", "上海", "广州", "深圳"] self.register_field("button1_selected", "北京") menu1 = MMenu(parent=self) menu1.set_data(cities) size_list = [ ("Large", dayu_theme.large), ("Medium", dayu_theme.medium), ("Small", dayu_theme.small), ] size_lay = QtWidgets.QHBoxLayout() for label, size in size_list: combo_box = MComboBox() combo_box.set_dayu_size(size) combo_box.set_menu(menu1) size_lay.addWidget(combo_box) self.bind( "button1_selected", combo_box, "value", signal="sig_value_changed" ) self.register_field("button2_selected", ["北京"]) menu2 = MMenu(exclusive=False, parent=self) menu2.set_data(cities) select2 = MComboBox() select2.set_menu(menu2) self.bind("button2_selected", select2, "value", signal="sig_value_changed") ``` ---------------------------------------- TITLE: Initializing ToolButtonGroup Example UI in Python DESCRIPTION: Example of how to initialize and configure the UI for a ToolButtonGroupExample widget. It demonstrates creating MToolButtonGroup instances with different configurations, including horizontal and vertical orientation, exclusive and non-exclusive selection modes, adding buttons via lists of dictionaries, and arranging them using QVBoxLayout and QHBoxLayout. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_53 LANGUAGE: Python CODE: ``` tool_group_h = MToolButtonGroup(size=dayu_theme.small) tool_group_h.set_button_list(["Apple", {"text": "Banana"}, {"text": "Pear"}]) tool_1_lay = QtWidgets.QHBoxLayout() tool_1_lay.addWidget(tool_group_h) tool_1_lay.addStretch() app_data = [ {"text": "Maya", "icon": MIcon("app-maya.png"), "checkable": True}, {"text": "Nuke", "icon": MIcon("app-nuke.png"), "checkable": True}, {"text": "Houdini", "icon": MIcon("app-houdini.png"), "checkable": True}, ] tool_group_v = MToolButtonGroup( exclusive=True, size=dayu_theme.small, orientation=QtCore.Qt.Vertical ) tool_group_v.set_button_list(app_data) tool_group_button_h = MToolButtonGroup() tool_group_button_h.set_button_list(app_data) tool_2_lay = QtWidgets.QHBoxLayout() tool_2_lay.addWidget(tool_group_button_h) tool_2_lay.addStretch() tool_grp_excl_true = MToolButtonGroup( orientation=QtCore.Qt.Horizontal, exclusive=True ) tool_grp_excl_true.set_button_list( [ {"svg": "table_view.svg", "checkable": True, "tooltip": "Table View"}, {"svg": "list_view.svg", "checkable": True, "tooltip": "List View"}, {"svg": "tree_view.svg", "checkable": True, "tooltip": "Tree View"}, {"svg": "big_view.svg", "checkable": True, "tooltip": "Big View"}, ] ) tool_grp_excl_true.set_dayu_checked(0) tool_excl_lay = QtWidgets.QHBoxLayout() tool_excl_lay.addWidget(tool_grp_excl_true) tool_excl_lay.addStretch() tool_grp_excl_false = MToolButtonGroup( orientation=QtCore.Qt.Horizontal, exclusive=False ) tool_grp_excl_false.set_button_list( [ {"tooltip": "加粗", "svg": "bold.svg", "checkable": True}, {"tooltip": "倾斜", "svg": "italic.svg", "checkable": True}, {"tooltip": "下划线", "svg": "underline.svg", "checkable": True}, ] ) tool_excl_2_lay = QtWidgets.QHBoxLayout() tool_excl_2_lay.addWidget(tool_grp_excl_false) tool_excl_2_lay.addStretch() main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("orientation=Qt.Horizontal ")) main_lay.addLayout(tool_1_lay) main_lay.addWidget(MDivider("orientation=Qt.Vertical")) main_lay.addWidget(tool_group_v) main_lay.addWidget(MDivider("orientation=Qt.Horizontal")) main_lay.addLayout(tool_2_lay) main_lay.addWidget(MDivider("checkable=True; exclusive=True")) main_lay.addLayout(tool_excl_lay) main_lay.addWidget(MDivider("checkable=True; exclusive=False")) main_lay.addLayout(tool_excl_2_lay) main_lay.addStretch() self.setLayout(main_lay) ``` ---------------------------------------- TITLE: Using SplitterExample Widget Python DESCRIPTION: This snippet demonstrates the basic usage of the `SplitterExample` widget, showing how to import the necessary application context and display the example widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_39 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets.qt import application with application() as app: test = SplitterExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Initializing ProgressBarExample UI (Python) DESCRIPTION: Example of how to initialize and configure various types of `MProgressBar` widgets, including standard, success, error, and auto-coloring versions, and arrange them in different layouts within a `ProgressBarExample` widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_26 LANGUAGE: python CODE: ``` progress_1 = MProgressBar() progress_1.setValue(10) progress_1.setAlignment(QtCore.Qt.AlignCenter) progress_2 = MProgressBar() progress_2.setValue(80) progress_normal = MProgressBar() progress_normal.setValue(30) progress_success = MProgressBar().success() progress_success.setValue(100) progress_error = MProgressBar().error() progress_error.setValue(50) form_lay = QtWidgets.QFormLayout() form_lay.addRow("Primary:", progress_normal) form_lay.addRow("Success:", progress_success) form_lay.addRow("Error:", progress_error) self.progress_count = 0 self.timer = QtCore.QTimer() self.timer.setInterval(10) self.timer.timeout.connect(self.slot_timeout) run_button = MPushButton(text="Run Something") run_button.clicked.connect(self.slot_run) self.auto_color_progress = MProgressBar().auto_color() auto_color_lay = QtWidgets.QVBoxLayout() auto_color_lay.addWidget(run_button) auto_color_lay.addWidget(self.auto_color_progress) main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("Basic")) main_lay.addWidget(progress_1) main_lay.addWidget(progress_2) main_lay.addWidget(MDivider("different type")) main_lay.addLayout(form_lay) main_lay.addWidget(MDivider("auto color")) main_lay.addLayout(auto_color_lay) main_lay.addStretch() self.setLayout(main_lay) ``` ---------------------------------------- TITLE: Initializing LabelExample UI DESCRIPTION: Configures the UI for LabelExample by adding various MLabel instances showcasing different text levels (h1-h4), types (normal, secondary, warning, danger), attributes (mark, code, underline, delete, strong, mixed), elide modes (Left, Middle, Right), and hyperlink capabilities. It also includes a data binding example and arranges all elements using various Qt layout managers and MDivider. Requires dayu_widgets.MLabel, dayu_widgets.MPushButton, dayu_widgets.MDivider, QtCore.Qt, and QtWidgets. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_9 LANGUAGE: Python CODE: ``` title_lay = QtWidgets.QGridLayout() title_lay.addWidget(MLabel("一级标题").h1(), 0, 0) title_lay.addWidget(MLabel("二级标题").h2(), 1, 0) title_lay.addWidget(MLabel("三级标题").h3(), 2, 0) title_lay.addWidget(MLabel("四级标题").h4(), 3, 0) title_lay.addWidget(MLabel("h1 Level").h1(), 0, 1) title_lay.addWidget(MLabel("h2 Level").h2(), 1, 1) title_lay.addWidget(MLabel("h3 Level").h3(), 2, 1) title_lay.addWidget(MLabel("h4 Level").h4(), 3, 1) text_type_lay = QtWidgets.QHBoxLayout() text_type_lay.addWidget(MLabel("MLabel: Normal")) text_type_lay.addWidget(MLabel("MLabel: Secondary").secondary()) text_type_lay.addWidget(MLabel("MLabel: Warning").warning()) text_type_lay.addWidget(MLabel("MLabel: Danger").danger()) disable_text = MLabel("MLabel: Disabled") disable_text.setEnabled(False) text_type_lay.addWidget(disable_text) text_attr_lay = QtWidgets.QHBoxLayout() text_attr_lay.addWidget(MLabel("MLabel: Mark").mark()) text_attr_lay.addWidget(MLabel("MLabel: Code").code()) text_attr_lay.addWidget(MLabel("MLabel: Underline").underline()) text_attr_lay.addWidget(MLabel("MLabel: Delete").delete()) text_attr_lay.addWidget(MLabel("MLabel: Strong").strong()) text_mix_lay = QtWidgets.QHBoxLayout() text_mix_lay.addWidget( MLabel("MLabel: Strong & Underline").strong().underline() ) text_mix_lay.addWidget(MLabel("MLabel: Danger & Delete").danger().delete()) text_mix_lay.addWidget(MLabel("MLabel: Warning & Strong").warning().strong()) text_mix_lay.addWidget(MLabel("MLabel: H4 & Mark").h4().mark()) data_bind_lay = QtWidgets.QHBoxLayout() data_bind_label = MLabel() button = MPushButton(text="Random An Animal").primary() button.clicked.connect(self.slot_change_text) data_bind_lay.addWidget(data_bind_label) data_bind_lay.addWidget(button) data_bind_lay.addStretch() self.register_field("show_text", "Guess") self.bind("show_text", data_bind_label, "text") lay_elide = QtWidgets.QVBoxLayout() label_none = MLabel( "This is a elide NONE mode label. " "Ellipsis should NOT appear in the text." ) label_left = MLabel( "This is a elide LEFT mode label. " "The ellipsis should appear at the beginning of the text. " "xiao mao xiao gou xiao ci wei" ) label_left.set_elide_mode(QtCore.Qt.ElideLeft) label_middle = MLabel( "This is a elide MIDDLE mode label. " "The ellipsis should appear in the middle of the text. " "xiao mao xiao gou xiao ci wei" ) label_middle.set_elide_mode(QtCore.Qt.ElideMiddle) label_right = MLabel() label_right.setText( "This is a elide RIGHT mode label. " "The ellipsis should appear at the end of the text. " "Some text to fill the line bala bala bala." ) label_right.set_elide_mode(QtCore.Qt.ElideRight) lay_elide.addWidget(label_none) lay_elide.addWidget(label_left) lay_elide.addWidget(label_middle) lay_elide.addWidget(label_right) hyper_label_1 = MLabel() hyper_label_1.set_link("https://baidu.com", text="baidu") hyper_label_2 = MLabel() hyper_label_2.set_link("https://baidu.com") hyper_label_3 = MLabel() hyper_label_3.set_link( "https://github.com/phenom-films/dayu_widgets", text="Dayu Widgets" ) hyperlink_lay = QtWidgets.QVBoxLayout() hyperlink_lay.addWidget(hyper_label_1) hyperlink_lay.addWidget(hyper_label_2) hyperlink_lay.addWidget(hyper_label_3) # hyperlink_lay.addWidget() main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("different level")) main_lay.addLayout(title_lay) main_lay.addWidget(MDivider("different type")) main_lay.addLayout(text_type_lay) main_lay.addWidget(MDivider("different property")) main_lay.addLayout(text_attr_lay) main_lay.addWidget(MDivider("mix")) main_lay.addLayout(text_mix_lay) # main_lay.addWidget(MDivider('data bind')) # main_lay.addLayout(data_bind_lay) main_lay.addWidget(MDivider("elide mode")) main_lay.addLayout(lay_elide) main_lay.addWidget(MDivider("hyperlink")) main_lay.addLayout(hyperlink_lay) main_lay.addStretch() self.setLayout(main_lay) ``` ---------------------------------------- TITLE: Install Project Dependencies with poetry DESCRIPTION: After cloning the repository and installing Poetry, this command installs all project dependencies specified in the poetry.lock or pyproject.toml file into the project's virtual environment. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/README.md#_snippet_4 LANGUAGE: Shell CODE: ``` poetry install ``` ---------------------------------------- TITLE: Configuring Page Example UI - Python DESCRIPTION: Defines the UI layout for the PageExample, creating multiple MPage widgets with different total counts and connecting a signal from one page widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_25 LANGUAGE: Python CODE: ``` page_1 = MPage() page_1.set_total(255) page_1.sig_page_changed.connect(print) page_2 = MPage() page_2.set_total(100) main_lay = QtWidgets.QVBoxLayout() self.setLayout(main_lay) main_lay.addWidget(MDivider()) main_lay.addWidget(page_1) main_lay.addWidget(MDivider()) main_lay.addWidget(page_2) main_lay.addStretch() ``` ---------------------------------------- TITLE: Initializing MSwitch Widgets Python DESCRIPTION: Demonstrates the initialization of multiple MSwitch widgets, setting their checked state and enabled state, and arranging them in horizontal and form layouts with dividers. Shows how to apply different predefined sizes to MSwitch widgets. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_40 LANGUAGE: python CODE: ``` check_box_1 = MSwitch() check_box_1.setChecked(True) check_box_2 = MSwitch() check_box_3 = MSwitch() check_box_3.setEnabled(False) lay = QtWidgets.QHBoxLayout() lay.addWidget(check_box_1) lay.addWidget(check_box_2) lay.addWidget(check_box_3) size_lay = QtWidgets.QFormLayout() size_lay.addRow("Huge", MSwitch().huge()) size_lay.addRow("Large", MSwitch().large()) size_lay.addRow("Medium", MSwitch().medium()) size_lay.addRow("Small", MSwitch().small()) size_lay.addRow("Tiny", MSwitch().tiny()) main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("Basic")) main_lay.addLayout(lay) main_lay.addWidget(MDivider("different size")) main_lay.addLayout(size_lay) main_lay.addStretch() self.setLayout(main_lay) ``` ---------------------------------------- TITLE: Using MPushButtonDelegate Widget DESCRIPTION: Sets up a QApplication and displays the DelegateButtonExample widget from the dayu_widgets library, applying the default dayu_theme. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_3 LANGUAGE: Python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = DelegateButtonExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Initializing CollapseExample UI DESCRIPTION: Example of how to initialize and configure the UI for CollapseExample widget. It demonstrates creating labels with multi-language text, enabling word wrap, creating a list of sections with titles, expand status, and widgets, and adding them to an MCollapse widget within a QVBoxLayout. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_0 LANGUAGE: Python CODE: ``` label_1 = MLabel( "史蒂夫·乔布斯(Steve Jobs),1955年2月24日生于美国加利福尼亚州旧金山,美国发明家、企业家、美国苹果公司联合创办人。" ) label_2 = MLabel( "斯蒂夫·盖瑞·沃兹尼亚克(Stephen Gary Wozniak),美国电脑工程师,曾与史蒂夫·乔布斯合伙创立苹果电脑(今之苹果公司)。斯蒂夫·盖瑞·沃兹尼亚克曾就读于美国科罗拉多大学,后转学入美国著名高等学府加州大学伯克利分校(UC Berkeley)并获得电机工程及计算机(EECS)本科学位(1987年)。" ) label_3 = MLabel( "乔纳森·伊夫是一位工业设计师,现任Apple公司设计师兼资深副总裁,英国爵士。他曾参与设计了iPod,iMac,iPhone,iPad等众多苹果产品。除了乔布斯,他是对苹果那些著名的产品最有影响力的人。" ) label_1.setWordWrap(True) label_2.setWordWrap(True) label_3.setWordWrap(True) section_list = [ {"title": "史蒂夫乔布斯", "expand": True, "widget": label_1}, { "title": "可关闭的", "expand": True, "widget": MLabel("This is a closable collapse item"), "closable": True, }, {"title": "斯蒂夫·盖瑞·沃兹尼亚克", "expand": True, "widget": label_2}, ] section_group = MCollapse() section_group.add_section_list(section_list) main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(section_group) main_lay.addStretch() self.setLayout(main_lay) ``` ---------------------------------------- TITLE: Using SequenceFileExample Widget Python DESCRIPTION: This snippet provides an example of how to instantiate and display the `SequenceFileExample` widget from the `dayu_widgets` library within a standard Qt application environment. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_34 LANGUAGE: python CODE: ``` # Import local modules from dayu_widgets import dayu_theme from dayu_widgets.qt import application with application() as app: test = SequenceFileExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Initializing ProgressCircleExample UI (Python) DESCRIPTION: Example of how to initialize and configure various types of `MProgressCircle` widgets, including standard, dashboard style, different sizes, data-bound, and custom content, arranging them in different layouts within a `ProgressCircleExample` widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_28 LANGUAGE: python CODE: ``` main_lay = QtWidgets.QVBoxLayout() self.setLayout(main_lay) main_lay.addWidget(MDivider("circle")) lay1 = QtWidgets.QHBoxLayout() circle_1 = MProgressCircle(parent=self) circle_1.setFormat("%p Days") circle_1.setValue(80) circle_2 = MProgressCircle(parent=self) circle_2.set_dayu_color(dayu_theme.success_color) circle_2.setValue(100) circle_3 = MProgressCircle(parent=self) circle_3.set_dayu_color(dayu_theme.error_color) circle_3.setValue(40) dashboard_1 = MProgressCircle.dashboard(parent=self) dashboard_1.setFormat("%p Days") dashboard_1.setValue(80) dashboard_2 = MProgressCircle.dashboard(parent=self) dashboard_2.set_dayu_color(dayu_theme.success_color) dashboard_2.setValue(100) dashboard_3 = MProgressCircle.dashboard(parent=self) dashboard_3.set_dayu_color(dayu_theme.error_color) dashboard_3.setValue(40) lay1.addWidget(circle_1) lay1.addWidget(circle_2) lay1.addWidget(circle_3) dashboard_lay = QtWidgets.QHBoxLayout() dashboard_lay.addWidget(dashboard_1) dashboard_lay.addWidget(dashboard_2) dashboard_lay.addWidget(dashboard_3) main_lay.addLayout(lay1) main_lay.addWidget(MDivider("dashboard")) main_lay.addLayout(dashboard_lay) main_lay.addWidget(MDivider("different radius")) scale_x, _ = get_scale_factor() circle_4 = MProgressCircle(parent=self) circle_4.set_dayu_width(100 * scale_x) circle_4.setValue(40) circle_5 = MProgressCircle(parent=self) circle_5.setValue(40) circle_6 = MProgressCircle(parent=self) circle_6.set_dayu_width(160 * scale_x) circle_6.setValue(40) lay2 = QtWidgets.QHBoxLayout() lay2.addWidget(circle_4) lay2.addWidget(circle_5) lay2.addWidget(circle_6) main_lay.addLayout(lay2) main_lay.addWidget(MDivider("data bind")) self.register_field("percent", 0) self.register_field("color", self.get_color) self.register_field("format", self.get_format) circle = MProgressCircle(parent=self) self.bind("percent", circle, "value") self.bind("color", circle, "dayu_color") self.bind("format", circle, "format") lay3 = QtWidgets.QHBoxLayout() button_grp = MPushButtonGroup() button_grp.set_dayu_type(MPushButton.DefaultType) button_grp.set_button_list( [ { "text": "+", "clicked": functools.partial(self.slot_change_percent, 10), }, { "text": "-", "clicked": functools.partial(self.slot_change_percent, -10), }, ] ) lay3.addWidget(circle) lay3.addWidget(button_grp) lay3.addStretch() main_lay.addLayout(lay3) custom_widget = QtWidgets.QWidget() custom_layout = QtWidgets.QVBoxLayout() custom_layout.setContentsMargins(20, 20, 20, 20) custom_layout.addStretch() custom_widget.setLayout(custom_layout) lab1 = MLabel(text="42,001,776").h3() lab2 = MLabel(text="消费人群规模").secondary() lab3 = MLabel(text="总占人数 75%").secondary() lab1.setAlignment(QtCore.Qt.AlignCenter) lab2.setAlignment(QtCore.Qt.AlignCenter) lab3.setAlignment(QtCore.Qt.AlignCenter) custom_layout.addWidget(lab1) custom_layout.addWidget(lab2) custom_layout.addWidget(MDivider()) custom_layout.addWidget(lab3) custom_layout.addStretch() custom_circle = MProgressCircle() custom_circle.set_dayu_width(180 * scale_x) custom_circle.setValue(75) custom_circle.set_widget(custom_widget) main_lay.addWidget(MDivider("custom circle")) main_lay.addWidget(custom_circle) main_lay.addStretch() ``` ---------------------------------------- TITLE: Initializing MPushButtonDelegate UI DESCRIPTION: Example of how to initialize and configure the UI for MPushButtonDelegate widget. It demonstrates setting up an MTableView with MTableModel and MSortFilterModel, applying an MPushButtonDelegate to a specific column, and connecting a signal for button clicks. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_4 LANGUAGE: Python CODE: ``` model_1 = MTableModel() model_1.set_header_list(header_list) model_sort = MSortFilterModel() model_sort.setSourceModel(model_1) table_grid = MTableView(size=dayu_theme.small, show_row_count=True) table_grid.setShowGrid(True) table_grid.setModel(model_sort) model_sort.set_header_list(header_list) table_grid.set_header_list(header_list) button_delegate = MPushButtonDelegate(parent=self) table_grid.setItemDelegateForColumn(4, button_delegate) button_delegate.sig_clicked.connect(self.slot_cell_clicked) model_1.set_data_list( [ { "name": "John Brown", "sex": "Male", "sex_list": ["Male", "Female"], "age": 18, "score": 89, "city": "New York", "city_list": ["New York", "Ottawa", "London", "Sydney"], "date": "2016-10-03", }, { "name": "Jim Green", "sex": "Male", "sex_list": ["Male", "Female"], "age": 24, "score": 55, "city": "London", "city_list": ["New York", "Ottawa", "London", "Sydney"], "date": "2016-10-01", }, ] ) main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(table_grid) self.setLayout(main_lay) ``` ---------------------------------------- TITLE: Initializing PushButtonGroupExample UI (Python) DESCRIPTION: Example of how to initialize and configure horizontal and vertical `MPushButtonGroup` widgets with different button types, icons, and sizes, arranging them in layouts within a `PushButtonGroupExample` widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_31 LANGUAGE: python CODE: ``` button_config_list = [ { "text": "Add", "icon": MIcon("add_line.svg", "#fff"), "type": MPushButton.PrimaryType, }, { "text": "Edit", "icon": MIcon("edit_fill.svg", "#fff"), "type": MPushButton.WarningType, }, { "text": "Delete", "icon": MIcon("trash_line.svg", "#fff"), "type": MPushButton.DangerType, }, ] button_group_h = MPushButtonGroup() button_group_h.set_dayu_size(dayu_theme.large) button_group_h.set_button_list(button_config_list) h_lay = QtWidgets.QHBoxLayout() h_lay.addWidget(button_group_h) h_lay.addStretch() button_group_v = MPushButtonGroup(orientation=QtCore.Qt.Vertical) button_group_v.set_button_list(button_config_list) h_lay_2 = QtWidgets.QHBoxLayout() h_lay_2.addWidget(button_group_v) h_lay_2.addStretch() main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget( MLabel( "MPushButtonGroup is MPushButton collection. they are not exclusive." ) ) main_lay.addWidget(MDivider("MPushButton group: Horizontal & Small Size")) main_lay.addLayout(h_lay) main_lay.addWidget(MDivider("MPushButton group: Vertical & Default Size")) main_lay.addLayout(h_lay_2) main_lay.addStretch() self.setLayout(main_lay) ``` ---------------------------------------- TITLE: Running Dayu Widgets Application (Python) DESCRIPTION: Initializes and runs a PyQt application using the dayu_widgets application context manager. It creates the main widget, applies the dayu_theme, and displays the widget. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_54 LANGUAGE: Python CODE: ``` with application() as app: test = TreeViewExample() dayu_theme.apply(test) test.show() ``` ---------------------------------------- TITLE: Run dayu_widgets Examples via uvx DESCRIPTION: This command runs the example program using the uvx command-line tool. It's the recommended way as uvx can automatically handle and set up the necessary Python version and Qt dependencies (specified by --with pyside2). SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/README.md#_snippet_2 LANGUAGE: Shell CODE: ``` uvx --python 3.10 --with pyside2 dayu_widgets ``` ---------------------------------------- TITLE: Configuring MenuTabWidget Example UI - Python DESCRIPTION: Defines the layout and content for the MenuTabWidgetExample, including creating menu items, various MMenuTabWidget instances (different sizes, orientation), adding labels and tool buttons, and arranging them in a QVBoxLayout. SOURCE: https://github.com/phenom-films/dayu_widgets/blob/master/llms.txt#_snippet_21 LANGUAGE: Python CODE: ``` item_list = [ { "text": "Overview", "svg": "home_line.svg", "clicked": functools.partial(MMessage.info, "首页", parent=self), }, { "text": "我的", "svg": "user_line.svg", "clicked": functools.partial(MMessage.info, "编辑账户", parent=self), }, { "text": "Notice", "svg": "alert_line.svg", "clicked": functools.partial(MMessage.info, "查看通知", parent=self), }, ] tool_bar = MMenuTabWidget() tool_bar_huge = MMenuTabWidget() tool_bar_huge.set_dayu_size(dayu_theme.huge) tool_bar_huge_v = MMenuTabWidget(orientation=QtCore.Qt.Vertical) tool_bar_huge_v.set_dayu_size(dayu_theme.huge) tool_bar.tool_bar_insert_widget(MLabel("DaYu").h4().secondary().strong()) tool_bar_huge.tool_bar_insert_widget(MLabel("DaYu").h4().secondary().strong()) dayu_icon = MLabel("DaYu").h4().secondary().strong() dayu_icon.setContentsMargins(10, 10, 10, 10) tool_bar_huge_v.tool_bar_insert_widget(dayu_icon) tool_bar.tool_bar_append_widget( MBadge.dot( show=True, widget=MToolButton().icon_only().svg("user_fill.svg").large() ) ) for index, data_dict in enumerate(item_list): tool_bar.add_menu(data_dict, index) tool_bar_huge.add_menu(data_dict, index) tool_bar_huge_v.add_menu(data_dict, index) tool_bar.tool_button_group.set_dayu_checked(0) tool_bar_huge.tool_button_group.set_dayu_checked(0) tool_bar_huge_v.tool_button_group.set_dayu_checked(0) main_lay = QtWidgets.QVBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.addWidget(MLabel("Menu Tab Widget (Large)")) main_lay.addWidget(tool_bar) main_lay.addWidget(MLabel("Menu Tab Widget (Huge)")) main_lay.addWidget(tool_bar_huge) main_lay.addWidget(MLabel("Menu Vertical Tab Widget (Huge)")) main_lay.addWidget(tool_bar_huge_v) self.setLayout(main_lay) ```