def __init__(self, window, screen, widget, children=None, buttons=None, toolbar=None, submenu=None, help={}): super(ViewCalendar, self).__init__(window, screen, widget, children, buttons, toolbar, submenu) self.view_type = 'calendar' self.view = widget self.model_add_new = False self.widget = widget.widget self.help = help if self.help: action_tips = common.action_tips(self.help) self.help_frame = action_tips.help_frame if self.help_frame: vbox = gtk.VBox() vbox.pack_start(self.help_frame, expand=False, fill=False, padding=2) vbox.pack_end(self.widget) vbox.show_all() self.widget = vbox self.view.screen = screen self.reload = False
def add_filter(self, screen): self.filter_vbox = gtk.VBox(spacing=1) self.filter_vbox.set_border_width(1) if self.help and not self.win_search: action_tips = common.action_tips(self.help) self.help_frame = action_tips.help_frame if self.help_frame: self.filter_vbox.pack_start(self.help_frame, expand=False, fill=False, padding=3) self.filter_vbox.pack_start(screen.filter_widget.widget, expand=True, fill=True) hs = gtk.HBox(homogeneous=False, spacing=0) hb1 = gtk.HButtonBox() hb1.set_layout(gtk.BUTTONBOX_START) #Find Clear Buttons button_clear = gtk.Button(stock=gtk.STOCK_CLEAR) button_clear.connect('clicked', screen.search_clear) self.button = gtk.Button(stock=gtk.STOCK_FIND) self.button.connect('clicked', screen.search_filter) if self.win_search: hb3 = hb1 hs.pack_start(hb3, expand=False, fill=False) hb3.pack_start(self.button, expand=False, fill=False) hb3.pack_start(button_clear, expand=False, fill=False) else: hb1.set_spacing(5) hb2 = gtk.HBox(homogeneous=False, spacing=0) hb3 = gtk.HBox(homogeneous=False, spacing=0) hs.pack_start(hb1, expand=False, fill=False) hs.pack_start(hb2, expand=True, fill=True) hs.pack_end(hb3, expand=False, fill=False) self.button.set_property('can_default', True) hb1.pack_start(self.button, expand=False, fill=False) hb1.pack_start(button_clear, expand=False, fill=False) #Action Filter and custom Filter Button #actions combo self.action_list = gtk.ListStore(gobject.TYPE_INT, # action_id gobject.TYPE_STRING, # domain gobject.TYPE_STRING, # context gobject.TYPE_INT, # user_id gobject.TYPE_STRING, # action name gobject.TYPE_STRING) # display name self.action_combo = gtk.ComboBox(self.action_list) cell = gtk.CellRendererText() self.action_combo.pack_start(cell, True) self.action_combo.add_attribute(cell, 'text', 5) self.fill_filter_combo(screen.name) self.action_combo.set_active(0) self.handler_id = self.action_combo.connect('changed', screen.execute_action) #Custom Filter Button img2 = gtk.Image() img2.set_from_stock('gtk-add', gtk.ICON_SIZE_BUTTON) self.button_dynamic = gtk.Button() self.button_dynamic.set_image(img2) self.button_dynamic.set_relief(gtk.RELIEF_NONE) self.button_dynamic.set_alignment(0.3,0.3) self.button_dynamic.connect('clicked', self.add_custom_filter, screen) hb2.pack_start(gtk.Label(''), expand=True, fill=True) hb2.pack_start(self.action_combo, expand=False, fill=False) hb2.pack_start(self.button_dynamic, expand=False, fill=False) hb2.pack_start(gtk.Label(''), expand=True, fill=True) # Limit combo self.limit_combo = gtk.ListStore(object, str) self.combo = gtk.ComboBox(self.limit_combo) cell = gtk.CellRendererText() self.combo.pack_start(cell, True) self.combo.add_attribute(cell, 'text', 1) self.selection = [] hb3.pack_start(self.combo, expand=False, fill=False) self.fill_limit_combo(screen.limit) #Back Forward Buttons self.but_previous = gtk.Button() icon = gtk.Image() icon.set_from_stock('gtk-go-back', gtk.ICON_SIZE_SMALL_TOOLBAR) self.but_previous.set_image(icon) self.but_previous.set_relief(gtk.RELIEF_NONE) self.but_previous.connect('clicked', screen.search_offset_previous) icon2 = gtk.Image() icon2.set_from_stock('gtk-go-forward', gtk.ICON_SIZE_SMALL_TOOLBAR) self.but_next = gtk.Button() self.but_next.set_image(icon2) self.but_next.set_relief(gtk.RELIEF_NONE) self.but_next.connect('clicked', screen.search_offset_next) self.next_prev_box = hb3 if self.win_search: self.next_prev_box = gtk.HBox(homogeneous=False, spacing=0) hs.pack_start(self.next_prev_box, expand=False, fill=False) self.next_prev_box.pack_start(gtk.VSeparator(),padding=3, expand=False, fill=False) self.next_prev_box.pack_start(self.but_previous, expand=False, fill=False) self.next_prev_box.pack_start(self.but_next, expand=False, fill=False) hs.show_all() self.filter_vbox.pack_start(hs, expand=False, fill=False) hs = gtk.HSeparator() hs.show() self.filter_vbox.pack_start(hs, expand=True, fill=False) self.vbox.pack_start(self.filter_vbox, expand=False, fill=True)
def __init__(self, window, screen, widget, children=None, state_aware_widgets=None, toolbar=None, submenu=None, help={}): super(ViewForm, self).__init__(window, screen, widget, children, state_aware_widgets, toolbar, submenu) self.view_type = 'form' self.model_add_new = False self.prev = 0 self.window = window self.flag = False self.current = 0 for w in self.state_aware_widgets: if isinstance(w.widget, Button): w.widget.form = self self.widgets = dict([(name, ViewWidget(self, widget, name)) for name, widget in children.items()]) sm_vbox = False self.help = help self.help_frame = False if self.help: action_tips = common.action_tips(self.help) self.help_frame = action_tips.help_frame if self.help_frame: vbox = gtk.VBox() vbox.pack_start(self.help_frame, expand=False, fill=False, padding=2) vbox.pack_end(self.widget) vbox.show_all() self.widget = vbox if submenu: expander = gtk.Expander("Submenus") sm_vbox = gtk.VBox() sm_hbox = gtk.HBox() sm_eb = gtk.EventBox() sm_eb.add(sm_hbox) sm_eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("gray")) expander.add(sm_eb) for sub in eval(submenu): sbutton = gtk.Button() icon = gtk.Image() file_path = os.path.realpath("icons") iname = sub.get('icon', 'terp-marketing').split('-')[1] pixbuf = gtk.gdk.pixbuf_new_from_file(file_path + '/' + iname + '.png') icon_set = gtk.IconSet(pixbuf) icon.set_from_icon_set(icon_set, gtk.ICON_SIZE_BUTTON) lbl = gtk.Label(sub.get('name', 'Undefined')) lbl.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black")) hb = gtk.HBox(False, 5) hb.pack_start(icon, False, False) hb.pack_start(lbl, False, False) sbutton.add(hb) sm_hbox.pack_start(sbutton, False, False, 0) def _action_submenu(but, action): act_id = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.model.data', 'search', [('name','=',action['action_id'])]) res_model = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.model.data', 'read', act_id, ['res_id']) data = {} context = self.screen.context act = action.copy() self.screen.save_current() id = self.screen.current_model and self.screen.current_model.id if not (id): common.message(_('You must save this record to use the relate button !')) return False self.screen.display() obj = service.LocalService('action.main') if not res_model: common.message(_('Action not defined !')) return None res = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.actions.act_window', 'read', res_model[0]['res_id'], False) res['domain'] = self.screen.current_model.expr_eval(res['domain'], check_load=False) res['context'] = str(self.screen.current_model.expr_eval(res['context'], check_load=False)) value = obj._exec_action(res, data, context) self.screen.reload() return value sbutton.connect('clicked', _action_submenu, sub) sm_vbox.pack_start(expander, False, False, 1) sm_vbox.pack_end(self.widget, True, True, 0) if toolbar: hb = gtk.HBox() if sm_vbox: hb.pack_start(sm_vbox) else: hb.pack_start(self.widget) tb = gtk.VBox() eb = gtk.EventBox() hb.pack_start(eb, False, False) eb.add(tb) eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("lightgrey")) self.widget = hb sep = False for icontype in ('print', 'action', 'relate'): if icontype in ('action','relate') and sep: tb.pack_start(gtk.HSeparator(), False, False, 2) sep = False for tool in toolbar[icontype]: iconstock = { 'print': gtk.STOCK_PRINT, 'action': gtk.STOCK_EXECUTE, 'relate': gtk.STOCK_JUMP_TO, }.get(icontype, gtk.STOCK_ABOUT) icon = gtk.Image() icon.set_from_stock(iconstock, gtk.ICON_SIZE_BUTTON) lbl = gtk.Label(tool['string']) lbl.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black")) hb = gtk.HBox(False, 5) hb.pack_start(icon, False, False) hb.pack_start(lbl, False, False) tbutton = gtk.Button() tbutton.add(hb) tbutton.set_relief(gtk.RELIEF_NONE) tb.pack_start(tbutton, False, False, 2) def _action(button, action, type): data = {} context = self.screen.context if 'group_by' in context: del context['group_by'] act = action.copy() if type in ('print', 'action'): self.screen.save_current() id = self.screen.current_model and self.screen.current_model.id if not (id): common.message(_('You must save this record to use the action button !')) return False self.screen.display() data = { 'model': self.screen.name, 'id': id, 'ids': [id], 'report_type': act.get('report_type', 'pdf'), } if type == 'relate': id = self.screen.current_model and self.screen.current_model.id if not (id): common.message(_('You must select a record to use the relate button !')) return False if act.get('domain',False): act['domain'] = self.screen.current_model.expr_eval(act['domain'], check_load=False) if act.get('context',False): act['context'] = str(self.screen.current_model.expr_eval(act['context'], check_load=False)) data = { 'model': self.screen.name, 'id': id, 'ids': [id], } obj = service.LocalService('action.main') value = obj._exec_action(act, data, context) if type in ('print', 'action') or type == 'relate' and act.get('target') == 'new': self.screen.reload() return value def _translate_label(self, event, tool, window): if event.button != 3: return False def callback(self, tool, window): lang_ids = rpc.session.rpc_exec_auth('/object', 'execute', 'res.lang', 'search', [('translatable', '=', '1')]) if not lang_ids: common.message(_('No other language available!'), parent=window) return False langs = rpc.session.rpc_exec_auth('/object', 'execute', 'res.lang', 'read', lang_ids, ['code', 'name']) win = gtk.Dialog(_('Add Translation'), window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) win.vbox.set_spacing(5) win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) win.set_icon(common.OPENERP_ICON) vbox = gtk.VBox(spacing=5) entries_list = [] for lang in langs: code = lang['code'] val = rpc.session.rpc_exec_auth('/object', 'execute', tool['type'], 'read', [tool['id']], ['name'], {'lang': code}) val = val[0] label = gtk.Label(lang['name']) entry = gtk.Entry() entry.set_text(val['name']) entries_list.append((code, entry)) hbox = gtk.HBox(homogeneous=True) hbox.pack_start(label, expand=False, fill=False) hbox.pack_start(entry, expand=True, fill=True) vbox.pack_start(hbox, expand=False, fill=True) vp = gtk.Viewport() vp.set_shadow_type(gtk.SHADOW_NONE) vp.add(vbox) sv = gtk.ScrolledWindow() sv.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sv.set_shadow_type(gtk.SHADOW_NONE) sv.add(vp) win.vbox.add(sv) win.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) win.resize(400,200) win.show_all() res = win.run() if res == gtk.RESPONSE_OK: to_save = map(lambda x: (x[0], x[1].get_text()), entries_list) while to_save: code, val = to_save.pop() rpc.session.rpc_exec_auth('/object', 'execute', tool['type'], 'write', [tool['id']], {'name': val}, {'lang': code}) window.present() win.destroy() return res menu = gtk.Menu() item = gtk.ImageMenuItem(_('Translate label')) item.connect("activate", callback, tool, window) item.set_sensitive(1) item.show() menu.append(item) menu.popup(None,None,None,event.button,event.time) return True tbutton.connect('clicked', _action, tool, icontype) tbutton.connect('button_press_event', _translate_label, tool, self.window) sep = True
def __init__(self, view, model, res_id=False, domain=[], context={}, help={}, window=None, name=False): self.glade = glade.XML(common.terp_path("openerp.glade"),'win_tree_container',gettext.textdomain()) self.widget = self.glade.get_widget('win_tree_container') self.widget.show_all() self.model = view['model'] self.domain2 = domain if view.get('field_parent', False): self.domain = [] else: self.domain = domain self.view = view self.window=window self.context=context self.tree_res = view_tree.view_tree(view, [], res_id, True, context=context) self.tree_res.view.connect('row-activated', self.sig_open) sel = self.tree_res.view.get_selection() sel.connect('changed', self.expand_one) if not name: self.name = self.tree_res.name else: self.name = name self.vp = self.glade.get_widget('main_tree_sw') wid = self.glade.get_widget('widget_vbox') wid.show() widget_sc = self.glade.get_widget('win_tree_sc') widget_sc.connect('row-activated', self.sc_go) self.tree_sc = view_tree.view_tree_sc(widget_sc, self.model) self.handlers = { 'but_reload': self.sig_reload, 'but_switch': self.sig_edit, 'but_chroot': self.sig_chroot, 'but_open': self.sig_action, 'but_action': self.sig_action, 'but_print': self.sig_print, 'but_print_html': self.sig_print_html, 'but_close': self.sig_close, 'but_save_as': self.sig_save_as, } dict = { 'on_but_sc_go_clicked': self.sc_go, 'on_but_sc_add_clicked': self.sc_add, 'on_but_sc_del_clicked': self.sc_del, 'on_but_expand_collapse_clicked': self.expand_collapse_all, 'on_tbsc_clicked': self.sc_btn, } self.help = help self.help_frame = False wid = self.tree_res.widget_get() if self.help: action_tips = common.action_tips(self.help) self.help_frame = action_tips.help_frame if self.help_frame: vbox = gtk.VBox() vbox.pack_start(self.help_frame, expand=False, fill=False, padding=2) vbox.pack_end(wid) vbox.show_all() wid = vbox if self.help_frame: self.vp.add_with_viewport(wid) else: self.vp.add(wid) self.sig_reload() for signal in dict: self.glade.signal_connect(signal, dict[signal]) self.expand = True
def add_filter(self, widget, fnct, clear_fnct, next_fnct, prev_fnct, execute_action=None, add_custom=None, model=None, limit=100): self.filter_vbox = gtk.VBox(spacing=1) self.filter_vbox.set_border_width(1) if self.help and not self.win_search: action_tips = common.action_tips(self.help) self.help_frame = action_tips.help_frame if self.help_frame: self.filter_vbox.pack_start(self.help_frame, expand=False, fill=False, padding=3) self.filter_vbox.pack_start(widget, expand=True, fill=True) hs = gtk.HBox(homogeneous=False, spacing=0) hb1 = gtk.HButtonBox() hb1.set_layout(gtk.BUTTONBOX_START) button_clear = gtk.Button(stock=gtk.STOCK_CLEAR) button_clear.connect('clicked', clear_fnct) if self.win_search: hb3 = hb1 hs.pack_start(hb3, expand=False, fill=False) hb3.pack_start(button_clear, expand=False, fill=False) else: hb1.set_spacing(5) hb2 = gtk.HBox(homogeneous=False, spacing=0) hb3 = gtk.HBox(homogeneous=False, spacing=0) hs.pack_start(hb1, expand=False, fill=False) hs.pack_start(hb2, expand=True, fill=True) hs.pack_end(hb3, expand=False, fill=False) #Find Clear Buttons self.button = gtk.Button(stock=gtk.STOCK_FIND) self.button.connect('clicked', fnct) self.button.set_property('can_default', True) hb1.pack_start(self.button, expand=False, fill=False) hb1.pack_start(button_clear, expand=False, fill=False) #Action Filter and custom Filter Button #actions combo self.action_list = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING) self.action_combo = gtk.ComboBox(self.action_list) cell = gtk.CellRendererText() self.action_combo.pack_start(cell, True) self.action_combo.add_attribute(cell, 'text', 2) self.fill_filter_combo(model) self.action_combo.set_active(0) self.handler_id = self.action_combo.connect( 'changed', execute_action) #Custom Filter Button img2 = gtk.Image() img2.set_from_stock('gtk-add', gtk.ICON_SIZE_BUTTON) self.button_dynamic = gtk.Button() self.button_dynamic.set_image(img2) self.button_dynamic.set_relief(gtk.RELIEF_NONE) self.button_dynamic.set_alignment(0.3, 0.3) self.button_dynamic.connect('clicked', add_custom) hb2.pack_start(gtk.Label(''), expand=True, fill=True) hb2.pack_start(self.action_combo, expand=False, fill=False) hb2.pack_start(self.button_dynamic, expand=False, fill=False) hb2.pack_start(gtk.Label(''), expand=True, fill=True) # Limit combo self.limit_combo = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) self.combo = gtk.ComboBox(self.limit_combo) cell = gtk.CellRendererText() self.combo.pack_start(cell, True) self.combo.add_attribute(cell, 'text', 1) self.selection = [] hb3.pack_start(self.combo, expand=False, fill=False) self.fill_limit_combo(limit) #Back Forward Buttons self.but_previous = gtk.Button() icon = gtk.Image() icon.set_from_stock('gtk-go-back', gtk.ICON_SIZE_SMALL_TOOLBAR) self.but_previous.set_image(icon) self.but_previous.set_relief(gtk.RELIEF_NONE) self.but_previous.connect('clicked', prev_fnct) icon2 = gtk.Image() icon2.set_from_stock('gtk-go-forward', gtk.ICON_SIZE_SMALL_TOOLBAR) self.but_next = gtk.Button() self.but_next.set_image(icon2) self.but_next.set_relief(gtk.RELIEF_NONE) self.but_next.connect('clicked', next_fnct) next_prev_box = hb3 if self.win_search: next_prev_box = gtk.HBox(homogeneous=False, spacing=0) hs.pack_start(next_prev_box, expand=False, fill=False) next_prev_box.pack_start(gtk.VSeparator(), padding=3, expand=False, fill=False) next_prev_box.pack_start(self.but_previous, expand=False, fill=False) next_prev_box.pack_start(self.but_next, expand=False, fill=False) hs.show_all() self.filter_vbox.pack_start(hs, expand=False, fill=False) hs = gtk.HSeparator() hs.show() self.filter_vbox.pack_start(hs, expand=True, fill=False) self.vbox.pack_start(self.filter_vbox, expand=False, fill=True)