-
Notifications
You must be signed in to change notification settings - Fork 502
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
Enhacements to list_manager: #1346
Conversation
method filter_option. To filter options based on selected entry attrib. last_choice. Which is the last action executed before exiting the loop
I think there's some viability to differentiating an exit of the menu to perform actions based on it so I think it might be handy
I haven't taken a look at the other PR yet but I think this sounds rather dangerous, are you saying that any action in the list menu will have possible consequences of actually running a command and creating/deleting things? If that is the case then than I think we should really not do that. Also having any bugs in this code might erase someones data without any intention what so ever so which is really bad. |
It is only an use case where i need buffered actions beyond the mere list management. And to control how it exits |
@svartkanin You commented (doesn't appers to me at github but i got the mail)
Daniel , you know what I would answer, and I know what you would ;-) Assuming the theoretical (not pythonic) answer: public attributes only if they are to be referenced outside the class:. |
My reasoning for initially suggesting a private variable (which I removed then again) was the use case for it, namely that it should be read-only basically.
will prevent someone from trying to write the variable
because it throws an Exception. I do understand that writing code like that gets annoying to implement since it is way more verbose and seems unnecessary for such a small thing but in general it does help to prevent bugs from happening So yeah I do agree that here it's fine to keep it that way as is :) |
You're right with the read-only character. I'll update the code accordingly. |
I've added last_choice to selection_menu also |
Two small changes to ListManager:
The idea is, given an object selected, filter (or if developer desires change the shown text) the available options, allowing to display only a subset.
I have three potential use-cases for it:
First (what i need) is, when having heterogeneous list, only the pertinent options for the type selected will be shown (imagine a list with disk/partitions or folder/files).
The second use (just theoretical) is that the options shown can be filtered on user-defined security levels. Haven't yet found a use for us, but ...
Third, to change the text of the option. f.i. in a user list, the promote/demote action could be shown just as demote or promote depends of which user is selected. Has its downsides -might need some code elsewhere- and might be not worth in this particular instance, but could be useful.
In this case I don't use a
NotImplementedError
exception but return the whole option list, as it is the default usageIt holds the last_choice selected by the user from the main list ONLY
The main use-case is when we need to know if the list was exited either with a cancel or a confirm_and_exit and perform some different action after each instance. Usually cancel wouldn't do anything and confirm_and_exit change the state of parts of the system.
If such behaviour is desired coding should be a bit different from the usual
ObjectList().run()
:Other, more convoluted example is my actual need. I have a list of partitions to manage. I want to be able to delete partitions not only from the list but in the real hardware. This action has to be done after the list is fully processed, before anything else and NEVER if cancel is invoked.
First I create an attribute
partitions_to_delete
which will hold the list of real partitions to be deletedThis attribute is filled during normal processing (a partition marked to be deleted is removed from the list, and is space is freed to define new partitons to be created). I could resort to some code like before, but in this case i don't need code branching, but to ensure that the deletion list is empty unless a confirm action is requested, so i decided to overcharge the run() method.
@svartkanin have a look at it please