These two patches add the discussed and proposed behaviour of the KeyboardSpoke: 1) Multiple layouts adding 2) Replace instead of remove when the last item remains
Video demonstrating these changes can be found at: http://vpodzime.fedorapeople.org/add_layouts.ogg
-- Vratislav Podzimek
--- pyanaconda/ui/gui/spokes/keyboard.py | 24 +++++++++++++++--------- pyanaconda/ui/gui/spokes/keyboard.ui | 4 +++- 2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/pyanaconda/ui/gui/spokes/keyboard.py b/pyanaconda/ui/gui/spokes/keyboard.py index 8e9e56d..30b7925 100644 --- a/pyanaconda/ui/gui/spokes/keyboard.py +++ b/pyanaconda/ui/gui/spokes/keyboard.py @@ -75,14 +75,17 @@ class AddLayoutDialog(UIObject): return rc
@property - def chosen_layout(self): - return self._chosen_layout + def chosen_layouts(self): + return self._chosen_layouts
def on_confirm_add_clicked(self, *args): treeview = self.builder.get_object("newLayoutView") selection = treeview.get_selection() - (model, itr) = selection.get_selected() - self._chosen_layout = model[itr][0] + (store, pathlist) = selection.get_selected_rows() + self._chosen_layouts = [] + for path in pathlist: + itr = store.get_iter(path) + self._chosen_layouts.append(store[itr][0])
def on_cancel_clicked(self, *args): print "CANCELING" @@ -155,13 +158,16 @@ class KeyboardSpoke(NormalSpoke): response = dialog.run() lightbox.destroy() if response == 1: - found = False + duplicates = set() itr = self._store.get_iter_first() - while itr and not found: - found = self._store[itr][0] == dialog.chosen_layout + while itr: + item = self._store[itr][0] + if item in dialog.chosen_layouts: + duplicates.add(item) itr = self._store.iter_next(itr) - if not found: - self._addLayout(self._store, dialog.chosen_layout) + for layout in dialog.chosen_layouts: + if layout not in duplicates: + self._addLayout(self._store, layout)
def on_remove_clicked(self, button): selection = self.builder.get_object("layoutSelection") diff --git a/pyanaconda/ui/gui/spokes/keyboard.ui b/pyanaconda/ui/gui/spokes/keyboard.ui index c471287..6fd9bfd 100644 --- a/pyanaconda/ui/gui/spokes/keyboard.ui +++ b/pyanaconda/ui/gui/spokes/keyboard.ui @@ -110,7 +110,9 @@ <property name="headers_visible">False</property> <property name="headers_clickable">False</property> <child internal-child="selection"> - <object class="GtkTreeSelection" id="newLayoutSelection"/> + <object class="GtkTreeSelection" id="newLayoutSelection"> + <property name="mode">multiple</property> + </object> </child> <child> <object class="GtkTreeViewColumn" id="name">
--- pyanaconda/ui/gui/spokes/keyboard.py | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/pyanaconda/ui/gui/spokes/keyboard.py b/pyanaconda/ui/gui/spokes/keyboard.py index 30b7925..a8fb5c9 100644 --- a/pyanaconda/ui/gui/spokes/keyboard.py +++ b/pyanaconda/ui/gui/spokes/keyboard.py @@ -23,7 +23,7 @@ import gettext _ = lambda x: gettext.ldgettext("anaconda", x) N_ = lambda x: x
-from gi.repository import Gtk, AnacondaWidgets +from gi.repository import Gtk, GLib, AnacondaWidgets
from pyanaconda.ui.gui import UIObject from pyanaconda.ui.gui.spokes import NormalSpoke @@ -110,6 +110,10 @@ class KeyboardSpoke(NormalSpoke): icon = "accessories-character-map" title = N_("KEYBOARD")
+ def __init__(self, *args): + NormalSpoke.__init__(self, *args) + self._remove_last_attempt = False + def apply(self): pass
@@ -165,6 +169,9 @@ class KeyboardSpoke(NormalSpoke): if item in dialog.chosen_layouts: duplicates.add(item) itr = self._store.iter_next(itr) + if self._remove_last_attempt: + self._store.remove(self._store.get_iter_first()) + self._remove_last_attempt = False for layout in dialog.chosen_layouts: if layout not in duplicates: self._addLayout(self._store, layout) @@ -181,8 +188,12 @@ class KeyboardSpoke(NormalSpoke): itr2 = store.iter_next(itr2) if itr2: #next one existing selection.select_iter(itr2) - #nothing left to be selected - store.remove(itr) + store.remove(itr) + return + #nothing left, run AddLayout dialog to replace the current layout + self._remove_last_attempt = True + add_button = self.builder.get_object("addLayoutButton") + GLib.idle_add(self.on_add_clicked, add_button) return
#the selected item is not the first, select the previous one
@@ -165,6 +169,9 @@ class KeyboardSpoke(NormalSpoke): if item in dialog.chosen_layouts: duplicates.add(item) itr = self._store.iter_next(itr)
if self._remove_last_attempt:
self._store.remove(self._store.get_iter_first())
self._remove_last_attempt = False for layout in dialog.chosen_layouts: if layout not in duplicates: self._addLayout(self._store, layout)
Please add some blank lines between blocks.
@@ -181,8 +188,12 @@ class KeyboardSpoke(NormalSpoke): itr2 = store.iter_next(itr2) if itr2: #next one existing selection.select_iter(itr2)
#nothing left to be selected
store.remove(itr)
store.remove(itr)
return
#nothing left, run AddLayout dialog to replace the current layout
self._remove_last_attempt = True
add_button = self.builder.get_object("addLayoutButton")
GLib.idle_add(self.on_add_clicked, add_button) return
Why is the idle_add call necessary?
- Chris
On Tue, 2012-01-31 at 11:56 -0500, Chris Lumens wrote:
@@ -165,6 +169,9 @@ class KeyboardSpoke(NormalSpoke): if item in dialog.chosen_layouts: duplicates.add(item) itr = self._store.iter_next(itr)
if self._remove_last_attempt:
self._store.remove(self._store.get_iter_first())
self._remove_last_attempt = False for layout in dialog.chosen_layouts: if layout not in duplicates: self._addLayout(self._store, layout)
Please add some blank lines between blocks.
ok
@@ -181,8 +188,12 @@ class KeyboardSpoke(NormalSpoke): itr2 = store.iter_next(itr2) if itr2: #next one existing selection.select_iter(itr2)
#nothing left to be selected
store.remove(itr)
store.remove(itr)
return
#nothing left, run AddLayout dialog to replace the current layout
self._remove_last_attempt = True
add_button = self.builder.get_object("addLayoutButton")
GLib.idle_add(self.on_add_clicked, add_button) return
Why is the idle_add call necessary?
It is probably not necessary. I just wanted to make sure the UI redraws correctly before invoking AddLayout dialog and it's lightbox. Should I remove it?
Why is the idle_add call necessary?
It is probably not necessary. I just wanted to make sure the UI redraws correctly before invoking AddLayout dialog and it's lightbox. Should I remove it?
Hm, I don't know. I'd just try it and see. I'm not objecting to it being there. I just want to know why it's necessary.
Also, make sure to add yourself to the authors list up top. You've probably got at least as much code in there as I do now, and most of what I did is just boilerplate.
- Chris
anaconda-devel@lists.stg.fedoraproject.org