diff --git a/CHANGELOG b/CHANGELOG index 543591ed36..68b2ff0186 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Remove generic default value on right-click * Made numpad locale aware * Selection widget used for many2one dynamically change their content following the domain specification diff --git a/doc/usage.rst b/doc/usage.rst index 0212d10414..877f5e8879 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -146,8 +146,7 @@ next one. The second mouse button (usually right mouse button) provides an additional contextual menu for some views and fields. In this context menu the user finds -:term:`actions` to copy and paste contents or setting up default values or -selections for several fields. +:term:`actions` to copy and paste contents or selections for several fields. Tool Bar diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index 3275a97843..0493b4956f 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -39,8 +39,6 @@ class CharField(object): return if self.attrs.get('on_change', False): record.on_change(self.name, self.attrs['on_change']) - if self.attrs.get('change_default', False): - record.cond_default(self.attrs['name'], self.get(record)) record.on_change_with(self.name) def domains_get(self, record): diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index 2ce4109f85..c32beaa02d 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -438,19 +438,6 @@ class Record(SignalEvent): return self.group.fields[fieldname].set_on_change(self, res) - def cond_default(self, field_name, value): - ctx = rpc.CONTEXT.copy() - ctx.update(self.context_get()) - args = ('model', 'ir.default', 'get_default', self.model_name, - field_name + '=' + str(value), ctx) - try: - res = rpc.execute(*args) - except Exception, exception: - res = common.process_exception(exception, self.window, *args) - if not res: - return - self.set_default(res) - def get_attachment_count(self, reload=False): if self.id < 0: return 0 diff --git a/tryton/gui/window/view_form/view/form_gtk/calendar.py b/tryton/gui/window/view_form/view/form_gtk/calendar.py index 80b080759b..d8afdf414c 100644 --- a/tryton/gui/window/view_form/view/form_gtk/calendar.py +++ b/tryton/gui/window/view_form/view/form_gtk/calendar.py @@ -27,7 +27,6 @@ class Calendar(WidgetInterface): self.entry = self.widget.widget self.entry.set_property('activates_default', True) self.entry.connect('key_press_event', self.sig_key_press) - self.entry.connect('populate-popup', self._populate_popup) 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()) @@ -164,7 +163,6 @@ class DateTime(WidgetInterface): self.entry = self.widget.widget self.entry.set_property('activates_default', True) self.entry.connect('key_press_event', self.sig_key_press) - self.entry.connect('populate-popup', self._populate_popup) self.entry.connect('focus-in-event', lambda x, y: self._focus_in()) self.entry.connect('focus-out-event', lambda x, y: self._focus_out()) 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 28fad0dde1..4bf4df841e 100644 --- a/tryton/gui/window/view_form/view/form_gtk/char.py +++ b/tryton/gui/window/view_form/view/form_gtk/char.py @@ -20,7 +20,6 @@ class Char(WidgetInterface): self.entry.set_max_length(int(attrs.get('size', 0))) self.entry.set_width_chars(5) - self.entry.connect('populate-popup', self._populate_popup) 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()) diff --git a/tryton/gui/window/view_form/view/form_gtk/checkbox.py b/tryton/gui/window/view_form/view/form_gtk/checkbox.py index acd5d9f6f4..f3d5bc34a6 100644 --- a/tryton/gui/window/view_form/view/form_gtk/checkbox.py +++ b/tryton/gui/window/view_form/view/form_gtk/checkbox.py @@ -14,7 +14,6 @@ class CheckBox(WidgetInterface): self.widget = gtk.CheckButton() self.widget.connect('focus-in-event', lambda x, y: self._focus_in()) self.widget.connect('focus-out-event', lambda x, y: self._focus_out()) - self.widget.connect('button_press_event', self._menu_open) self.widget.connect_after('toggled', self.sig_activate) def _readonly_set(self, value): diff --git a/tryton/gui/window/view_form/view/form_gtk/float_time.py b/tryton/gui/window/view_form/view/form_gtk/float_time.py index 738b09eae6..3fa5c60b25 100644 --- a/tryton/gui/window/view_form/view/form_gtk/float_time.py +++ b/tryton/gui/window/view_form/view/form_gtk/float_time.py @@ -17,7 +17,6 @@ class FloatTime(WidgetInterface): self.entry.set_alignment(1.0) self.entry.set_property('activates_default', True) - self.entry.connect('populate-popup', self._populate_popup) 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()) diff --git a/tryton/gui/window/view_form/view/form_gtk/interface.py b/tryton/gui/window/view_form/view/form_gtk/interface.py index 8d72d4ceb4..b1644d4ee2 100644 --- a/tryton/gui/window/view_form/view/form_gtk/interface.py +++ b/tryton/gui/window/view_form/view/form_gtk/interface.py @@ -1,67 +1,7 @@ #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 -import tryton.rpc as rpc -from tryton.common import COLORS, process_exception, message -from tryton.config import TRYTON_ICON -from tryton.gui.window.view_form.view.form_gtk.preference \ - import WidgetFieldPreference -import gettext - -_ = gettext.gettext - -def field_pref_set(field, name, model_name, value, client_value, dependance, - window, reset=False): - dialog = WidgetFieldPreference(window, reset=reset) - if dependance is None: - dependance = [] - entry = dialog.entry_field_name - entry.set_text(name) - entry = dialog.entry_default_value - entry.set_text((client_value and str(client_value)) or _('')) - - radio = dialog.radio_current_user - - vbox = dialog.vbox_condition - widgets = {} - addwidget = False - widget = None - if dependance: - widget = gtk.RadioButton(widget, _('Always')) - vbox.pack_start(widget) - for (fname, name, fvalue, dvalue) in dependance: - if fvalue: - addwidget = True - widget = gtk.RadioButton(widget, name + ' = ' + str(dvalue)) - widgets[(fname, fvalue)] = widget - vbox.pack_start(widget) - if not len(dependance) or not addwidget: - vbox.pack_start(gtk.Label(_('Always applicable!'))) - vbox.show_all() - - res = dialog.run() - - clause = False - for val, widget in widgets.iteritems(): - if widget.get_active(): - clause = val[0] + '=' + str(val[1]) - break - user = False - if radio.get_active(): - user = rpc._USER - if res == gtk.RESPONSE_OK: - if reset: - method = 'reset_default' - else: - method = 'set_default' - args = ('model', 'ir.default', method, model_name, field, clause, - value, user, rpc.CONTEXT) - try: - rpc.execute(*args) - except Exception, exception: - process_exception(exception, window, *args) - return True - return False +from tryton.common import COLORS class WidgetInterface(object): @@ -75,14 +15,6 @@ class WidgetInterface(object): for attr_name in ('readonly', 'invisible'): if attr_name in self.attrs: self.attrs[attr_name] = bool(int(self.attrs[attr_name])) - self._menu_entries = [ - (_('Set to default value'), - lambda x: self._menu_sig_default_get(), 1), - (_('Set as default'), - lambda x: self._menu_sig_default_set(), 1), - (_('Reset default'), - lambda x: self._menu_sig_default_set(reset=True), 1), - ] self.widget = None self.position = 0 self.colors = {} @@ -104,39 +36,6 @@ class WidgetInterface(object): def destroy(self): pass - def _menu_sig_default_get(self): - if self.field.get_state_attrs(self.record).get('readonly', False): - return False - model_name = self.field.parent.model_name - args = ('model', model_name, 'default_get', [self.attrs['name']], - rpc.CONTEXT) - try: - res = rpc.execute(*args) - except Exception, exception: - process_exception(exception, self.window, *args) - self.field.set_default(self.record, - res.get(self.attrs['name'], False), modified=True) - self.display(self.record, self.field) - - def _menu_sig_default_set(self, reset=False): - deps = [] - for wname, wviews in self.view.widgets.iteritems(): - for wview in wviews: - if wview.field.attrs.get('change_default', False): - wvalue = wview.field.get(self.record) - name = wview.field.attrs.get('string', wname) - value = wview.field.get_client(self.record) - deps.append((wname, name, wvalue, value)) - if not self.field.validate(self.record): - message(_('Invalid field!'), parent=self.window) - return - value = self.field.get_default(self.record) - client_value = self.display_value() - model_name = self.field.parent.model_name - field_pref_set(self.field_name, - self.attrs.get('string', self.field_name), model_name, - value, client_value, deps, self.window, reset=reset) - def sig_activate(self, widget=None): # emulate a focus_out so that the onchange is called if needed self._focus_out() @@ -214,38 +113,6 @@ class WidgetInterface(object): def display_value(self): return self.field.get_client(self.record) - def _menu_open(self, obj, event): - if event.button == 3: - menu = gtk.Menu() - for stock_id, callback, sensitivity in self._menu_entries: - if stock_id: - item = gtk.ImageMenuItem(stock_id) - if callback: - item.connect("activate", callback) - item.set_sensitive(sensitivity) - else: - item = gtk.SeparatorMenuItem() - item.show() - menu.append(item) - menu.popup(None, None, None, event.button, event.time) - return True - - def _populate_popup(self, widget, menu): - menu_entries = [] - menu_entries.append((None, None, None)) - menu_entries += self._menu_entries - for stock_id, callback, sensitivity in menu_entries: - if stock_id: - item = gtk.ImageMenuItem(stock_id) - if callback: - item.connect("activate", callback) - item.set_sensitive(sensitivity) - else: - item = gtk.SeparatorMenuItem() - item.show() - menu.append(item) - return True - def _focus_in(self): pass diff --git a/tryton/gui/window/view_form/view/form_gtk/many2many.py b/tryton/gui/window/view_form/view/form_gtk/many2many.py index 058c2692c5..f2ef976968 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -25,7 +25,6 @@ class Many2Many(WidgetInterface): self.wid_text = gtk.Entry() self.wid_text.set_property('width_chars', 13) self.wid_text.connect('activate', self._sig_activate) - self.wid_text.connect('button_press_event', self._menu_open) hbox.pack_start(self.wid_text, expand=True, fill=True) hbox.pack_start(gtk.VSeparator(), padding=2, expand=False, fill=False) diff --git a/tryton/gui/window/view_form/view/form_gtk/many2one.py b/tryton/gui/window/view_form/view/form_gtk/many2one.py index f0597d5a1f..d8290a7075 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2one.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2one.py @@ -310,7 +310,6 @@ class Many2One(WidgetInterface): return False menu_entries = [] menu_entries.append((None, None, None)) - menu_entries += self._menu_entries menu_entries.append((None, None, None)) menu_entries.append((_('Actions'), lambda x: self.click_and_action('form_action'),0)) diff --git a/tryton/gui/window/view_form/view/form_gtk/one2many.py b/tryton/gui/window/view_form/view/form_gtk/one2many.py index db1958e6cd..585bb709ea 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -21,35 +21,17 @@ class One2Many(WidgetInterface): super(One2Many, self).__init__(field_name, model_name, window, attrs=attrs) - self.widget = gtk.VBox(homogeneous=False, spacing=5) + self.widget = gtk.VBox(homogeneous=False, spacing=2) self._readonly = True hbox = gtk.HBox(homogeneous=False, spacing=0) - menubar = gtk.MenuBar() - if hasattr(menubar, 'set_pack_direction') and \ - hasattr(menubar, 'set_child_pack_direction'): - menubar.set_pack_direction(gtk.PACK_DIRECTION_LTR) - menubar.set_child_pack_direction(gtk.PACK_DIRECTION_LTR) + hbox.set_border_width(2) - menuitem_title = gtk.ImageMenuItem(stock_id='tryton-preferences') + label = gtk.Label(attrs.get('string', '')) + label.set_alignment(0.0, 0.5) + hbox.pack_start(label, expand=True, fill=True) - menu_title = gtk.Menu() - menuitem_set_to_default = gtk.MenuItem(_('Set to default value'), True) - menuitem_set_to_default.connect('activate', - lambda *x: self._menu_sig_default_get()) - menu_title.add(menuitem_set_to_default) - menuitem_set_default = gtk.MenuItem(_('Set as default'), True) - menuitem_set_default.connect('activate', - lambda *x: self._menu_sig_default_set()) - menu_title.add(menuitem_set_default) - menuitem_reset_default = gtk.MenuItem(_('Reset default'), True) - menuitem_reset_default.connect('activate', - lambda *x: self._menu_sig_default_set(reset=True)) - menu_title.add(menuitem_reset_default) - menuitem_title.set_submenu(menu_title) - - menubar.add(menuitem_title) - hbox.pack_start(menubar, expand=True, fill=True) + hbox.pack_start(gtk.VSeparator(), expand=False, fill=True) tooltips = common.Tooltips() @@ -166,7 +148,10 @@ class One2Many(WidgetInterface): tooltips.enable() - self.widget.pack_start(hbox, expand=False, fill=True) + frame = gtk.Frame() + frame.add(hbox) + frame.set_shadow_type(gtk.SHADOW_OUT) + self.widget.pack_start(frame, expand=False, fill=True) self.screen = Screen(attrs['relation'], self.window, view_type=attrs.get('mode', 'tree,form').split(','), @@ -174,7 +159,6 @@ class One2Many(WidgetInterface): row_activate=self._on_activate, exclude_field=attrs.get('relation_field', None)) self.screen.signal_connect(self, 'record-message', self._sig_label) - menuitem_title.get_child().set_text(attrs.get('string', '')) if not isinstance(self.screen.window, gtk.Dialog): self.screen.widget.set_size_request(0, 0) diff --git a/tryton/gui/window/view_form/view/form_gtk/preference.py b/tryton/gui/window/view_form/view/form_gtk/preference.py deleted file mode 100644 index a8c6bdbe54..0000000000 --- a/tryton/gui/window/view_form/view/form_gtk/preference.py +++ /dev/null @@ -1,116 +0,0 @@ -# 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 -import gettext -import tryton.common as common -from tryton.config import CONFIG, TRYTON_ICON -import tryton.rpc as rpc - -_ = gettext.gettext - - -class WidgetFieldPreference(object): - """ - Widget for field preferences. - """ - def __init__(self, window, reset=False): - self.parent = window - self.dialog = gtk.Dialog( - title=_("Field Preference"), - parent=window, - flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT - | gtk.WIN_POS_CENTER_ON_PARENT) - self.dialog.set_icon(TRYTON_ICON) - self.dialog.add_button("gtk-cancel", gtk.RESPONSE_CANCEL) - - if not reset: - button_ok = gtk.Button(_("Set")) - else: - button_ok = gtk.Button(_("Reset")) - button_ok.set_flags(gtk.CAN_DEFAULT) - button_ok.set_flags(gtk.HAS_DEFAULT) - img_ok = gtk.Image() - img_ok.set_from_stock("gtk-ok", gtk.ICON_SIZE_BUTTON) - button_ok.set_image(img_ok) - self.dialog.add_action_widget(button_ok, gtk.RESPONSE_OK) - self.dialog.set_default_response(gtk.RESPONSE_OK) - vbox = gtk.VBox() - self.dialog.vbox.pack_start(vbox) - table = gtk.Table(4, 2, False) - table.set_border_width(4) - table.set_row_spacings(4) - table.set_col_spacings(4) - vbox.pack_start(table, True, True, 0) - - label_field_name = gtk.Label(_("Field Name:")) - label_field_name.set_justify(gtk.JUSTIFY_RIGHT) - label_field_name.set_alignment(1, 0.5) - table.attach(label_field_name, 0, 1, 0, 1) - self.entry_field_name = gtk.Entry() - self.entry_field_name.set_editable(False) - style = self.entry_field_name.get_style() - self.entry_field_name.modify_bg(gtk.STATE_NORMAL, - style.bg[gtk.STATE_INSENSITIVE]) - self.entry_field_name.modify_base(gtk.STATE_NORMAL, - style.base[gtk.STATE_INSENSITIVE]) - self.entry_field_name.modify_fg(gtk.STATE_NORMAL, - style.fg[gtk.STATE_INSENSITIVE]) - table.attach(self.entry_field_name, 1, 2, 0, 1) - label_default_value = gtk.Label(_("Default value:")) - label_default_value.set_alignment(1, 0.5) - table.attach(label_default_value, 0, 1, 1, 2) - self.entry_default_value = gtk.Entry() - self.entry_default_value.set_editable(False) - self.entry_default_value.set_width_chars(32) - style = self.entry_field_name.get_style() - self.entry_default_value.modify_bg(gtk.STATE_NORMAL, - style.bg[gtk.STATE_INSENSITIVE]) - self.entry_default_value.modify_base(gtk.STATE_NORMAL, - style.base[gtk.STATE_INSENSITIVE]) - self.entry_default_value.modify_fg(gtk.STATE_NORMAL, - style.fg[gtk.STATE_INSENSITIVE]) - table.attach(self.entry_default_value, 1, 2, 1, 2) - - frame_user = gtk.Frame() - alignment_user = gtk.Alignment(0.5, 0.5, 1, 1) - alignment_user.set_padding(0, 0, 12, 0) - frame_user.add(alignment_user) - label_user = gtk.Label(_("Value applicable for:")) - label_user.set_use_markup(True) - frame_user.set_label_widget(label_user) - hbox_user = gtk.HBox(True, 0) - alignment_user.add(hbox_user) - hbox_user.set_border_width(6) - self.radio_current_user = gtk.RadioButton(None, _("Current _User")) - radio_all_user = gtk.RadioButton(self.radio_current_user, - _("_All Users")) - hbox_user.pack_start(self.radio_current_user, False, False, 0) - hbox_user.pack_start(radio_all_user, False, False, 0) - radio_all_user.set_active(True) - table.attach(frame_user, 0, 2, 2, 3) - - frame_condition = gtk.Frame() - alignment_condition = gtk.Alignment(0.5, 0.5, 1, 1) - alignment_condition.set_padding(0, 0, 12, 0) - frame_condition.add(alignment_condition) - label_condition = gtk.Label(_("Value applicable if:")) - label_condition.set_use_markup(True) - frame_condition.set_label_widget(label_condition) - self.vbox_condition = gtk.VBox(False, 0) - alignment_condition.add(self.vbox_condition) - table.attach(frame_condition, 0, 2, 3, 4) - - self.dialog.show_all() - if reset: - label_default_value.hide() - self.entry_default_value.hide() - - radio_all_user.grab_focus() - - def run(self): - while True: - res = self.dialog.run() - if res : - self.parent.present() - self.dialog.destroy() - return res diff --git a/tryton/gui/window/view_form/view/form_gtk/reference.py b/tryton/gui/window/view_form/view/form_gtk/reference.py index 7ce53262cb..4942995707 100644 --- a/tryton/gui/window/view_form/view/form_gtk/reference.py +++ b/tryton/gui/window/view_form/view/form_gtk/reference.py @@ -36,7 +36,6 @@ class Reference(WidgetInterface): self.wid_text = gtk.Entry() self.wid_text.set_property('width-chars', 13) self.wid_text.connect('key_press_event', self.sig_key_press) - self.wid_text.connect('populate-popup', self._populate_popup) self.wid_text.connect_after('changed', self.sig_changed) self.changed = True self.wid_text.connect_after('activate', self.sig_activate) diff --git a/tryton/gui/window/view_form/view/form_gtk/selection.py b/tryton/gui/window/view_form/view/form_gtk/selection.py index 94a032fd3c..e4ace6bd2f 100644 --- a/tryton/gui/window/view_form/view/form_gtk/selection.py +++ b/tryton/gui/window/view_form/view/form_gtk/selection.py @@ -23,7 +23,6 @@ class Selection(WidgetInterface): child.connect('changed', self.sig_changed) self.changed = True - child.connect('button_press_event', self._menu_open) child.connect('key_press_event', self.sig_key_press) child.connect('activate', self.sig_activate) child.connect_after('focus-out-event', self.sig_activate) diff --git a/tryton/gui/window/view_form/view/form_gtk/textbox.py b/tryton/gui/window/view_form/view/form_gtk/textbox.py index 114a86beb6..459092f7d3 100644 --- a/tryton/gui/window/view_form/view/form_gtk/textbox.py +++ b/tryton/gui/window/view_form/view/form_gtk/textbox.py @@ -26,7 +26,6 @@ class TextBox(WidgetInterface): self.textview = gtk.TextView() self.textview.set_wrap_mode(gtk.WRAP_WORD) - self.textview.connect('populate-popup', self._populate_popup) #TODO better tab solution self.textview.set_accepts_tab(False) self.textview.connect('focus-in-event', lambda x, y: self._focus_in())