def _parse_label(self, node, container, attributes): if 'name' in attributes: field = self.screen.group.fields[attributes['name']] if attributes['name'] == self.screen.exclude_field: container.add(None, attributes) return if 'states' not in attributes and 'states' in field.attrs: attributes['states'] = field.attrs['states'] if 'string' not in attributes: if gtk.widget_get_default_direction() == \ gtk.TEXT_DIR_RTL: attributes['string'] = _(':') + field.attrs['string'] else: attributes['string'] = field.attrs['string'] + _(':') if CONFIG['client.modepda']: attributes['xalign'] = 0.0 label = Label(attributes.get('string', ''), attrs=attributes) label.set_alignment(float(attributes.get('xalign', 1.0)), float(attributes.get('yalign', 0.0))) label.set_angle(int(attributes.get('angle', 0))) attributes.setdefault('xexpand', 0) self.state_widgets.append(label) container.add(label, attributes) return label
def __popup_position(self, menu): path, col = self.get_cursor() if col is None: col = self.get_column(0) # get a rectangle describing the cell render area (assume 3 px pad) rect = self.get_cell_area(path, col) rect.x += 3 rect.width -= 6 rect.y += 3 rect.height -= 6 dx, dy = self.window.get_origin() dy += self.get_bin_window().get_position()[1] # fit menu to screen, aligned per text direction screen_width = gtk.gdk.screen_width() screen_height = gtk.gdk.screen_height() menu.realize() ma = menu.allocation menu_y = rect.y + rect.height + dy if menu_y + ma.height > screen_height and rect.y + dy - ma.height > 0: menu_y = rect.y + dy - ma.height if gtk.widget_get_default_direction() == gtk.TEXT_DIR_LTR: menu_x = min(rect.x + dx, screen_width - ma.width) else: menu_x = max(0, rect.x + dx - ma.width + rect.width) return (menu_x, menu_y, True) # x, y, move_within_screen
def _create_technical(self): vbox = hippo.CanvasBox() vbox.props.spacing = style.DEFAULT_SPACING lines = [ _('Kind: %s') % (self._metadata.get('mime_type') or _('Unknown'), ), _('Date: %s') % (self._format_date(), ), _('Size: %s') % (format_size( int( self._metadata.get( 'filesize', model.get_file_size( self._metadata['uid']))))), ] for line in lines: text = hippo.CanvasText( text=line, font_desc=style.FONT_NORMAL.get_pango_desc()) text.props.color = style.COLOR_BUTTON_GREY.get_int() if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: text.props.xalign = hippo.ALIGNMENT_END else: text.props.xalign = hippo.ALIGNMENT_START vbox.append(text) return vbox
def add_line(self, key): self.fields[key] = DICT_ENTRIES[self.keys[key]['type_']](key, self) field = self.fields[key] alignment = gtk.Alignment( float(self.attrs.get('xalign', 0.0)), float(self.attrs.get('yalign', 0.5)), float(self.attrs.get('xexpand', 1.0)), float(self.attrs.get('yexpand', 1.0))) hbox = gtk.HBox() hbox.pack_start(field.widget, expand=field.expand, fill=field.fill) alignment.add(hbox) n_rows = self.table.props.n_rows self.table.resize(n_rows + 1, 3) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: text = _(':') + self.keys[key]['string'] else: text = self.keys[key]['string'] + _(':') label = gtk.Label(text) label.set_alignment(1., .5) self.table.attach(label, 0, 1, n_rows - 1, n_rows, xoptions=gtk.FILL, yoptions=False, xpadding=2) label.set_mnemonic_widget(field.widget) label.show() self.table.attach(alignment, 1, 2, n_rows - 1, n_rows, xoptions=gtk.FILL | gtk.EXPAND, yoptions=False, xpadding=2) alignment.show_all() remove_but = self._new_remove_btn() self.tooltips.set_tip(remove_but, _('Remove "%s"') % self.keys[key]['string']) self.table.attach(remove_but, 2, 3, n_rows - 1, n_rows, xoptions=gtk.FILL, yoptions=False, xpadding=2) remove_but.connect('clicked', self._sig_remove, key) remove_but.show_all() self.rows[key] = [label, alignment, remove_but] self.buttons[key] = remove_but
def _update_position(self): if self.get_property('xalign') > 0.5: self._icon_pos = gtk.POS_LEFT else: self._icon_pos = gtk.POS_RIGHT # If the text is right to left, we have to use the oposite side RTL = gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL if RTL: if self._icon_pos == gtk.POS_LEFT: self._icon_pos = gtk.POS_RIGHT else: self._icon_pos = gtk.POS_LEFT
def expose(self, area, event): gc = area.window.new_gc() alloc = area.get_allocation() gc.line_style = gtk.gdk.LINE_SOLID gc.line_width = 2 if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: area.window.draw_line(gc, alloc.width / 2, alloc.height / 2, alloc.width, alloc.height / 2) else: area.window.draw_line(gc, 0, alloc.height / 2, alloc.width / 2, alloc.height / 2) area.window.draw_line(gc, alloc.width / 2, 0, alloc.width / 2, alloc.height)
def labelize(text, widget): box = hippo.CanvasBox() box.props.spacing = style.DEFAULT_SPACING text = hippo.CanvasText(text=text) text.props.color = style.COLOR_SELECTION_GREY.get_int() if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: text.props.xalign = hippo.ALIGNMENT_END else: text.props.xalign = hippo.ALIGNMENT_START box.append(text) box.append(widget, hippo.PACK_EXPAND) return box
def tab_compare(a, b): text_direction = gtk.widget_get_default_direction() y1 = a.allocation.y + a.allocation.height // 2 y2 = b.allocation.y + b.allocation.height // 2 if y1 == y2: x1 = a.allocation.x + a.allocation.width // 2 x2 = b.allocation.x + b.allocation.width // 2 if text_direction == gtk.TEXT_DIR_RTL: return (x2 > x1) - (x2 < x1) else: return (x1 > x2) - (x1 < x2) else: return (y1 > y2) - (y1 < y2)
def _create_body(self): body = hippo.CanvasBox() body.props.orientation = hippo.ORIENTATION_VERTICAL body.props.background_color = style.COLOR_WHITE.get_int() body.props.padding_top = style.DEFAULT_SPACING * 3 header = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, padding=style.DEFAULT_PADDING, padding_right=style.GRID_CELL_SIZE, spacing=style.DEFAULT_SPACING) body.append(header) descriptions = hippo.CanvasBox( orientation=hippo.ORIENTATION_HORIZONTAL, spacing=style.DEFAULT_SPACING * 3, padding_left=style.GRID_CELL_SIZE, padding_right=style.GRID_CELL_SIZE, padding_top=style.DEFAULT_SPACING * 3) body.append(descriptions, hippo.PACK_EXPAND) first_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL, spacing=style.DEFAULT_SPACING) descriptions.append(first_column) second_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL, spacing=style.DEFAULT_SPACING) descriptions.append(second_column, hippo.PACK_EXPAND) self._favorite_icon = self._create_favorite_icon() header.append(self._favorite_icon) entry_icon = self._create_entry_icon() header.append(entry_icon) self._title = self._create_title() header.append(self._title, hippo.PACK_EXPAND) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: header.reverse() description_box, self._description = self._create_description() second_column.append(description_box) tags_box, self._tags = self._create_tags() second_column.append(tags_box) return body
def add_sum(self, attributes): if 'sum' not in attributes: return if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: text = _(':') + attributes['sum'] else: text = attributes['sum'] + _(':') label, sum_ = gtk.Label(text), gtk.Label() hbox = gtk.HBox() hbox.pack_start(label, expand=True, fill=False, padding=2) hbox.pack_start(sum_, expand=True, fill=False, padding=2) hbox.show_all() self.sum_box.pack_start(hbox, expand=False, fill=False) self.sum_widgets.append((attributes['name'], sum_))
def _create_body(self): body = hippo.CanvasBox() body.props.orientation = hippo.ORIENTATION_VERTICAL body.props.background_color = style.COLOR_WHITE.get_int() body.props.padding_top = style.DEFAULT_SPACING * 3 header = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, padding=style.DEFAULT_PADDING, padding_right=style.GRID_CELL_SIZE, spacing=style.DEFAULT_SPACING) body.append(header) descriptions = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, spacing=style.DEFAULT_SPACING * 3, padding_left=style.GRID_CELL_SIZE, padding_right=style.GRID_CELL_SIZE, padding_top=style.DEFAULT_SPACING * 3) body.append(descriptions, hippo.PACK_EXPAND) first_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL, spacing=style.DEFAULT_SPACING) descriptions.append(first_column) second_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL, spacing=style.DEFAULT_SPACING) descriptions.append(second_column, hippo.PACK_EXPAND) self._favorite_icon = self._create_favorite_icon() header.append(self._favorite_icon) entry_icon = self._create_entry_icon() header.append(entry_icon) self._title = self._create_title() header.append(self._title, hippo.PACK_EXPAND) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: header.reverse() description_box, self._description = self._create_description() second_column.append(description_box) tags_box, self._tags = self._create_tags() second_column.append(tags_box) return body
def update_gui(): global color_h_bg,color_h_fg global color_h_bg_s,color_h_fg_s #global color_h2_bg,color_h2_bg_s global cell,days_l,title,g_e,h_e if not colors: get_theme_colors() # cal.set_week_start(0) # you can set week start (and thus week end) if gtk.widget_get_default_direction()==gtk.TEXT_DIR_LTR: cal.set_direction(-1) # LTR else: cal.set_direction(1) # RTL if (cal.Y,cal.M)==cal.today[0:2]: cal.goto_today() title.set_text(months[cal.M-1]+" "+str(cal.Y)) g_e.set_text(str(cal.gy)) h_e.set_text(str(cal.Y)) #h_str="%d من %s لعام %d هـ" % (cal.D, months[cal.M-1], cal.Y) #g_str="%d من %s لعام %d م" % (cal.gd, gmonths[cal.gm-1], cal.gy) #current_l.set_markup('<span weight="bold" foreground="#ffffff" background="#000000">%s</span>\n<span weight="bold" foreground="#000000" background="#ffffff">%s</span>' % (h_str,g_str)) a=cal.get_array() b=cal.get_g_array() for i in xrange(7): days_l[i].set_text(week_days[wday_index(i)]) # [is_holyday][normal selected inactive]=[fg,bg,fg_s,bg_s] days_l[i].modify_fg(gtk.STATE_NORMAL,colors[1][1][0]) days_l[i].parent.modify_fg(gtk.STATE_NORMAL,colors[1][1][0]) days_l[i].parent.modify_bg(gtk.STATE_NORMAL,colors[1][1][1]); holyday_col=wday_from_index((6+cal.get_week_start())%7) for j in range(6): cell[j][holyday_col].parent.modify_bg(gtk.STATE_NORMAL,colors[1][1][1]) for n in xrange(42): i=n%7; j=n/7; if (a[j][i]): if a[j][i]==cal.D: is_selected=0 else: is_selected=1 if i==holyday_col: is_holyday=1 else: is_holyday=0 cell[j][i].set_markup('<span size="large" weight="bold" foreground="%s" background="%s">%02d</span>\n<span size="small" weight="bold" foreground="grey">%02d/%02d</span>' % ( colors[is_holyday][is_selected][2],colors[is_holyday][is_selected][3], a[j][i], b[j][i][0],b[j][i][1])) h_str="%d من %s لعام %d هـ" % (a[j][i], months[cal.M-1], cal.Y) g_str="%d من %s لعام %d م" % (b[j][i][0], gmonths[b[j][i][1]-1], b[j][i][2]) set_tip(cell[j][i],"%s\n%s" % (h_str,g_str)) else: cell[j][i].set_text('-'); set_tip(cell[j][i],None)
def expose(self, area, event): gc = area.window.new_gc() alloc = area.get_allocation() idx = area.get_data("idx") gc.line_style = gtk.gdk.LINE_SOLID gc.line_width = 2 x1 = 0 if gtk.widget_get_default_direction( ) == gtk.TEXT_DIR_RTL else alloc.width if idx % 2 == 0: area.window.draw_line(gc, x1, alloc.height / 2, alloc.width / 2, alloc.height / 2) area.window.draw_line(gc, alloc.width / 2, 0, alloc.width / 2, alloc.height / 2) else: area.window.draw_line(gc, x1, alloc.height / 2, alloc.width / 2, alloc.height / 2) area.window.draw_line(gc, alloc.width / 2, alloc.height, alloc.width / 2, alloc.height / 2)
def pos_func(menu, widget=widget): screen = widget.get_screen() ref = get_top_parent(widget) menu.set_screen(screen) x, y = widget.translate_coordinates(ref, 0, 0) dx, dy = ref.window.get_origin() wa = widget.allocation # fit menu to screen, aligned per text direction screen_width = screen.get_width() screen_height = screen.get_height() menu.realize() ma = menu.allocation menu_y = y + dy + wa.height if menu_y + ma.height > screen_height and y + dy - ma.height > 0: menu_y = y + dy - ma.height if gtk.widget_get_default_direction() == gtk.TEXT_DIR_LTR: menu_x = min(x + dx, screen_width - ma.width) else: menu_x = max(0, x + dx - ma.width + wa.width) return (menu_x, menu_y, True) # x, y, move_within_screen
def _create_tags(self): vbox = hippo.CanvasBox() vbox.props.spacing = style.DEFAULT_SPACING text = hippo.CanvasText(text=_('Tags:'), font_desc=style.FONT_NORMAL.get_pango_desc()) text.props.color = style.COLOR_BUTTON_GREY.get_int() if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: text.props.xalign = hippo.ALIGNMENT_END else: text.props.xalign = hippo.ALIGNMENT_START vbox.append(text) tags = self._activity.metadata.get('tags', '') text_view = CanvasTextView(tags, box_height=style.GRID_CELL_SIZE * 2) vbox.append(text_view, hippo.PACK_EXPAND) text_view.text_view_widget.props.accepts_tab = False return vbox, text_view
def _create_buddy_list(self): vbox = hippo.CanvasBox() vbox.props.spacing = style.DEFAULT_SPACING text = hippo.CanvasText(text=_('Participants:'), font_desc=style.FONT_NORMAL.get_pango_desc()) text.props.color = style.COLOR_BUTTON_GREY.get_int() if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: text.props.xalign = hippo.ALIGNMENT_END else: text.props.xalign = hippo.ALIGNMENT_START vbox.append(text) if self._metadata.get('buddies'): buddies = simplejson.loads(self._metadata['buddies']).values() vbox.append(BuddyList(buddies)) return vbox else: return vbox
def __init__(self, content, heading=None): self.content = content self.heading = heading self.lines_per_page = 20 self.setDrawFunction("drawDefaultReport") self.builder = get_builder("report") self.treeview = self.builder.get_object("previewBox") self.treeview.set_direction(gtk.TEXT_DIR_LTR) self.liststore = gtk.ListStore(*([str] * len(self.heading))) self.pagecount = self.builder.get_object("pagecount") self.pageNumber = self.builder.get_object("pageNumber") self.current_page = 1 self.pageNumber.set_value(self.current_page) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: halign = 1 else: halign = 0 index = 0 for label in self.heading: column = gtk.TreeViewColumn(label, gtk.CellRendererText(), text=index) column.set_alignment(halign) column.set_spacing(10) column.set_resizable(True) self.treeview.append_column(column) index += 1 self.treeview.set_model(self.liststore) self.window = self.builder.get_object("previewWidget") self.window.show_all() self.builder.connect_signals(self)
def _create_description(self): vbox = hippo.CanvasBox() vbox.props.spacing = style.DEFAULT_SPACING text = hippo.CanvasText(text=_('Description:'), font_desc=style.FONT_NORMAL.get_pango_desc()) text.props.color = style.COLOR_BUTTON_GREY.get_int() if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: text.props.xalign = hippo.ALIGNMENT_END else: text.props.xalign = hippo.ALIGNMENT_START vbox.append(text) text_view = CanvasTextView('', box_height=style.GRID_CELL_SIZE * 2) vbox.append(text_view, hippo.PACK_EXPAND) text_view.text_view_widget.props.accepts_tab = False text_view.text_view_widget.connect( 'focus-out-event', self._description_focus_out_event_cb) return vbox, text_view
def __init__(self, content, heading=None): self.content = content self.heading = heading self.lines_per_page = 20 self.setDrawFunction("drawDefaultReport") self.builder = get_builder("report") self.treeview = self.builder.get_object("previewBox") self.treeview.set_direction(gtk.TEXT_DIR_LTR) self.liststore = gtk.ListStore(*([str] * len(self.heading))) self.pagecount = self.builder.get_object("pagecount") self.pageNumber = self.builder.get_object("pageNumber") self.current_page = 1 self.pageNumber.set_value(self.current_page) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL : halign = 1 else: halign = 0 index = 0 for label in self.heading: column = gtk.TreeViewColumn(label, gtk.CellRendererText(), text=index) column.set_alignment(halign) column.set_spacing(10) column.set_resizable(True) self.treeview.append_column(column) index += 1 self.treeview.set_model(self.liststore) self.window = self.builder.get_object("previewWidget") self.window.show_all() self.builder.connect_signals(self)
def _create_technical(self): vbox = hippo.CanvasBox() vbox.props.spacing = style.DEFAULT_SPACING lines = [ _('Kind: %s') % (self._metadata.get('mime_type') or _('Unknown'),), _('Date: %s') % (self._format_date(),), _('Size: %s') % (format_size(int(self._metadata.get('filesize', model.get_file_size(self._metadata['uid']))))), ] for line in lines: text = hippo.CanvasText(text=line, font_desc=style.FONT_NORMAL.get_pango_desc()) text.props.color = style.COLOR_BUTTON_GREY.get_int() if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: text.props.xalign = hippo.ALIGNMENT_END else: text.props.xalign = hippo.ALIGNMENT_START vbox.append(text) return vbox
def __init__(self): hippo.CanvasBox.__init__( self, orientation=hippo.ORIENTATION_HORIZONTAL, border=style.LINE_WIDTH, background_color=style.COLOR_PANEL_GREY.get_int(), border_color=style.COLOR_SELECTION_GREY.get_int(), padding=style.DEFAULT_PADDING, padding_left=style.DEFAULT_SPACING, spacing=style.DEFAULT_SPACING) icon = CanvasIcon(icon_name='go-previous', size=style.SMALL_ICON_SIZE, fill_color=style.COLOR_TOOLBAR_GREY.get_svg()) self.append(icon) label = hippo.CanvasText(text=_('Back'), font_desc=style.FONT_NORMAL.get_pango_desc()) self.append(label) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: self.reverse() self.connect('motion-notify-event', self.__motion_notify_event_cb)
def _create_description(self): vbox = hippo.CanvasBox() vbox.props.spacing = style.DEFAULT_SPACING text = hippo.CanvasText(text=_('Description:'), font_desc=style.FONT_NORMAL.get_pango_desc()) text.props.color = style.COLOR_BUTTON_GREY.get_int() if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: text.props.xalign = hippo.ALIGNMENT_END else: text.props.xalign = hippo.ALIGNMENT_START vbox.append(text) text_view = CanvasTextView('', box_height=style.GRID_CELL_SIZE * 2) vbox.append(text_view, hippo.PACK_EXPAND) text_view.text_view_widget.props.accepts_tab = False text_view.text_view_widget.connect('focus-out-event', self._description_focus_out_event_cb) return vbox, text_view
def __init__(self): hippo.CanvasBox.__init__( self, orientation=hippo.ORIENTATION_HORIZONTAL, border=style.LINE_WIDTH, background_color=style.COLOR_PANEL_GREY.get_int(), border_color=style.COLOR_SELECTION_GREY.get_int(), padding=style.DEFAULT_PADDING, padding_left=style.DEFAULT_SPACING, spacing=style.DEFAULT_SPACING, ) icon = CanvasIcon( icon_name="go-previous", size=style.SMALL_ICON_SIZE, fill_color=style.COLOR_TOOLBAR_GREY.get_svg() ) self.append(icon) label = hippo.CanvasText(text=_("Back"), font_desc=style.FONT_NORMAL.get_pango_desc()) self.append(label) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: self.reverse() self.connect("motion-notify-event", self.__motion_notify_event_cb)
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 __init__ (self, ledgers_only=False): gobject.GObject.__init__(self) self.builder = get_builder("notebook") self.window = self.builder.get_object("subjectswindow") self.window.set_modal(True) self.treeview = self.builder.get_object("treeview") self.treeview.set_direction(gtk.TEXT_DIR_LTR) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL : halign = 1 else: halign = 0 self.treestore = gtk.TreeStore(str, str, str, str) column = gtk.TreeViewColumn(_("Subject Code"), gtk.CellRendererText(), text=0) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Name"), gtk.CellRendererText(), text=1) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Debtor or Creditor"), gtk.CellRendererText(), text=2) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Sum"), gtk.CellRendererText(), text=3) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE) self.code = numberentry.NumberEntry() box = self.builder.get_object("codebox") box.add(self.code) self.code.show() config.db.session = config.db.session Subject1 = aliased(Subject, name="s1") Subject2 = aliased(Subject, name="s2") #Find top level ledgers (with parent_id equal to 0) query = config.db.session.query(Subject1.code, Subject1.name, Subject1.type, Subject1.lft, Subject1.rgt, count(Subject2.id)) query = query.select_from(outerjoin(Subject1, Subject2, Subject1.id == Subject2.parent_id)) result = query.filter(Subject1.parent_id == 0).group_by(Subject1.id).all() for a in result : type = _(self.__class__.subjecttypes[a[2]]) code = a[0] if config.digittype == 1: code = utility.convertToPersian(code) #-------- subject_sum = config.db.session.query(sum(Notebook.value)).select_from(outerjoin(Subject, Notebook, Subject.id == Notebook.subject_id)) subject_sum = subject_sum.filter(and_(Subject.lft >= a.lft, Subject.lft <= a.rgt)).first() subject_sum = subject_sum[0] if(subject_sum == None): subject_sum = utility.showNumber("0") else : if(subject_sum < 0): subject_sum = "( -" + utility.showNumber(-subject_sum) + " )" else : subject_sum = utility.showNumber(subject_sum) iter = self.treestore.append(None, (code, a[1], type, subject_sum)) if (a[5] != 0 and ledgers_only == False) : #Add empty subledger to show expander for ledgers which have chidren self.treestore.append(iter, ("", "", "", "")) if ledgers_only == True: btn = self.builder.get_object("addsubtoolbutton") btn.hide() self.treeview.set_model(self.treestore) self.treestore.set_sort_column_id(0, gtk.SORT_ASCENDING) self.window.show_all() self.builder.connect_signals(self)
def init (): global _dirn _dirn = gtk.widget_get_default_direction ()
def __init__(self, widget, languages, readonly): NoModal.__init__(self) self.widget = widget self.win = gtk.Dialog(_('Translation'), self.parent, gtk.DIALOG_DESTROY_WITH_PARENT) self.win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.win.set_icon(TRYTON_ICON) self.win.set_decorated(False) self.win.connect('response', self.response) self.accel_group = gtk.AccelGroup() self.win.add_accel_group(self.accel_group) cancel_button = self.win.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) cancel_button.set_always_show_image(True) ok_button = self.win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) ok_button.set_always_show_image(True) ok_button.add_accelerator('clicked', self.accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) tooltips = common.Tooltips() self.widgets = {} table = gtk.Table(len(languages), 4) table.set_homogeneous(False) table.set_col_spacings(3) table.set_row_spacings(2) table.set_border_width(1) for i, language in enumerate(languages): if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: label = _(':') + language['name'] else: label = language['name'] + _(':') label = gtk.Label(label) label.set_alignment(1.0, 0.0 if self.widget.expand else 0.5) table.attach(label, 0, 1, i, i + 1, xoptions=gtk.FILL, xpadding=2) context = dict( language=language['code'], fuzzy_translation=False, ) try: value = RPCExecute('model', self.widget.record.model_name, 'read', [self.widget.record.id], [self.widget.field_name], context={'language': language['code'] })[0][self.widget.field_name] except RPCException: return context['fuzzy_translation'] = True try: fuzzy_value = RPCExecute( 'model', self.widget.record.model_name, 'read', [self.widget.record.id], [self.widget.field_name], context=context)[0][self.widget.field_name] except RPCException: return widget = self.widget.translate_widget() label.set_mnemonic_widget(widget) self.widget.translate_widget_set(widget, fuzzy_value) self.widget.translate_widget_set_readonly(widget, True) yopt = 0 if self.widget.expand: yopt = gtk.EXPAND | gtk.FILL table.attach(widget, 1, 2, i, i + 1, yoptions=yopt) editing = gtk.CheckButton() editing.connect('toggled', self.editing_toggled, widget) editing.props.sensitive = not readonly tooltips.set_tip(editing, _('Edit')) table.attach(editing, 2, 3, i, i + 1, xoptions=gtk.FILL) fuzzy = gtk.CheckButton() fuzzy.set_active(value != fuzzy_value) fuzzy.props.sensitive = False tooltips.set_tip(fuzzy, _('Fuzzy')) table.attach(fuzzy, 4, 5, i, i + 1, xoptions=gtk.FILL) self.widgets[language['code']] = (widget, editing, fuzzy) tooltips.enable() vbox = gtk.VBox() vbox.pack_start(table, self.widget.expand, True) viewport = gtk.Viewport() viewport.set_shadow_type(gtk.SHADOW_NONE) viewport.add(vbox) scrolledwindow = gtk.ScrolledWindow() scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolledwindow.set_shadow_type(gtk.SHADOW_NONE) scrolledwindow.add(viewport) self.win.vbox.pack_start(scrolledwindow, True, True) # JCA Specific: Lower by 5% sensible_allocation = self.sensible_widget.get_allocation() self.win.set_default_size(int(sensible_allocation.width * 0.95), int(sensible_allocation.height * 0.95)) self.win.show_all() self.register() self.show()
def _move_to(self, x, y, w, h, ww, wh, pad=3): if gtk.widget_get_default_direction() == gtk.TEXT_DIR_LTR: return ((x + w + pad), (y + (h - wh)//2)) else: return ((x - (ww + pad)), (y + (h - wh)//2))
def translate(self, widget, event, model, name, src, widget_entry, screen, window): """Translation window for object data strings""" #widget accessor functions def value_get(widget): if type(widget) == type(gtk.Entry()): return widget.get_text() elif type(widget.child) == type(gtk.TextView()): buffer = widget.child.get_buffer() iter_start = buffer.get_start_iter() iter_end = buffer.get_end_iter() return buffer.get_text(iter_start,iter_end,False) else: return None def value_set(widget, value): if type(widget) == type(gtk.Entry()): widget.set_text(value) elif type(widget.child) == type(gtk.TextView()): if value==False: value='' buffer = widget.child.get_buffer() buffer.delete(buffer.get_start_iter(), buffer.get_end_iter()) iter_start = buffer.get_start_iter() buffer.insert(iter_start, value) def widget_duplicate(widget): if type(widget) == type(gtk.Entry()): entry = gtk.Entry() entry.set_property('activates_default', True) entry.set_max_length(widget.get_max_length()) entry.set_width_chars(widget.get_width_chars()) return entry, gtk.FILL elif type(widget.child) == type(gtk.TextView()): tv = gtk.TextView() tv.set_wrap_mode(gtk.WRAP_WORD) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) sw.set_shadow_type(gtk.SHADOW_NONE) sw.set_size_request(-1, 80) sw.add(tv) tv.set_accepts_tab(False) return sw, gtk.FILL | gtk.EXPAND else: return None, False if not value_get(widget_entry): common.message( _('Enter some text to the related field before adding translations!'), parent=self.window) return False id = screen.current_model.id if not id: common.message( _('You need to save resource before adding translations!'), parent=self.window) return False id = screen.current_model.save(reload=False) uid = rpc.session.uid # Find the translatable languages 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']) # get the code of the current language current_lang = rpc.session.context.get('lang', 'en_US') # There used to be a adapt_context() function here, to make sure we sent # False instead of 'en_US'. But why do that at all ? # Window win = gtk.Dialog(_('Add Translation'), window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) win.vbox.set_spacing(5) win.set_property('default-width', 600) win.set_property('default-height', 400) win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) win.set_icon(common.OPENERP_ICON) # Accelerators accel_group = gtk.AccelGroup() win.add_accel_group(accel_group) # Buttons but_cancel = win.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) but_cancel.add_accelerator('clicked', accel_group, gtk.keysyms.Escape, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) but_ok = win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) but_ok.add_accelerator('clicked', accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) # Vertical box vbox = gtk.VBox(spacing=5) # Grid with all the translations entries_list = [] table = gtk.Table(len(langs), 2) table.set_homogeneous(False) table.set_col_spacings(3) table.set_row_spacings(0) table.set_border_width(1) i = 0 for lang in langs: # Make sure the context won't mutate context = copy.copy(rpc.session.context) context['lang'] = lang['code'] # Read the string in this language val = rpc.session.rpc_exec_auth('/object', 'execute', model, 'read', [id], [name], context) val = val[0] # Label #TODO space before ':' depends of lang (ex: english no space) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: label = gtk.Label(': ' + lang['name']) else: label = gtk.Label(lang['name'] + ' :') label.set_alignment(1.0, 0.5) (entry, yoptions) = widget_duplicate(widget_entry) # Setting the writable property according to main widget if isinstance(entry,gtk.Entry): entry.set_sensitive(widget_entry.get_editable()) elif isinstance(entry,gtk.ScrolledWindow): entry.child.set_sensitive(widget_entry.child.get_editable()) # Label and text box side by side hbox = gtk.HBox(homogeneous=False) # Take the latest text in the user's language if lang['code'] == current_lang: value_set(entry,value_get(widget_entry)) else: value_set(entry,val[name]) entries_list.append((lang['code'], entry)) table.attach(label, 0, 1, i, i+1, yoptions=False, xoptions=gtk.FILL, ypadding=2, xpadding=5) table.attach(entry, 1, 2, i, i+1, yoptions=yoptions, ypadding=2, xpadding=5) i += 1 # Open the window vbox.pack_start(table) 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.show_all() # process the response ok = False data = [] while not ok: response = win.run() ok = True if response == gtk.RESPONSE_OK: # Get the values of all the text boxes for code, entry in entries_list: value=value_get(entry) # update the previous form if the string in the user's language was just changed if code == current_lang: value_set(widget_entry, value) # write the new translation context = copy.copy(rpc.session.context) context['lang'] = code rpc.session.rpc_exec_auth('/object', 'execute', model, 'write', [id], {str(name): value}, context) if response == gtk.RESPONSE_CANCEL: window.present() win.destroy() return screen.current_model.reload() window.present() win.destroy() return True
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_name, root_node, fields, notebook=None, paned=None, tooltips=None): dict_widget = {} state_widgets = [] notebook_list = [] attrs = common.node_attributes(root_node) on_write = attrs.get('on_write', '') if not tooltips: tooltips = common.Tooltips() container = _container(tooltips) if CONFIG['client.modepda']: container.new(col=1) else: container.new(col=int(attrs.get('col', 4))) cursor_widget = attrs.get('cursor') if not self.title: self.title = attrs.get('string', 'Unknown') for node in root_node.childNodes: if not node.nodeType == node.ELEMENT_NODE: continue attrs = common.node_attributes(node) if not cursor_widget: if (attrs.get('name') and fields.get(attrs['name']) and not int(attrs.get('invisible', 0)) and not int(attrs.get('readonly', 0)) and attrs['name'] != self.screen.exclude_field): cursor_widget = attrs.get('name') yexpand = int(attrs.get('yexpand', 0)) yfill = int(attrs.get('yfill', 0)) xexpand = int(attrs.get('xexpand', 1)) xfill = int(attrs.get('xfill', 1)) colspan = int(attrs.get('colspan', 1)) if node.localName == 'image': common.ICONFACTORY.register_icon(attrs['name']) icon = Image(attrs=attrs) state_widgets.append(icon) icon.set_from_stock(attrs['name'], gtk.ICON_SIZE_DIALOG) container.wid_add(icon, help_tip=attrs.get('help', False), colspan=colspan, yexpand=yexpand, yfill=yfill, ypadding=10, xexpand=xexpand, xfill=xfill) elif node.localName == 'separator': text = attrs.get('string', '') if 'name' in attrs: for attr_name in ('states', 'invisible'): if attr_name not in attrs and attrs['name'] in fields: if attr_name in fields[attrs['name']].attrs: attrs[attr_name] = fields[attrs['name'] ].attrs[attr_name] if not text: text = fields[attrs['name']].attrs['string'] vbox = VBox(attrs=attrs) state_widgets.append(vbox) if text: label = gtk.Label(text) label.set_alignment(float(attrs.get('xalign', 0.0)), 0.5) vbox.pack_start(label) vbox.pack_start(gtk.HSeparator()) container.wid_add(vbox, help_tip=attrs.get('help', False), colspan=colspan, yexpand=yexpand, yfill=yfill, ypadding=10, xexpand=xexpand, xfill=xfill) elif node.localName == 'label': text = attrs.get('string', '') if 'name' in attrs and attrs['name'] in fields: if attrs['name'] == self.screen.exclude_field: container.empty_add(int(attrs.get('colspan', 1))) continue for attr_name in ('states', 'invisible'): if attr_name not in attrs \ and attr_name in fields[attrs['name']].attrs: attrs[attr_name] = fields[attrs['name'] ].attrs[attr_name] if 'string' not in attrs: if gtk.widget_get_default_direction() == \ gtk.TEXT_DIR_RTL: text = _(':') + \ fields[attrs['name']].attrs['string'] else: text = fields[attrs['name']].attrs['string'] + \ _(':') if 'xalign' not in attrs: attrs['xalign'] = 1.0 elif not text: for node in node.childNodes: if node.nodeType == node.TEXT_NODE: text += node.data else: text += node.toxml() label = Label(text, attrs=attrs) state_widgets.append(label) if CONFIG['client.modepda']: attrs['xalign'] = 0.0 label.set_alignment(float(attrs.get('xalign', 1.0)), float(attrs.get('yalign', 0.0))) label.set_angle(int(attrs.get('angle', 0))) xexpand = bool(attrs.get('xexpand', 0)) container.wid_add(label, help_tip=attrs.get('help', False), colspan=colspan, yexpand=yexpand, yfill=yfill, xexpand=xexpand, xfill=xfill) elif node.localName == 'newline': container.newline() elif node.localName == 'button': button = Button(attrs) state_widgets.append(button) container.wid_add(button, help_tip=attrs.get('help', False), colspan=colspan, yexpand=yexpand, yfill=yfill, xexpand=xexpand, xfill=xfill) elif node.localName == 'notebook': notebook = Notebook(attrs=attrs) state_widgets.append(notebook) notebook.set_scrollable(True) notebook_list.append(notebook) if CONFIG['client.form_tab'] == 'top': pos = gtk.POS_TOP elif CONFIG['client.form_tab'] == 'left': pos = gtk.POS_LEFT elif CONFIG['client.form_tab'] == 'right': pos = gtk.POS_RIGHT elif CONFIG['client.form_tab'] == 'bottom': pos = gtk.POS_BOTTOM notebook.set_tab_pos(pos) notebook.set_border_width(3) colspan = int(attrs.get('colspan', 4)) yexpand = bool(attrs.get('yexpand', 1)) yfill = bool(attrs.get('yfill', 1)) container.wid_add(notebook, colspan=colspan, yexpand=yexpand, yfill=yfill, xexpand=xexpand, xfill=xfill) (widget, widgets, state_widgets2, spam, notebook_list2, cursor_widget2) = self.parse(model_name, node, fields, notebook, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) state_widgets += state_widgets2 for widget_name, widgets in widgets.items(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) elif node.localName == 'page': if CONFIG['client.form_tab'] == 'left': angle = 90 tab_box = gtk.VBox(spacing=3) image_pos, image_rotate = ('end', gtk.gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE) elif CONFIG['client.form_tab'] == 'right': angle = -90 tab_box = gtk.VBox(spacing=3) image_pos, image_rotate = ('start', gtk.gdk.PIXBUF_ROTATE_CLOCKWISE) else: angle = 0 tab_box = gtk.HBox(spacing=3) image_pos, image_rotate = ('start', gtk.gdk.PIXBUF_ROTATE_NONE) text = attrs.get('string', '') if 'name' in attrs and attrs['name'] in fields: if attrs['name'] == self.screen.exclude_field: continue for attr_name in ('states', 'invisible'): if attr_name in fields[attrs['name']].attrs: attrs[attr_name] = \ fields[attrs['name']].attrs[attr_name] if not text: text = fields[attrs['name']].attrs['string'] if not text: text = _('No String Attr.') if '_' not in text: text = '_' + text tab_label = gtk.Label(text) tab_label.set_angle(angle) tab_label.set_use_underline(True) tab_box.pack_start(tab_label) if 'icon' in attrs: common.ICONFACTORY.register_icon(attrs['icon']) pixbuf = tab_box.render_icon(attrs['icon'], gtk.ICON_SIZE_SMALL_TOOLBAR) pixbuf = pixbuf.rotate_simple(image_rotate) icon = gtk.Image() icon.set_from_pixbuf(pixbuf) if image_pos == 'end': tab_box.pack_end(icon) else: tab_box.pack_start(icon) tab_box.show_all() (widget, widgets, state_widgets2, spam, notebook_list2, cursor_widget2) = self.parse(model_name, node, fields, notebook, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) state_widgets += state_widgets2 for widget_name, widgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) viewport = gtk.Viewport() viewport.set_shadow_type(gtk.SHADOW_NONE) viewport.add(widget) viewport.show() scrolledwindow = ScrolledWindow(attrs=attrs) scrolledwindow.set_shadow_type(gtk.SHADOW_NONE) scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolledwindow.add(viewport) state_widgets.append(scrolledwindow) notebook.append_page(scrolledwindow, tab_box) elif node.localName == 'field': name = str(attrs['name']) if name == self.screen.exclude_field: container.empty_add(int(attrs.get('colspan', 1))) continue if name not in fields: container.empty_add(int(attrs.get('colspan', 1))) log = logging.getLogger(__name__) log.error('Unknown field "%s"' % str(name)) continue ftype = attrs.get('widget', fields[name].attrs['type']) if not ftype in WIDGETS_TYPE: container.empty_add(int(attrs.get('colspan', 1))) continue for attr_name in ('relation', 'domain', 'selection', 'relation_field', 'string', 'views', 'invisible', 'add_remove', 'sort', 'context', 'size', 'filename', 'autocomplete', 'translate', 'create', 'delete', 'selection_change_with', 'schema_model'): if attr_name in fields[name].attrs and \ not attr_name in attrs: attrs[attr_name] = fields[name].attrs[attr_name] widget_act = WIDGETS_TYPE[ftype][0](name, model_name, attrs) self.widget_id += 1 widget_act.position = self.widget_id dict_widget.setdefault(name, []) dict_widget[name].append(widget_act) yexpand = bool(attrs.get('yexpand', WIDGETS_TYPE[ftype][2])) yfill = bool(attrs.get('yfill', WIDGETS_TYPE[ftype][3])) hlp = fields[name].attrs.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))) container.wid_add(Alignment(widget_act.widget, attrs), fields[name].attrs['string'], fname=name, help_tip=hlp, colspan=colspan, yexpand=yexpand, yfill=yfill, xexpand=xexpand, xfill=xfill) elif node.localName == 'group': (widget, widgets, state_widgets2, spam, notebook_list2, cursor_widget2) = self.parse(model_name, node, fields, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) for widget_name, lwidgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(lwidgets) state_widgets += state_widgets2 text = '' if 'name' in attrs and attrs['name'] in fields: if attrs['name'] == self.screen.exclude_field: container.empty_add(int(attrs.get('colspan', 1))) continue for attr_name in ('states', 'invisible'): if attr_name in fields[attrs['name']].attrs: attrs[attr_name] = fields[attrs['name'] ].attrs[attr_name] text = fields[attrs['name']].attrs['string'] if attrs.get('string'): text = attrs['string'] widget.set_homogeneous(bool(int(attrs.get('homogeneous', 0)))) frame = Frame(text, attrs=attrs, widgets=widgets) frame.add(widget) state_widgets.append(frame) container.wid_add(frame, colspan=colspan, yexpand=yexpand, yfill=yfill, ypadding=0, xexpand=xexpand, xfill=xfill, xpadding=0) elif node.localName == 'hpaned': hpaned = gtk.HPaned() container.wid_add(hpaned, colspan=int(attrs.get('colspan', 4)), yexpand=True, yfill=True) (widget, widgets, state_widgets2, spam, notebook_list2, cursor_widget2) = self.parse(model_name, node, fields, paned=hpaned, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) state_widgets += state_widgets2 for widget_name, widgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) if 'position' in attrs: hpaned.set_position(int(attrs['position'])) elif node.localName == 'vpaned': vpaned = gtk.VPaned() container.wid_add(vpaned, colspan=int(attrs.get('colspan', 4)), yexpand=True, yfill=True) (widget, widgets, state_widgets2, spam, notebook_list2, cursor_widget2) = self.parse(model_name, node, fields, paned=vpaned, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) state_widgets += state_widgets2 for widget_name, widgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) if 'position' in attrs: vpaned.set_position(int(attrs['position'])) elif node.localName == 'child': (widget, widgets, state_widgets2, spam, notebook_list2, cursor_widget2) = self.parse(model_name, node, fields, paned=paned, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) state_widgets += state_widgets2 for widget_name, widgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) if not paned.get_child1(): paned.pack1(widget, resize=True, shrink=True) elif not paned.get_child2(): paned.pack2(widget, resize=True, shrink=True) return container.pop(), dict_widget, state_widgets, on_write, \ notebook_list, cursor_widget
def __init__(self, number=0, background=None): self.main_window_background = background self.new_items = [] self.deleted_items = [] self.edit_items = [] self.builder = get_builder("document") self.window = self.builder.get_object("window1") self.window.set_title(_("Register new document")) self.date = dateentry.DateEntry() box = self.builder.get_object("datebox") box.add(self.date) self.date.show() self.code = numberentry.NumberEntry() box = self.builder.get_object("codebox") box.add(self.code) self.code.show() self.code.connect("activate", self.selectSubject) self.code.set_tooltip_text(_("Press Enter to see available subjects.")) self.amount = numberentry.NumberEntry() box = self.builder.get_object("amountbox") box.add(self.amount) self.amount.set_activates_default(True) self.amount.show() self.treeview = self.builder.get_object("treeview") #self.treeview.set_direction(gtk.TEXT_DIR_LTR) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL : halign = 1 else: halign = 0 self.liststore = gtk.ListStore(str, str, str, str, str, str, str) column = gtk.TreeViewColumn(_("Index"), gtk.CellRendererText(), text=0) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Code"), gtk.CellRendererText(), text=1) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Name"), gtk.CellRendererText(), text=2) column.set_spacing(5) column.set_resizable(True) money_cell_renderer = gtk.CellRendererText() #money_cell_renderer.set_alignment(1.0, 0.5) #incompatible with pygtk2.16 self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Debt"), money_cell_renderer, text=3) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Credit"), money_cell_renderer, text=4) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Description"), gtk.CellRendererText(), text=5) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) #column = gtk.TreeViewColumn(_("Notebook ID") , gtk.CellRendererText(), text=6) #column.set_alignment(halign) #column.set_spacing(5) #column.set_resizable(True) #self.treeview.append_column(column) self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE) self.debt_sum = 0 self.credit_sum = 0 self.numrows = 0 self.auto_win = None self.cl_document = class_document.Document() if number > 0: if self.cl_document.set_bill(number): self.showRows() self.window.set_title(_("Edit document")) else: numstring = utility.LN(number) msg = _("No document found with number %s\nDo you want to register a document with this number?") % numstring msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK_CANCEL, msg) msgbox.set_title(_("No Documents found")) result = msgbox.run() msgbox.destroy() if result == gtk.RESPONSE_CANCEL: return else: self.builder.get_object("docnumber").set_text (numstring) self.treeview.set_model(self.liststore) self.window.show_all() if self.cl_document.permanent: self.builder.get_object("editable").hide() self.builder.get_object("non-editable").show() else: self.builder.get_object("editable").show() self.builder.get_object("non-editable").hide() self.builder.connect_signals(self)
def wksub_text_direction(self): direction = gtk.widget_get_default_direction() if direction == gtk.TEXT_DIR_RTL: return 'DIR="RTL"' elif direction == gtk.TEXT_DIR_LTR: return 'DIR="LTR"'
def __init__(self): hippo.CanvasBox.__init__(self) self.props.orientation = hippo.ORIENTATION_VERTICAL self.props.background_color = style.COLOR_WHITE.get_int() self.props.padding_top = style.DEFAULT_SPACING * 3 self._metadata = None self._update_title_sid = None # Create header header = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, padding=style.DEFAULT_PADDING, padding_right=style.GRID_CELL_SIZE, spacing=style.DEFAULT_SPACING) self.append(header) # Create two column body body = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, spacing=style.DEFAULT_SPACING * 3, padding_left=style.GRID_CELL_SIZE, padding_right=style.GRID_CELL_SIZE, padding_top=style.DEFAULT_SPACING * 3) self.append(body, hippo.PACK_EXPAND) first_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL, spacing=style.DEFAULT_SPACING) body.append(first_column) second_column = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL, spacing=style.DEFAULT_SPACING) body.append(second_column, hippo.PACK_EXPAND) # Header self._keep_icon = self._create_keep_icon() header.append(self._keep_icon) self._icon = None self._icon_box = hippo.CanvasBox() header.append(self._icon_box) self._title = self._create_title() header.append(self._title, hippo.PACK_EXPAND) # TODO: create a version list popup instead of a date label self._date = self._create_date() header.append(self._date) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: header.reverse() # First column self._preview_box = hippo.CanvasBox() first_column.append(self._preview_box) self._technical_box = hippo.CanvasBox() first_column.append(self._technical_box) # Second column description_box, self._description = self._create_description() second_column.append(description_box) tags_box, self._tags = self._create_tags() second_column.append(tags_box) self._buddy_list = hippo.CanvasBox() second_column.append(self._buddy_list)
def translate(self, widget, event, model, name, src, widget_entry, screen, window): """Translation window for object data strings""" #widget accessor functions def value_get(widget): if type(widget) == type(gtk.Entry()): return widget.get_text() elif type(widget.child) == type(gtk.TextView()): buffer = widget.child.get_buffer() iter_start = buffer.get_start_iter() iter_end = buffer.get_end_iter() return buffer.get_text(iter_start, iter_end, False) else: return None def value_set(widget, value): if type(widget) == type(gtk.Entry()): widget.set_text(value) elif type(widget.child) == type(gtk.TextView()): if value == False: value = '' buffer = widget.child.get_buffer() buffer.delete(buffer.get_start_iter(), buffer.get_end_iter()) iter_start = buffer.get_start_iter() buffer.insert(iter_start, value) def widget_duplicate(widget): if type(widget) == type(gtk.Entry()): entry = gtk.Entry() entry.set_property('activates_default', True) entry.set_max_length(widget.get_max_length()) entry.set_width_chars(widget.get_width_chars()) return entry, gtk.FILL elif type(widget.child) == type(gtk.TextView()): tv = gtk.TextView() tv.set_wrap_mode(gtk.WRAP_WORD) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) sw.set_shadow_type(gtk.SHADOW_NONE) sw.set_size_request(-1, 80) sw.add(tv) tv.set_accepts_tab(False) return sw, gtk.FILL | gtk.EXPAND else: return None, False if not value_get(widget_entry): common.message(_( 'Enter some text to the related field before adding translations!' ), parent=self.window) return False id = screen.current_model.id if not id: common.message( _('You need to save resource before adding translations!'), parent=self.window) return False id = screen.current_model.save(reload=False) uid = rpc.session.uid # Find the translatable languages 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']) # get the code of the current language current_lang = rpc.session.context.get('lang', 'en_US') # There used to be a adapt_context() function here, to make sure we sent # False instead of 'en_US'. But why do that at all ? # Window win = gtk.Dialog(_('Add Translation'), window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) win.vbox.set_spacing(5) win.set_property('default-width', 600) win.set_property('default-height', 400) win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) win.set_icon(common.OPENERP_ICON) # Accelerators accel_group = gtk.AccelGroup() win.add_accel_group(accel_group) # Buttons but_cancel = win.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) but_cancel.add_accelerator('clicked', accel_group, gtk.keysyms.Escape, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) but_ok = win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) but_ok.add_accelerator('clicked', accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) # Vertical box vbox = gtk.VBox(spacing=5) # Grid with all the translations entries_list = [] table = gtk.Table(len(langs), 2) table.set_homogeneous(False) table.set_col_spacings(3) table.set_row_spacings(0) table.set_border_width(1) i = 0 for lang in langs: # Make sure the context won't mutate context = copy.copy(rpc.session.context) context['lang'] = lang['code'] # Read the string in this language val = rpc.session.rpc_exec_auth('/object', 'execute', model, 'read', [id], [name], context) val = val[0] # Label #TODO space before ':' depends of lang (ex: english no space) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: label = gtk.Label(': ' + lang['name']) else: label = gtk.Label(lang['name'] + ' :') label.set_alignment(1.0, 0.5) (entry, yoptions) = widget_duplicate(widget_entry) # Setting the writable property according to main widget if isinstance(entry, gtk.Entry): entry.set_sensitive(widget_entry.get_editable()) elif isinstance(entry, gtk.ScrolledWindow): entry.child.set_sensitive(widget_entry.child.get_editable()) # Label and text box side by side hbox = gtk.HBox(homogeneous=False) # Take the latest text in the user's language if lang['code'] == current_lang: value_set(entry, value_get(widget_entry)) else: value_set(entry, val[name]) entries_list.append((lang['code'], entry)) table.attach(label, 0, 1, i, i + 1, yoptions=False, xoptions=gtk.FILL, ypadding=2, xpadding=5) table.attach(entry, 1, 2, i, i + 1, yoptions=yoptions, ypadding=2, xpadding=5) i += 1 # Open the window vbox.pack_start(table) 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.show_all() # process the response ok = False data = [] while not ok: response = win.run() ok = True if response == gtk.RESPONSE_OK: # Get the values of all the text boxes for code, entry in entries_list: value = value_get(entry) # update the previous form if the string in the user's language was just changed if code == current_lang: value_set(widget_entry, value) # write the new translation context = copy.copy(rpc.session.context) context['lang'] = code rpc.session.rpc_exec_auth('/object', 'execute', model, 'write', [id], {str(name): value}, context) if response == gtk.RESPONSE_CANCEL: window.present() win.destroy() return screen.current_model.reload() window.present() win.destroy() return True
def text_direction_is_ltr(): return gtk.widget_get_default_direction() != gtk.TEXT_DIR_RTL
def __init__(self, ledgers_only=False): gobject.GObject.__init__(self) self.builder = get_builder("notebook") self.window = self.builder.get_object("subjectswindow") self.window.set_modal(True) self.treeview = self.builder.get_object("treeview") self.treeview.set_direction(gtk.TEXT_DIR_LTR) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: halign = 1 else: halign = 0 self.treestore = gtk.TreeStore(str, str, str, str) column = gtk.TreeViewColumn(_("Subject Code"), gtk.CellRendererText(), text=0) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Name"), gtk.CellRendererText(), text=1) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Debtor or Creditor"), gtk.CellRendererText(), text=2) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Sum"), gtk.CellRendererText(), text=3) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE) self.code = numberentry.NumberEntry() box = self.builder.get_object("codebox") box.add(self.code) self.code.show() config.db.session = config.db.session Subject1 = aliased(Subject, name="s1") Subject2 = aliased(Subject, name="s2") #Find top level ledgers (with parent_id equal to 0) query = config.db.session.query(Subject1.code, Subject1.name, Subject1.type, Subject1.lft, Subject1.rgt, count(Subject2.id)) query = query.select_from( outerjoin(Subject1, Subject2, Subject1.id == Subject2.parent_id)) result = query.filter(Subject1.parent_id == 0).group_by( Subject1.id).all() for a in result: type = _(self.__class__.subjecttypes[a[2]]) code = a[0] if config.digittype == 1: code = utility.convertToPersian(code) #-------- subject_sum = config.db.session.query(sum( Notebook.value)).select_from( outerjoin(Subject, Notebook, Subject.id == Notebook.subject_id)) subject_sum = subject_sum.filter( and_(Subject.lft >= a.lft, Subject.lft <= a.rgt)).first() subject_sum = subject_sum[0] if (subject_sum == None): subject_sum = utility.showNumber("0") else: if (subject_sum < 0): subject_sum = "( -" + utility.showNumber( -subject_sum) + " )" else: subject_sum = utility.showNumber(subject_sum) iter = self.treestore.append(None, (code, a[1], type, subject_sum)) if (a[5] != 0 and ledgers_only == False): #Add empty subledger to show expander for ledgers which have chidren self.treestore.append(iter, ("", "", "", "")) if ledgers_only == True: btn = self.builder.get_object("addsubtoolbutton") btn.hide() self.treeview.set_model(self.treestore) self.treestore.set_sort_column_id(0, gtk.SORT_ASCENDING) self.window.show_all() self.builder.connect_signals(self)
def __init__(self, number=0): self.builder = get_builder("document") self.window = self.builder.get_object("window1") self.window.set_title(_("Register new document")) self.date = dateentry.DateEntry() box = self.builder.get_object("datebox") box.add(self.date) self.date.show() self.code = numberentry.NumberEntry() box = self.builder.get_object("codebox") box.add(self.code) self.code.show() self.code.connect("activate", self.selectSubject) self.code.set_tooltip_text(_("Press Enter to see available subjects.")) self.amount = numberentry.NumberEntry() box = self.builder.get_object("amountbox") box.add(self.amount) self.amount.set_activates_default(True) self.amount.show() self.treeview = self.builder.get_object("treeview") self.treeview.set_direction(gtk.TEXT_DIR_LTR) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL : halign = 1 else: halign = 0 self.liststore = gtk.ListStore(str, str, str, str, str, str) column = gtk.TreeViewColumn(_("Index"), gtk.CellRendererText(), text=0) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Code"), gtk.CellRendererText(), text=1) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Name"), gtk.CellRendererText(), text=2) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) money_cell_renderer = gtk.CellRendererText() #money_cell_renderer.set_alignment(1.0, 0.5) #incompatible with pygtk2.16 self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Debt"), money_cell_renderer, text=3) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Credit"), money_cell_renderer, text=4) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Description"), gtk.CellRendererText(), text=5) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE) # self.session = config.db.session self.debt_sum = 0 self.credit_sum = 0 self.numrows = 0 self.permanent = False if number > 0: query = config.db.session.query(Bill).select_from(Bill) bill = query.filter(Bill.number == number).first() self.docnumber = number if bill == None: numstring = str(number) if config.digittype == 1: numstring = utility.convertToPersian(numstring) msg = _("No document found with number %s\nDo you want to register a document with this number?") % numstring msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK_CANCEL, msg) msgbox.set_title(_("No Documents found")) result = msgbox.run() msgbox.destroy() if result == gtk.RESPONSE_CANCEL: return else: self.docid = 0 docnum = str(self.docnumber) if config.digittype == 1: docnum = utility.convertToPersian(docnum) self.builder.get_object("docnumber").set_text (docnum) else: self.showRows(number) self.permanent = bill.permanent self.window.set_title(_("Edit document")) else: self.docnumber = 0 self.docid = 0 self.treeview.set_model(self.liststore) self.window.show_all() if self.permanent: self.builder.get_object("editable").hide() self.builder.get_object("non-editable").show() else: self.builder.get_object("editable").show() self.builder.get_object("non-editable").hide() self.builder.connect_signals(self)
def __init__(self, widget, languages): NoModal.__init__(self) self.widget = widget self.win = gtk.Dialog(_('Translation'), self.parent, gtk.DIALOG_DESTROY_WITH_PARENT) self.win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.win.set_icon(TRYTON_ICON) self.win.connect('response', self.response) self.accel_group = gtk.AccelGroup() self.win.add_accel_group(self.accel_group) self.win.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK).add_accelerator( 'clicked', self.accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) tooltips = common.Tooltips() self.widgets = {} table = gtk.Table(len(languages), 4) table.set_homogeneous(False) table.set_col_spacings(3) table.set_row_spacings(2) table.set_border_width(1) for i, language in enumerate(languages): if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: label = _(':') + language['name'] else: label = language['name'] + _(':') label = gtk.Label(label) label.set_alignment(1.0, 0.0 if self.widget.expand else 0.5) table.attach(label, 0, 1, i, i + 1, xoptions=gtk.FILL) context = dict( language=language['code'], fuzzy_translation=False, ) try: value = RPCExecute('model', self.widget.record.model_name, 'read', [self.widget.record.id], [self.widget.field_name], context={'language': language['code']} )[0][self.widget.field_name] except RPCException: return context['fuzzy_translation'] = True try: fuzzy_value = RPCExecute('model', self.widget.record.model_name, 'read', [self.widget.record.id], [self.widget.field_name], context=context)[0][self.widget.field_name] except RPCException: return widget = self.widget.translate_widget() label.set_mnemonic_widget(widget) self.widget.translate_widget_set(widget, fuzzy_value) self.widget.translate_widget_set_readonly(widget, True) yopt = 0 if self.widget.expand: yopt |= gtk.EXPAND | gtk.FILL table.attach(widget, 1, 2, i, i + 1, yoptions=yopt) editing = gtk.CheckButton() editing.connect('toggled', self.editing_toggled, widget) tooltips.set_tip(editing, _('Edit')) table.attach(editing, 2, 3, i, i + 1, xoptions=gtk.FILL) fuzzy = gtk.CheckButton() fuzzy.set_active(value != fuzzy_value) fuzzy.props.sensitive = False tooltips.set_tip(fuzzy, _('Fuzzy')) table.attach(fuzzy, 4, 5, i, i + 1, xoptions=gtk.FILL) self.widgets[language['code']] = (widget, editing, fuzzy) tooltips.enable() vbox = gtk.VBox() vbox.pack_start(table, self.widget.expand, True) viewport = gtk.Viewport() viewport.set_shadow_type(gtk.SHADOW_NONE) viewport.add(vbox) scrolledwindow = gtk.ScrolledWindow() scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolledwindow.set_shadow_type(gtk.SHADOW_NONE) scrolledwindow.add(viewport) self.win.vbox.pack_start(scrolledwindow, True, True) sensible_allocation = self.sensible_widget.get_allocation() self.win.set_default_size(int(sensible_allocation.width * 0.95), int(sensible_allocation.height * 0.95)) self.register() self.win.show_all() common.center_window(self.win, self.parent, self.sensible_widget)
def parse(self, model_name, root_node, fields, notebook=None, paned=None, tooltips=None): dict_widget = {} button_list = [] notebook_list = [] attrs = common.node_attributes(root_node) on_write = attrs.get('on_write', '') if not tooltips: tooltips = common.Tooltips() container = _container(tooltips) if CONFIG['client.modepda']: container.new(col=1) else: container.new(col=int(attrs.get('col', 4))) cursor_widget = attrs.get('cursor') if not self.title: self.title = attrs.get('string', 'Unknown') for node in root_node.childNodes: if not node.nodeType == node.ELEMENT_NODE: continue attrs = common.node_attributes(node) if not cursor_widget: if attrs.get('name') and fields.get(attrs['name']) \ and attrs['name'] != self.screen.exclude_field: cursor_widget = attrs.get('name') yexpand = int(attrs.get('yexpand', 0)) yfill = int(attrs.get('yfill', 0)) xexpand = int(attrs.get('xexpand', 1)) xfill = int(attrs.get('xfill', 1)) colspan = int(attrs.get('colspan', 1)) if node.localName == 'image': common.ICONFACTORY.register_icon(attrs['name']) icon = Image(attrs) button_list.append(icon) icon.set_from_stock(attrs['name'], gtk.ICON_SIZE_DIALOG) container.wid_add(icon, help_tip=attrs.get('help', False), colspan=colspan, yexpand=yexpand, yfill=yfill, ypadding=10, xexpand=xexpand, xfill=xfill) elif node.localName == 'separator': text = attrs.get('string', '') if 'name' in attrs: for attr_name in ('states', 'invisible'): if attr_name not in attrs and attrs['name'] in fields: if attr_name in fields[attrs['name']].attrs: attrs[attr_name] = fields[attrs['name'] ].attrs[attr_name] if not text: text = fields[attrs['name']].attrs['string'] vbox = VBox(attrs=attrs) button_list.append(vbox) if text: label = gtk.Label(text) label.set_use_markup(True) label.set_alignment(float(attrs.get('xalign', 0.0)), 0.5) vbox.pack_start(label) vbox.pack_start(gtk.HSeparator()) container.wid_add(vbox, help_tip=attrs.get('help', False), colspan=colspan, yexpand=yexpand, yfill=yfill, ypadding=10, xexpand=xexpand, xfill=xfill) elif node.localName == 'label': text = attrs.get('string', '') if 'name' in attrs and attrs['name'] in fields: if attrs['name'] == self.screen.exclude_field: container.empty_add(int(attrs.get('colspan', 1))) continue for attr_name in ('states', 'invisible'): if attr_name not in attrs \ and attr_name in fields[attrs['name']].attrs: attrs[attr_name] = fields[attrs['name'] ].attrs[attr_name] if not text: if gtk.widget_get_default_direction() == \ gtk.TEXT_DIR_RTL: text = _(':') + \ fields[attrs['name']].attrs['string'] else: text = fields[attrs['name']].attrs['string'] + \ _(':') if 'xalign' not in attrs: attrs['xalign'] = 1.0 elif not text: for node in node.childNodes: if node.nodeType == node.TEXT_NODE: text += node.data else: text += node.toxml() if not text: container.empty_add(int(attrs.get('colspan', 1))) continue label = Label(text, attrs) button_list.append(label) label.set_use_markup(True) if CONFIG['client.modepda']: attrs['xalign'] = 0.0 label.set_alignment(float(attrs.get('xalign', 1.0)), float(attrs.get('yalign', 0.0))) label.set_angle(int(attrs.get('angle', 0))) xexpand = bool(attrs.get('xexpand', 0)) container.wid_add(label, help_tip=attrs.get('help', False), colspan=colspan, yexpand=yexpand, yfill=yfill, xexpand=xexpand, xfill=xfill) elif node.localName == 'newline': container.newline() elif node.localName == 'button': button = Button(attrs) button_list.append(button) container.wid_add(button, help_tip=attrs.get('help', False), colspan=colspan, yexpand=yexpand, yfill=yfill, xexpand=xexpand, xfill=xfill) elif node.localName == 'notebook': notebook = gtk.Notebook() notebook.set_scrollable(True) notebook_list.append(notebook) if CONFIG['client.form_tab'] == 'top': pos = gtk.POS_TOP elif CONFIG['client.form_tab'] == 'left': pos = gtk.POS_LEFT elif CONFIG['client.form_tab'] == 'right': pos = gtk.POS_RIGHT elif CONFIG['client.form_tab'] == 'bottom': pos = gtk.POS_BOTTOM notebook.set_tab_pos(pos) notebook.set_border_width(3) colspan = int(attrs.get('colspan', 4)) yexpand = bool(attrs.get('yexpand', 1)) yfill = bool(attrs.get('yfill', 1)) container.wid_add(notebook, colspan=colspan, yexpand=yexpand, yfill=yfill, xexpand=xexpand, xfill=xfill) widget, widgets, buttons, spam, notebook_list2, cursor_widget2\ = self.parse(model_name, node, fields, notebook, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) button_list += buttons for widget_name, widgets in widgets.items(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) elif node.localName == 'page': if CONFIG['client.form_tab'] == 'left': angle = 90 tab_box = gtk.VBox(spacing=3) image_pos, image_rotate = ('end', gtk.gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE) elif CONFIG['client.form_tab'] == 'right': angle = -90 tab_box = gtk.VBox(spacing=3) image_pos, image_rotate = ('start', gtk.gdk.PIXBUF_ROTATE_CLOCKWISE) else: angle = 0 tab_box = gtk.HBox(spacing=3) image_pos, image_rotate = ('start', gtk.gdk.PIXBUF_ROTATE_NONE) text = attrs.get('string', '') if 'name' in attrs and attrs['name'] in fields: if attrs['name'] == self.screen.exclude_field: continue for attr_name in ('states', 'invisible'): if attr_name in fields[attrs['name']].attrs: attrs[attr_name] = \ fields[attrs['name']].attrs[attr_name] if not text: text = fields[attrs['name']].attrs['string'] if not text: text = _('No String Attr.') if '_' not in text: text = '_' + text tab_label = gtk.Label(text) tab_label.set_angle(angle) tab_label.set_use_underline(True) tab_box.pack_start(tab_label) if 'icon' in attrs: common.ICONFACTORY.register_icon(attrs['icon']) pixbuf = tab_box.render_icon(attrs['icon'], gtk.ICON_SIZE_SMALL_TOOLBAR) pixbuf = pixbuf.rotate_simple(image_rotate) icon = gtk.Image() icon.set_from_pixbuf(pixbuf) if image_pos == 'end': tab_box.pack_end(icon) else: tab_box.pack_start(icon) tab_box.show_all() widget, widgets, buttons, spam, notebook_list2, cursor_widget2\ = self.parse(model_name, node, fields, notebook, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) button_list += buttons for widget_name, widgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) viewport = gtk.Viewport() viewport.set_shadow_type(gtk.SHADOW_NONE) viewport.add(widget) viewport.show() scrolledwindow = ScrolledWindow(attrs=attrs) scrolledwindow.set_shadow_type(gtk.SHADOW_NONE) scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolledwindow.add(viewport) button_list.append(scrolledwindow) notebook.append_page(scrolledwindow, tab_box) elif node.localName == 'field': name = str(attrs['name']) if name == self.screen.exclude_field: container.empty_add(int(attrs.get('colspan', 1))) continue if name not in fields: container.empty_add(int(attrs.get('colspan', 1))) log = logging.getLogger('view') log.error('Unknown field "%s"' % str(name)) continue ftype = attrs.get('widget', fields[name].attrs['type']) if not ftype in WIDGETS_TYPE: container.empty_add(int(attrs.get('colspan', 1))) continue for attr_name in ('relation', 'domain', 'selection', 'relation_field', 'string', 'views', 'invisible', 'add_remove', 'sort', 'context', 'size', 'filename', 'autocomplete', 'translate'): if attr_name in fields[name].attrs and \ not attr_name in attrs: attrs[attr_name] = fields[name].attrs[attr_name] widget_act = WIDGETS_TYPE[ftype][0](name, model_name, attrs) self.widget_id += 1 widget_act.position = self.widget_id dict_widget.setdefault(name, []) dict_widget[name].append(widget_act) yexpand = bool(attrs.get('yexpand', WIDGETS_TYPE[ftype][2])) yfill = bool(attrs.get('yfill', WIDGETS_TYPE[ftype][3])) hlp = fields[name].attrs.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))) container.wid_add(Alignment(widget_act.widget, attrs), fields[name].attrs['string'], fname=name, help_tip=hlp, colspan=colspan, yexpand=yexpand, yfill=yfill, xexpand=xexpand, xfill=xfill) elif node.localName == 'group': widget, widgets, buttons, spam, notebook_list2, cursor_widget2\ = self.parse(model_name, node, fields, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) for widget_name, widgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) button_list += buttons text = '' if 'name' in attrs and attrs['name'] in fields: if attrs['name'] == self.screen.exclude_field: container.empty_add(int(attrs.get('colspan', 1))) continue for attr_name in ('states', 'invisible'): if attr_name in fields[attrs['name']].attrs: attrs[attr_name] = fields[attrs['name'] ].attrs[attr_name] text = fields[attrs['name']].attrs['string'] if attrs.get('string'): text = attrs['string'] frame = Frame(text, attrs) frame.add(widget) button_list.append(frame) container.wid_add(frame, colspan=colspan, yexpand=yexpand, yfill=yfill, ypadding=0, xexpand=xexpand, xfill=xfill, xpadding=0) elif node.localName == 'hpaned': hpaned = gtk.HPaned() container.wid_add(hpaned, colspan=int(attrs.get('colspan', 4)), yexpand=True, yfill=True) widget, widgets, buttons, spam, notebook_list2, cursor_widget2\ = self.parse(model_name, node, fields, paned=hpaned, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) button_list += buttons for widget_name, widgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) if 'position' in attrs: hpaned.set_position(int(attrs['position'])) elif node.localName == 'vpaned': vpaned = gtk.VPaned() container.wid_add(vpaned, colspan=int(attrs.get('colspan', 4)), yexpand=True, yfill=True) widget, widgets, buttons, spam, notebook_list, cursor_widget2\ = self.parse(model_name, node, fields, paned=vpaned, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) button_list += buttons for widget_name, widgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) if 'position' in attrs: vpaned.set_position(int(attrs['position'])) elif node.localName == 'child': widget, widgets, buttons, spam, notebook_list2, cursor_widget2\ = self.parse(model_name, node, fields, paned=paned, tooltips=tooltips) if not cursor_widget: cursor_widget = cursor_widget2 notebook_list.extend(notebook_list2) button_list += buttons for widget_name, widgets in widgets.iteritems(): dict_widget.setdefault(widget_name, []) dict_widget[widget_name].extend(widgets) if not paned.get_child1(): paned.pack1(widget, resize=True, shrink=True) elif not paned.get_child2(): paned.pack2(widget, resize=True, shrink=True) return container.pop(), dict_widget, button_list, on_write, \ notebook_list, cursor_widget
def __init__(self): gobject.GObject.__init__(self) self.builder = get_builder("setting") self.window = self.builder.get_object("window1") self.filechooser = self.builder.get_object("filechooser") self.filename = self.builder.get_object("filename") self.treeview = self.builder.get_object("databases-table") self.treeview.set_direction(gtk.TEXT_DIR_LTR) self.liststore = gtk.ListStore(gobject.TYPE_BOOLEAN, str, str) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL : halign = 1 else: halign = 0 crtoggle = gtk.CellRendererToggle() crtoggle.set_radio(True) # crtoggle.set_activatable(True) crtoggle.connect('toggled', self.changeCurrentDb, 0) column = gtk.TreeViewColumn(_("Current"), crtoggle, active=0) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Name"), gtk.CellRendererText(), text=1) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Path"), gtk.CellRendererText(), text=2) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) self.treeview.set_model(self.liststore) i = 0 for dbpath in config.dblist: if i == config.currentdb - 1: self.active_iter = self.liststore.append((True, config.dbnames[i], dbpath)) else: self.liststore.append((False, config.dbnames[i], dbpath)) i += 1 # self.olddb = self.builder.get_object("olddb") # self.newdb = self.builder.get_object("newdb") self.infolabel = self.builder.get_object("infolabel") self.infolabel.set_text(config.db.dbfile) self.langlist = self.builder.get_object("language") comboInsertItems(self.langlist, config.langlist) self.langlist.set_active(config.localelist.index(config.locale)) self.dateformat = self.builder.get_object("dateformat") comboInsertItems(self.dateformat, config.datetypes) self.dateformat.set_active(config.datetype) self.delimiter = self.builder.get_object("delimiter") comboInsertItems(self.delimiter, config.datedelims) self.delimiter.set_active(config.datedelim) self.dateorder = self.builder.get_object("dateorder") comboInsertItems(self.dateorder, []) for order in config.dateorders: self.dateorder.append_text(order[0] + " - " + order[1] + " - " + order[2]) self.dateorder.set_active(config.dateorder) self.uselatin = self.builder.get_object("uselatin") if config.digittype == 0: self.uselatin.set_active(True) else: self.uselatin.set_active(False) self.repair_atstart = self.builder.get_object("repair_atstart") self.repair_atstart.set_active(config.repair_atstart) self.builder.get_object("topmargin").set_value(config.topmargin) self.builder.get_object("botmargin").set_value(config.botmargin) self.builder.get_object("rightmargin").set_value(config.rightmargin) self.builder.get_object("leftmargin").set_value(config.leftmargin) self.builder.get_object("namefont").set_value(config.namefont) self.builder.get_object("headerfont").set_value(config.headerfont) self.builder.get_object("contentfont").set_value(config.contentfont) self.builder.get_object("footerfont").set_value(config.footerfont) paper_size = gtk.paper_size_new_from_ppd(config.paper_ppd, config.paper_name, config.paper_width, config.paper_height) self.page_setup = gtk.PageSetup() self.page_setup.set_paper_size(paper_size) self.page_setup.set_orientation(config.paper_orientation) self.builder.get_object("papersize").set_text(config.paper_name) self.setup_config_tab() self.window.show_all() self.builder.connect_signals(self)
def translate(self, widget, event, model, name, src, widget_entry, screen, window): #widget accessor functions def value_get(widget): if type(widget) == type(gtk.Entry()): return widget.get_text() elif type(widget.child) == type(gtk.TextView()): buffer = widget.child.get_buffer() iter_start = buffer.get_start_iter() iter_end = buffer.get_end_iter() return buffer.get_text(iter_start, iter_end, False) else: return None def value_set(widget, value): if type(widget) == type(gtk.Entry()): widget.set_text(value) elif type(widget.child) == type(gtk.TextView()): if value == False: value = '' buffer = widget.child.get_buffer() buffer.delete(buffer.get_start_iter(), buffer.get_end_iter()) iter_start = buffer.get_start_iter() buffer.insert(iter_start, value) def widget_duplicate(widget): if type(widget) == type(gtk.Entry()): entry = gtk.Entry() entry.set_property('activates_default', True) entry.set_max_length(widget.get_max_length()) entry.set_width_chars(widget.get_width_chars()) return entry, gtk.FILL elif type(widget.child) == type(gtk.TextView()): tv = gtk.TextView() tv.set_wrap_mode(gtk.WRAP_WORD) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) sw.set_shadow_type(gtk.SHADOW_NONE) sw.set_size_request(-1, 80) sw.add(tv) tv.set_accepts_tab(False) return sw, gtk.FILL | gtk.EXPAND else: return None, False if not value_get(widget_entry): common.message(_( 'Enter some text to the related field before adding translations!' ), parent=self.window) return False id = screen.current_model.id if not id: common.message( _('You need to save resource before adding translations!'), parent=self.window) return False id = screen.current_model.save(reload=False) uid = rpc.session.uid 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']) code = rpc.session.context.get('lang', 'en_US') #change 'en' to false for context def adapt_context(val): if val == 'en_US': return False else: return val win = gtk.Dialog(_('Add Translation'), window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) win.vbox.set_spacing(5) win.set_property('default-width', 600) win.set_property('default-height', 400) win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) win.set_icon(common.OPENERP_ICON) accel_group = gtk.AccelGroup() win.add_accel_group(accel_group) but_cancel = win.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) but_cancel.add_accelerator('clicked', accel_group, gtk.keysyms.Escape, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) but_ok = win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) but_ok.add_accelerator('clicked', accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) vbox = gtk.VBox(spacing=5) entries_list = [] table = gtk.Table(len(langs), 2) table.set_homogeneous(False) table.set_col_spacings(3) table.set_row_spacings(0) table.set_border_width(1) i = 0 for lang in langs: context = copy.copy(rpc.session.context) context['lang'] = adapt_context(lang['code']) val = rpc.session.rpc_exec_auth('/object', 'execute', model, 'read', [id], [name], context) val = val[0] #TODO space before ':' depends of lang (ex: english no space) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: label = gtk.Label(': ' + lang['name']) else: label = gtk.Label(lang['name'] + ' :') label.set_alignment(1.0, 0.5) (entry, yoptions) = widget_duplicate(widget_entry) hbox = gtk.HBox(homogeneous=False) if code == lang['code']: value_set(entry, value_get(widget_entry)) else: value_set(entry, val[name]) entries_list.append((val['id'], lang['code'], entry)) table.attach(label, 0, 1, i, i + 1, yoptions=False, xoptions=gtk.FILL, ypadding=2, xpadding=5) table.attach(entry, 1, 2, i, i + 1, yoptions=yoptions, ypadding=2, xpadding=5) i += 1 vbox.pack_start(table) 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.show_all() ok = False data = [] while not ok: response = win.run() ok = True if response == gtk.RESPONSE_OK: to_save = map(lambda x: (x[0], x[1], value_get(x[2])), entries_list) while to_save != []: new_val = {} new_val['id'], new_val['code'], new_val[ 'value'] = to_save.pop() #update form field if new_val['code'] == code: value_set(widget_entry, new_val['value']) context = copy.copy(rpc.session.context) context['lang'] = adapt_context(new_val['code']) rpc.session.rpc_exec_auth('/object', 'execute', model, 'write', [id], {str(name): new_val['value']}, context) if response == gtk.RESPONSE_CANCEL: window.present() win.destroy() return screen.current_model.reload() window.present() win.destroy() return True
def translate(self, widget, event, model, name, src, widget_entry, screen, window): #widget accessor functions def value_get(widget): if type(widget) == type(gtk.Entry()): return widget.get_text() elif type(widget.child) == type(gtk.TextView()): buffer = widget.child.get_buffer() iter_start = buffer.get_start_iter() iter_end = buffer.get_end_iter() return buffer.get_text(iter_start,iter_end,False) else: return None def value_set(widget, value): if type(widget) == type(gtk.Entry()): widget.set_text(value) elif type(widget.child) == type(gtk.TextView()): if value==False: value='' buffer = widget.child.get_buffer() buffer.delete(buffer.get_start_iter(), buffer.get_end_iter()) iter_start = buffer.get_start_iter() buffer.insert(iter_start, value) def widget_duplicate(widget): if type(widget) == type(gtk.Entry()): entry = gtk.Entry() entry.set_property('activates_default', True) entry.set_max_length(widget.get_max_length()) entry.set_width_chars(widget.get_width_chars()) return entry, gtk.FILL elif type(widget.child) == type(gtk.TextView()): tv = gtk.TextView() tv.set_wrap_mode(gtk.WRAP_WORD) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) sw.set_shadow_type(gtk.SHADOW_NONE) sw.set_size_request(-1, 80) sw.add(tv) tv.set_accepts_tab(False) return sw, gtk.FILL | gtk.EXPAND else: return None, False if not value_get(widget_entry): common.message( _('Enter some text to the related field before adding translations!'), parent=self.window) return False id = screen.current_model.id if not id: common.message( _('You need to save resource before adding translations!'), parent=self.window) return False id = screen.current_model.save(reload=False) uid = rpc.session.uid 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']) code = rpc.session.context.get('lang', 'en_US') #change 'en' to false for context def adapt_context(val): if val == 'en_US': return False else: return val win = gtk.Dialog(_('Add Translation'), window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) win.vbox.set_spacing(5) win.set_property('default-width', 600) win.set_property('default-height', 400) win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) win.set_icon(common.OPENERP_ICON) accel_group = gtk.AccelGroup() win.add_accel_group(accel_group) but_cancel = win.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) but_cancel.add_accelerator('clicked', accel_group, gtk.keysyms.Escape, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) but_ok = win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) but_ok.add_accelerator('clicked', accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) vbox = gtk.VBox(spacing=5) entries_list = [] table = gtk.Table(len(langs), 2) table.set_homogeneous(False) table.set_col_spacings(3) table.set_row_spacings(0) table.set_border_width(1) i = 0 for lang in langs: context = copy.copy(rpc.session.context) context['lang'] = adapt_context(lang['code']) val = rpc.session.rpc_exec_auth('/object', 'execute', model, 'read', [id], [name], context) val = val[0] #TODO space before ':' depends of lang (ex: english no space) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: label = gtk.Label(': ' + lang['name']) else: label = gtk.Label(lang['name'] + ' :') label.set_alignment(1.0, 0.5) (entry, yoptions) = widget_duplicate(widget_entry) hbox = gtk.HBox(homogeneous=False) if code == lang['code']: value_set(entry,value_get(widget_entry)) else: value_set(entry,val[name]) entries_list.append((val['id'], lang['code'], entry)) table.attach(label, 0, 1, i, i+1, yoptions=False, xoptions=gtk.FILL, ypadding=2, xpadding=5) table.attach(entry, 1, 2, i, i+1, yoptions=yoptions, ypadding=2, xpadding=5) i += 1 vbox.pack_start(table) 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.show_all() ok = False data = [] while not ok: response = win.run() ok = True if response == gtk.RESPONSE_OK: to_save = map(lambda x : (x[0], x[1], value_get(x[2])), entries_list) while to_save != []: new_val = {} new_val['id'],new_val['code'], new_val['value'] = to_save.pop() #update form field if new_val['code'] == code: value_set(widget_entry, new_val['value']) context = copy.copy(rpc.session.context) context['lang'] = adapt_context(new_val['code']) rpc.session.rpc_exec_auth('/object', 'execute', model, 'write', [id], {str(name): new_val['value']}, context) if response == gtk.RESPONSE_CANCEL: window.present() win.destroy() return screen.current_model.reload() window.present() win.destroy() return True
import gobject gobject.set_prgname('gajim') import gtk except Warning, msg2: if str(msg2) == 'could not open display': print >> sys.stderr, _('Gajim needs X server to run. Quiting...') else: print >> sys.stderr, _('importing PyGTK failed: %s') % str(msg2) sys.exit() warnings.resetwarnings() if os.name == 'nt': warnings.filterwarnings(action='ignore') if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: i18n.direction_mark = u'\u200F' pritext = '' from common import exceptions try: from common import gajim except exceptions.DatabaseMalformed: pritext = _('Database Error') sectext = _('The database file (%s) cannot be read. Try to repair it (see ' 'http://trac.gajim.org/wiki/DatabaseBackup) or remove it (all history ' 'will be lost).') % common.logger.LOG_DB_PATH else: from common import dbus_support if dbus_support.supported: from music_track_listener import MusicTrackListener
def __init__(self, number=0): self.builder = get_builder("document") self.window = self.builder.get_object("window1") self.window.set_title(_("Register new document")) self.date = dateentry.DateEntry() box = self.builder.get_object("datebox") box.add(self.date) self.date.show() self.code = numberentry.NumberEntry() box = self.builder.get_object("codebox") box.add(self.code) self.code.show() self.code.connect("activate", self.selectSubject) self.code.set_tooltip_text(_("Press Enter to see available subjects.")) self.amount = numberentry.NumberEntry() box = self.builder.get_object("amountbox") box.add(self.amount) self.amount.set_activates_default(True) self.amount.show() self.treeview = self.builder.get_object("treeview") self.treeview.set_direction(gtk.TEXT_DIR_LTR) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: halign = 1 else: halign = 0 self.liststore = gtk.ListStore(str, str, str, str, str, str) column = gtk.TreeViewColumn(_("Index"), gtk.CellRendererText(), text=0) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Code"), gtk.CellRendererText(), text=1) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Name"), gtk.CellRendererText(), text=2) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) money_cell_renderer = gtk.CellRendererText() #money_cell_renderer.set_alignment(1.0, 0.5) #incompatible with pygtk2.16 self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Debt"), money_cell_renderer, text=3) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Credit"), money_cell_renderer, text=4) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Description"), gtk.CellRendererText(), text=5) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE) # self.session = config.db.session self.debt_sum = 0 self.credit_sum = 0 self.numrows = 0 self.permanent = False if number > 0: query = config.db.session.query(Bill).select_from(Bill) bill = query.filter(Bill.number == number).first() self.docnumber = number if bill == None: numstring = str(number) if config.digittype == 1: numstring = utility.convertToPersian(numstring) msg = _( "No document found with number %s\nDo you want to register a document with this number?" ) % numstring msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK_CANCEL, msg) msgbox.set_title(_("No Documents found")) result = msgbox.run() msgbox.destroy() if result == gtk.RESPONSE_CANCEL: return else: self.docid = 0 docnum = str(self.docnumber) if config.digittype == 1: docnum = utility.convertToPersian(docnum) self.builder.get_object("docnumber").set_text(docnum) else: self.showRows(number) self.permanent = bill.permanent self.window.set_title(_("Edit document")) else: self.docnumber = 0 self.docid = 0 self.treeview.set_model(self.liststore) self.window.show_all() if self.permanent: self.builder.get_object("editable").hide() self.builder.get_object("non-editable").show() else: self.builder.get_object("editable").show() self.builder.get_object("non-editable").hide() self.builder.connect_signals(self)
def _startup(self): options = {} options['monthNames'] = dateutils.get_month_names() options['monthNamesShort'] = dateutils.get_short_month_names() options['dayNames'] = dateutils.get_day_names() options['dayNamesShort'] = dateutils.get_short_day_names() options['buttonText'] = { "today": _('today'), "month": _('month'), "week": _('week'), "day": _('day') } options['defaultView'] = api.user_settings.get('calendar-view', 'month') # FIXME: This should not be tied to the language, rather be # picked up from libc, but it's a bit of work to translate # one into another so just take a shortcut options['columnFormat'] = { # month column format, eg "Mon", see: # http://arshaw.com/fullcalendar/docs/text/columnFormat/ 'month': _('ddd'), # week column format: eg, "Mon 9/7", see: # http://arshaw.com/fullcalendar/docs/text/columnFormat/ 'week': _('ddd M/d'), # day column format : eg "Monday 9/7", see: # http://arshaw.com/fullcalendar/docs/text/columnFormat/ 'day': _('dddd M/d'), } options['timeFormat'] = { # for agendaWeek and agendaDay, eg "5:00 - 6:30", see: # http://arshaw.com/fullcalendar/docs/text/timeFormat/ 'agenda': _('h:mm{ - h:mm}'), # for all other views, eg "7p", see: # http://arshaw.com/fullcalendar/docs/text/timeFormat/ '': _('h(:mm)t'), } options['titleFormat'] = { # month title, eg "September 2009", see: # http://arshaw.com/fullcalendar/docs/text/titleFormat/ 'month': _('MMMM yyyy'), # week title, eg "Sep 7 - 13 2009" see: # http://arshaw.com/fullcalendar/docs/text/titleFormat/ 'week': _("MMM d[ yyyy]{ '—'[ MMM] d yyyy}"), # day time, eg "Tuesday, Sep 8, 2009" see: # http://arshaw.com/fullcalendar/docs/text/titleFormat/ 'day': _('dddd, MMM d, yyyy'), } if get_weekday_start() == MO: firstday = 1 else: firstday = 0 options['firstDay'] = firstday options['isRTL'] = ( gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL) options['data'] = self._show_events options['loading_msg'] = _('Loading calendar content, please wait...') self.js_function_call('startup', options) self._update_title()
def init(): global _dirn _dirn = gtk.widget_get_default_direction()
def _startup(self): options = {} options['monthNames'] = dateutils.get_month_names() options['monthNamesShort'] = dateutils.get_short_month_names() options['dayNames'] = dateutils.get_day_names() options['dayNamesShort'] = dateutils.get_short_day_names() options['buttonText'] = {"today": _('today'), "month": _('month'), "week": _('week'), "day": _('day')} options['defaultView'] = api.user_settings.get( 'calendar-view', 'month') # FIXME: This should not be tied to the language, rather be # picked up from libc, but it's a bit of work to translate # one into another so just take a shortcut options['columnFormat'] = { # month column format, eg "Mon", see: # http://arshaw.com/fullcalendar/docs/text/columnFormat/ 'month': _('ddd'), # week column format: eg, "Mon 9/7", see: # http://arshaw.com/fullcalendar/docs/text/columnFormat/ 'week': _('ddd M/d'), # day column format : eg "Monday 9/7", see: # http://arshaw.com/fullcalendar/docs/text/columnFormat/ 'day': _('dddd M/d'), } options['timeFormat'] = { # for agendaWeek and agendaDay, eg "5:00 - 6:30", see: # http://arshaw.com/fullcalendar/docs/text/timeFormat/ 'agenda': _('h:mm{ - h:mm}'), # for all other views, eg "7p", see: # http://arshaw.com/fullcalendar/docs/text/timeFormat/ '': _('h(:mm)t'), } options['titleFormat'] = { # month title, eg "September 2009", see: # http://arshaw.com/fullcalendar/docs/text/titleFormat/ 'month': _('MMMM yyyy'), # week title, eg "Sep 7 - 13 2009" see: # http://arshaw.com/fullcalendar/docs/text/titleFormat/ 'week': _("MMM d[ yyyy]{ '—'[ MMM] d yyyy}"), # day time, eg "Tuesday, Sep 8, 2009" see: # http://arshaw.com/fullcalendar/docs/text/titleFormat/ 'day': _('dddd, MMM d, yyyy'), } if get_weekday_start() == MO: firstday = 1 else: firstday = 0 options['firstDay'] = firstday options['isRTL'] = ( gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL) options['data'] = self._show_events options['loading_msg'] = _('Loading calendar content, please wait...') self.js_function_call('startup', options) self._update_title()
def __init__(self): gobject.GObject.__init__(self) self.builder = get_builder("setting") self.window = self.builder.get_object("window1") self.filechooser = self.builder.get_object("filechooser") self.filename = self.builder.get_object("filename") self.treeview = self.builder.get_object("databases-table") self.treeview.set_direction(gtk.TEXT_DIR_LTR) self.liststore = gtk.ListStore(gobject.TYPE_BOOLEAN, str, str) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL : halign = 1 else: halign = 0 crtoggle = gtk.CellRendererToggle() crtoggle.set_radio(True) # crtoggle.set_activatable(True) crtoggle.connect('toggled', self.changeCurrentDb, 0) column = gtk.TreeViewColumn(_("Current"), crtoggle, active=0) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Name"), gtk.CellRendererText(), text=1) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Path"), gtk.CellRendererText(), text=2) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) self.treeview.set_model(self.liststore) i = 0 for dbpath in config.dblist: if i == config.currentdb - 1: self.active_iter = self.liststore.append((True, config.dbnames[i], dbpath)) else: self.liststore.append((False, config.dbnames[i], dbpath)) i += 1 # self.olddb = self.builder.get_object("olddb") # self.newdb = self.builder.get_object("newdb") self.infolabel = self.builder.get_object("infolabel") self.infolabel.set_text(config.db.dbfile) self.langlist = self.builder.get_object("language") comboInsertItems(self.langlist, config.langlist) self.langlist.set_active(config.localelist.index(config.locale)) self.dateformat = self.builder.get_object("dateformat") comboInsertItems(self.dateformat, config.datetypes) self.dateformat.set_active(config.datetype) self.delimiter = self.builder.get_object("delimiter") comboInsertItems(self.delimiter, config.datedelims) self.delimiter.set_active(config.datedelim) self.dateorder = self.builder.get_object("dateorder") comboInsertItems(self.dateorder, []) for order in config.dateorders: self.dateorder.append_text(order[0] + " - " + order[1] + " - " + order[2]) self.dateorder.set_active(config.dateorder) self.uselatin = self.builder.get_object("uselatin") if config.digittype == 0: self.uselatin.set_active(True) else: self.uselatin.set_active(False) self.repair_atstart = self.builder.get_object("repair_atstart") self.repair_atstart.set_active(config.repair_atstart) self.builder.get_object("topmargin").set_value(config.topmargin) self.builder.get_object("botmargin").set_value(config.botmargin) self.builder.get_object("rightmargin").set_value(config.rightmargin) self.builder.get_object("leftmargin").set_value(config.leftmargin) self.builder.get_object("namefont").set_value(config.namefont) self.builder.get_object("headerfont").set_value(config.headerfont) self.builder.get_object("contentfont").set_value(config.contentfont) self.builder.get_object("footerfont").set_value(config.footerfont) paper_size = gtk.paper_size_new_from_ppd(config.paper_ppd, config.paper_name, config.paper_width, config.paper_height) self.page_setup = gtk.PageSetup() self.page_setup.set_paper_size(paper_size) self.page_setup.set_orientation(config.paper_orientation) self.builder.get_object("papersize").set_text(config.paper_name) self.window.show_all() self.builder.connect_signals(self)