Merge host and port field in profile editor

issue4350
review14681002
This commit is contained in:
Robin Baumgartner committed 2014-11-21 09:46:08 +01:00
1 parent a7588e3826
commit aad0e82db0
2 files changed
+26 -46

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Merge host and port field in profile editor
* New color scheme for graph
* Replace img_{width,height} by width and height attributes
+25 -46
View File
@@ -67,7 +67,7 @@ class DBListEditor(object):
table = gtk.Table(4, 2, homogeneous=False)
table.set_row_spacings(3)
table.set_col_spacings(3)
host = gtk.Label(_(u'Hostname:'))
host = gtk.Label(_(u'Host:'))
host.set_alignment(1, 0.5)
host.set_padding(3, 3)
self.host_entry = gtk.Entry()
@@ -76,16 +76,6 @@ class DBListEditor(object):
self.host_entry.set_activates_default(True)
table.attach(host, 0, 1, 1, 2, yoptions=False, xoptions=gtk.FILL)
table.attach(self.host_entry, 1, 2, 1, 2, yoptions=False)
port = gtk.Label(_(u'Port:'))
port.set_alignment(1, 0.5)
port.set_padding(3, 3)
self.port_entry = gtk.Entry()
self.port_entry.connect('focus-out-event', self.display_dbwidget)
self.port_entry.connect('changed', self.update_profiles, 'port')
self.port_entry.connect('insert_text', self.insert_text_port)
self.port_entry.set_activates_default(True)
table.attach(port, 0, 1, 2, 3, yoptions=False, xoptions=gtk.FILL)
table.attach(self.port_entry, 1, 2, 2, 3, yoptions=False)
database = gtk.Label(_(u'Database:'))
database.set_alignment(1, 0.5)
database.set_padding(3, 3)
@@ -123,8 +113,8 @@ class DBListEditor(object):
cwidth, cheight = child.size_request()
width, height = max(width, cwidth), max(height, cheight)
db_box.set_size_request(width, height)
table.attach(database, 0, 1, 3, 4, yoptions=False, xoptions=gtk.FILL)
table.attach(db_box, 1, 2, 3, 4, yoptions=False)
table.attach(database, 0, 1, 2, 3, yoptions=False, xoptions=gtk.FILL)
table.attach(db_box, 1, 2, 2, 3, yoptions=False)
username = gtk.Label(_(u'Username:'))
username.set_alignment(1, 0.5)
username.set_padding(3, 3)
@@ -132,8 +122,8 @@ class DBListEditor(object):
self.username_entry.connect('changed', self.update_profiles,
'username')
self.username_entry.set_activates_default(True)
table.attach(username, 0, 1, 4, 5, yoptions=False, xoptions=gtk.FILL)
table.attach(self.username_entry, 1, 2, 4, 5, yoptions=False)
table.attach(username, 0, 1, 3, 4, yoptions=False, xoptions=gtk.FILL)
table.attach(self.username_entry, 1, 2, 3, 4, yoptions=False)
hpaned.add2(table)
hpaned.set_position(250)
@@ -171,13 +161,10 @@ class DBListEditor(object):
return {'name': model[selection][0], 'iter': selection}
def clear_entries(self):
for entryname in ('host', 'port', 'database', 'username'):
for entryname in ('host', 'database', 'username'):
entry = getattr(self, '%s_entry' % entryname)
entry.handler_block_by_func(self.update_profiles)
if entryname == 'port':
entry.set_text('8000')
else:
entry.set_text('')
entry.set_text('')
entry.handler_unblock_by_func(self.update_profiles)
self.current_database = None
self.database_combo.set_active(-1)
@@ -218,7 +205,7 @@ class DBListEditor(object):
selection = treeview.get_selection()
selection.select_iter(self.old_profile['iter'])
return
fields = ('host', 'port', 'database', 'username')
fields = ('host', 'database', 'username')
for field in fields:
entry = getattr(self, '%s_entry' % field)
try:
@@ -274,14 +261,15 @@ class DBListEditor(object):
if not selection:
return
active = all(self.profiles.has_option(profile_name, option)
for option in ('host', 'port', 'database'))
for option in ('host', 'database'))
model[selection][1] = active
def display_dbwidget(self, entry, event, dbname=None):
host = self.host_entry.get_text()
port = self.port_entry.get_text()
if not (host and port):
netloc = self.host_entry.get_text()
host = common.get_hostname(netloc)
if not host:
return
port = common.get_port(netloc)
if (host, port, self.current_profile['name']) == self.db_cache:
return
if self.updating_db:
@@ -289,14 +277,13 @@ class DBListEditor(object):
if dbname is None:
dbname = self.current_database
dbprogress = common.DBProgress(host, int(port))
dbprogress = common.DBProgress(host, port)
self.hide_database_info()
self.add_button.set_sensitive(False)
self.remove_button.set_sensitive(False)
self.ok_button.set_sensitive(False)
self.cell.set_property('editable', False)
self.host_entry.set_sensitive(False)
self.port_entry.set_sensitive(False)
self.updating_db = True
def callback(dbs):
@@ -323,7 +310,6 @@ class DBListEditor(object):
self.ok_button.set_sensitive(True)
self.cell.set_property('editable', True)
self.host_entry.set_sensitive(True)
self.port_entry.set_sensitive(True)
dbprogress.update(self.database_combo,
self.database_progressbar, callback, dbname)
@@ -331,8 +317,9 @@ class DBListEditor(object):
def db_create(self, button):
if not self.current_profile['name']:
return
host = self.host_entry.get_text()
port = int(self.port_entry.get_text())
netloc = self.host_entry.get_text()
host = common.get_hostname(netloc)
port = common.get_port(netloc)
dia = DBCreate(host, port)
dbname = dia.run()
self.db_cache = None
@@ -516,10 +503,7 @@ class DBLogin(object):
except ConfigParser.NoOptionError:
username = ''
host = self.profiles.get(profile, 'host')
if ':' in host:
host = '[%s]' % host
port = self.profiles.get(profile, 'port')
self.entry_host.set_text('%s:%s' % (host, port))
self.entry_host.set_text('%s' % host)
self.entry_database.set_text(self.profiles.get(profile, 'database'))
if username:
self.entry_login.set_text(username)
@@ -529,19 +513,17 @@ class DBLogin(object):
def clear_profile_combo(self, entry, event):
netloc = self.entry_host.get_text()
host = common.get_hostname(netloc)
try:
port = str(common.get_port(netloc))
except ValueError:
host = ''
port = ''
port = common.get_port(netloc)
database = self.entry_database.get_text().strip()
for idx, profile_info in enumerate(self.profile_store):
if not profile_info[1]:
continue
profile = profile_info[0]
if (host == self.profiles.get(profile, 'host')
and port == self.profiles.get(profile, 'port')
and database == self.profiles.get(profile, 'database')):
profile_host = self.profiles.get(profile, 'host')
profile_db = self.profiles.get(profile, 'database')
if (host == common.get_hostname(profile_host)
and port == common.get_port(profile_host)
and database == profile_db):
break
else:
idx = -1
@@ -606,10 +588,7 @@ class DBLogin(object):
CONFIG['login.profile'] = profile
netloc = self.entry_host.get_text()
host = common.get_hostname(netloc)
try:
port = common.get_port(netloc)
except ValueError:
continue
port = common.get_port(netloc)
try:
if not common.test_server_version(host, port):
common.warning('',