TagStudio
TagStudio copied to clipboard
refactor: field widgets
Summary
Various refactors of the different entry field widgets (field_widget.py, text_field.py, color_box.py, and tag_box_view.py/tag_box_controller.py).
- Field widgets have been grouped into a
fieldsdirectory under their respective directories (soviews/fieldsandcontrollers/fields) to make locating them easier.- I'm aware that this isn't reflective of the current organization of the frontend, and can revert the change if this is an unwanted one. I've just personally found the lack of organization of the frontend a bit tedious to work with, and would love to see more deliberate organization as opposed to big, unorganized lists of files. Again, though, this can be reverted if this is something that's unwanted.
- Field widgets have been split (where applicable) and moved from
mixedinto eitherviews/fieldsorcontrollers/fields. - Some field widgets have had their file and/or class names changed for consistency.
- Docstrings and return types have been added to most classes and methods.
- Some variables and methods have been renamed to be more descriptive, consistent, or better fitting.
- Some code has had spacing tweaks and comments added to help improve readability, particularly in large, repetitive sections of UI initialization.
mixed/field_widget.py
-
field_widget.pyhas had it's classesFieldWidgetandFieldContainersplit into their own files,views/preview_panel/fields/field_widget.pyandviews/preview_panel/fields/field_container.py.- Having both the base class that field widgets inherit from and the container widget both in the same file isn't the best idea in my opinion. Both classes serve fairly different purposes, and having both in the same file makes either a bit difficult to find. Having them split makes things simpler and easier.
- The stylesheet and icons have been moved from inside the class to above it.
- The stylesheet has also been changed to use a multi-line f-string.
-
root_layouthas been renamed to__root_layoutfor consistency. -
FieldContainer.set_inner_widget()and variables referencinginner_widgethave been renamed toset_field_widget()andfield_widgetrespectively.- This makes the intention more obvious. A
FieldContainer'sfield_widgetis more intuitive than aninner_widget, which can easily be confused for something internal and not the intended method.
- This makes the intention more obvious. A
-
root_layouthas been renamed tobase_layoutfor consistency. -
inner_layouthas been renamed tocontainer_layout. - In the
enterEvent, the copy, edit, and remove buttons now have their visibility set to whether their respective callbackis None, as opposed to conditionally setting it to false.- This helps reduce the number of lines needed while retaining the same behavior.
- As an example:
toif self.__copy_callback: self.copy_button.setHidden(False)self.copy_button.setHidden(self.__copy_callback is None)
- In the
leaveEvent, the checks for callbacks have been removed, now setting all the buttons to hidden regardless of if they have a callback or not.- I'm not entirely sure why this was there in the first place. The buttons will be hidden if they don't have a callback, so avoiding setting the buttons without a callback to be hidden is redundant. Also, it could potentially lead to issues where if a button were to somehow have it's callback removed while visible, it would then not be set to hidden upon the cursor leaving the field container, becoming permanently stuck as visible.
Things to look into:
- The field container widget itself is named
"fieldContainer", but contains a child widget also named"fieldContainer".
mixed/text_field.py
- Moved and renamed to
views/preview_panel/fields/text_field_widget.py. -
TextWidgethas been renamed toTextFieldWidget. -
base_layouthas been renamed to__root_layoutfor consistency.
mixed/color_box.py
- Split into a view and controller in accordance to #950.
- Located at
views/preview_panel/fields/color_box_widget_view.pyandcontrollers/preview_panel/fields/color_box_widget_controller.py.
- Located at
-
base_layouthas been renamed to__root_layoutfor consistency. -
updatesignal has been renamed toon_updateto be more consistent with the tag box widget. - The 'add button' stylesheet has been moved from inside the class to above it.
- Again, the stylesheet has also been changed to use a multi-line f-string.
-
edit_color()anddelete_color()have been renamed to_on_edit_color()and_on_delete_color().
views/tag_box_view.py
- Moved and renamed to
views/tag_box_widget_view.py.
controllers/tag_box_controller.py
- Moved and renamed to
controllers/tag_box_widget_controller.py.
Tasks Completed
- Platforms Tested:
- [x] Windows x86
- [ ] Windows ARM
- [ ] macOS x86
- [ ] macOS ARM
- [ ] Linux x86
- [ ] Linux ARM
- Tested For:
- [x] Basic functionality
- [ ] PyInstaller executable