From 23954ec0418635fcb31768f643cea4244bf230f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 30 Oct 2008 14:08:45 +0100 Subject: [PATCH] Factorize url widget --- .../window/view_form/view/form_gtk/char.py | 2 ++ .../gui/window/view_form/view/form_gtk/url.py | 30 ++----------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/tryton/gui/window/view_form/view/form_gtk/char.py b/tryton/gui/window/view_form/view/form_gtk/char.py index 522e62d5a0..d6d42babef 100644 --- a/tryton/gui/window/view_form/view/form_gtk/char.py +++ b/tryton/gui/window/view_form/view/form_gtk/char.py @@ -6,6 +6,8 @@ class Char(WidgetInterface): "Char" def __init__(self, window, parent, model, attrs=None): + if attrs is None: + attrs = {} super(Char, self).__init__(window, parent, model=model, attrs=attrs) self.widget = gtk.HBox() diff --git a/tryton/gui/window/view_form/view/form_gtk/url.py b/tryton/gui/window/view_form/view/form_gtk/url.py index 897d38a468..9d72d320f8 100644 --- a/tryton/gui/window/view_form/view/form_gtk/url.py +++ b/tryton/gui/window/view_form/view/form_gtk/url.py @@ -1,11 +1,11 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. import gettext import gtk -from interface import WidgetInterface +from char import Char import webbrowser -class URL(WidgetInterface): +class URL(Char): "url" def __init__(self, window, parent, model, attrs=None): @@ -13,17 +13,6 @@ class URL(WidgetInterface): attrs = {} super(URL, self).__init__(window, parent, model, attrs=attrs) - self.widget = gtk.HBox(homogeneous=False, spacing=0) - - self.entry = gtk.Entry() - self.entry.set_max_length(int(attrs.get('size', 0))) - self.entry.set_width_chars(5) - self.entry.set_property('activates_default', True) - self.entry.connect('activate', self.sig_activate) - self.entry.connect('focus-in-event', lambda x, y: self._focus_in()) - self.entry.connect('focus-out-event', lambda x, y: self._focus_out()) - self.widget.pack_start(self.entry, expand=True, fill=True) - self.tooltips = gtk.Tooltips() self.button = gtk.Button() img = gtk.Image() @@ -35,18 +24,8 @@ class URL(WidgetInterface): self.button.set_property('can-focus', False) self.widget.pack_start(self.button, expand=False, fill=False) - def grab_focus(self): - return self.entry.grab_focus() - - def set_value(self, model, model_field): - return model_field.set_client(model, self.entry.get_text() or False) - def display(self, model, model_field): - if not model_field: - self.entry.set_text('') - return False super(URL, self).display(model, model_field) - self.entry.set_text(model_field.get(model) or '') self.set_tooltips() def set_tooltips(self): @@ -58,8 +37,7 @@ class URL(WidgetInterface): self.tooltips.disable() def _readonly_set(self, value): - self.entry.set_editable(not value) - self.entry.set_sensitive(not value) + super(URL, self)._readonly_set(value) if value: self.entry.hide() else: @@ -71,8 +49,6 @@ class URL(WidgetInterface): if value: webbrowser.open(value, new=2) - def _color_widget(self): - return self.entry class Email(URL): "email"