I'm starting to write a program with 'quickly'. A list of desired languages will be one prefereces.
Example:
languages = ["en", "de"]
The (automaticly created) quickly code that handles the preference part looks like this:
# Define your preferences dictionary in the __init__.main() function.
# The widget names in the PreferencesTestProjectDialog.ui
# file need to correspond to the keys in the preferences dictionary.
#
# Each preference also need to be defined in the 'widget_methods' map below
# to show up in the dialog itself. Provide three bits of information:
# 1) The first entry is the method on the widget that grabs a value from the
# widget.
# 2) The second entry is the method on the widget that sets the widgets value
# from a stored preference.
# 3) The third entry is a signal the widget will send when the contents have
# been changed by the user. The preferences dictionary is always up to
# date and will signal the rest of the application about these changes.
# The values will be saved to desktopcouch when the application closes.
#
# TODO: replace widget_methods with your own values
widget_methods = {
'languages': ['getter', 'setter', 'changed'],
}
In the GUI, it seems as if the widget of choice in gtk for a list is a ListStore (which isn't a widget, but a model, but it's defined in the Glade file…). Can someone tell me what would work for a ListStore for the'getter'
, 'setter'
and 'changed'
in the code above?
The approach looks easy for simple entry widgets and such, but I don't know how to use it with lists.
Alternatively, I would of course accept any other way to deal with lists as preferences, provided that the length of the list is not fixed.
Best Answer
Disclaimer: I didn't know anything about quickly until I read your post, or about gui programming in general for that matter. Therefore I honestly have no business attempting to answer this question :)
That said, quickly is a neat project. I scanned the boilerplate source briefly and identified the following potential approaches for adding a ListStore backed list-style preference:
set_widget_from_preference
andset_preference
in the project's subclass of PreferencesDialog (the subclass is Preferences$PROJECTNAME$Dialog), and do something different whenkey
orwidget
is your ListStore backed TreeView widget.To test them out, I implemented all three of these ideas -- each worked as intended, and AFAICT, identically. In the end, the third (in particular) seemed the cleanest to me, and closer to conventions used throughout the boilerplate, despite initially expecting the opposite.
Here are the steps I followed for number three ...
Using glade via
quickly design
(quickly 11.10, btw), and loosely following this tutorial (part 2), add a ScrolledWindow widget to the Preferences$PROJECTNAME$Dialog.ui, drop a TreeView onto it, name the TreeViewlanguage_treeview
. Create a new ListStore model for the TreeView when prompted, and name it language_liststore, etc ... eventually I ended up with something like this:Next, add a glade catalog (data/ui/preferences_$PROJECTNAME$_treeview.xml) with the following contents:
Then, edit Preferences$PROJECTNAME$Dialog.ui, adding ...
... to the top, under the requires tag. And change the class attribute of language_treeview to Preferences$PROJECTNAME$TreeView, in preparation for a later step.
Finally, add the following element to widget_methods list in Preferences$PROJECTNAME$Dialog.py
And at the end of the same file (Preferences$PROJECTNAME$Dialog.py), add
If you're interested in seeing my attempts for one and two, I'm happy to oblige.
Edit: For the casual reader, replace any occurrence of $PROJECTNAME$ with the actual name of your quickly project (as specified in
quickly create
).HTH!