how to programmatically select item(s) in selection list #218
Replies: 8 comments
-
I expect you could manage this with a lot of inheriting and overriding methods. The UISelectionList is made up of UIButtons, so you'd need to subclass both of those and then override the It'd likely be a fair chunk of work. You could also fake the mouse events using: https://www.pygame.org/docs/ref/event.html#pygame.event.post This is what I do for testing. There is a plan to eventually add some keyboard (and from there, controller buttons) controls to the overall UI, much as you can use Tab and Return to move around and activate a highlight on most normally mouse driven GUIs. |
Beta Was this translation helpful? Give feedback.
-
"Actually, it's super easy, barely an inconvenience!", at least for what I needed. I just used your testing code to simulate a click/selection/deselection....
As for the simulating hovering, and 'keyboard-ifying' the UI, yeah, I can how that'd take some time. Thx for the reply and the library. |
Beta Was this translation helpful? Give feedback.
-
I can't help but think there's a fairly easy way to do this. Some questions ...
Q: Since it was so easy to use that method to post a click event, couldn't a hover/unhover event be posted to an item in a selection list? If so, how would I express that to pygame_gui? Q: Via code (not a .json theme file), can we set individual theme properties for individual items in a selection list? Or at least dynamically assign a theme declaration to an individual item in a selection list? What I'm implementing here is a multi-selection-list that gains focus via the keyboard, and then, with cursor keys, the user can scroll up and down to highlight, then select/deselect items in the selection list... ... which means that there could be 4 themes declared in the json file: normal-notselected, normal-selected, highlighted-notselected, highlighted-selected However, if theme properties can be set directly in code, it seems that would be easier... ... especially if font properties of the items can be set directly/dynamically, which would mean that a highlighted item can simply be changed to a larger font size, or bold/italic. |
Beta Was this translation helpful? Give feedback.
-
Lots of nested questions here.
then call as an example. So long as you don't trigger a reload of the theme file itself the data in the them in memory will be whatever you set for that button's ID. You could load your new font in the standard way or use the pygame gui font dictionary. I hope some of that helps. Apologies there has not been much movement on keyboard navigation yet. It's been a slow year for open source stuff for me due to still ongoing COVID pandemic increasers to my the work part of my work/fun code/life balance. |
Beta Was this translation helpful? Give feedback.
-
thx much for the help and the library. will post my results. |
Beta Was this translation helpful? Give feedback.
-
The complexity of how to get/set theming properties via code is beyond my comprehension without docs and examples. Would you mind providing an example? Here's the code I'm using to fire an event...
Could you write out how exactly to get and set the font color for |
Beta Was this translation helpful? Give feedback.
-
Well the font colour specifically is easiest to set with a theme file so it is all setup ahead of time, but outside of that... the snippet I posted above should set you on the right path:
in your case above the element will be a button and you want to change a colour, not a font so you can switch it to:
if you want to change the colour of the text after selection (the states for text colour are called 'normal_text', 'hovered_text', 'disabled_text', 'selected_text', 'active_text'). What we are doing here is editing the data for the theme file that exists in memory after the theme file is loaded (or technically after the default theme file and any custom theme files are loaded). so the first Elements have a list of IDs preceding from most specific to least specific (this is the I haven't tested this setup, this description of how it works is from memory and looking at the code afresh this morning - you may encounter some unforeseen issues in practice but the basic thrust of it should be sound. |
Beta Was this translation helpful? Give feedback.
-
I would add my vote to implementing "programmatically select item(s) in selection list". |
Beta Was this translation helpful? Give feedback.
-
(thanks for making this library!)
I need to 'select' (and maybe 'hover') items in a selection list via code, not just with mouse clicks.
Suggestions?
1st example: Single select: the selection list box responds to keypress events to scroll up/down thru the items, and the item under the 'scroll cursor' is 'selected'.
2nd example: Multi select: the selection list box responds to keypress events to scroll thru the items, 'hovering' the current cursor position, then responds to another keypress to select/deselect that item.
Thanks much.
Beta Was this translation helpful? Give feedback.
All reactions