diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index ca68ac1930..89f2c5d018 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -13,7 +13,7 @@ from tryton.gui.window.win_import import WinImport from tryton.gui.window.attachment import Attachment from tryton.gui.window.revision import Revision from tryton.signal_event import SignalEvent -from tryton.common import message, sur, sur_3b, COLOR_SCHEMES, timezoned_date +from tryton.common import message, sur, sur_3b, timezoned_date import tryton.common as common from tryton.common import RPCExecute, RPCException from tryton.common.datetime_strftime import datetime_strftime @@ -230,7 +230,8 @@ class Form(SignalEvent, TabContent): def sig_logs(self, widget=None): obj_id = self.id_get() if obj_id < 0 or obj_id is False: - self.message_info(_('You have to select one record!')) + self.message_info( + _('You have to select one record.'), gtk.MESSAGE_INFO) return False fields = [ @@ -314,9 +315,9 @@ class Form(SignalEvent, TabContent): msg = _('Are you sure to remove those records?') if sur(msg): if not self.screen.remove(delete=True, force_remove=True): - self.message_info(_('Records not removed!')) + self.message_info(_('Records not removed.'), gtk.MESSAGE_ERROR) else: - self.message_info(_('Records removed!'), 'green') + self.message_info(_('Records removed.'), gtk.MESSAGE_INFO) def sig_import(self, widget=None): WinImport(self.model, self.screen.context) @@ -334,7 +335,7 @@ class Form(SignalEvent, TabContent): if not self.modified_save(): return self.screen.new() - self.message_info('') + self.message_info() self.activate_save() def sig_copy(self, widget=None): @@ -343,8 +344,8 @@ class Form(SignalEvent, TabContent): if not self.modified_save(): return self.screen.copy() - self.message_info(_('Working now on the duplicated record(s)!'), - 'green') + self.message_info(_('Working now on the duplicated record(s).'), + gtk.MESSAGE_INFO) def sig_save(self, widget=None): if widget: @@ -353,24 +354,24 @@ class Form(SignalEvent, TabContent): if not common.MODELACCESS[self.model]['write']: return if self.screen.save_current(): - self.message_info(_('Record saved!'), 'green') + self.message_info(_('Record saved.'), gtk.MESSAGE_INFO) return True else: - self.message_info(_('Invalid form!')) + self.message_info(_('Invalid form.'), gtk.MESSAGE_ERROR) return False def sig_previous(self, widget=None): if not self.modified_save(): return self.screen.display_prev() - self.message_info('') + self.message_info() self.activate_save() def sig_next(self, widget=None): if not self.modified_save(): return self.screen.display_next() - self.message_info('') + self.message_info() self.activate_save() def sig_reload(self, test_modified=True): @@ -391,7 +392,7 @@ class Form(SignalEvent, TabContent): set_cursor = True break self.screen.display(set_cursor=set_cursor) - self.message_info('') + self.message_info() self.activate_save() return True @@ -440,16 +441,6 @@ class Form(SignalEvent, TabContent): menu.show_all() menu.popup(None, None, menu_position, 0, 0) - def message_info(self, message, color='red'): - if message: - self.info_label.set_label(message) - self.eb_info.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse( - COLOR_SCHEMES.get(color, 'white'))) - self.eb_info.show_all() - else: - self.info_label.set_label('') - self.eb_info.hide() - def _record_message(self, screen, signal_data): name = '_' if signal_data[0]: @@ -467,7 +458,7 @@ class Form(SignalEvent, TabContent): if signal_data[1] < signal_data[2]: msg += _(' of ') + str(signal_data[2]) self.status_label.set_text(msg) - self.message_info('') + self.message_info() self.activate_save() self.url_entry.set_text(self.screen.get_url()) diff --git a/tryton/gui/window/infobar.py b/tryton/gui/window/infobar.py new file mode 100644 index 0000000000..3585e11645 --- /dev/null +++ b/tryton/gui/window/infobar.py @@ -0,0 +1,24 @@ +# 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 gtk + + +class InfoBar(object): + + def create_info_bar(self): + self.info_label = gtk.Label() + + self.info_bar = gtk.InfoBar() + self.info_bar.get_content_area().pack_start( + self.info_label, False, False) + self.info_bar.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) + self.info_bar.connect('response', lambda i, r: i.hide()) + + def message_info(self, message=None, type_=gtk.MESSAGE_ERROR): + if message: + self.info_label.set_label(message) + self.info_bar.set_message_type(type_) + self.info_bar.show_all() + else: + self.info_bar.hide() diff --git a/tryton/gui/window/tabcontent.py b/tryton/gui/window/tabcontent.py index 780704e533..d077067ced 100644 --- a/tryton/gui/window/tabcontent.py +++ b/tryton/gui/window/tabcontent.py @@ -8,11 +8,12 @@ import pango import tryton.common as common from tryton.config import CONFIG from tryton.gui import Main +from .infobar import InfoBar _ = gettext.gettext -class TabContent(object): +class TabContent(InfoBar): def create_tabcontent(self): self.buttons = {} @@ -25,6 +26,9 @@ class TabContent(object): title_box = self.make_title_bar() self.widget.pack_start(title_box, expand=False, fill=True, padding=3) + self.create_info_bar() + self.widget.pack_start(self.info_bar, False, True) + self.toolbar = self.create_toolbar(self.get_toolbars()) self.toolbar.show_all() self.widget.pack_start(self.toolbar, False, True) @@ -63,19 +67,6 @@ class TabContent(object): title_menu.append(title_item) title_menu.show_all() - self.info_label = gtk.Label() - self.info_label.set_padding(3, 3) - self.info_label.set_alignment(1.0, 0.5) - - self.eb_info = gtk.EventBox() - self.eb_info.add(self.info_label) - self.eb_info.connect('button-release-event', - lambda *a: self.message_info('')) - - vbox = gtk.VBox() - vbox.pack_start(self.eb_info, expand=True, fill=True, padding=5) - vbox.show() - self.status_label = gtk.Label() self.status_label.set_padding(5, 4) self.status_label.set_alignment(0.0, 0.5) @@ -83,7 +74,6 @@ class TabContent(object): hbox = gtk.HBox() hbox.pack_start(title, expand=True, fill=True) - hbox.pack_start(vbox, expand=False, fill=True, padding=20) hbox.pack_start(self.status_label, expand=False, fill=True) hbox.show() @@ -106,7 +96,6 @@ class TabContent(object): title_box.pack_start(frame_menu, expand=False, fill=True) title_box.pack_start(eb, expand=True, fill=True) title_box.show() - return title_box def create_base_toolbar(self, toolbar): diff --git a/tryton/gui/window/win_form.py b/tryton/gui/window/win_form.py index 1272f1690e..25137220eb 100644 --- a/tryton/gui/window/win_form.py +++ b/tryton/gui/window/win_form.py @@ -1,17 +1,18 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from tryton.common import TRYTON_ICON, COLOR_SCHEMES +from tryton.common import TRYTON_ICON import tryton.common as common import gtk import pango import gettext from tryton.gui.window.nomodal import NoModal from tryton.common.domain_parser import quote +from .infobar import InfoBar _ = gettext.gettext -class WinForm(NoModal): +class WinForm(NoModal, InfoBar): "Form window" def __init__(self, screen, callback, view_type='form', @@ -91,22 +92,8 @@ class WinForm(NoModal): title.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) title.show() - self.info_label = gtk.Label() - self.info_label.set_padding(3, 3) - self.info_label.set_alignment(1.0, 0.5) - - self.eb_info = gtk.EventBox() - self.eb_info.add(self.info_label) - self.eb_info.connect('button-release-event', - lambda *a: self.message_info('')) - - vbox = gtk.VBox() - vbox.pack_start(self.eb_info, expand=True, fill=True, padding=5) - vbox.show() - hbox = gtk.HBox() hbox.pack_start(title, expand=True, fill=True) - hbox.pack_start(vbox, expand=False, fill=True, padding=20) hbox.show() frame = gtk.Frame() @@ -121,6 +108,9 @@ class WinForm(NoModal): self.win.vbox.pack_start(eb, expand=False, fill=True, padding=3) + self.create_info_bar() + self.win.vbox.pack_start(self.info_bar, False, True) + if view_type == 'tree': hbox = gtk.HBox(homogeneous=False, spacing=0) tooltips = common.Tooltips() @@ -282,16 +272,6 @@ class WinForm(NoModal): self.screen.display() self.screen.current_view.set_cursor() - def message_info(self, message, color='red'): - if message: - self.info_label.set_label(message) - self.eb_info.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse( - COLOR_SCHEMES.get(color, 'white'))) - self.eb_info.show_all() - else: - self.info_label.set_label('') - self.eb_info.hide() - def on_keypress(self, widget, event): if (event.keyval == gtk.keysyms.F3) \ and self.but_new.get_property('sensitive'): @@ -415,9 +395,11 @@ class WinForm(NoModal): if record: validate = record.pre_validate() if not validate: + self.message_info(_('Invalid form.'), gtk.MESSAGE_ERROR) self.screen.set_cursor() self.screen.display() return + self.message_info() if response_id == gtk.RESPONSE_ACCEPT: self.new() return diff --git a/tryton/gui/window/wizard.py b/tryton/gui/window/wizard.py index 1c73c38a78..9a894e1315 100644 --- a/tryton/gui/window/wizard.py +++ b/tryton/gui/window/wizard.py @@ -13,10 +13,11 @@ from tryton.gui.window.nomodal import NoModal from tryton.common.button import Button from tryton.common import RPCExecute, RPCException from tryton.common import TRYTON_ICON +from .infobar import InfoBar _ = gettext.gettext -class Wizard(object): +class Wizard(InfoBar): def __init__(self, name=False): super(Wizard, self).__init__() @@ -144,7 +145,9 @@ class Wizard(object): if (not self.screen.current_record.validate() and state != self.end_state): self.screen.display(set_cursor=True) + self.message_info(_('Invalid form.'), gtk.MESSAGE_ERROR) return + self.message_info() self.state = state self.process() @@ -183,22 +186,8 @@ class Wizard(object): title.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) title.show() - self.info_label = gtk.Label() - self.info_label.set_padding(3, 3) - self.info_label.set_alignment(1.0, 0.5) - - self.eb_info = gtk.EventBox() - self.eb_info.add(self.info_label) - self.eb_info.connect('button-release-event', - lambda *a: self.message_info('')) - - vbox = gtk.VBox() - vbox.pack_start(self.eb_info, expand=True, fill=True, padding=5) - vbox.show() - hbox = gtk.HBox() hbox.pack_start(title, expand=True, fill=True) - hbox.pack_start(vbox, expand=False, fill=True, padding=20) hbox.show() frame = gtk.Frame() @@ -213,6 +202,9 @@ class Wizard(object): self.widget.pack_start(eb, expand=False, fill=True, padding=3) + self.create_info_bar() + self.widget.pack_start(self.info_bar, False, True) + if self.toolbar_box: self.widget.pack_start(self.toolbar_box, False, True)