def parse(self, model, root_node, fields): attrs = tools.node_attributes(root_node) self.title = attrs.get('string', 'Unknown') on_write = '' #attrs.get('on_write', '') axis = [] axis_data = {} for node in root_node: node_attrs = tools.node_attributes(node) if node.tag == 'field': axis.append(str(node_attrs['name'])) axis_data[str(node_attrs['name'])] = node_attrs # # TODO: parse root_node to fill in axis # try: import graph view = graph.ViewGraph(model, axis, fields, axis_data, attrs) except Exception, e: import common import traceback import sys tb_s = reduce( lambda x, y: x + y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)) common.error('Graph', _('Can not generate graph !'), details=tb_s, parent=self.window) view = EmptyGraph(model, axis, fields, axis_data, attrs)
def parse(self, model, root_node, fields): attrs = tools.node_attributes(root_node) self.title = attrs.get('string', 'Unknown') on_write = '' #attrs.get('on_write', '') axis = [] axis_data = {} for node in root_node.childNodes: node_attrs = tools.node_attributes(node) if node.localName == 'field': axis.append(str(node_attrs['name'])) axis_data[str(node_attrs['name'])] = node_attrs # # TODO: parse root_node to fill in axis # try: import graph view = graph.ViewGraph(model, axis, fields, axis_data, attrs) except Exception, e: import common import traceback import sys tb_s = reduce(lambda x, y: x + y, traceback.format_exception( sys.exc_type, sys.exc_value, sys.exc_traceback)) common.error('Graph', _('Can not generate graph !'), details=tb_s, parent=self.window) view = EmptyGraph(model, axis, fields, axis_data, attrs)
def parse(self, model, root_node, fields): attrs = tools.node_attributes(root_node) self.title = attrs.get("string", "Unknown") on_write = "" # attrs.get('on_write', '') axis = [] axis_data = {} for node in root_node: node_attrs = tools.node_attributes(node) if node.tag == "field": axis.append(str(node_attrs["name"])) axis_data[str(node_attrs["name"])] = node_attrs # # TODO: parse root_node to fill in axis # try: import graph view = graph.ViewGraph(model, axis, fields, axis_data, attrs) except Exception, e: import common import traceback import sys tb_s = reduce( lambda x, y: x + y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback) ) common.error("Graph", _("Can not generate graph !"), details=tb_s, parent=self.window) view = EmptyGraph(model, axis, fields, axis_data, attrs)
def parse(self, model, root_node, fields): attrs = node_attributes(root_node) self.title = attrs.get('string', 'Calendar') axis = [] axis_data = {} for node in root_node: node_attrs = node_attributes(node) if node.tag == 'field': axis.append(str(node_attrs['name'])) axis_data[str(node_attrs['name'])] = node_attrs view = ViewCalendar(model, axis, fields, attrs) return view, {}, [], ''
def parse(self, model, root_node, fields): attrs = node_attributes(root_node) self.title = attrs.get("string", "Calendar") axis = [] axis_data = {} for node in root_node: node_attrs = node_attributes(node) if node.tag == "field": axis.append(str(node_attrs["name"])) axis_data[str(node_attrs["name"])] = node_attrs view = ViewCalendar(model, axis, fields, attrs) return view, {}, [], ""
def parse(self, model, root_node, fields): attrs = tools.node_attributes(root_node) self.title = attrs.get('string', 'Unknown') on_write = '' view = EmptyGantt(model) return view, {}, [], on_write
def parse(self, model, root_node, fields): attrs = tools.node_attributes(root_node) self.title = attrs.get('string', 'Unknown') on_write = '' view = EmptyCalendar(model) return view, {}, [], on_write
def _parse_fields(node, fields): if node.nodeType == node.ELEMENT_NODE: if node.localName=='field': attrs = tools.node_attributes(node) if attrs.get('widget', False): if attrs['widget']=='one2many_list': attrs['widget']='one2many' attrs['type'] = attrs['widget'] fields[unicode(attrs['name'])].update(attrs) for node2 in node.childNodes: _parse_fields(node2, fields)
def _parse_fields(node, fields): if node.nodeType == node.ELEMENT_NODE: if node.localName == 'field': attrs = tools.node_attributes(node) if attrs.get('widget', False): if attrs['widget'] == 'one2many_list': attrs['widget'] = 'one2many' attrs['type'] = attrs['widget'] fields[unicode(attrs['name'])].update(attrs) for node2 in node.childNodes: _parse_fields(node2, fields)
def _parse_fields(node, fields): if node.tag =='field': attrs = tools.node_attributes(node) if attrs.get('widget', False): if attrs['widget']=='one2many_list': attrs['widget']='one2many' attrs['type'] = attrs['widget'] if attrs.get('selection',[]): attrs['selection'] = eval(attrs['selection']) for att_key, att_val in attrs['selection'].items(): for sel in fields[str(attrs['name'])]['selection']: if att_key == sel[0]: sel[1] = att_val attrs['selection'] = fields[str(attrs['name'])]['selection'] fields[unicode(attrs['name'])].update(attrs) for node2 in node: _parse_fields(node2, fields)
def _parse_fields(node, fields): if node.tag == 'field': attrs = tools.node_attributes(node) if attrs.get('widget', False): if attrs['widget'] == 'one2many_list': attrs['widget'] = 'one2many' attrs['type'] = attrs['widget'] if attrs.get('selection', []): attrs['selection'] = eval(attrs['selection']) for att_key, att_val in attrs['selection'].items(): for sel in fields[str(attrs['name'])]['selection']: if att_key == sel[0]: sel[1] = att_val attrs['selection'] = fields[str( attrs['name'])]['selection'] fields[unicode(attrs['name'])].update(attrs) for node2 in node: _parse_fields(node2, fields)
def parse(self, model, root_node, fields): attrs = node_attributes(root_node) self.title = attrs.get('string', 'diagram') node_attr = None arrow_attr = None for node in root_node: node_attrs = node_attributes(node) node_fields = [] if node.tag == 'node': node_attr = node_attrs if node.tag == 'arrow': arrow_attr = node_attrs if node.tag in ['node', 'arrow']: for child in node: if node_attributes(child) and node_attributes(child).get( 'name', False): node_fields.append(node_attributes(child)['name']) fields = rpc.session.rpc_exec_auth( '/object', 'execute', node_attrs.get('object', False), 'fields_get', node_fields, rpc.session.context) for key, val in fields.iteritems(): fields[key]['name'] = key attrs[node.tag] = { 'string': node_attributes(root_node).get('string', False), 'views': { 'form': { 'fields': fields, 'arch': node } } } if node_attr.get('form_view_ref', False): node_attr['form_view_ref'] = self.get_view( node_attr.get('form_view_ref', '')) else: node_attr['form_view_ref'] = False if arrow_attr.get('form_view_ref', False): arrow_attr['form_view_ref'] = self.get_view( arrow_attr.get('form_view_ref', '')) else: arrow_attr['form_view_ref'] = False view = Viewdiagram(self.window, model, node_attr, arrow_attr, attrs, self.screen) return view, {}, [], ''
def parse(self, model, root_node, fields): attrs = node_attributes(root_node) self.title = attrs.get('string', 'diagram') node_attr = None arrow_attr = None for node in root_node: node_attrs = node_attributes(node) node_fields = [] if node.tag == 'node': node_attr = node_attrs if node.tag == 'arrow': arrow_attr = node_attrs if node.tag in ['node','arrow']: for child in node: if node_attributes(child) and node_attributes(child).get('name', False): node_fields.append(node_attributes(child)['name']) fields = rpc.session.rpc_exec_auth('/object', 'execute', node_attrs.get('object',False),'fields_get', node_fields, rpc.session.context) for key, val in fields.iteritems(): fields[key]['name'] = key attrs[node.tag] = {'string' :node_attributes(root_node).get('string', False), 'views':{'form': {'fields': fields,'arch' : node}} } if node_attr.get('form_view_ref', False): node_attr['form_view_ref'] = self.get_view(node_attr.get('form_view_ref','')) else: node_attr['form_view_ref'] = False if arrow_attr.get('form_view_ref', False): arrow_attr['form_view_ref'] = self.get_view(arrow_attr.get('form_view_ref','')) else: arrow_attr['form_view_ref'] = False view = Viewdiagram(self.window, model, node_attr, arrow_attr, attrs, self.screen) return view, {}, [], ''
def parse(self, model, root_node, fields): dict_widget = {} btn_list=[] attrs = tools.node_attributes(root_node) on_write = attrs.get('on_write', '') editable = attrs.get('editable', False) if editable: treeview = EditableTreeView(editable) else: treeview = DecoratedTreeView(editable) treeview.colors = dict() self.treeview = treeview for color_spec in attrs.get('colors', '').split(';'): if color_spec: colour, test = color_spec.split(':') treeview.colors[colour] = test treeview.set_property('rules-hint', True) if not self.title: self.title = attrs.get('string', 'Unknown') treeview.sequence = False for node in root_node.childNodes: node_attrs = tools.node_attributes(node) if node.localName == 'button': cell = Cell('button')(node_attrs['string']) cell.attrs=node_attrs cell.name=node_attrs['name'] cell.type=node_attrs.get('type','object') cell.context=node_attrs.get('context',{}) cell.model=model treeview.cells[node_attrs['name']] = cell col = gtk.TreeViewColumn(None, cell) btn_list.append(col) cell.set_property('editable',False) col._type = 'Button' col.name = node_attrs['name'] if node.localName == 'field': fname = str(node_attrs['name']) if fields[fname]['type'] in ('image', 'binary'): continue # not showed types if fname == 'sequence': treeview.sequence = True for boolean_fields in ('readonly', 'required'): if boolean_fields in node_attrs: if node_attrs[boolean_fields] in ('True', 'False'): node_attrs[boolean_fields] = eval(node_attrs[boolean_fields]) else: node_attrs[boolean_fields] = bool(int(node_attrs[boolean_fields])) fields[fname].update(node_attrs) node_attrs.update(fields[fname]) cell = Cell(fields[fname]['type'])(fname, treeview, node_attrs, self.window) treeview.cells[fname] = cell renderer = cell.renderer write_enable = editable and not node_attrs.get('readonly', False) if isinstance(renderer, gtk.CellRendererToggle): renderer.set_property('activatable', write_enable) elif isinstance(renderer, (gtk.CellRendererText, gtk.CellRendererCombo, date_renderer.DecoratorRenderer)): renderer.set_property('editable', write_enable) if write_enable: renderer.connect_after('editing-started', send_keys, treeview) col = gtk.TreeViewColumn(None, renderer) col_label = gtk.Label('') if fields[fname].get('required', False): col_label.set_markup('<b>%s</b>' % cgi.escape(fields[fname]['string'])) else: col_label.set_text(fields[fname]['string']) col_label.show() col.set_widget(col_label) col.name = fname col._type = fields[fname]['type'] col.set_cell_data_func(renderer, cell.setter) col.set_clickable(True) twidth = { 'integer': 60, 'float': 80, 'float_time': 80, 'date': 70, 'datetime': 120, 'selection': 90, 'char': 100, 'one2many': 50, 'many2many': 50, 'boolean': 20, } if 'width' in fields[fname]: width = int(fields[fname]['width']) else: width = twidth.get(fields[fname]['type'], 100) col.set_min_width(width) if not treeview.sequence: col.connect('clicked', sort_model, treeview) col.set_resizable(True) #col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) visval = eval(str(fields[fname].get('invisible', 'False')), {'context':self.screen.context}) col.set_visible(not visval) n = treeview.append_column(col) for tree_op in TREE_OPS: if tree_op in fields[fname]: if tree_op in ('sum', 'avg') \ and fields[fname]['type'] not in ('integer', 'float', 'float_time'): continue label = gtk.Label() label.set_use_markup(True) label_str = fields[fname][tree_op] + ': ' label_bold = bool(int(fields[fname].get( '%s_bold' % tree_op, 0)) ) if label_bold: label.set_markup('<b>%s</b>' % label_str) else: label.set_markup(label_str) label_wid = gtk.Label() label_wid.set_use_markup(True) dict_widget[n] = ( fname, label, label_wid, fields[fname].get('digits', (16,2))[1], label_bold, tree_op ) for btn in btn_list: treeview.append_column(btn) return treeview, dict_widget, [], on_write
def parse(self, model, root_node, fields, notebook=None, paned=None): dict_widget = {} saw_list = [] # state aware widget list attrs = tools.node_attributes(root_node) on_write = attrs.get('on_write', '') container = _container() container.new(col=int(attrs.get('col', 4))) self.container = container if not self.title: attrs = tools.node_attributes(root_node) self.title = attrs.get('string', 'Unknown') for node in root_node: attrs = tools.node_attributes(node) if node.tag == 'image': icon = gtk.Image() icon.set_from_stock(attrs['name'], gtk.ICON_SIZE_DIALOG) container.wid_add(icon, colspan=int(attrs.get('colspan', 1)), expand=int(attrs.get('expand', 0)), ypadding=10, fill=int(attrs.get('fill', 0))) elif node.tag == 'separator': orientation = attrs.get('orientation', 'horizontal') if orientation == 'vertical': vbox = gtk.HBox(homogeneous=False, spacing=0) else: vbox = gtk.VBox() if 'string' in attrs: text = attrs.get('string', 'No String Attr.') l = gtk.Label('<b>' + (text.replace('&', '&').replace( '<', '<').replace('>', '>')) + '</b>') l.set_use_markup(True) l.set_alignment(0.0, 0.5) eb = gtk.EventBox() eb.set_events(gtk.gdk.BUTTON_PRESS_MASK) eb.add(l) container.trans_box_label.append((eb, text, None)) vbox.pack_start(eb) if orientation == 'vertical': vsep = gtk.VSeparator() rowspan = int(attrs.get('rowspan', '1')) vsep.set_size_request(1, 20 * rowspan) vbox.pack_start(vsep, False, False, 5) xoptions = gtk.SHRINK else: xoptions = False vbox.pack_start(gtk.HSeparator()) container.wid_add(vbox, colspan=int(attrs.get('colspan', 1)), xoptions=xoptions, expand=int(attrs.get('expand', 0)), ypadding=10, fill=int(attrs.get('fill', 0))) elif node.tag == 'label': text = attrs.get('string', '') if not text: for node in node: text += node.text align = float(attrs.get('align', 0)) eb = container.create_label(text, markup=True, align=align, width=int(attrs.get('width', -1)), angle=attrs.get('angle'), wrap=attrs.get('wrap', True), help=attrs.get('help')) container.trans_box_label.append((eb, text, None)) container.wid_add(eb, colspan=int(attrs.get('colspan', 1)), expand=False, fill=int(attrs.get('fill', 0))) elif node.tag == 'newline': container.newline() elif node.tag == 'button': if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context': self.screen.context}) if visval: continue if 'default_focus' in attrs and not self.default_focus_button: attrs['focus_button'] = attrs['default_focus'] self.default_focus_button = True button = Button(attrs) states = [e for e in attrs.get('states', '').split(',') if e] saw_list.append(StateAwareWidget(button, states=states)) container.wid_add(button.widget, colspan=int(attrs.get('colspan', 1))) elif node.tag == 'notebook': if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context': self.screen.context}) if visval: continue nb = gtk.Notebook() if attrs and 'tabpos' in attrs: pos = { 'up': gtk.POS_TOP, 'down': gtk.POS_BOTTOM, 'left': gtk.POS_LEFT, 'right': gtk.POS_RIGHT }[attrs['tabpos']] else: if options.options['client.form_tab'] == 'top': pos = gtk.POS_TOP elif options.options['client.form_tab'] == 'left': pos = gtk.POS_LEFT elif options.options['client.form_tab'] == 'right': pos = gtk.POS_RIGHT elif options.options['client.form_tab'] == 'bottom': pos = gtk.POS_BOTTOM nb.set_tab_pos(pos) nb.set_border_width(3) container.wid_add(nb, colspan=attrs.get('colspan', 3), expand=True, fill=True) _, widgets, saws, on_write = self.parse( model, node, fields, nb) saw_list += saws dict_widget.update(widgets) elif node.tag == 'page': if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context': self.screen.context}) if visval: continue if attrs and 'angle' in attrs: angle = int(attrs['angle']) else: angle = int(options.options['client.form_tab_orientation']) l = gtk.Label(attrs.get('string', 'No String Attr.')) l.attrs = attrs.copy() l.set_angle(angle) widget, widgets, saws, on_write = self.parse( model, node, fields, notebook) saw_list += saws dict_widget.update(widgets) notebook.append_page(widget, l) elif node.tag == 'field': name = str(attrs['name']) del attrs['name'] name = unicode(name) type = attrs.get('widget', fields[name]['type']) if 'selection' in attrs: attrs['selection'] = fields[name]['selection'] fields[name].update(attrs) fields[name]['model'] = model if not type in widgets_type: continue fields[name]['name'] = name if 'saves' in attrs: fields[name]['saves'] = attrs['saves'] if 'filename' in attrs: fields[name]['filename'] = attrs['filename'] if 'default_focus' in attrs and not self.default_focus_field: fields[name]['focus_field'] = attrs['default_focus'] self.default_focus_field = True widget_act = widgets_type[type][0](self.window, self.parent, model, fields[name]) self.widget_id += 1 widget_act.position = self.widget_id label = None if not int(attrs.get('nolabel', 0)): # TODO space before ':' depends of lang (ex: english no space) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: label = ': ' + fields[name]['string'] else: label = fields[name]['string'] + ' :' dict_widget[name] = widget_act size = int(attrs.get('colspan', widgets_type[type][1])) expand = widgets_type[type][2] fill = widgets_type[type][3] hlp = fields[name].get('help', attrs.get('help', False)) if attrs.get('height', False) or attrs.get('width', False): widget_act.widget.set_size_request( int(attrs.get('width', -1)), int(attrs.get('height', -1))) if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context': self.screen.context}) if visval: continue translate = fields[name]['string'] if fields[name].get( 'translate') else None detail_tooltip = False if options.options['debug_mode_tooltips']: detail_tooltip = self.create_detail_tooltip( name, fields[name]) widget_label = container.create_label( label, help=hlp, fname=name, detail_tooltip=detail_tooltip) if label else None if attrs.get('attrs'): saw_list.append(StateAwareWidget(widget_act, widget_label)) container.wid_add(widget=widget_act.widget, label=widget_label, expand=expand, translate=translate, colspan=size, fname=name, fill=fill) elif node.tag == 'group': frame = gtk.Frame(attrs.get('string', None)) frame.attrs = attrs frame.set_border_width(0) states = [e for e in attrs.get('states', '').split(',') if e] if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context': self.screen.context}) if visval: continue state_aware = StateAwareWidget(frame, states=states) saw_list.append(state_aware) if attrs.get("width", False) or attrs.get("height"): frame.set_size_request(int(attrs.get('width', -1)), int(attrs.get('height', -1))) hbox = gtk.HBox(homogeneous=False, spacing=0) hbox.pack_start(frame, expand=False, fill=False, padding=0) group_wid = hbox else: group_wid = frame container.wid_add(group_wid, colspan=int(attrs.get('colspan', 1)), expand=int(attrs.get('expand', 0)), rowspan=int(attrs.get('rowspan', 1)), ypadding=0, fill=int(attrs.get('fill', 1))) container.new(int(attrs.get('col', 4))) widget, widgets, saws, on_write = self.parse( model, node, fields) state_aware.frame_child.update(widgets) dict_widget.update(widgets) saw_list += saws frame.add(widget) if not attrs.get('string', None): frame.set_shadow_type(gtk.SHADOW_NONE) container.get().set_border_width(0) container.pop() elif node.tag == 'hpaned': hp = gtk.HPaned() container.wid_add(hp, colspan=int(attrs.get('colspan', 4)), expand=True, fill=True) _, widgets, saws, on_write = self.parse(model, node, fields, paned=hp) saw_list += saws dict_widget.update(widgets) #if 'position' in attrs: # hp.set_position(int(attrs['position'])) elif node.tag == 'vpaned': hp = gtk.VPaned() container.wid_add(hp, colspan=int(attrs.get('colspan', 4)), expand=True, fill=True) _, widgets, saws, on_write = self.parse(model, node, fields, paned=hp) saw_list += saws dict_widget.update(widgets) if 'position' in attrs: hp.set_position(int(attrs['position'])) elif node.tag == 'child1': widget, widgets, saws, on_write = self.parse(model, node, fields, paned=paned) saw_list += saws dict_widget.update(widgets) paned.pack1(widget, resize=True, shrink=True) elif node.tag == 'child2': widget, widgets, saws, on_write = self.parse(model, node, fields, paned=paned) saw_list += saws dict_widget.update(widgets) paned.pack2(widget, resize=True, shrink=True) elif node.tag == 'action': from action import action name = str(attrs['name']) widget_act = action(self.window, self.parent, model, attrs) dict_widget[name] = widget_act container.wid_add(widget_act.widget, colspan=int(attrs.get('colspan', 3)), expand=True, fill=True) for (ebox, src, name, widget) in container.trans_box: ebox.connect('button_press_event', self.translate, model, name, src, widget, self.screen, self.window) for (ebox, src, name) in container.trans_box_label: ebox.connect('button_press_event', self.translate_label, model, name, src, self.window) return container.pop(), dict_widget, saw_list, on_write
def parse(self, model, root_node, fields): dict_widget = {} attrs = tools.node_attributes(root_node) on_write = attrs.get('on_write', '') editable = attrs.get('editable', False) treeview = EditableTreeView(editable) treeview.colors = dict() self.treeview = treeview for color_spec in attrs.get('colors', '').split(';'): if color_spec: colour, test = color_spec.split(':') treeview.colors.setdefault(colour, []) treeview.colors[colour].append(test) if not self.title: self.title = attrs.get('string', 'Unknown') treeview.set_property('rules-hint', True) treeview.sequence = False treeview.connect("motion-notify-event", treeview.set_tooltip) treeview.connect('key-press-event', treeview.on_tree_key_press) for node in root_node: node_attrs = tools.node_attributes(node) if node.tag == 'button': cell = Cell('button')(node_attrs['string'], treeview, node_attrs) cell.name = node_attrs['name'] cell.attrs = node_attrs cell.type = node_attrs.get('type', 'object') cell.context = node_attrs.get('context', {}) cell.model = model treeview.cells[node_attrs['name']] = cell col = gtk.TreeViewColumn(None, cell.renderer) col.set_clickable(True) col.set_cell_data_func(cell.renderer, cell.setter) col.name = node_attrs['name'] col.attrs = node_attrs col._type = 'Button' col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) col.tooltip = node_attrs['string'] if node_attrs.get('help', False): col.tooltip = node_attrs['string'] + ':\n' + node_attrs[ 'help'] col.set_fixed_width(20) visval = eval(str(node_attrs.get('invisible', 'False')), {'context': self.screen.context}) col.set_visible(not visval) treeview.append_column(col) if node.tag == 'field': handler_id = False fname = str(node_attrs['name']) if fields[fname]['type'] in ('image', 'binary'): continue # not showed types if fname == 'sequence': treeview.sequence = True for boolean_fields in ('readonly', 'required'): if boolean_fields in node_attrs: if node_attrs[boolean_fields] in ('True', 'False'): node_attrs[boolean_fields] = eval( node_attrs[boolean_fields]) else: node_attrs[boolean_fields] = bool( int(node_attrs[boolean_fields])) if fields[fname]['type'] == 'selection': if fields[fname].get('selection', []): node_attrs['selection'] = fields[fname]['selection'] fields[fname].update(node_attrs) node_attrs.update(fields[fname]) node_attrs['editable'] = editable cell = Cell(fields[fname]['type'])(fname, treeview, node_attrs, self.window) treeview.cells[fname] = cell renderer = cell.renderer write_enable = editable and not node_attrs.get( 'readonly', False) if isinstance(renderer, gtk.CellRendererToggle): renderer.set_property('activatable', write_enable) elif isinstance(renderer, (gtk.CellRendererText, gtk.CellRendererCombo, date_renderer.DecoratorRenderer)): renderer.set_property('editable', write_enable) if write_enable: handler_id = renderer.connect_after( 'editing-started', send_keys, treeview) col = gtk.TreeViewColumn(None, renderer) treeview.handlers[col] = handler_id col_label = gtk.Label('') if fields[fname].get('required', False): col_label.set_markup('<b>%s</b>' % cgi.escape(fields[fname]['string'])) else: col_label.set_text(fields[fname]['string']) col_label.show() col.set_widget(col_label) col.name = fname col._type = fields[fname]['type'] col.set_cell_data_func(renderer, cell.setter) col.set_clickable(True) twidth = { 'integer': (60, 170), 'float': (80, 300), 'float_time': (80, 150), 'date': (70, False), 'datetime': (145, 145), 'selection': (90, 250), 'char': (100, False), 'one2many': (50, False), 'many2many': (50, False), 'boolean': (20, 80), 'progressbar': (150, 200) } if col._type not in twidth: col.set_expand(True) else: if 'width' in fields[fname]: min_width = max_width = int(fields[fname]['width']) else: min_width, max_width = twidth[col._type] col.set_min_width(min_width) if max_width: col.set_max_width(max_width) col.connect('clicked', sort_model, self.screen) col.set_resizable(True) #col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) visval = eval(str(fields[fname].get('invisible', 'False')), {'context': self.screen.context}) col.set_visible(not visval) n = treeview.append_column(col) calculate = '' if 'sum' in node_attrs.keys(): calculate = 'sum' elif 'avg' in node_attrs.keys(): calculate = 'avg' if calculate and fields[fname]['type'] \ in ('integer', 'float', 'float_time'): label = gtk.Label() label.set_use_markup(True) label_str = fields[fname][calculate] + ': ' label_bold = bool(int(fields[fname].get('bold', 0))) if label_bold: label.set_markup('<b>%s</b>' % label_str) else: label.set_markup(label_str) label_sum = gtk.Label() label_sum.set_use_markup(True) dict_widget[n] = (fname, label, label_sum, fields[fname].get('digits', (16, 2))[1], label_bold, calculate) return treeview, dict_widget, [], on_write
def parse(self, model, root_node, fields): dict_widget = {} attrs = tools.node_attributes(root_node) on_write = attrs.get('on_write', '') editable = attrs.get('editable', False) treeview = EditableTreeView(editable) treeview.colors = dict() self.treeview = treeview for color_spec in attrs.get('colors', '').split(';'): if color_spec: colour, test = color_spec.split(':') treeview.colors.setdefault(colour,[]) treeview.colors[colour].append(test) if not self.title: self.title = attrs.get('string', 'Unknown') treeview.set_property('rules-hint', True) treeview.sequence = False treeview.connect("motion-notify-event", treeview.set_tooltip) treeview.connect('key-press-event', treeview.on_tree_key_press) for node in root_node: node_attrs = tools.node_attributes(node) if node.tag == 'button': cell = Cell('button')(node_attrs['string'], treeview, node_attrs) cell.name = node_attrs['name'] cell.attrs = node_attrs cell.type = node_attrs.get('type','object') cell.context = node_attrs.get('context',{}) cell.model = model treeview.cells[node_attrs['name']] = cell col = gtk.TreeViewColumn(None, cell.renderer) col.set_clickable(True) col.set_cell_data_func(cell.renderer, cell.setter) col.name = node_attrs['name'] col.attrs = node_attrs col._type = 'Button' col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) col.tooltip = node_attrs['string'] if node_attrs.get('help',False): col.tooltip = node_attrs['string'] +':\n' + node_attrs['help'] col.set_fixed_width(20) visval = eval(str(node_attrs.get('invisible', 'False')), {'context':self.screen.context}) col.set_visible(not visval) treeview.append_column(col) if node.tag == 'field': handler_id = False fname = str(node_attrs['name']) if fields[fname]['type'] in ('image', 'binary'): continue # not showed types if fname == 'sequence': treeview.sequence = True for boolean_fields in ('readonly', 'required'): if boolean_fields in node_attrs: if node_attrs[boolean_fields] in ('True', 'False'): node_attrs[boolean_fields] = eval(node_attrs[boolean_fields]) else: node_attrs[boolean_fields] = bool(int(node_attrs[boolean_fields])) if fields[fname]['type'] == 'selection': if fields[fname].get('selection',[]): node_attrs['selection'] = fields[fname]['selection'] fields[fname].update(node_attrs) node_attrs.update(fields[fname]) node_attrs['editable'] = editable cell = Cell(fields[fname]['type'])(fname, treeview, node_attrs, self.window) treeview.cells[fname] = cell renderer = cell.renderer write_enable = editable and not node_attrs.get('readonly', False) if isinstance(renderer, gtk.CellRendererToggle): renderer.set_property('activatable', write_enable) elif isinstance(renderer, (gtk.CellRendererText, gtk.CellRendererCombo, date_renderer.DecoratorRenderer)): renderer.set_property('editable', write_enable) if write_enable: handler_id = renderer.connect_after('editing-started', send_keys, treeview) col = gtk.TreeViewColumn(None, renderer) treeview.handlers[col] = handler_id col_label = gtk.Label('') if fields[fname].get('required', False): col_label.set_markup('<b>%s</b>' % cgi.escape(fields[fname]['string'])) else: col_label.set_text(fields[fname]['string']) col_label.show() col.set_widget(col_label) col.name = fname col._type = fields[fname]['type'] col.set_cell_data_func(renderer, cell.setter) col.set_clickable(True) twidth = { 'integer': (60, 170), 'float': (80, 300), 'float_time': (80,150), 'date': (70, False), 'datetime': (145, 145), 'selection': (90, 250), 'char': (100, False), 'one2many': (50, False), 'many2many': (50, False), 'boolean': (20, 80), 'progressbar':(150, 200) } if col._type not in twidth: col.set_expand(True) else: if 'width' in fields[fname]: min_width = max_width = int(fields[fname]['width']) else: min_width, max_width = twidth[col._type] col.set_min_width(min_width) if max_width: col.set_max_width(max_width) col.connect('clicked', sort_model, self.screen) col.set_resizable(True) #col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) visval = eval(str(fields[fname].get('invisible', 'False')), {'context':self.screen.context}) col.set_visible(not visval) n = treeview.append_column(col) calculate = '' if 'sum' in node_attrs.keys(): calculate = 'sum' elif 'avg' in node_attrs.keys(): calculate = 'avg' if calculate and fields[fname]['type'] \ in ('integer', 'float', 'float_time'): label = gtk.Label() label.set_use_markup(True) label_str = fields[fname][calculate] + ': ' label_bold = bool(int(fields[fname].get('bold', 0))) if label_bold: label.set_markup('<b>%s</b>' % label_str) else: label.set_markup(label_str) label_sum = gtk.Label() label_sum.set_use_markup(True) dict_widget[n] = (fname, label, label_sum, fields[fname].get('digits', (16,2))[1], label_bold, calculate) return treeview, dict_widget, [], on_write
def parse(self, model, root_node, fields, notebook=None, paned=None): dict_widget = {} saw_list = [] # state aware widget list attrs = tools.node_attributes(root_node) on_write = attrs.get('on_write', '') container = _container() container.new(col=int(attrs.get('col', 4))) self.container = container if not self.title: attrs = tools.node_attributes(root_node) self.title = attrs.get('string', 'Unknown') for node in root_node: attrs = tools.node_attributes(node) if node.tag=='image': icon = gtk.Image() icon.set_from_stock(attrs['name'], gtk.ICON_SIZE_DIALOG) container.wid_add(icon,colspan=int(attrs.get('colspan',1)),expand=int(attrs.get('expand',0)), ypadding=10, fill=int(attrs.get('fill', 0))) elif node.tag=='separator': orientation = attrs.get('orientation', 'horizontal') if orientation == 'vertical': vbox = gtk.HBox(homogeneous=False, spacing=0) else: vbox = gtk.VBox() if 'string' in attrs: text = attrs.get('string', 'No String Attr.') l = gtk.Label('<b>'+(text.replace('&','&').replace('<','<').replace('>','>'))+'</b>') l.set_use_markup(True) l.set_alignment(0.0, 0.5) eb = gtk.EventBox() eb.set_events(gtk.gdk.BUTTON_PRESS_MASK) eb.add(l) container.trans_box_label.append((eb, text, None)) vbox.pack_start(eb) if orientation == 'vertical': vsep = gtk.VSeparator() rowspan = int(attrs.get('rowspan', '1')) vsep.set_size_request(1, 20*rowspan) vbox.pack_start(vsep, False, False, 5) xoptions = gtk.SHRINK else: xoptions = False vbox.pack_start(gtk.HSeparator()) container.wid_add(vbox,colspan=int(attrs.get('colspan',1)), xoptions=xoptions,expand=int(attrs.get('expand',0)), ypadding=10, fill=int(attrs.get('fill', 0))) elif node.tag=='label': text = attrs.get('string', '') if not text: for node in node: text += node.text align = float(attrs.get('align', 0)) eb = container.create_label(text, markup=True, align=align, width=int(attrs.get('width', -1)), angle=attrs.get('angle'), wrap=attrs.get('wrap', True), help=attrs.get('help')) container.trans_box_label.append((eb, text, None)) container.wid_add( eb, colspan=int(attrs.get('colspan', 1)), expand=False, fill=int(attrs.get('fill', 0)) ) elif node.tag=='newline': container.newline() elif node.tag=='button': if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context':self.screen.context}) if visval: continue if 'default_focus' in attrs and not self.default_focus_button: attrs['focus_button'] = attrs['default_focus'] self.default_focus_button = True button = Button(attrs) states = [e for e in attrs.get('states','').split(',') if e] saw_list.append(StateAwareWidget(button, states=states)) container.wid_add(button.widget, colspan=int(attrs.get('colspan', 1))) elif node.tag=='notebook': if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context':self.screen.context}) if visval: continue nb = gtk.Notebook() if attrs and 'tabpos' in attrs: pos = {'up':gtk.POS_TOP, 'down':gtk.POS_BOTTOM, 'left':gtk.POS_LEFT, 'right':gtk.POS_RIGHT }[attrs['tabpos']] else: if options.options['client.form_tab'] == 'top': pos = gtk.POS_TOP elif options.options['client.form_tab'] == 'left': pos = gtk.POS_LEFT elif options.options['client.form_tab'] == 'right': pos = gtk.POS_RIGHT elif options.options['client.form_tab'] == 'bottom': pos = gtk.POS_BOTTOM nb.set_tab_pos(pos) nb.set_border_width(3) container.wid_add(nb, colspan=attrs.get('colspan', 3), expand=True, fill=True ) _, widgets, saws, on_write = self.parse(model, node, fields, nb) saw_list += saws dict_widget.update(widgets) elif node.tag=='page': if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context':self.screen.context}) if visval: continue if attrs and 'angle' in attrs: angle = int(attrs['angle']) else: angle = int(options.options['client.form_tab_orientation']) l = gtk.Label(attrs.get('string','No String Attr.')) l.attrs=attrs.copy() l.set_angle(angle) widget, widgets, saws, on_write = self.parse(model, node, fields, notebook) saw_list += saws dict_widget.update(widgets) notebook.append_page(widget, l) elif node.tag =='field': name = str(attrs['name']) del attrs['name'] name = unicode(name) type = attrs.get('widget', fields[name]['type']) if 'selection' in attrs: attrs['selection'] = fields[name]['selection'] fields[name].update(attrs) fields[name]['model'] = model if not type in widgets_type: continue fields[name]['name'] = name if 'saves' in attrs: fields[name]['saves'] = attrs['saves'] if 'filename' in attrs: fields[name]['filename'] = attrs['filename'] if 'default_focus' in attrs and not self.default_focus_field: fields[name]['focus_field'] = attrs['default_focus'] self.default_focus_field = True widget_act = widgets_type[type][0](self.window, self.parent, model, fields[name]) self.widget_id += 1 widget_act.position = self.widget_id label = None if not int(attrs.get('nolabel', 0)): # TODO space before ':' depends of lang (ex: english no space) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: label = ': '+fields[name]['string'] else: label = fields[name]['string']+' :' dict_widget[name] = widget_act size = int(attrs.get('colspan', widgets_type[ type ][1])) expand = widgets_type[ type ][2] fill = widgets_type[ type ][3] hlp = fields[name].get('help', attrs.get('help', False)) if attrs.get('height', False) or attrs.get('width', False): widget_act.widget.set_size_request( int(attrs.get('width', -1)), int(attrs.get('height', -1))) if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context':self.screen.context}) if visval: continue translate = fields[name]['string'] if fields[name].get('translate') else None detail_tooltip = False if options.options['debug_mode_tooltips']: detail_tooltip = self.create_detail_tooltip(name, fields[name]) widget_label = container.create_label(label, help=hlp, fname=name, detail_tooltip=detail_tooltip) if label else None if attrs.get('attrs'): saw_list.append(StateAwareWidget(widget_act, widget_label)) container.wid_add(widget=widget_act.widget, label=widget_label, expand=expand, translate=translate, colspan=size, fname=name, fill=fill) elif node.tag =='group': frame = gtk.Frame(attrs.get('string', None)) frame.attrs=attrs frame.set_border_width(0) states = [e for e in attrs.get('states','').split(',') if e] if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context':self.screen.context}) if visval: continue state_aware = StateAwareWidget(frame, states=states) saw_list.append(state_aware) if attrs.get("width",False) or attrs.get("height"): frame.set_size_request(int(attrs.get('width', -1)) ,int(attrs.get('height', -1))) hbox = gtk.HBox(homogeneous=False, spacing=0) hbox.pack_start(frame, expand=False, fill=False, padding=0) group_wid = hbox else: group_wid = frame container.wid_add(group_wid, colspan=int(attrs.get('colspan', 1)), expand=int(attrs.get('expand',0)), rowspan=int(attrs.get('rowspan', 1)), ypadding=0, fill=int(attrs.get('fill', 1))) container.new(int(attrs.get('col',4))) widget, widgets, saws, on_write = self.parse(model, node, fields) state_aware.frame_child.update(widgets) dict_widget.update(widgets) saw_list += saws frame.add(widget) if not attrs.get('string', None): frame.set_shadow_type(gtk.SHADOW_NONE) container.get().set_border_width(0) container.pop() elif node.tag =='hpaned': hp = gtk.HPaned() container.wid_add(hp, colspan=int(attrs.get('colspan', 4)), expand=True, fill=True) _, widgets, saws, on_write = self.parse(model, node, fields, paned=hp) saw_list += saws dict_widget.update(widgets) #if 'position' in attrs: # hp.set_position(int(attrs['position'])) elif node.tag =='vpaned': hp = gtk.VPaned() container.wid_add(hp, colspan=int(attrs.get('colspan', 4)), expand=True, fill=True) _, widgets, saws, on_write = self.parse(model, node, fields, paned=hp) saw_list += saws dict_widget.update(widgets) if 'position' in attrs: hp.set_position(int(attrs['position'])) elif node.tag =='child1': widget, widgets, saws, on_write = self.parse(model, node, fields, paned=paned) saw_list += saws dict_widget.update(widgets) paned.pack1(widget, resize=True, shrink=True) elif node.tag =='child2': widget, widgets, saws, on_write = self.parse(model, node, fields, paned=paned) saw_list += saws dict_widget.update(widgets) paned.pack2(widget, resize=True, shrink=True) elif node.tag =='action': from action import action name = str(attrs['name']) widget_act = action(self.window, self.parent, model, attrs) dict_widget[name] = widget_act container.wid_add(widget_act.widget, colspan=int(attrs.get('colspan', 3)), expand=True, fill=True) for (ebox,src,name,widget) in container.trans_box: ebox.connect('button_press_event',self.translate, model, name, src, widget, self.screen, self.window) for (ebox,src,name) in container.trans_box_label: ebox.connect('button_press_event', self.translate_label, model, name, src, self.window) return container.pop(), dict_widget, saw_list, on_write
def parse(self, model, root_node, fields): dict_widget = {} attrs = tools.node_attributes(root_node) on_write = attrs.get("on_write", "") editable = attrs.get("editable", False) treeview = EditableTreeView(editable) treeview.colors = dict() self.treeview = treeview for color_spec in attrs.get("colors", "").split(";"): if color_spec: colour, test = color_spec.split(":") treeview.colors.setdefault(colour, []) treeview.colors[colour].append(test) if not self.title: self.title = attrs.get("string", "Unknown") treeview.set_property("rules-hint", True) treeview.sequence = False treeview.connect("motion-notify-event", treeview.set_tooltip) treeview.connect("key-press-event", treeview.on_tree_key_press) for node in root_node: node_attrs = tools.node_attributes(node) if node.tag == "button": cell = Cell("button")(node_attrs["string"], treeview, node_attrs) cell.name = node_attrs["name"] cell.attrs = node_attrs cell.type = node_attrs.get("type", "object") cell.context = node_attrs.get("context", {}) cell.model = model treeview.cells[node_attrs["name"]] = cell col = gtk.TreeViewColumn(None, cell.renderer) col.set_clickable(True) col.set_cell_data_func(cell.renderer, cell.setter) col.name = node_attrs["name"] col.attrs = node_attrs col._type = "Button" col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) col.tooltip = node_attrs["string"] if node_attrs.get("help", False): col.tooltip = node_attrs["string"] + ":\n" + node_attrs["help"] col.set_fixed_width(20) visval = eval(str(node_attrs.get("invisible", "False")), {"context": self.screen.context}) col.set_visible(not visval) treeview.append_column(col) if node.tag == "field": handler_id = False fname = str(node_attrs["name"]) self.field_list.setdefault(fname, 0) self.field_list[fname] += 1 if self.field_list[fname] > 1: continue if fields[fname]["type"] in ("image", "binary"): continue # not showed types if fname == "sequence": treeview.sequence = True for boolean_fields in ("readonly", "required"): if boolean_fields in node_attrs: if node_attrs[boolean_fields] in ("True", "False"): node_attrs[boolean_fields] = eval(node_attrs[boolean_fields]) else: node_attrs[boolean_fields] = bool(int(node_attrs[boolean_fields])) if fields[fname]["type"] == "selection": if fields[fname].get("selection", []): node_attrs["selection"] = fields[fname]["selection"] fields[fname].update(node_attrs) node_attrs.update(fields[fname]) node_attrs["editable"] = editable cell = Cell(fields[fname]["type"])(fname, treeview, node_attrs, self.window) treeview.cells[fname] = cell renderer = cell.renderer write_enable = editable and not node_attrs.get("readonly", False) if isinstance(renderer, gtk.CellRendererToggle): renderer.set_property("activatable", write_enable) elif isinstance( renderer, (gtk.CellRendererText, gtk.CellRendererCombo, date_renderer.DecoratorRenderer) ): renderer.set_property("editable", write_enable) if write_enable: handler_id = renderer.connect_after("editing-started", send_keys, treeview) col = gtk.TreeViewColumn(None, renderer) treeview.handlers[col] = handler_id col_label = gtk.Label("") if fields[fname].get("required", False): col_label.set_markup("<b>%s</b>" % cgi.escape(fields[fname]["string"])) else: col_label.set_text(fields[fname]["string"]) col_label.show() col.set_widget(col_label) col.name = fname col._type = fields[fname]["type"] col.set_cell_data_func(renderer, cell.setter) col.set_clickable(True) twidth = { "integer": (60, 170), "float": (80, 300), "float_time": (80, 150), "date": (70, False), "datetime": (145, False), "selection": (90, 250), "char": (100, False), "one2many": (50, False), "many2many": (50, False), "boolean": (20, False), "progressbar": (150, 200), } if col._type not in twidth: col.set_expand(True) else: if "width" in fields[fname]: min_width = max_width = int(fields[fname]["width"]) else: min_width, max_width = twidth[col._type] col.set_min_width(min_width) if max_width: col.set_max_width(max_width) col.connect("clicked", sort_model, self.screen) col.set_resizable(True) # col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) visval = eval(str(fields[fname].get("invisible", "False")), {"context": self.screen.context}) col.set_visible(not visval) n = treeview.append_column(col) calculate = "" if "sum" in node_attrs.keys(): calculate = "sum" elif "avg" in node_attrs.keys(): calculate = "avg" if calculate and fields[fname]["type"] in ("integer", "float", "float_time"): label = gtk.Label() label.set_use_markup(True) label_str = fields[fname][calculate] + ": " label_bold = bool(int(fields[fname].get("bold", 0))) if label_bold: label.set_markup("<b>%s</b>" % label_str) else: label.set_markup(label_str) label_sum = gtk.Label() label_sum.set_use_markup(True) dict_widget[n] = ( fname, label, label_sum, fields[fname].get("digits", (16, 2))[1], label_bold, calculate, fields[fname]["type"], ) return treeview, dict_widget, [], on_write
def parse_filter(self, xml_data, max_width, root_node, call=None): psr = expat.ParserCreate() psr.StartElementHandler = self.dummy_start psr.EndElementHandler = self._psr_end psr.CharacterDataHandler = self._psr_char self.notebooks = [] dict_widget = {} psr.Parse(xml_data) self.name_lst += self.name_lst1 container = _container(max_width) attrs = tools.node_attributes(root_node) container.new() self.container = container for node in root_node: attrs = tools.node_attributes(node) if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context':call[0].context}) if visval: continue if node.tag =='field': field_name = str(attrs['name']) field_dic = self.fields[field_name] type = attrs.get('widget', field_dic['type']) field_dic.update(attrs) field_dic['model'] = self.model if type not in widgets_type: continue widget_act = widgets_type[type][0](field_name, self.parent, field_dic, screen=call[0]) if 'string' in field_dic: label = field_dic['string']+' :' else: label = None if not self.focusable: self.focusable = widget_act.widget mywidget = widget_act.widget if node is not None and len(node): mywidget = gtk.HBox(homogeneous=False, spacing=0) mywidget.pack_start(widget_act.widget,expand=True,fill=True) for node_child in node: attrs_child = tools.node_attributes(node_child) if attrs_child.get('invisible', False): visval = eval(attrs_child['invisible'], {'context':call[0].context}) if visval: continue if node_child.tag == 'filter': widget_child = widgets_type['filter'][0]('', self.parent, attrs_child, call) mywidget.pack_start(widget_child.widget) dict_widget[str(attrs['name']) + str(uuid.uuid1())] = (widget_child, mywidget, 1) elif node_child.tag == 'separator': if attrs_child.get('orientation','vertical') == 'horizontal': sep = gtk.HSeparator() sep.set_size_request(30,5) mywidget.pack_start(sep,False,True,5) else: sep = gtk.VSeparator() sep.set_size_request(3,40) mywidget.pack_start(sep,False,False,5) # mywidget.pack_start(widget_act.widget,expand=False,fill=False) xoptions = gtk.SHRINK wid = container.wid_add(mywidget, 1,label, int(self.fields[str(attrs['name'])].get('expand',0)),xoptions=xoptions) dict_widget[str(attrs['name'])] = (widget_act, wid, 1) elif node.tag == 'filter': name = str(attrs.get('string','filter')) widget_act = filter.filter(name, self.parent, attrs, call) help = attrs.get('help', False) or name wid = container.wid_add(widget_act.butt, xoptions=gtk.SHRINK, help=help) dict_widget[name + str(uuid.uuid1())] = (widget_act, widget_act, 1) elif node.tag == 'separator': if attrs.get('orientation','vertical') == 'horizontal': sep_box = gtk.VBox(homogeneous=False, spacing=0) sep = gtk.HSeparator() sep.set_size_request(30,5) sep_box.pack_start(gtk.Label(''),expand=False,fill=False) sep_box.pack_start(sep,False,True,5) else: sep_box = gtk.HBox(homogeneous=False, spacing=0) sep = gtk.VSeparator() sep.set_size_request(3,45) sep_box.pack_start(sep,False,False,5) wid = container.wid_add(sep_box,xoptions=gtk.SHRINK) wid.show() elif node.tag=='newline': container.newline(node.getparent() is not None and node.getparent().tag == 'group') elif node.tag=='group': if attrs.get('invisible', False): continue if attrs.get('expand', False): attrs['expand'] = tools.expr_eval(attrs.get('expand',False),{'context':call[0].context}) frame = gtk.Expander(attrs.get('string', None)) frame.set_expanded(bool(attrs['expand'])) else: frame = gtk.Frame(attrs.get('string', None)) if not attrs.get('string', None): frame.set_shadow_type(gtk.SHADOW_NONE) frame.attrs = attrs frame.set_border_width(0) container.wid_add(frame, colspan=1, expand=int(attrs.get('expand',0)), ypadding=0) container.new() widget, widgets = self.parse_filter(xml_data, max_width, node, call= call) dict_widget.update(widgets) if isinstance(widget, list): tb = gtk.Table(1, 1, True) row = 1 for table in widget: tb.attach(table, 0, 1, row-1, row) row +=1 frame.add(tb) else: frame.add(widget) if not attrs.get('string', None): container.get().set_border_width(0) container.pop() self.widget = container.pop() self.container = container return self.widget, dict_widget
def parse_filter(self, xml_data, max_width, root_node, call=None): psr = expat.ParserCreate() psr.StartElementHandler = self.dummy_start psr.EndElementHandler = self._psr_end psr.CharacterDataHandler = self._psr_char self.notebooks = [] dict_widget = {} psr.Parse(xml_data) self.name_lst += self.name_lst1 container = _container(max_width) attrs = tools.node_attributes(root_node) container.new() self.container = container for node in root_node: self.filter_order += 1 attrs = tools.node_attributes(node) if attrs.get('invisible', False): visval = eval(attrs['invisible'], {'context': call[0].context}) if visval: continue if node.tag == 'field': field_name = str(attrs['name']) field_dic = self.fields[field_name] type = attrs.get('widget', field_dic['type']) field_dic.update(attrs) field_dic['model'] = self.model if type not in widgets_type: continue widget_act = widgets_type[type][0](field_name, self.parent, field_dic, screen=call[0]) if 'string' in field_dic: label = field_dic['string'] + ' :' else: label = None if not self.focusable: self.focusable = widget_act.widget mywidget = widget_act.widget if node is not None and len(node): mywidget = gtk.HBox(homogeneous=False, spacing=0) mywidget.pack_start(widget_act.widget, expand=True, fill=True) for node_child in node: attrs_child = tools.node_attributes(node_child) if attrs_child.get('invisible', False): visval = eval(attrs_child['invisible'], {'context': call[0].context}) if visval: continue if node_child.tag == 'filter': widget_child = widgets_type['filter'][0]( '', self.parent, attrs_child, call) mywidget.pack_start(widget_child.widget) dict_widget[str(attrs['name']) + str(uuid.uuid1())] = ( widget_child, mywidget, 1, self.filter_order) elif node_child.tag == 'separator': if attrs_child.get('orientation', 'vertical') == 'horizontal': sep = gtk.HSeparator() sep.set_size_request(30, 5) mywidget.pack_start(sep, False, True, 5) else: sep = gtk.VSeparator() sep.set_size_request(3, 40) mywidget.pack_start(sep, False, False, 5) # mywidget.pack_start(widget_act.widget,expand=False,fill=False) xoptions = gtk.SHRINK wid = container.wid_add(mywidget, 1, label, int(self.fields[str( attrs['name'])].get('expand', 0)), xoptions=xoptions) dict_widget[str(attrs['name'])] = (widget_act, wid, 1, self.filter_order) elif node.tag == 'filter': name = str(attrs.get('string', 'filter')) widget_act = filter.filter(name, self.parent, attrs, call) help = attrs.get('help', False) or name wid = container.wid_add(widget_act.butt, xoptions=gtk.SHRINK, help=help) dict_widget[name + str(uuid.uuid1())] = (widget_act, widget_act, 1, self.filter_order) elif node.tag == 'separator': if attrs.get('orientation', 'vertical') == 'horizontal': sep_box = gtk.VBox(homogeneous=False, spacing=0) sep = gtk.HSeparator() sep.set_size_request(30, 5) sep_box.pack_start(gtk.Label(''), expand=False, fill=False) sep_box.pack_start(sep, False, True, 5) else: sep_box = gtk.HBox(homogeneous=False, spacing=0) sep = gtk.VSeparator() sep.set_size_request(3, 45) sep_box.pack_start(sep, False, False, 5) wid = container.wid_add(sep_box, xoptions=gtk.SHRINK) wid.show() elif node.tag == 'newline': container.newline(node.getparent() is not None and node.getparent().tag == 'group') elif node.tag == 'group': if attrs.get('invisible', False): continue if attrs.get('expand', False): attrs['expand'] = tools.expr_eval( attrs.get('expand', False), {'context': call[0].context}) frame = gtk.Expander(attrs.get('string', None)) frame.set_expanded(bool(attrs['expand'])) else: frame = gtk.Frame(attrs.get('string', None)) if not attrs.get('string', None): frame.set_shadow_type(gtk.SHADOW_NONE) frame.attrs = attrs frame.set_border_width(0) container.wid_add(frame, colspan=1, expand=int(attrs.get('expand', 0)), ypadding=0) container.new() widget, widgets = self.parse_filter(xml_data, max_width, node, call=call) dict_widget.update(widgets) if isinstance(widget, list): tb = gtk.Table(1, 1, True) row = 1 for table in widget: tb.attach(table, 0, 1, row - 1, row) row += 1 frame.add(tb) else: frame.add(widget) if not attrs.get('string', None): container.get().set_border_width(0) container.pop() self.widget = container.pop() self.container = container return self.widget, dict_widget
def parse(self, model, root_node, fields): dict_widget = {} btn_list = [] attrs = tools.node_attributes(root_node) on_write = attrs.get('on_write', '') editable = attrs.get('editable', False) if editable: treeview = EditableTreeView(editable) else: treeview = DecoratedTreeView(editable) treeview.colors = dict() self.treeview = treeview for color_spec in attrs.get('colors', '').split(';'): if color_spec: colour, test = color_spec.split(':') treeview.colors[colour] = test treeview.set_property('rules-hint', True) if not self.title: self.title = attrs.get('string', 'Unknown') treeview.sequence = False for node in root_node.childNodes: node_attrs = tools.node_attributes(node) if node.localName == 'button': cell = Cell('button')(node_attrs['string']) cell.attrs = node_attrs cell.name = node_attrs['name'] cell.type = node_attrs.get('type', 'object') cell.context = node_attrs.get('context', {}) cell.model = model treeview.cells[node_attrs['name']] = cell col = gtk.TreeViewColumn(None, cell) btn_list.append(col) cell.set_property('editable', False) col._type = 'Button' col.name = node_attrs['name'] if node.localName == 'field': fname = str(node_attrs['name']) if fields[fname]['type'] in ('image', 'binary'): continue # not showed types if fname == 'sequence': treeview.sequence = True for boolean_fields in ('readonly', 'required'): if boolean_fields in node_attrs: if node_attrs[boolean_fields] in ('True', 'False'): node_attrs[boolean_fields] = eval( node_attrs[boolean_fields]) else: node_attrs[boolean_fields] = bool( int(node_attrs[boolean_fields])) fields[fname].update(node_attrs) node_attrs.update(fields[fname]) cell = Cell(fields[fname]['type'])(fname, treeview, node_attrs, self.window) treeview.cells[fname] = cell renderer = cell.renderer write_enable = editable and not node_attrs.get( 'readonly', False) if isinstance(renderer, gtk.CellRendererToggle): renderer.set_property('activatable', write_enable) elif isinstance(renderer, (gtk.CellRendererText, gtk.CellRendererCombo, date_renderer.DecoratorRenderer)): renderer.set_property('editable', write_enable) if write_enable: renderer.connect_after('editing-started', send_keys, treeview) col = gtk.TreeViewColumn(None, renderer) col_label = gtk.Label('') if fields[fname].get('required', False): col_label.set_markup('<b>%s</b>' % cgi.escape(fields[fname]['string'])) else: col_label.set_text(fields[fname]['string']) col_label.show() col.set_widget(col_label) col.name = fname col._type = fields[fname]['type'] col.set_cell_data_func(renderer, cell.setter) col.set_clickable(True) twidth = { 'integer': 60, 'float': 80, 'float_time': 80, 'date': 70, 'datetime': 120, 'selection': 90, 'char': 100, 'one2many': 50, 'many2many': 50, 'boolean': 20, } if 'width' in fields[fname]: width = int(fields[fname]['width']) else: width = twidth.get(fields[fname]['type'], 100) col.set_min_width(width) if not treeview.sequence: col.connect('clicked', sort_model, treeview) col.set_resizable(True) #col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) visval = eval(str(fields[fname].get('invisible', 'False')), {'context': self.screen.context}) col.set_visible(not visval) n = treeview.append_column(col) for tree_op in TREE_OPS: if tree_op in fields[fname]: if tree_op in ('sum', 'avg') \ and fields[fname]['type'] not in ('integer', 'float', 'float_time'): continue label = gtk.Label() label.set_use_markup(True) label_str = fields[fname][tree_op] + ': ' label_bold = bool( int(fields[fname].get('%s_bold' % tree_op, 0))) if label_bold: label.set_markup('<b>%s</b>' % label_str) else: label.set_markup(label_str) label_wid = gtk.Label() label_wid.set_use_markup(True) dict_widget[n] = (fname, label, label_wid, fields[fname].get('digits', (16, 2))[1], label_bold, tree_op) for btn in btn_list: treeview.append_column(btn) return treeview, dict_widget, [], on_write