Reviewers: ,
Please review this at http://codereview.tryton.org/30007/
Affected files:
M tryton/gui/window/dblogin.py
Index: tryton/gui/window/dblogin.py
===================================================================
--- a/tryton/gui/window/dblogin.py
+++ b/tryton/gui/window/dblogin.py
@@ -49,11 +49,25 @@
self.profile_tree.insert_column_with_attributes(-1, _(u'Profile'),
self.cell, text=0)
self.profile_tree.connect('cursor-changed', self.profile_selected)
+
scroll = gtk.ScrolledWindow()
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scroll.add(self.profile_tree)
+ self.up_button = gtk.Button(_(u'Up'))
+ self.up_button.connect('clicked', self.updown_profile, lambda x:
x-1)
+ up_image = gtk.Image()
+ up_image.set_from_stock('gtk-go-up', gtk.ICON_SIZE_BUTTON)
+ self.up_button.set_image(up_image)
+ self.down_button= gtk.Button(_(u'Down'))
+ self.down_button.connect('clicked', self.updown_profile, lambda x:
x+1)
+ down_image = gtk.Image()
+ down_image.set_from_stock('gtk-go-down', gtk.ICON_SIZE_BUTTON)
+ self.down_button.set_image(down_image)
self.add_button = gtk.Button(_(u'_Add'))
self.add_button.connect('clicked', self.profile_create)
+ updown_box = gtk.HBox(homogeneous=True)
+ updown_box.pack_start(self.up_button)
+ updown_box.pack_start(self.down_button)
add_image = gtk.Image()
add_image.set_from_stock('gtk-add', gtk.ICON_SIZE_BUTTON)
self.add_button.set_image(add_image)
@@ -63,6 +77,7 @@
remove_image.set_from_stock('gtk-remove', gtk.ICON_SIZE_BUTTON)
self.remove_button.set_image(remove_image)
vbox_profiles.pack_start(scroll, expand=True, fill=True)
+ vbox_profiles.pack_start(updown_box, expand=False, fill=True)
vbox_profiles.pack_start(self.add_button, expand=False, fill=True)
vbox_profiles.pack_start(self.remove_button, expand=False,
fill=True)
hpaned.add1(vbox_profiles)
@@ -291,6 +306,8 @@
self.hide_database_info()
self.add_button.set_sensitive(False)
self.remove_button.set_sensitive(False)
+ self.up_button.set_sensitive(False)
+ self.down_button.set_sensitive(False)
self.ok_button.set_sensitive(False)
self.cell.set_property('editable', False)
self.updating_db = True
@@ -318,6 +335,8 @@
self.add_button.set_sensitive(True)
self.remove_button.set_sensitive(True)
+ self.up_button.set_sensitive(True)
+ self.down_button.set_sensitive(True)
self.ok_button.set_sensitive(True)
self.cell.set_property('editable', True)
@@ -354,6 +373,22 @@
except ValueError:
entry.stop_emission('insert-text')
+ def updown_profile(self, button, function):
+ selection = self.profile_tree.get_selection()
+ model, selected_iter = selection.get_selected()
+ selected_idx, = model.get_path(selected_iter)
+ other_idx = function(selected_idx)
+ if not (0 <= other_idx < len(model)):
+ return
+ other_iter = model.get_iter(other_idx)
+ selected_profile = model[selected_idx][0]
+ other_profile = model[other_idx][0]
+ current_position = self.profiles.set(selected_profile, 'index',
+ str(other_idx))
+ other_position = self.profiles.set(other_profile, 'index',
+ str(selected_idx))
+ model.swap(selected_iter, other_iter)
+
class DBLogin(object):
def __init__(self, parent):
@@ -463,7 +498,8 @@
# Profile informations
self.profile_cfg = os.path.join(get_config_dir(), 'profiles.cfg')
- self.profiles = ConfigParser.SafeConfigParser({'port': '8070'})
+ self.profiles = ConfigParser.SafeConfigParser(
+ {'port': '8070', 'index': 0})
if not os.path.exists(self.profile_cfg):
short_version = '.'.join(VERSION.split('.', 2)[:2])
name = 'demo%s.tryton.org' % short_version
@@ -474,10 +510,19 @@
self.profiles.set(name, 'username', 'demo')
else:
self.profiles.read(self.profile_cfg)
- for section in self.profiles.sections():
+ order = []
+ for idx, section in enumerate(self.profiles.sections()):
active = all(self.profiles.has_option(section, option)
for option in ('host', 'port', 'database'))
+ try:
+ section_index = self.profiles.getint(section, 'index')
+ except ValueError:
+ # For profile created before the index option existed
+ section_index = 0
self.profile_store.append([section, active])
+ order.append((section_index, idx))
+ order.sort()
+ self.profile_store.reorder([e[1] for e in order])
def profile_manage(self, widget):
dia = DBListEditor(self.dialog, self.profile_store, self.profiles)
--
[email protected] mailing list