diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 6deff2dfb6..849812a125 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -237,8 +237,8 @@ class Screen(SignalEvent): else: if self.current_view.view_type == 'form': self.new() - self.display() self.current_view.set_cursor() + self.display() # TODO: set True or False accoring to the type def load_view_to_load(self): @@ -346,9 +346,9 @@ class Screen(SignalEvent): self.models.model_add(model, self.new_model_position()) self.current_model = model self.current_model.validate_set() - self.display() if self.current_view: self.current_view.set_cursor(new=True) + self.display() return self.current_model def new_model_position(self): @@ -376,8 +376,8 @@ class Screen(SignalEvent): if self.current_model.validate(): obj_id = self.current_model.save(force_reload=True) else: - self.current_view.display() self.current_view.set_cursor() + self.current_view.display() return False if self.current_view.view_type == 'tree': for model in self.models.models: @@ -386,11 +386,11 @@ class Screen(SignalEvent): obj_id = model.save(force_reload=True) else: self.current_model = model - self.display() self.current_view.set_cursor() + self.display() return False - self.display() self.current_view.set_cursor() + self.display() if self.current_model not in self.models: self.models.model_add(self.current_model) return obj_id @@ -450,8 +450,8 @@ class Screen(SignalEvent): self.current_model = None if reload_ids: self.models.reload(reload_ids) - self.display() self.current_view.set_cursor() + self.display() res = obj_id if self.current_view.view_type == 'tree': ids = self.current_view.sel_ids_get() @@ -472,8 +472,8 @@ class Screen(SignalEvent): self.current_model = None if reload_ids: self.models.reload(reload_ids) - self.display() self.current_view.set_cursor() + self.display() res = ids return res @@ -513,8 +513,8 @@ class Screen(SignalEvent): and self.models.models[0] if self.current_model: self.current_model.validate_set() - self.display() self.current_view.set_cursor() + self.display() def display_prev(self): self.current_view.set_value() @@ -529,8 +529,8 @@ class Screen(SignalEvent): if self.current_model: self.current_model.validate_set() - self.display() self.current_view.set_cursor() + self.display() def sel_ids_get(self): return self.current_view.sel_ids_get() diff --git a/tryton/gui/window/view_form/view/form.py b/tryton/gui/window/view_form/view/form.py index ae096379b9..afec35d3e7 100644 --- a/tryton/gui/window/view_form/view/form.py +++ b/tryton/gui/window/view_form/view/form.py @@ -61,9 +61,9 @@ class ViewWidget(object): class ViewForm(ParserView): def __init__(self, window, screen, widget, children=None, - buttons=None, toolbar=None): + buttons=None, toolbar=None, notebooks=None, cursor_widget=''): super(ViewForm, self).__init__(window, screen, widget, children, - buttons, toolbar) + buttons, toolbar, notebooks, cursor_widget) self.view_type = 'form' self.model_add_new = False @@ -198,4 +198,7 @@ class ViewForm(ParserView): return True def set_cursor(self, new=False): - pass + for notebook in self.notebooks: + notebook.set_current_page(0) + if self.cursor_widget in self.widgets: + self.widgets[self.cursor_widget].widget.grab_focus() diff --git a/tryton/gui/window/view_form/view/form_gtk/binary.py b/tryton/gui/window/view_form/view/form_gtk/binary.py index cdd010645c..05b72a68c0 100644 --- a/tryton/gui/window/view_form/view/form_gtk/binary.py +++ b/tryton/gui/window/view_form/view/form_gtk/binary.py @@ -60,6 +60,9 @@ class Binary(WidgetInterface): self.but_new.show() self.but_remove.show() + def grab_focus(self): + return self.wid_text.grab_focus() + def sig_new(self, widget=None): try: filename = file_selection(_('Open...'), 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 b6599638f0..0072de14df 100644 --- a/tryton/gui/window/view_form/view/form_gtk/calendar.py +++ b/tryton/gui/window/view_form/view/form_gtk/calendar.py @@ -56,6 +56,9 @@ class Calendar(WidgetInterface): self.entry.set_sensitive(not value) self.but_open.set_sensitive(not value) + def grab_focus(self): + return self.entry.grab_focus() + def get_value(self, model): value = self.entry.get_text() if value == '': @@ -167,6 +170,9 @@ class DateTime(WidgetInterface): self.entry.set_editable(not value) self.entry.set_sensitive(not value) + def grab_focus(self): + return self.entry.grab_focus() + def get_value(self, model, timezone=True): value = self.entry.get_text() if value == '': 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 63df6b6332..b034edf42c 100644 --- a/tryton/gui/window/view_form/view/form_gtk/char.py +++ b/tryton/gui/window/view_form/view/form_gtk/char.py @@ -22,6 +22,9 @@ class Char(WidgetInterface): def _color_widget(self): return self.entry + 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) diff --git a/tryton/gui/window/view_form/view/form_gtk/image.py b/tryton/gui/window/view_form/view/form_gtk/image.py index 2d8bb05ee1..443f9a03d5 100644 --- a/tryton/gui/window/view_form/view/form_gtk/image.py +++ b/tryton/gui/window/view_form/view/form_gtk/image.py @@ -72,6 +72,9 @@ class Image(WidgetInterface): self.update_img() + def grab_focus(self): + return self.image.grab_focus() + def sig_add(self, widget): filter_all = gtk.FileFilter() filter_all.set_name(_('All files')) 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 7e58c4a379..222bdb349d 100644 --- a/tryton/gui/window/view_form/view/form_gtk/interface.py +++ b/tryton/gui/window/view_form/view/form_gtk/interface.py @@ -123,6 +123,9 @@ class WidgetInterface(object): def _invisible_widget(self): return self.widget + def grab_focus(self): + return self.widget.grab_focus() + def color_set(self, name): widget = self._color_widget() colormap = widget.get_colormap() 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 a4ceef2cd7..24e5c16a9c 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -49,6 +49,9 @@ class Many2Many(WidgetInterface): self.old = None + def grab_focus(self): + return self.wid_text.grab_focus() + def destroy(self): self.screen.destroy() self.widget.destroy() 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 aa2c969150..64d7f40f94 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2one.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2one.py @@ -153,6 +153,9 @@ class Many2One(WidgetInterface): if ids: self.load_completion(ids) + def grab_focus(self): + return self.wid_text.grab_focus() + def _focus_out(self): return WidgetInterface._focus_out(self) 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 1a82be510d..b6d6aeda6b 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -338,6 +338,9 @@ class One2Many(WidgetInterface): self.screen.widget.connect('key_press_event', self.on_keypress) + def grab_focus(self): + return self.screen.widget.grab_focus() + def on_keypress(self, widget, event): if (event.keyval == gtk.keysyms.N \ and event.state & gtk.gdk.CONTROL_MASK \ diff --git a/tryton/gui/window/view_form/view/form_gtk/parser.py b/tryton/gui/window/view_form/view/form_gtk/parser.py index 8356dba47f..d506b70577 100644 --- a/tryton/gui/window/view_form/view/form_gtk/parser.py +++ b/tryton/gui/window/view_form/view/form_gtk/parser.py @@ -257,12 +257,14 @@ class ParserForm(ParserInterface): tooltips=None): dict_widget = {} button_list = [] + notebook_list = [] attrs = common.node_attributes(root_node) on_write = attrs.get('on_write', '') if not tooltips: tooltips = gtk.Tooltips() container = _container(tooltips) container.new(col=int(attrs.get('col', 4))) + cursor_widget = attrs.get('cursor') if not self.title: self.title = attrs.get('string', 'Unknown') @@ -271,6 +273,8 @@ class ParserForm(ParserInterface): if not node.nodeType == node.ELEMENT_NODE: continue attrs = common.node_attributes(node) + if not cursor_widget: + cursor_widget = attrs.get('name') if node.localName == 'image': icon = Image(attrs) button_list.append(icon) @@ -356,6 +360,7 @@ class ParserForm(ParserInterface): elif node.localName == 'notebook': notebook = gtk.Notebook() + notebook_list.append(notebook) if attrs and 'tabpos' in attrs: pos = {'up':gtk.POS_TOP, 'down':gtk.POS_BOTTOM, @@ -375,8 +380,12 @@ class ParserForm(ParserInterface): notebook.set_border_width(3) container.wid_add(notebook, colspan=attrs.get('colspan', 4), expand=True, fill=True) - widget, widgets, buttons, on_write = self.parse(model, node, - fields, notebook, tooltips=tooltips) + widget, widgets, buttons, on_write, notebook_list2, cursor_widget2 = \ + self.parse(model, node, fields, notebook, + tooltips=tooltips) + if not cursor_widget: + cursor_widget = cursor_widget2 + notebook_list.extend(notebook_list2) button_list += buttons dict_widget.update(widgets) @@ -387,8 +396,12 @@ class ParserForm(ParserInterface): angle = int(CONFIG['client.form_tab_orientation']) label = gtk.Label(attrs.get('string','No String Attr.')) label.set_angle(angle) - widget, widgets, buttons, on_write = self.parse(model, node, - fields, notebook, tooltips=tooltips) + widget, widgets, buttons, on_write, notebook_list2, cursor_widget2 = \ + self.parse(model, node, fields, notebook, + tooltips=tooltips) + if not cursor_widget: + cursor_widget = cursor_widget2 + notebook_list.extend(notebook_list2) button_list += buttons dict_widget.update(widgets) notebook.append_page(widget, label) @@ -436,8 +449,11 @@ class ParserForm(ParserInterface): xexpand=xexpand, xfill=xfill) elif node.localName == 'group': - widget, widgets, buttons, on_write = self.parse(model, node, - fields, tooltips=tooltips) + widget, widgets, buttons, on_write, notebook_list2, cursor_widget2 = \ + self.parse(model, node, fields, tooltips=tooltips) + if not cursor_widget: + cursor_widget = cursor_widget2 + notebook_list.extend(notebook_list2) dict_widget.update(widgets) button_list += buttons if attrs.get('string', None): @@ -453,8 +469,12 @@ class ParserForm(ParserInterface): hpaned = gtk.HPaned() container.wid_add(hpaned, colspan=int(attrs.get('colspan', 4)), expand=True, fill=True) - widget, widgets, buttons, on_write = self.parse(model, node, - fields, paned=hpaned, tooltips=tooltips) + widget, widgets, buttons, on_write, notebook_list2, cursor_widget2 = \ + self.parse(model, node, fields, paned=hpaned, + tooltips=tooltips) + if not cursor_widget: + cursor_widget = cursor_widget2 + notebook_list.extend(notebook_list2) button_list += buttons dict_widget.update(widgets) if 'position' in attrs: @@ -463,28 +483,41 @@ class ParserForm(ParserInterface): vpaned = gtk.VPaned() container.wid_add(vpaned, colspan=int(attrs.get('colspan', 4)), expand=True, fill=True) - widget, widgets, buttons, on_write = self.parse(model, node, - fields, paned=vpaned, tooltips=tooltips) + widget, widgets, buttons, on_write, notebook_list, cursor_widget2 = \ + self.parse(model, node, fields, paned=vpaned, + tooltips=tooltips) + if not cursor_widget: + cursor_widget = cursor_widget2 + notebook_list.extend(notebook_list2) button_list += buttons dict_widget.update(widgets) if 'position' in attrs: vpaned.set_position(int(attrs['position'])) elif node.localName == 'child1': - widget, widgets, buttons, on_write = self.parse(model, node, - fields, paned=paned, tooltips=tooltips) + widget, widgets, buttons, on_write, notebook_list2, cursor_widget2 = \ + self.parse(model, node, fields, paned=paned, + tooltips=tooltips) + if not cursor_widget: + cursor_widget = cursor_widget2 + notebook_list.extend(notebook_list2) button_list += buttons dict_widget.update(widgets) paned.pack1(widget, resize=True, shrink=True) elif node.localName == 'child2': - widget, widgets, buttons, on_write = self.parse(model, node, - fields, paned=paned, tooltips=tooltips) + widget, widgets, buttons, on_write, notebook_list, cursor_widget2 = \ + self.parse(model, node, fields, paned=paned, + tooltips=tooltips) + if not cursor_widget: + cursor_widget = cursor_widget2 + notebook_list.extend(notebook_list2) button_list += buttons dict_widget.update(widgets) paned.pack2(widget, resize=True, shrink=True) for (button, src, name, widget) in container.trans_box: button.connect('clicked', self.translate, model, name, src, widget) - return container.pop(), dict_widget, button_list, on_write + return container.pop(), dict_widget, button_list, on_write, \ + notebook_list, cursor_widget def translate(self, widget, model, name, src, widget_entry): obj_id = self.screen.current_model.id 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 e95993d416..14aeddcbfb 100644 --- a/tryton/gui/window/view_form/view/form_gtk/reference.py +++ b/tryton/gui/window/view_form/view/form_gtk/reference.py @@ -87,6 +87,9 @@ class Reference(WidgetInterface): self.last_key = (None, 0) self.key_catalog = {} + def grab_focus(self): + return self.widget_combo.grab_focus() + def get_model(self): child = self.widget_combo.get_child() res = child.get_text() 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 f18a391a91..9a8fd1036e 100644 --- a/tryton/gui/window/view_form/view/form_gtk/selection.py +++ b/tryton/gui/window/view_form/view/form_gtk/selection.py @@ -44,6 +44,9 @@ class Selection(WidgetInterface): self.set_popdown(selection) self.last_key = (None, 0) + def grab_focus(self): + return self.entry.grab_focus() + def set_popdown(self, selection): model = gtk.ListStore(gobject.TYPE_STRING) self._selection = {} 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 a8539d5309..e63b78406e 100644 --- a/tryton/gui/window/view_form/view/form_gtk/textbox.py +++ b/tryton/gui/window/view_form/view/form_gtk/textbox.py @@ -25,6 +25,9 @@ class TextBox(WidgetInterface): self.widget.pack_start(self.scrolledwindow) + def grab_focus(self): + return self.textview.grab_focus() + def _readonly_set(self, value): super(TextBox, self)._readonly_set(value) self.textview.set_editable(not value) 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 20c81894e3..337d7dbbf8 100644 --- a/tryton/gui/window/view_form/view/form_gtk/url.py +++ b/tryton/gui/window/view_form/view/form_gtk/url.py @@ -33,6 +33,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) diff --git a/tryton/gui/window/view_form/view/graph.py b/tryton/gui/window/view_form/view/graph.py index c5c9cff204..a259318d0c 100644 --- a/tryton/gui/window/view_form/view/graph.py +++ b/tryton/gui/window/view_form/view/graph.py @@ -4,9 +4,9 @@ from interface import ParserView class ViewGraph(ParserView): def __init__(self, window, screen, widget, children=None, - buttons=None, toolbar=None): + buttons=None, toolbar=None, notebooks=None, cursor_widget=None): super(ViewGraph, self).__init__(window, screen, widget, children, - buttons, toolbar) + buttons, toolbar, notebooks, cursor_widget) self.view_type = 'graph' self.model_add_new = False self.widgets = children diff --git a/tryton/gui/window/view_form/view/graph_gtk/parser.py b/tryton/gui/window/view_form/view/graph_gtk/parser.py index 1c09320087..075be57c56 100644 --- a/tryton/gui/window/view_form/view/graph_gtk/parser.py +++ b/tryton/gui/window/view_form/view/graph_gtk/parser.py @@ -136,4 +136,4 @@ class ParserGraph(ParserInterface): event.add(widget) event.connect('button-press-event', button_press, widget, self.window) - return event, {'root': widget}, [], '' + return event, {'root': widget}, [], '', [], None diff --git a/tryton/gui/window/view_form/view/interface.py b/tryton/gui/window/view_form/view/interface.py index 06b4a751ec..83ec8c9bf4 100644 --- a/tryton/gui/window/view_form/view/interface.py +++ b/tryton/gui/window/view_form/view/interface.py @@ -15,7 +15,7 @@ class ParserInterface(object): class ParserView(object): def __init__(self, window, screen, widget, children=None, buttons=None, - toolbar=None): + toolbar=None, notebooks=None, cursor_widget=None): self.window = window self.screen = screen self.widget = widget @@ -24,3 +24,7 @@ class ParserView(object): buttons = [] self.buttons = buttons self.toolbar = toolbar + if notebooks is None: + notebooks = [] + self.notebooks = notebooks + self.cursor_widget = cursor_widget diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index c4ec18011f..82222571c9 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -136,9 +136,9 @@ class AdaptModelGroup(gtk.GenericTreeModel): class ViewList(ParserView): def __init__(self, window, screen, widget, children=None, buttons=None, - toolbar=None): + toolbar=None, notebooks=None, cursor_widget=None): super(ViewList, self).__init__(window, screen, widget, children, - buttons, toolbar) + buttons, toolbar, notebooks, cursor_widget) self.store = None self.view_type = 'tree' self.model_add_new = True diff --git a/tryton/gui/window/view_form/view/list_gtk/parser.py b/tryton/gui/window/view_form/view/list_gtk/parser.py index 6da8a8a306..8d462b2b54 100644 --- a/tryton/gui/window/view_form/view/list_gtk/parser.py +++ b/tryton/gui/window/view_form/view/list_gtk/parser.py @@ -177,7 +177,7 @@ class ParserTree(ParserInterface): dict_widget[i] = (fname, label, label_sum, fields.get('digits', (16,2))[1], label_bold) treeview.set_fixed_height_mode(True) - return treeview, dict_widget, [], on_write + return treeview, dict_widget, [], on_write, [], None class Char(object): diff --git a/tryton/gui/window/view_form/view/widget_parse.py b/tryton/gui/window/view_form/view/widget_parse.py index e922d00ad3..050d5e3a6b 100644 --- a/tryton/gui/window/view_form/view/widget_parse.py +++ b/tryton/gui/window/view_form/view/widget_parse.py @@ -33,11 +33,11 @@ class WidgetParse(ParserInterface): if node.localName in PARSERS: widget = PARSERS[node.localName](self.window, self.parent, self.attrs, screen) - wid, child, buttons, on_write = widget.parse(screen.resource, - node, fields) + wid, child, buttons, on_write, notebooks, cursor_widget = \ + widget.parse(screen.resource, node, fields) screen.set_on_write(on_write) res = PARSERS2[node.localName](self.window, screen, wid, child, - buttons, toolbar) + buttons, toolbar, notebooks, cursor_widget) res.title = widget.title widget = res break diff --git a/tryton/wizard/main.py b/tryton/wizard/main.py index fb0a9d7579..9958a3cf7f 100644 --- a/tryton/wizard/main.py +++ b/tryton/wizard/main.py @@ -39,9 +39,7 @@ class Dialog(object): val[i] = fields[i]['value'] self.screen = Screen(obj_name, self.dia, view_type=[], context=context) - self.screen.new(default=False) self.screen.add_view_custom(arch, fields, display=True) - self.screen.current_model.set(val) width, height = self.screen.screen_container.size_get() parent_width, parent_height = parent.get_size() @@ -52,6 +50,9 @@ class Dialog(object): self.dia.vbox.pack_start(self.screen.widget) self.dia.set_title(self.dia.get_title() + ' - ' + self.screen.current_view.title) self.dia.show() + self.screen.new(default=False) + self.screen.current_model.set(val) + self.screen.current_view.set_cursor() def run(self, datas=None): if datas is None: