-
Notifications
You must be signed in to change notification settings - Fork 386
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
Only show 'Close Library' if your in a library #462
Conversation
I would suggest also hiding the "Refresh Directories", "Save Library" and "Save Library Backup" Buttons |
I honestly did not even think of that but this hides all the buttons in the "files" menu that do not have any effect until you open a library I will look to see if there is anything else that might benefit from being hidden til you open a library. |
I looked at how the items were disabled in the version you showed (Alpha 9.4.0) and decided to add the "update_clipboard_actions" function over. Not the code from it since none of that is added yet just the function its self. This means that all the buttons will be enabled at first but since its the same function the ones that need to be disabled will be checked then disabled in the same code so its not a problem. |
I woke up to a lot of merges and this no longer working so ill have a look at what broke it and fix this pr lol |
@CarterPillow Is this something you're still interested in working on? |
@CyanVoxel Actually yeah! I'll have a look and see if I can't update the code to work. |
That didn't take long! hopefully this is all working again lol. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It's not enabling the actions when i close the library and reopen a library. to fix it call
update_clipboard_actions()
from theQtDriver.open_library()
method so it will enable actions when opening a library. - format with
ruff
and do mypy check. (Installpre-commit
if you haven’t yet.)
- why are there two options for enabling and disabling? what if there is only one option named
toggle_action_state
that stores a bool value? if it'sTrue
, the action should be enabled or disabled and ifFalse
, it should not. - I prefer storing actions and/or menus (only if all the menu items are should be toggled) that need to be toggled when opening and closing the library, rather than enabling everything and explicitly disabling unwanted actions with the
data()
option.
btw, i personally like using QAction.property()
rather than QAction.data()
for its simplicity in this case.
@@ -138,6 +139,8 @@ def __init__(self, backend, args): | |||
self.frame_content = [] | |||
self.filter = FilterState() | |||
self.pages_count = 0 | |||
|
|||
self.menus = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.menus = [] | |
self.menus: list[QMenu] = [] |
A very minor nit, but the function name calls the toolbar a clipboard, which usually refers to copy/paste. I feel update_menu_actions or update_toolbar_actions would be a more proper name. Thanks! |
|
This is a good idea. I think i only used update_clipboard_actions name because when i started this it was already a method but not sure. anyways now that the method is just this code I changed it to update_menu_actions. |
i meant only set the data if it’s a library related action. then enable or disable only those actions. alternatively you could just create a list of library related actions and toggle all of them together. it’d be simpler. no need to bother with any properties. |
I feel like 1 lists with properties would be more efficient then 2 lists. |
action.setDisabled( | ||
False | ||
if action.property("enable") is None | ||
else not action.property("enable") | ||
if action.property("enable") is False | ||
else False | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point I feel the amount of crisscrossing boolean logic is simply a trap waiting to confuse anyone in the future who will need to touch this code.
Let's take a step back and look at what we'd like to do:
- There's several menu options that we'd like to always enable whenever a library is open
- There's several menu options that we'd always like to disable whenever a library is not open
- There's a few menu options we'd like to only disable under specific library circumstances (i.e. there's nothing in the user's clipboard to "Paste" with
The use of setProperty
/setData
here is probably unnecessary to accomplish this. Instead we can simply add references to each menu item we know should always be disabled when a library is closed to a list
. When a library is closed, we can call logic to iterate over that list and ensure that all options are disabled, regardless of their previous state. This list could be called something clear, such as "menus_to_disable_on_close
". Likewise we could have another list that only contains references to menus that we know we always want open when a library is open. This would be iterated over in a similar fashion, this time enabling the options.
For any other cases, such as the "Paste" example mentioned earlier, we leave that logic up to the library. And if we were to have cases where an option should always be disabled (such as an incomplete feature, etc.) then we can just disable that on startup.
These lists would have clear names that let other people reading the code know what they're for. In the update method(s), the loops would be clearly iterating over them to perform the same unambiguous state change. If we ever find ourselves needing to account for a third predictable scenario, say if the program gains an additional "view mode" that changes what menu options are available, then we can easily follow the pattern we've laid out and add one or more additional lists of menu item references that we can cleanly iterate over during update methods. This ensures that developers can quickly see and understand the pattern that is here, and have an extensible pattern to work off of to build future features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also meant to mention: if the menu items that need to be disabled on close on enabled on open are the same, then we can store those in a single list that can have either disable or enable each option based on whether or not a library is open.
@CarterPillow Any updates or help needed on this? |
working on this in #713 |
This is my first commit like ever on anything I know I made a lot of changes but I don't think this should have any effect outside of just only showing the close button when inside a library!