def __init__(self, revisions, revision=None, format_='%x %H:%M:%S.%f'): self.parent = get_toplevel_window() self.win = gtk.Dialog( _('Revision'), self.parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) Main().add_window(self.win) cancel_button = self.win.add_button(set_underline(_("Cancel")), gtk.RESPONSE_CANCEL) cancel_button.set_image( IconFactory.get_image('tryton-cancel', gtk.ICON_SIZE_BUTTON)) cancel_button.set_always_show_image(True) ok_button = self.win.add_button(set_underline(_("OK")), gtk.RESPONSE_OK) ok_button.set_image( IconFactory.get_image('tryton-ok', gtk.ICON_SIZE_BUTTON)) ok_button.set_always_show_image(True) self.win.set_default_response(gtk.RESPONSE_OK) self.win.set_icon(TRYTON_ICON) self.win.vbox.set_spacing(3) self.win.vbox.pack_start(gtk.Label(_('Select a revision')), expand=False, fill=True) self.win.vbox.pack_start(gtk.HSeparator()) hbox = gtk.HBox(spacing=3) label = gtk.Label(_('Revision:')) hbox.pack_start(label, expand=True, fill=True) list_store = gtk.ListStore(str, str) # Set model on instantiation to get the default cellrenderer as text combobox = gtk.ComboBoxEntry(model=list_store) # JCA : Force set text colmn for gtk2 combobox.set_text_column(0) self.entry = combobox.get_child() self.entry.connect('focus-out-event', self.focus_out) self.entry.connect('activate', self.activate) label.set_mnemonic_widget(self.entry) combobox.connect('changed', self.changed) self.entry.set_property('activates_default', True) self._format = format_ if revision: self.entry.set_text(datetime_strftime(revision, self._format)) self._value = revision active = -1 else: self._value = None active = 0 list_store.append(('', '')) for i, (rev, id_, name) in enumerate(revisions, 1): list_store.append((datetime_strftime(rev, self._format), name)) if rev == revision: active = i combobox.set_active(active) cell = gtk.CellRendererText() combobox.pack_start(cell, True) combobox.add_attribute(cell, 'text', 1) hbox.pack_start(combobox, expand=True, fill=True) combobox.set_entry_text_column(0) self.win.vbox.pack_start(hbox, expand=True, fill=True) self.win.show_all()
def _parse_page(self, node, attributes): tab_box = Gtk.HBox(spacing=3) if 'name' in attributes and attributes['name'] == self.exclude_field: return label = Gtk.Label(label=set_underline(attributes['string'])) label.set_use_underline(True) if 'icon' in attributes: tab_box.pack_start(IconFactory.get_image( attributes['icon'], Gtk.IconSize.SMALL_TOOLBAR), expand=True, fill=True, padding=0) tab_box.pack_start(label, expand=True, fill=True, padding=0) tab_box.show_all() viewport = Gtk.Viewport() viewport.set_shadow_type(Gtk.ShadowType.NONE) scrolledwindow = ScrolledWindow(attrs=attributes) scrolledwindow.set_shadow_type(Gtk.ShadowType.NONE) scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrolledwindow.add(viewport) scrolledwindow.show_all() self.view.state_widgets.append(scrolledwindow) self.container.append_page(scrolledwindow, tab_box) container = Container.constructor(int(attributes.get('col', 4)), attributes.get('homogeneous', False)) self.parse_child(node, container) viewport.add(container.container)
def _parse_page(self, node, notebook, attributes): tab_box = gtk.HBox(spacing=3) if 'name' in attributes: field = self.screen.group.fields[attributes['name']] if attributes['name'] == self.screen.exclude_field: return for attr in ('states', 'string'): if attr not in attributes and attr in field.attrs: attributes[attr] = field.attrs[attr] label = gtk.Label(set_underline(attributes['string'])) label.set_use_underline(True) if 'icon' in attributes: tab_box.pack_start(IconFactory.get_image( attributes['icon'], gtk.ICON_SIZE_SMALL_TOOLBAR)) tab_box.pack_start(label) tab_box.show_all() viewport = gtk.Viewport() viewport.set_shadow_type(gtk.SHADOW_NONE) scrolledwindow = ScrolledWindow(attrs=attributes) scrolledwindow.set_shadow_type(gtk.SHADOW_NONE) scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolledwindow.add(viewport) scrolledwindow.show_all() self.state_widgets.append(scrolledwindow) notebook.append_page(scrolledwindow, tab_box) container = self.parse(node) viewport.add(container.table)
def _new_remove_btn(self): but_remove = gtk.Button() but_remove.add( IconFactory.get_image('tryton-remove', gtk.ICON_SIZE_SMALL_TOOLBAR)) but_remove.set_relief(gtk.RELIEF_NONE) return but_remove
def _parse_page(self, node, notebook, attributes): tab_box = Gtk.HBox(spacing=3) if '_' not in attributes['string']: attributes['string'] = '_' + attributes['string'] label = Gtk.Label(label=attributes['string']) label.set_use_underline(True) tab_box.pack_start(label, expand=True, fill=True, padding=0) if 'icon' in attributes: tab_box.pack_start(IconFactory.get_image( attributes['icon'], Gtk.IconSize.SMALL_TOOLBAR), expand=True, fill=True, padding=0) tab_box.show_all() viewport = Gtk.Viewport() viewport.set_shadow_type(Gtk.ShadowType.NONE) scrolledwindow = Gtk.ScrolledWindow() scrolledwindow.set_shadow_type(Gtk.ShadowType.NONE) scrolledwindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrolledwindow.add(viewport) scrolledwindow.show_all() notebook.append_page(scrolledwindow, tab_box) container = self.parse(node) viewport.add(container.container)
def __init__(self, view, attrs): super(DictWidget, self).__init__(view, attrs) self.schema_model = attrs['schema_model'] self.fields = {} self.buttons = {} self.rows = {} self.widget = Gtk.Frame() # FEA#5633 Allow to not display label on group if not attrs.get('no_label', 0.0): label = Gtk.Label(label=set_underline(attrs.get('string', ''))) label.set_use_underline(True) self.widget.set_label_widget(label) self.widget.set_shadow_type(Gtk.ShadowType.OUT) vbox = Gtk.VBox() self.widget.add(vbox) self.grid = Gtk.Grid(column_spacing=3, row_spacing=3) vbox.pack_start(self.grid, expand=True, fill=True, padding=0) hbox = Gtk.HBox() hbox.set_border_width(2) self.wid_text = Gtk.Entry() # JCA: specific no_command = attrs.get('no_command', 0.0) if not no_command: self.wid_text.set_placeholder_text(_('Search')) self.wid_text.props.width_chars = 13 self.wid_text.connect('activate', self._sig_activate) hbox.pack_start(self.wid_text, expand=True, fill=True, padding=0) label.set_mnemonic_widget(self.wid_text) if int(self.attrs.get('completion', 1)): self.wid_completion = get_completion( search=False, create=False) self.wid_completion.connect('match-selected', self._completion_match_selected) self.wid_text.set_completion(self.wid_completion) self.wid_text.connect('changed', self._update_completion) else: self.wid_completion = None self.but_add = Gtk.Button(can_focus=False) self.but_add.connect('clicked', self._sig_add) self.but_add.add( IconFactory.get_image( 'tryton-add', Gtk.IconSize.SMALL_TOOLBAR)) self.but_add.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(self.but_add, expand=False, fill=False, padding=0) vbox.pack_start(hbox, expand=True, fill=True, padding=0) self.tooltips = Tooltips() if not no_command: self.tooltips.set_tip(self.but_add, _('Add value')) self.tooltips.enable() self._readonly = False self._record_id = None
def __init__(self): self.parent = get_toplevel_window() self.win = Gtk.Dialog(title=_('Limit'), transient_for=self.parent, modal=True, destroy_with_parent=True) Main().add_window(self.win) cancel_button = self.win.add_button(set_underline(_("Cancel")), Gtk.ResponseType.CANCEL) cancel_button.set_image( IconFactory.get_image('tryton-cancel', Gtk.IconSize.BUTTON)) cancel_button.set_always_show_image(True) ok_button = self.win.add_button(set_underline(_("OK")), Gtk.ResponseType.OK) ok_button.set_image( IconFactory.get_image('tryton-ok', Gtk.IconSize.BUTTON)) ok_button.set_always_show_image(True) self.win.set_default_response(Gtk.ResponseType.OK) self.win.set_icon(GNUHEALTH_ICON) self.win.vbox.set_spacing(3) self.win.vbox.pack_start(Gtk.Label(label=_('Search Limit Settings')), expand=False, fill=True, padding=0) self.win.vbox.pack_start(Gtk.HSeparator(), expand=True, fill=True, padding=0) hbox = Gtk.HBox(spacing=3) label = Gtk.Label(label=_('Limit:')) hbox.pack_start(label, expand=True, fill=True, padding=0) adjustment = Gtk.Adjustment(value=CONFIG['client.limit'], lower=1, upper=sys.maxsize, step_incr=10, page_incr=100) self.spin_limit = Gtk.SpinButton() self.spin_limit.configure(adjustment, climb_rate=1, digits=0) self.spin_limit.set_numeric(False) self.spin_limit.set_activates_default(True) label.set_mnemonic_widget(self.spin_limit) hbox.pack_start(self.spin_limit, expand=True, fill=True, padding=0) self.win.vbox.pack_start(hbox, expand=True, fill=True, padding=0) self.win.show_all()
def _set_icon(self, stock): self.set_always_show_image(bool(stock)) image = self.get_image() if not image and not stock: return if not stock: self.set_image(None) return self.set_image(IconFactory.get_image(stock, Gtk.IconSize.BUTTON))
def __init__(self, view, attrs): super(DictWidget, self).__init__(view, attrs) self.schema_model = attrs['schema_model'] self.fields = {} self.buttons = {} self.rows = {} self.widget = gtk.Frame() label = gtk.Label(set_underline(attrs.get('string', ''))) label.set_use_underline(True) self.widget.set_label_widget(label) self.widget.set_shadow_type(gtk.SHADOW_OUT) vbox = gtk.VBox() self.widget.add(vbox) self.table = gtk.Table(1, 3, homogeneous=False) self.table.set_col_spacings(0) self.table.set_row_spacings(0) self.table.set_border_width(0) vbox.pack_start(self.table, expand=True, fill=True) hbox = gtk.HBox() hbox.set_border_width(2) self.wid_text = gtk.Entry() self.wid_text.set_placeholder_text(_('Search')) self.wid_text.props.width_chars = 13 self.wid_text.connect('activate', self._sig_activate) hbox.pack_start(self.wid_text, expand=True, fill=True) label.set_mnemonic_widget(self.wid_text) if int(self.attrs.get('completion', 1)): self.wid_completion = get_completion(search=False, create=False) self.wid_completion.connect('match-selected', self._completion_match_selected) self.wid_text.set_completion(self.wid_completion) self.wid_text.connect('changed', self._update_completion) else: self.wid_completion = None self.but_add = gtk.Button() self.but_add.connect('clicked', self._sig_add) self.but_add.add( IconFactory.get_image('tryton-add', gtk.ICON_SIZE_SMALL_TOOLBAR)) self.but_add.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_add, expand=False, fill=False) hbox.set_focus_chain([self.wid_text]) vbox.pack_start(hbox, expand=True, fill=True) self.tooltips = Tooltips() self.tooltips.set_tip(self.but_add, _('Add value')) self.tooltips.enable() self._readonly = False self._record_id = None
def __init__(self): self.parent = get_toplevel_window() self.win = gtk.Dialog( _('Limit'), self.parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) Main().add_window(self.win) cancel_button = self.win.add_button(set_underline(_("Cancel")), gtk.RESPONSE_CANCEL) cancel_button.set_image( IconFactory.get_image('tryton-cancel', gtk.ICON_SIZE_BUTTON)) cancel_button.set_always_show_image(True) ok_button = self.win.add_button(set_underline(_("OK")), gtk.RESPONSE_OK) ok_button.set_image( IconFactory.get_image('tryton-ok', gtk.ICON_SIZE_BUTTON)) ok_button.set_always_show_image(True) self.win.set_default_response(gtk.RESPONSE_OK) self.win.set_icon(TRYTON_ICON) self.win.vbox.set_spacing(3) self.win.vbox.pack_start(gtk.Label(_('Search Limit Settings')), expand=False, fill=True) self.win.vbox.pack_start(gtk.HSeparator()) hbox = gtk.HBox(spacing=3) label = gtk.Label(_('Limit:')) hbox.pack_start(label, expand=True, fill=True) adjustment = gtk.Adjustment(value=CONFIG['client.limit'], lower=1, upper=sys.maxsize, step_incr=10, page_incr=100) self.spin_limit = gtk.SpinButton() self.spin_limit.configure(adjustment, climb_rate=1, digits=0) self.spin_limit.set_numeric(False) self.spin_limit.set_activates_default(True) label.set_mnemonic_widget(self.spin_limit) hbox.pack_start(self.spin_limit, expand=True, fill=True) self.win.vbox.pack_start(hbox, expand=True, fill=True) self.win.show_all()
def button_press(self, widget, event): if event.button == 3: menu = gtk.Menu() item = gtk.ImageMenuItem(_('Save As...')) item.set_image(IconFactory.get_image( 'tryton-save-as', gtk.ICON_SIZE_MENU)) item.connect('activate', self.save) item.show() menu.append(item) menu.popup(None, None, None, event.button, event.time) return True elif event.button == 1: self.widgets['root'].action()
def _add_file_button(self): tooltips = Tooltips() box = Gtk.HBox(spacing=3) self.files.pack_start(box, expand=False, fill=True, padding=0) file_ = Gtk.FileChooserButton(title=_("Select File")) box.pack_start(file_, expand=True, fill=True, padding=0) button = Gtk.Button() button.set_image( IconFactory.get_image('tryton-remove', Gtk.IconSize.BUTTON)) tooltips.set_tip(button, _("Remove File")) button.set_sensitive(False) box.pack_start(button, expand=False, fill=True, padding=0) box.show_all() file_.connect('file-set', self._file_set, button) button.connect('clicked', self._file_remove)
def _parse_page(self, node, notebook, attributes): tab_box = gtk.HBox(spacing=3) if '_' not in attributes['string']: attributes['string'] = '_' + attributes['string'] label = gtk.Label(attributes['string']) label.set_use_underline(True) tab_box.pack_start(label) if 'icon' in attributes: tab_box.pack_start( IconFactory.get_image(attributes['icon'], gtk.ICON_SIZE_SMALL_TOOLBAR)) tab_box.show_all() viewport = gtk.Viewport() viewport.set_shadow_type(gtk.SHADOW_NONE) scrolledwindow = gtk.ScrolledWindow() scrolledwindow.set_shadow_type(gtk.SHADOW_NONE) scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolledwindow.add(viewport) scrolledwindow.show_all() notebook.append_page(scrolledwindow, tab_box) container = self.parse(node) viewport.add(container.table)
def get_toolbar(self, textview): toolbar = Gtk.Toolbar() toolbar.set_style({ 'default': False, 'both': Gtk.ToolbarStyle.BOTH, 'text': Gtk.ToolbarStyle.TEXT, 'icons': Gtk.ToolbarStyle.ICONS, }[CONFIG['client.toolbar']]) tag_widgets = self.tag_widgets[textview] = {} for icon, label in [ ('bold', _("Bold")), ('italic', _("Italic")), ('underline', _("Underline")), ]: button = Gtk.ToggleToolButton() button.set_icon_widget( IconFactory.get_image('tryton-format-%s' % icon, Gtk.IconSize.SMALL_TOOLBAR)) button.set_label(label) button.connect('toggled', self.toggle_props, icon, textview) toolbar.insert(button, -1) tag_widgets[icon] = button toolbar.insert(Gtk.SeparatorToolItem(), -1) for name, options, active in [ ('family', FAMILIES, FAMILIES.index('normal')), ('size', SIZES, SIZES.index('4')), ]: combobox = Gtk.ComboBoxText() for option in options: combobox.append_text(option) combobox.set_active(active) combobox.set_focus_on_click(False) combobox.connect('changed', self.change_props, name, textview) tool = Gtk.ToolItem() tool.add(combobox) toolbar.insert(tool, -1) tag_widgets[name] = combobox toolbar.insert(Gtk.SeparatorToolItem(), -1) button = None for name, label in [ ('left', _("Align Left")), ('center', _("Align Center")), ('right', _("Align Right")), ('justify', _("Justify")), ]: icon = 'tryton-format-align-%s' % name button = Gtk.RadioToolButton.new_from_widget(button) button.set_icon_widget( IconFactory.get_image(icon, Gtk.IconSize.SMALL_TOOLBAR)) button.set_active(icon == 'left') button.set_label(label) button.connect('toggled', self.toggle_justification, name, textview) toolbar.insert(button, -1) tag_widgets[name] = button toolbar.insert(Gtk.SeparatorToolItem(), -1) for icon, label in [ ('foreground', _("Foreground Color")), # TODO ('background', _('Background')), ]: button = Gtk.ToolButton() if icon == 'foreground': button.set_icon_widget( IconFactory.get_image('tryton-format-color-text', Gtk.IconSize.SMALL_TOOLBAR)) button.set_label(label) button.connect('clicked', self.toggle_color, icon, textview) toolbar.insert(button, -1) tag_widgets[icon] = button return toolbar
def __init__(self, goocalendar): super(Toolbar, self).__init__() self.goocalendar = goocalendar self.accel_group = Main().accel_group today_button = Gtk.ToolButton() today_button.set_label(_('Today')) today_button.set_homogeneous(False) today_button.connect("clicked", self.on_today_button_clicked) today_button.add_accelerator( "clicked", self.accel_group, Gdk.KEY_t, Gdk.ModifierType.MODIFIER_MASK, Gtk.AccelFlags.VISIBLE) self.insert(today_button, -1) arrow_left = IconFactory.get_image('tryton-arrow-left') go_back = Gtk.ToolButton() go_back.set_icon_widget(arrow_left) go_back.set_label(_("go back")) go_back.set_expand(False) go_back.set_homogeneous(False) go_back.connect("clicked", self.on_go_back_clicked) self.insert(go_back, -1) self.current_page_label = Gtk.Label( width_chars=10, max_width_chars=10, ellipsize=True) self.current_page = Gtk.ToggleToolButton() self.current_page.set_label_widget(self.current_page_label) self.current_page.connect("clicked", self.on_current_page_clicked) self.insert(self.current_page, -1) self.__cal_popup = Gtk.Window(type=Gtk.WindowType.POPUP) self.__cal_popup.set_events( self.__cal_popup.get_events() | Gdk.EventMask.KEY_PRESS_MASK) self.__cal_popup.set_resizable(False) self.__cal_popup.connect('delete-event', self.on_cal_popup_closed) self.__cal_popup.connect( 'key-press-event', self.on_cal_popup_key_pressed) self.__cal_popup.connect( 'button-press-event', self.on_cal_popup_button_pressed) gtkcal = Gtk.Calendar() gtkcal.connect('day-selected', self.on_gtkcal_day_selected) gtkcal.connect( 'day-selected-double-click', self.on_gtkcal_day_selected_double_click) gtkcal.set_display_options( Gtk.CalendarDisplayOptions.SHOW_HEADING | Gtk.CalendarDisplayOptions.SHOW_WEEK_NUMBERS | Gtk.CalendarDisplayOptions.SHOW_DAY_NAMES) gtkcal.set_no_show_all(True) self.__cal_popup.add(gtkcal) gtkcal.show() self.gtkcal = gtkcal self.goocalendar.connect('day-selected', self.on_goocalendar_day_selected) arrow_right = IconFactory.get_image('tryton-arrow-right') go_forward = Gtk.ToolButton() go_forward.set_icon_widget(arrow_right) go_forward.set_label(_("go forward")) go_forward.set_expand(False) go_forward.set_homogeneous(False) go_forward.connect("clicked", self.on_go_forward_clicked) self.insert(go_forward, -1) arrow_left = IconFactory.get_image('tryton-arrow-left') previous_year = Gtk.ToolButton() previous_year.set_icon_widget(arrow_left) previous_year.set_label(_("previous year")) previous_year.set_expand(False) previous_year.set_homogeneous(False) previous_year.connect("clicked", self.on_previous_year_clicked) self.insert(previous_year, -1) self.current_year_label = Gtk.Label(width_chars=4) current_year = Gtk.ToolItem() current_year.add(self.current_year_label) self.insert(current_year, -1) arrow_right = IconFactory.get_image('tryton-arrow-right') next_year = Gtk.ToolButton() next_year.set_icon_widget(arrow_right) next_year.set_label(_("next year")) next_year.set_expand(False) next_year.set_homogeneous(False) next_year.connect("clicked", self.on_next_year_clicked) self.insert(next_year, -1) blank_widget = Gtk.ToolItem() blank_widget.set_expand(True) self.insert(blank_widget, -1) day_button = Gtk.RadioToolButton() day_button.set_label(_('Day View')) day_button.connect("clicked", self.on_day_button_clicked) day_button.add_accelerator( "clicked", self.accel_group, Gdk.KEY_d, Gdk.ModifierType.MODIFIER_MASK, Gtk.AccelFlags.VISIBLE) self.insert(day_button, -1) week_button = Gtk.RadioToolButton.new_from_widget(day_button) week_button.set_label(_('Week View')) week_button.connect("clicked", self.on_week_button_clicked) week_button.add_accelerator( "clicked", self.accel_group, Gdk.KEY_w, Gdk.ModifierType.MODIFIER_MASK, Gtk.AccelFlags.VISIBLE) self.insert(week_button, -1) month_button = Gtk.RadioToolButton.new_from_widget(week_button) month_button.set_label_widget(Gtk.Label(label=_('Month View'))) month_button.connect("clicked", self.on_month_button_clicked) month_button.add_accelerator( "clicked", self.accel_group, Gdk.KEY_m, Gdk.ModifierType.MODIFIER_MASK, Gtk.AccelFlags.VISIBLE) self.insert(month_button, -1) buttons = { 'month': month_button, 'week': week_button, 'day': day_button, } buttons[self.goocalendar.view].set_active(True) self.update_displayed_date() self.set_style(Gtk.ToolbarStyle.ICONS)
def get_toolbar(self, textview): toolbar = gtk.Toolbar() toolbar.set_style({ 'default': False, 'both': gtk.TOOLBAR_BOTH, 'text': gtk.TOOLBAR_TEXT, 'icons': gtk.TOOLBAR_ICONS }[CONFIG['client.toolbar']]) tag_widgets = self.tag_widgets[textview] = {} for icon in ['bold', 'italic', 'underline']: button = gtk.ToggleToolButton() button.set_icon_widget( IconFactory.get_image('tryton-format-%s' % icon, gtk.ICON_SIZE_SMALL_TOOLBAR)) button.connect('toggled', self.toggle_props, icon, textview) toolbar.insert(button, -1) tag_widgets[icon] = button toolbar.insert(gtk.SeparatorToolItem(), -1) for name, options, active in [ ('family', FAMILIES, FAMILIES.index('normal')), ('size', SIZES, SIZES.index('4')), ]: try: combobox = gtk.ComboBoxText() except AttributeError: combobox = gtk.combo_box_new_text() for option in options: combobox.append_text(option) combobox.set_active(active) combobox.set_focus_on_click(False) combobox.connect('changed', self.change_props, name, textview) tool = gtk.ToolItem() tool.add(combobox) toolbar.insert(tool, -1) tag_widgets[name] = combobox toolbar.insert(gtk.SeparatorToolItem(), -1) button = None for name in ['left', 'center', 'right', 'justify']: icon = 'tryton-format-align-%s' % name button = gtk.RadioToolButton.new_from_widget(button) button.set_icon_widget( IconFactory.get_image(icon, gtk.ICON_SIZE_SMALL_TOOLBAR)) button.set_active(icon == 'left') button.connect('toggled', self.toggle_justification, name, textview) toolbar.insert(button, -1) tag_widgets[name] = button toolbar.insert(gtk.SeparatorToolItem(), -1) for icon, label in [ ('foreground', _('Foreground')), # TODO ('background', _('Background')), ]: button = gtk.ToolButton() if icon == 'foreground': button.set_icon_widget( IconFactory.get_image('tryton-format-color-text', gtk.ICON_SIZE_SMALL_TOOLBAR)) button.set_label(label) button.connect('clicked', self.toggle_color, icon, textview) toolbar.insert(button, -1) tag_widgets[icon] = button return toolbar
def __init__(self): self.parent = get_toplevel_window() self.win = Gtk.Dialog(title=_('Email'), transient_for=self.parent, modal=True, destroy_with_parent=True) Main().add_window(self.win) cancel_button = self.win.add_button(set_underline(_("Cancel")), Gtk.ResponseType.CANCEL) cancel_button.set_image( IconFactory.get_image('tryton-cancel', Gtk.IconSize.BUTTON)) cancel_button.set_always_show_image(True) ok_button = self.win.add_button(set_underline(_("OK")), Gtk.ResponseType.OK) ok_button.set_image( IconFactory.get_image('tryton-ok', Gtk.IconSize.BUTTON)) ok_button.set_always_show_image(True) self.win.set_default_response(Gtk.ResponseType.OK) self.win.set_icon(TRYTON_ICON) self.win.vbox.set_spacing(3) self.win.vbox.pack_start(Gtk.Label(_('Email Program Settings')), expand=False, fill=True, padding=0) self.win.vbox.pack_start(Gtk.HSeparator(), expand=True, fill=True, padding=0) hbox = Gtk.HBox(spacing=3) label = Gtk.Label(label=_('Command Line:')) hbox.pack_start(label, expand=True, fill=True, padding=0) self.entry = Gtk.Entry() self.entry.set_property('activates_default', True) self.entry.set_width_chars(50) self.entry.set_text(CONFIG['client.email']) label.set_mnemonic_widget(label) hbox.pack_start(self.entry, expand=True, fill=True, padding=0) self.win.vbox.pack_start(hbox, expand=True, fill=True, padding=0) label = Gtk.Label(label=_('Legend of Available Placeholders:'), halign=Gtk.Align.START, margin_top=10, margin_bottom=5) self.win.vbox.pack_start(label, expand=False, fill=True, padding=0) hbox = Gtk.HBox(spacing=3) vboxl = Gtk.VBox(homogeneous=True, spacing=3) label = Gtk.Label(label=_('To:'), halign=Gtk.Align.START) vboxl.pack_start(label, expand=False, fill=False, padding=0) label = Gtk.Label(label=_('CC:'), halign=Gtk.Align.START) vboxl.pack_start(label, expand=False, fill=False, padding=0) label = Gtk.Label(label=_('Subject:'), halign=Gtk.Align.START) vboxl.pack_start(label, expand=False, fill=False, padding=0) label = Gtk.Label(label=_('Body:'), halign=Gtk.Align.START) vboxl.pack_start(label, expand=False, fill=False, padding=0) label = Gtk.Label(label=_('Attachment:'), halign=Gtk.Align.START) vboxl.pack_start(label, expand=False, fill=False, padding=0) vboxr = Gtk.VBox(homogeneous=True, spacing=3) label = Gtk.Label(label=' ${to}', halign=Gtk.Align.START) vboxr.pack_start(label, expand=False, fill=False, padding=0) label = Gtk.Label(label=' ${cc}', halign=Gtk.Align.START) vboxr.pack_start(label, expand=False, fill=False, padding=0) label = Gtk.Label(label=' ${subject}', halign=Gtk.Align.START) vboxr.pack_start(label, expand=False, fill=False, padding=0) label = Gtk.Label(label=' ${body}', halign=Gtk.Align.START) vboxr.pack_start(label, expand=False, fill=False, padding=0) label = Gtk.Label(label=' ${attachment}', halign=Gtk.Align.START) vboxr.pack_start(label, expand=False, fill=False, padding=0) hbox.pack_start(vboxl, expand=False, fill=False, padding=0) hbox.pack_start(vboxr, expand=False, fill=False, padding=0) self.win.vbox.pack_start(hbox, expand=True, fill=True, padding=0) self.win.show_all()
def __init__(self, user, callback): NoModal.__init__(self) self.callback = callback self.win = Gtk.Dialog(title=_('Preferences'), transient_for=self.parent, destroy_with_parent=True) Main().add_window(self.win) self.win.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) self.win.set_icon(TRYTON_ICON) self.accel_group = Gtk.AccelGroup() self.win.add_accel_group(self.accel_group) self.but_cancel = self.win.add_button(set_underline(_("Cancel")), Gtk.ResponseType.CANCEL) self.but_cancel.set_image( IconFactory.get_image('tryton-cancel', Gtk.IconSize.BUTTON)) self.but_cancel.set_always_show_image(True) self.but_ok = self.win.add_button(set_underline(_("OK")), Gtk.ResponseType.OK) self.but_ok.set_image( IconFactory.get_image('tryton-ok', Gtk.IconSize.BUTTON)) self.but_ok.set_always_show_image(True) self.but_ok.add_accelerator('clicked', self.accel_group, Gdk.KEY_Return, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE) self.win.set_default_response(Gtk.ResponseType.OK) self.win.connect('response', self.response) try: view = RPCExecute('model', 'res.user', 'get_preferences_fields_view') except RPCException: self.win.destroy() self.win = None return title = Gtk.Label(label=_('Edit User Preferences')) title.show() self.win.vbox.pack_start(title, expand=False, fill=True, padding=0) self.screen = Screen('res.user', mode=[]) # Reset readonly set automaticly by MODELACCESS self.screen.readonly = False self.screen.group.readonly = False self.screen.group.skip_model_access = True self.screen.add_view(view) self.screen.switch_view() self.screen.new(default=False) try: preferences = RPCExecute('model', 'res.user', 'get_preferences', False) except RPCException: self.win.destroy() self.win = None return self.screen.current_record.cancel() self.screen.current_record.set(preferences) self.screen.current_record.id = rpc._USER self.screen.current_record.validate(softvalidation=True) self.screen.display(set_cursor=True) self.screen.widget.show() self.win.vbox.pack_start(self.screen.widget, expand=True, fill=True, padding=0) self.win.set_title(_('Preference')) self.win.set_default_size(*self.default_size()) self.register() self.win.show()
def save(self, widget): parent = get_toplevel_window() dia = gtk.Dialog(_('Image Size'), parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) Main().add_window(dia) cancel_button = dia.add_button( set_underline(_("Cancel")), gtk.RESPONSE_CANCEL) cancel_button.set_image(IconFactory.get_image( 'tryton-cancel', gtk.ICON_SIZE_BUTTON)) cancel_button.set_always_show_image(True) ok_button = dia.add_button( set_underline(_("OK")), gtk.RESPONSE_OK) ok_button.set_image(IconFactory.get_image( 'tryton-ok', gtk.ICON_SIZE_BUTTON)) ok_button.set_always_show_image(True) dia.set_icon(TRYTON_ICON) dia.set_default_response(gtk.RESPONSE_OK) hbox = gtk.HBox(spacing=3) dia.vbox.pack_start(hbox, False, True) hbox.pack_start(gtk.Label(_('Width:')), False, True) spinwidth = gtk.SpinButton() spinwidth.configure(gtk.Adjustment(400.0, 0.0, sys.maxsize, 1.0, 10.0), climb_rate=1, digits=0) spinwidth.set_numeric(True) spinwidth.set_activates_default(True) hbox.pack_start(spinwidth, True, True) hbox.pack_start(gtk.Label(_('Height:')), False, True) spinheight = gtk.SpinButton() spinheight.configure(gtk.Adjustment( 200.0, 0.0, sys.maxsize, 1.0, 10.0), climb_rate=1, digits=0) spinheight.set_numeric(True) spinheight.set_activates_default(True) hbox.pack_start(spinheight, True, True) dia.show_all() filter = gtk.FileFilter() filter.set_name(_('PNG image (*.png)')) filter.add_mime_type('image/png') filter.add_pattern('*.png') while True: response = dia.run() width = spinwidth.get_value_as_int() height = spinheight.get_value_as_int() if response == gtk.RESPONSE_OK: filename = file_selection(_('Save As'), action=gtk.FILE_CHOOSER_ACTION_SAVE, preview=False, filters=[filter]) if width and height and filename: if not filename.endswith('.png'): filename = filename + '.png' try: self.widgets['root'].export_png( filename, width, height) break except MemoryError: message(_('Image size too large.'), dia, gtk.MESSAGE_ERROR) else: break parent.present() dia.destroy()
def __init__(self, revisions, revision=None, format_='%x %H:%M:%S.%f'): self.parent = get_toplevel_window() self.win = Gtk.Dialog(title=_('Revision'), transient_for=self.parent, modal=True, destroy_with_parent=True) Main().add_window(self.win) cancel_button = self.win.add_button(set_underline(_("Cancel")), Gtk.ResponseType.CANCEL) cancel_button.set_image( IconFactory.get_image('tryton-cancel', Gtk.IconSize.BUTTON)) cancel_button.set_always_show_image(True) ok_button = self.win.add_button(set_underline(_("OK")), Gtk.ResponseType.OK) ok_button.set_image( IconFactory.get_image('tryton-ok', Gtk.IconSize.BUTTON)) ok_button.set_always_show_image(True) self.win.set_default_response(Gtk.ResponseType.OK) self.win.set_icon(GNUHEALTH_ICON) self.win.vbox.set_spacing(3) self.win.vbox.pack_start(Gtk.Label(label=_('Select a revision')), expand=False, fill=True, padding=0) self.win.vbox.pack_start(Gtk.HSeparator(), expand=True, fill=True, padding=0) hbox = Gtk.HBox(spacing=3) label = Gtk.Label(label=_('Revision:')) hbox.pack_start(label, expand=True, fill=True, padding=0) list_store = Gtk.ListStore(str, str) # Set model on instantiation to get the default cellrenderer as text combobox = Gtk.ComboBox(model=list_store, has_entry=True) self.entry = combobox.get_child() self.entry.connect('focus-out-event', self.focus_out) self.entry.connect('activate', self.activate) label.set_mnemonic_widget(self.entry) combobox.connect('changed', self.changed) self.entry.set_property('activates_default', True) self._format = format_ if revision: self.entry.set_text(revision.strftime(self._format)) self._value = revision active = -1 else: self._value = None active = 0 list_store.append(('', '')) for i, (rev, id_, name) in enumerate(revisions, 1): list_store.append( (timezoned_date(rev).strftime(self._format), name)) if rev == revision: active = i combobox.set_active(active) cell = Gtk.CellRendererText() combobox.pack_start(cell, expand=True) combobox.add_attribute(cell, 'text', 1) hbox.pack_start(combobox, expand=True, fill=True, padding=0) combobox.set_entry_text_column(0) self.win.vbox.pack_start(hbox, expand=True, fill=True, padding=0) self.win.show_all()
def __init__(self): self.parent = get_toplevel_window() self.dialog = gtk.Dialog(_('Keyboard Shortcuts'), self.parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT | gtk.WIN_POS_CENTER_ON_PARENT | gtk.gdk.WINDOW_TYPE_HINT_DIALOG) Main().add_window(self.dialog) ok_button = self.dialog.add_button( set_underline(_("OK")), gtk.RESPONSE_OK) ok_button.set_image(IconFactory.get_image( 'tryton-ok', gtk.ICON_SIZE_BUTTON)) ok_button.set_always_show_image(True) self.dialog.set_icon(TRYTON_ICON) self.dialog.set_default_response(gtk.RESPONSE_OK) notebook = gtk.Notebook() self.dialog.vbox.pack_start(notebook) shortcuts = [ (_('Text Entries Shortcuts'),), ('<Ctrl> + X', _('Cut selected text')), ('<Ctrl> + C', _('Copy selected text')), ('<Ctrl> + V', _('Paste copied text')), ('<Tab>', _('Next widget')), ('<Shift> + <Tab>', _('Previous widget')), (_('Relation Entries Shortcuts'),), ('<F3>', _('Create new relation')), ('<F2>', _('Open/Search relation')), (_('List Entries Shortcuts'),), ('<F3>', _('Create new line')), ('<F2>', _('Open relation')), ('<Del>', _('Mark line for deletion')), ('<Ins>', _('Unmark line for deletion')), ] notebook.append_page(self._fill_table(shortcuts), gtk.Label(_('Edition Widgets'))) shortcuts = [ (_('Move Cursor'),), ('<Right>', _('Move to right')), ('<Left>', _('Move to left')), ('<Up>', _('Move up')), ('<Down>', _('Move down')), ('<Page Up>', _('Move up of one page')), ('<Page Down>', _('Move down of one page')), ('<Home>', _('Move to top')), ('<End>', _('Move to bottom')), ('<Backspace>', _('Move to parent')), (_('Selection'),), ('<Ctrl> + a', _('Select all')), ('<Ctrl> + /', _('Select all')), ('<Shift> + <Ctrl> + a', _('Unselect all')), ('<Shift> + <Ctrl> + /', _('Unselect all')), ('<Backspace>', _('Select parent')), ('<Space>', _('Select/Activate current row')), ('<Shift> + <Space>', _('Select/Activate current row')), ('<Return>', _('Select/Activate current row')), ('<Enter>', _('Select/Activate current row')), ('<Ctrl> + <Space>', _('Toggle selection')), (_('Expand/Collapse'),), ('+', _('Expand row')), ('-', _('Collapse row')), ('<Space>', _('Toggle row')), ('<Shift> + <Left>', _('Collapse all rows')), ('<Shift> + <Right>', _('Expand all rows')), ] notebook.append_page(self._fill_table(shortcuts), gtk.Label(_('Tree view'))) self.dialog.show_all()
def _parse_image(self, node, container, attributes): container.add( IconFactory.get_image(attributes['name'], Gtk.IconSize.DIALOG), attributes)
def __init__(self, *args, **kwargs): super(WinCSV, self).__init__(*args, **kwargs) self.dialog = Gtk.Dialog(transient_for=self.parent, destroy_with_parent=True) Main().add_window(self.dialog) self.dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) self.dialog.set_icon(TRYTON_ICON) self.dialog.set_default_size(*self.default_size()) self.dialog.connect('response', self.response) dialog_vbox = Gtk.VBox() hbox_mapping = Gtk.HBox(homogeneous=True) dialog_vbox.pack_start(hbox_mapping, expand=True, fill=True, padding=0) frame_fields = Gtk.Frame() frame_fields.set_shadow_type(Gtk.ShadowType.NONE) viewport_fields = Gtk.Viewport() scrolledwindow_fields = Gtk.ScrolledWindow() scrolledwindow_fields.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) viewport_fields.add(scrolledwindow_fields) frame_fields.add(viewport_fields) label_all_fields = Gtk.Label(label=_('<b>All fields</b>'), use_markup=True) frame_fields.set_label_widget(label_all_fields) hbox_mapping.pack_start(frame_fields, expand=True, fill=True, padding=0) vbox_buttons = Gtk.VBox(homogeneous=False, spacing=10) vbox_buttons.set_border_width(5) hbox_mapping.pack_start(vbox_buttons, expand=False, fill=True, padding=0) button_add = Gtk.Button(label=_('_Add'), stock=None, use_underline=True) button_add.set_image( IconFactory.get_image('tryton-add', Gtk.IconSize.BUTTON)) button_add.set_always_show_image(True) button_add.connect_after('clicked', self.sig_sel) vbox_buttons.pack_start(button_add, expand=False, fill=False, padding=0) button_remove = Gtk.Button(label=_('_Remove'), stock=None, use_underline=True) button_remove.set_image( IconFactory.get_image('tryton-remove', Gtk.IconSize.BUTTON)) button_remove.set_always_show_image(True) button_remove.connect_after('clicked', self.sig_unsel) vbox_buttons.pack_start(button_remove, expand=False, fill=False, padding=0) button_remove_all = Gtk.Button(label=_('_Clear'), stock=None, use_underline=True) button_remove_all.set_image( IconFactory.get_image('tryton-clear', Gtk.IconSize.BUTTON)) button_remove_all.set_always_show_image(True) button_remove_all.connect_after('clicked', self.sig_unsel_all) vbox_buttons.pack_start(button_remove_all, expand=False, fill=False, padding=0) hseparator_buttons = Gtk.HSeparator() vbox_buttons.pack_start(hseparator_buttons, expand=False, fill=False, padding=3) self.add_buttons(vbox_buttons) frame_fields_selected = Gtk.Frame() frame_fields_selected.set_shadow_type(Gtk.ShadowType.NONE) viewport_fields_selected = Gtk.Viewport() scrolledwindow_fields_selected = Gtk.ScrolledWindow() scrolledwindow_fields_selected.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) viewport_fields_selected.add(scrolledwindow_fields_selected) frame_fields_selected.add(viewport_fields_selected) label_fields_selected = Gtk.Label(label=_('<b>Fields selected</b>'), use_markup=True) frame_fields_selected.set_label_widget(label_fields_selected) hbox_mapping.pack_start(frame_fields_selected, expand=True, fill=True, padding=0) frame_csv_param = Gtk.Frame() frame_csv_param.set_shadow_type(Gtk.ShadowType.ETCHED_OUT) dialog_vbox.pack_start(frame_csv_param, expand=False, fill=True, padding=0) vbox_csv_param = Gtk.VBox() vbox_csv_param.props.margin = 7 frame_csv_param.add(vbox_csv_param) self.add_chooser(vbox_csv_param) expander_csv = Gtk.Expander() vbox_csv_param.pack_start(expander_csv, expand=False, fill=True, padding=0) label_csv_param = Gtk.Label(label=_('CSV Parameters')) expander_csv.set_label_widget(label_csv_param) box = Gtk.HBox(spacing=3) expander_csv.add(box) label_csv_delimiter = Gtk.Label(label=_('Delimiter:'), halign=Gtk.Align.END) box.pack_start(label_csv_delimiter, expand=False, fill=True, padding=0) self.csv_delimiter = Gtk.Entry() self.csv_delimiter.set_max_length(1) if os.name == 'nt' and ',' == locale.localeconv()['decimal_point']: delimiter = ';' else: delimiter = ',' self.csv_delimiter.set_text(delimiter) self.csv_delimiter.set_width_chars(1) label_csv_delimiter.set_mnemonic_widget(self.csv_delimiter) box.pack_start(self.csv_delimiter, expand=False, fill=True, padding=0) label_csv_quotechar = Gtk.Label(label=_("Quote char:"), halign=Gtk.Align.END) box.pack_start(label_csv_quotechar, expand=False, fill=True, padding=0) self.csv_quotechar = Gtk.Entry() self.csv_quotechar.set_text("\"") self.csv_quotechar.set_width_chars(1) label_csv_quotechar.set_mnemonic_widget(self.csv_quotechar) box.pack_start(self.csv_quotechar, expand=False, fill=True, padding=0) label_csv_enc = Gtk.Label(label=_("Encoding:"), halign=Gtk.Align.END) box.pack_start(label_csv_enc, expand=False, fill=True, padding=0) self.csv_enc = Gtk.ComboBoxText() for i, encoding in enumerate(encodings): self.csv_enc.append_text(encoding) if ((os.name == 'nt' and encoding == 'cp1252') or (os.name != 'nt' and encoding == 'utf_8')): self.csv_enc.set_active(i) label_csv_enc.set_mnemonic_widget(self.csv_enc) box.pack_start(self.csv_enc, expand=False, fill=True, padding=0) self.csv_locale = Gtk.CheckButton(label=_("Use locale format")) self.csv_locale.set_active(True) box.pack_start(self.csv_locale, expand=False, fill=True, padding=0) self.add_csv_header_param(box) button_cancel = self.dialog.add_button(set_underline(_("Cancel")), Gtk.ResponseType.CANCEL) button_cancel.set_image( IconFactory.get_image('tryton-cancel', Gtk.IconSize.BUTTON)) button_ok = self.dialog.add_button(set_underline(_("OK")), Gtk.ResponseType.OK) button_ok.set_image( IconFactory.get_image('tryton-ok', Gtk.IconSize.BUTTON)) self.dialog.vbox.pack_start(dialog_vbox, expand=True, fill=True, padding=0) self.view1 = Gtk.TreeView() self.view1.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) self.view1.connect('row-expanded', self.on_row_expanded) scrolledwindow_fields.add(self.view1) self.view2 = Gtk.TreeView() self.view2.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) scrolledwindow_fields_selected.add(self.view2) self.view1.set_headers_visible(False) self.view2.set_headers_visible(False) cell = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_('Field name'), cell, text=0) self.view1.append_column(column) cell = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_('Field name'), cell, text=0) self.view2.append_column(column) self.model1 = Gtk.TreeStore(GObject.TYPE_STRING, GObject.TYPE_STRING) self.model2 = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING) self.model_populate(self._get_fields(self.model)) self.view1.set_model(self.model1) self.view1.connect('row-activated', self.sig_sel) self.view2.set_model(self.model2) self.view2.connect('row-activated', self.sig_unsel) self.dialog.show_all() self.show() self.register() if sys.platform != 'darwin': self.view2.drag_source_set( Gdk.ModifierType.BUTTON1_MASK | Gdk.ModifierType.BUTTON3_MASK, [ Gtk.TargetEntry.new('EXPORT_TREE', Gtk.TargetFlags.SAME_WIDGET, 0) ], Gdk.DragAction.MOVE) self.view2.drag_dest_set(Gtk.DestDefaults.ALL, [ Gtk.TargetEntry.new('EXPORT_TREE', Gtk.TargetFlags.SAME_WIDGET, 0) ], Gdk.DragAction.MOVE) self.view2.connect('drag-begin', self.drag_begin) self.view2.connect('drag-motion', self.drag_motion) self.view2.connect('drag-drop', self.drag_drop) self.view2.connect("drag-data-get", self.drag_data_get) self.view2.connect('drag-data-received', self.drag_data_received) self.view2.connect('drag-data-delete', self.drag_data_delete) drag_column = Gtk.TreeViewColumn() drag_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) cell_pixbuf = Gtk.CellRendererPixbuf() cell_pixbuf.props.pixbuf = IconFactory.get_pixbuf('tryton-drag') drag_column.pack_start(cell_pixbuf, expand=False) self.view2.insert_column(drag_column, 0)
def __init__(self, name, record, prints, template=None): super().__init__() self.record = record self.dialog = Gtk.Dialog(transient_for=self.parent, destroy_with_parent=True) Main().add_window(self.dialog) self.dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) self.dialog.set_icon(TRYTON_ICON) self.dialog.set_default_size(*self.default_size()) self.dialog.connect('response', self.response) self.dialog.set_title(_('E-mail %s') % name) grid = Gtk.Grid(column_spacing=3, row_spacing=3, border_width=3) self.dialog.vbox.pack_start(grid, expand=True, fill=True, padding=0) label = Gtk.Label(set_underline(_("To:")), use_underline=True, halign=Gtk.Align.END) grid.attach(label, 0, 0, 1, 1) self.to = EmailEntry(hexpand=True, activates_default=True) widget_class(self.to, 'required', True) label.set_mnemonic_widget(self.to) grid.attach(self.to, 1, 0, 1, 1) label = Gtk.Label(set_underline(_("Cc:")), use_underline=True, halign=Gtk.Align.END) grid.attach(label, 0, 1, 1, 1) self.cc = EmailEntry(hexpand=True, activates_default=True) label.set_mnemonic_widget(self.cc) grid.attach(self.cc, 1, 1, 1, 1) label = Gtk.Label(set_underline(_("Bcc:")), use_underline=True, halign=Gtk.Align.END) grid.attach(label, 0, 2, 1, 1) self.bcc = EmailEntry(hexpand=True, activates_default=True) label.set_mnemonic_widget(self.bcc) grid.attach(self.bcc, 1, 2, 1, 1) label = Gtk.Label(set_underline(_("Subject:")), use_underline=True, halign=Gtk.Align.END) grid.attach(label, 0, 3, 1, 1) self.subject = Gtk.Entry(hexpand=True, activates_default=True) label.set_mnemonic_widget(self.subject) grid.attach(self.subject, 1, 3, 1, 1) self.body = Gtk.TextView() body_frame = Gtk.Frame() label = Gtk.Label(set_underline(_("Body")), use_underline=True, halign=Gtk.Align.END) label.set_mnemonic_widget(self.body) body_frame.set_label_widget(label) grid.attach(body_frame, 0, 4, 2, 1) body_box = Gtk.VBox(hexpand=True, vexpand=True) body_frame.add(body_box) register_format(self.body) body_toolbar = add_toolbar(self.body) body_box.pack_start(body_toolbar, expand=False, fill=True, padding=0) body_box.pack_start(self.body, expand=True, fill=True, padding=0) if GtkSpell and CONFIG['client.spellcheck']: checker = GtkSpell.Checker() checker.attach(self.body) language = os.environ.get('LANGUAGE', 'en') try: checker.set_language(language) except Exception: logger.error('Could not set spell checker for "%s"', language) checker.detach() attachments_box = Gtk.HBox() grid.attach(attachments_box, 0, 5, 2, 1) print_frame = Gtk.Frame(shadow_type=Gtk.ShadowType.NONE) print_frame.set_label(_("Reports")) attachments_box.pack_start(print_frame, expand=True, fill=True, padding=0) print_box = Gtk.VBox() print_frame.add(print_box) print_flowbox = Gtk.FlowBox(selection_mode=Gtk.SelectionMode.NONE) print_box.pack_start(print_flowbox, expand=False, fill=False, padding=0) self.print_actions = {} for print_ in prints: print_check = Gtk.CheckButton.new_with_mnemonic( set_underline(print_['name'])) self.print_actions[print_['id']] = print_check print_flowbox.add(print_check) attachment_frame = Gtk.Frame(shadow_type=Gtk.ShadowType.NONE) attachment_frame.set_label(_("Attachments")) attachments_box.pack_start(attachment_frame, expand=True, fill=True, padding=0) try: attachments = RPCExecute('model', 'ir.attachment', 'search_read', [ ('resource', '=', '%s,%s' % (record.model_name, record.id)), [ 'OR', ('data', '!=', None), ('file_id', '!=', None), ], ], 0, None, None, ['rec_name'], context=record.get_context()) except RPCException: logger.error('Could not fetch attachment for "%s"', record) attachments = [] scrolledwindow = Gtk.ScrolledWindow() if len(attachments) > 2: scrolledwindow.set_size_request(-1, 100) attachment_frame.add(scrolledwindow) scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.attachments = TreeViewControl() self.attachments.set_headers_visible(False) scrolledwindow.add(self.attachments) self.attachments.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) self.attachments.append_column( Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=0)) model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_INT) for attachment in attachments: model.append((attachment['rec_name'], attachment['id'])) self.attachments.set_model(model) self.attachments.set_search_column(0) file_frame = Gtk.Frame(shadow_type=Gtk.ShadowType.NONE) file_frame.set_label(_("Files")) attachments_box.pack_start(file_frame, expand=True, fill=True, padding=0) self.files = Gtk.VBox(spacing=6) file_frame.add(self.files) self._add_file_button() button_cancel = self.dialog.add_button(set_underline(_("Cancel")), Gtk.ResponseType.CANCEL) button_cancel.set_image( IconFactory.get_image('tryton-cancel', Gtk.IconSize.BUTTON)) button_send = self.dialog.add_button(set_underline(_("Send")), Gtk.ResponseType.OK) button_send.set_image( IconFactory.get_image('tryton-send', Gtk.IconSize.BUTTON)) self.dialog.set_default_response(Gtk.ResponseType.OK) self._fill_with(template) self.dialog.show_all() self.register()
def __init__(self, *args, **kwargs): super(WinCSV, self).__init__(*args, **kwargs) self.dialog = gtk.Dialog(parent=self.parent, flags=gtk.DIALOG_DESTROY_WITH_PARENT) Main().add_window(self.dialog) self.dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.dialog.set_icon(TRYTON_ICON) self.dialog.connect('response', self.response) dialog_vbox = gtk.VBox() hbox_mapping = gtk.HBox(True) dialog_vbox.pack_start(hbox_mapping, True, True, 0) frame_fields = gtk.Frame() frame_fields.set_shadow_type(gtk.SHADOW_NONE) viewport_fields = gtk.Viewport() scrolledwindow_fields = gtk.ScrolledWindow() scrolledwindow_fields.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) viewport_fields.add(scrolledwindow_fields) frame_fields.add(viewport_fields) label_all_fields = gtk.Label(_('<b>All fields</b>')) label_all_fields.set_use_markup(True) frame_fields.set_label_widget(label_all_fields) hbox_mapping.pack_start(frame_fields, True, True, 0) vbox_buttons = gtk.VBox(False, 10) vbox_buttons.set_border_width(5) hbox_mapping.pack_start(vbox_buttons, False, True, 0) button_add = gtk.Button(_('_Add'), stock=None, use_underline=True) button_add.set_image( IconFactory.get_image('tryton-add', gtk.ICON_SIZE_BUTTON)) button_add.set_always_show_image(True) button_add.connect_after('clicked', self.sig_sel) vbox_buttons.pack_start(button_add, False, False, 0) button_remove = gtk.Button(_('_Remove'), stock=None, use_underline=True) button_remove.set_image( IconFactory.get_image('tryton-remove', gtk.ICON_SIZE_BUTTON)) button_remove.set_always_show_image(True) button_remove.connect_after('clicked', self.sig_unsel) vbox_buttons.pack_start(button_remove, False, False, 0) button_remove_all = gtk.Button(_('_Clear'), stock=None, use_underline=True) button_remove_all.set_image( IconFactory.get_image('tryton-clear', gtk.ICON_SIZE_BUTTON)) button_remove_all.set_always_show_image(True) button_remove_all.connect_after('clicked', self.sig_unsel_all) vbox_buttons.pack_start(button_remove_all, False, False, 0) hseparator_buttons = gtk.HSeparator() vbox_buttons.pack_start(hseparator_buttons, False, False, 3) self.add_buttons(vbox_buttons) frame_fields_selected = gtk.Frame() frame_fields_selected.set_shadow_type(gtk.SHADOW_NONE) viewport_fields_selected = gtk.Viewport() scrolledwindow_fields_selected = gtk.ScrolledWindow() scrolledwindow_fields_selected.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) viewport_fields_selected.add(scrolledwindow_fields_selected) frame_fields_selected.add(viewport_fields_selected) label_fields_selected = gtk.Label(_('<b>Fields selected</b>')) label_fields_selected.set_use_markup(True) frame_fields_selected.set_label_widget(label_fields_selected) hbox_mapping.pack_start(frame_fields_selected, True, True, 0) frame_csv_param = gtk.Frame() frame_csv_param.set_shadow_type(gtk.SHADOW_ETCHED_OUT) dialog_vbox.pack_start(frame_csv_param, False, True, 0) alignment_csv_param = gtk.Alignment(0.5, 0.5, 1, 1) alignment_csv_param.set_padding(7, 7, 7, 7) frame_csv_param.add(alignment_csv_param) vbox_csv_param = gtk.VBox() alignment_csv_param.add(vbox_csv_param) self.add_chooser(vbox_csv_param) expander_csv = gtk.Expander() vbox_csv_param.pack_start(expander_csv, False, True, 0) label_csv_param = gtk.Label(_('CSV Parameters')) expander_csv.set_label_widget(label_csv_param) table = gtk.Table(2, 4, False) table.set_border_width(8) table.set_row_spacings(9) table.set_col_spacings(8) expander_csv.add(table) label_csv_delimiter = gtk.Label(_('Delimiter:')) label_csv_delimiter.set_alignment(1, 0.5) table.attach(label_csv_delimiter, 0, 1, 0, 1) self.csv_delimiter = gtk.Entry() self.csv_delimiter.set_max_length(1) if os.name == 'nt' and ',' == locale.localeconv()['decimal_point']: delimiter = ';' else: delimiter = ',' self.csv_delimiter.set_text(delimiter) self.csv_delimiter.set_width_chars(1) label_csv_delimiter.set_mnemonic_widget(self.csv_delimiter) table.attach(self.csv_delimiter, 1, 2, 0, 1) label_csv_quotechar = gtk.Label(_("Quote char:")) label_csv_quotechar.set_alignment(1, 0.5) table.attach(label_csv_quotechar, 2, 3, 0, 1) self.csv_quotechar = gtk.Entry() self.csv_quotechar.set_text("\"") self.csv_quotechar.set_width_chars(1) label_csv_quotechar.set_mnemonic_widget(self.csv_quotechar) table.attach(self.csv_quotechar, 3, 4, 0, 1) label_csv_enc = gtk.Label(_("Encoding:")) label_csv_enc.set_alignment(1, 0.5) table.attach(label_csv_enc, 0, 1, 1, 2) if hasattr(gtk, 'ComboBoxText'): self.csv_enc = gtk.ComboBoxText() else: self.csv_enc = gtk.combo_box_new_text() for i, encoding in enumerate(encodings): self.csv_enc.append_text(encoding) if ((os.name == 'nt' and encoding == 'cp1252') or (os.name != 'nt' and encoding == 'utf_8')): self.csv_enc.set_active(i) label_csv_enc.set_mnemonic_widget(self.csv_enc) table.attach(self.csv_enc, 1, 2, 1, 2) self.add_csv_header_param(table) button_cancel = self.dialog.add_button(set_underline(_("Cancel")), gtk.RESPONSE_CANCEL) button_cancel.set_image( IconFactory.get_image('tryton-cancel', gtk.ICON_SIZE_BUTTON)) button_ok = self.dialog.add_button(set_underline(_("OK")), gtk.RESPONSE_OK) button_ok.set_image( IconFactory.get_image('tryton-ok', gtk.ICON_SIZE_BUTTON)) self.dialog.vbox.pack_start(dialog_vbox) self.view1 = gtk.TreeView() self.view1.get_selection().set_mode(gtk.SELECTION_MULTIPLE) self.view1.connect('row-expanded', self.on_row_expanded) scrolledwindow_fields.add(self.view1) self.view2 = gtk.TreeView() self.view2.get_selection().set_mode(gtk.SELECTION_MULTIPLE) scrolledwindow_fields_selected.add(self.view2) self.view1.set_headers_visible(False) self.view2.set_headers_visible(False) cell = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Field name'), cell, text=0) self.view1.append_column(column) cell = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Field name'), cell, text=0) self.view2.append_column(column) self.model1 = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING) self.model2 = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) self.model_populate(self._get_fields(self.model)) self.view1.set_model(self.model1) self.view1.connect('row-activated', self.sig_sel) self.view2.set_model(self.model2) self.view2.connect('row-activated', self.sig_unsel) self.dialog.show_all() self.show() self.register() if sys.platform != 'darwin': self.view2.drag_source_set( gtk.gdk.BUTTON1_MASK | gtk.gdk.BUTTON3_MASK, [ gtk.TargetEntry.new('EXPORT_TREE', gtk.TARGET_SAME_WIDGET, 0) ], gtk.gdk.ACTION_MOVE) self.view2.drag_dest_set(gtk.DEST_DEFAULT_ALL, [ gtk.TargetEntry.new('EXPORT_TREE', gtk.TARGET_SAME_WIDGET, 0) ], gtk.gdk.ACTION_MOVE) self.view2.connect('drag-begin', self.drag_begin) self.view2.connect('drag-motion', self.drag_motion) self.view2.connect('drag-drop', self.drag_drop) self.view2.connect("drag-data-get", self.drag_data_get) self.view2.connect('drag-data-received', self.drag_data_received) self.view2.connect('drag-data-delete', self.drag_data_delete)
def add_toolbar(textview): toolbar = Gtk.Toolbar() tag_widgets = {} colors = {} for icon, label in [ ('bold', _("Bold")), ('italic', _("Italic")), ('underline', _("Underline")), ]: button = Gtk.ToggleToolButton() button.set_icon_widget(IconFactory.get_image( 'tryton-format-%s' % icon, Gtk.IconSize.SMALL_TOOLBAR)) button.set_label(label) button.connect('toggled', _toggle_props, icon, textview) toolbar.insert(button, -1) tag_widgets[icon] = button toolbar.insert(Gtk.SeparatorToolItem(), -1) for name, options, active in [ ('family', FAMILIES, FAMILIES.index('normal')), ('size', SIZES, SIZES.index('4')), ]: combobox = Gtk.ComboBoxText() for option in options: combobox.append_text(option) combobox.set_active(active) combobox.set_focus_on_click(False) combobox.connect('changed', _change_props, name, textview) tool = Gtk.ToolItem() tool.add(combobox) toolbar.insert(tool, -1) tag_widgets[name] = combobox toolbar.insert(Gtk.SeparatorToolItem(), -1) button = None for name, label in [ ('left', _("Align Left")), ('center', _("Align Center")), ('right', _("Align Right")), ('justify', _("Justify")), ]: icon = 'tryton-format-align-%s' % name button = Gtk.RadioToolButton.new_from_widget(button) button.set_icon_widget(IconFactory.get_image( icon, Gtk.IconSize.SMALL_TOOLBAR)) button.set_active(icon == 'left') button.set_label(label) button.connect( 'toggled', _toggle_justification, name, textview) toolbar.insert(button, -1) tag_widgets[name] = button toolbar.insert(Gtk.SeparatorToolItem(), -1) for icon, label in [ ('foreground', _("Foreground Color")), # TODO ('background', _('Background')), ]: button = Gtk.ToolButton() if icon == 'foreground': button.set_icon_widget(IconFactory.get_image( 'tryton-format-color-text', Gtk.IconSize.SMALL_TOOLBAR)) button.set_label(label) button.connect('clicked', _toggle_color, icon, textview, colors) toolbar.insert(button, -1) tag_widgets[icon] = button buffer_ = textview.get_buffer() buffer_.connect_after( 'insert-text', _insert_text_style, tag_widgets) textview.connect_after( 'move-cursor', lambda *a: _detect_style(textview, tag_widgets, colors)) textview.connect_after( 'button-release-event', lambda *a: _detect_style(textview, tag_widgets, colors)) return toolbar
def __init__(self, user, callback): NoModal.__init__(self) self.callback = callback self.win = gtk.Dialog(_('Preferences'), self.parent, gtk.DIALOG_DESTROY_WITH_PARENT) Main().add_window(self.win) self.win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.win.set_icon(TRYTON_ICON) self.accel_group = gtk.AccelGroup() self.win.add_accel_group(self.accel_group) self.but_cancel = self.win.add_button( set_underline(_("Cancel")), gtk.RESPONSE_CANCEL) self.but_cancel.set_image(IconFactory.get_image( 'tryton-cancel', gtk.ICON_SIZE_BUTTON)) self.but_cancel.set_always_show_image(True) self.but_ok = self.win.add_button( set_underline(_("OK")), gtk.RESPONSE_OK) self.but_ok.set_image(IconFactory.get_image( 'tryton-ok', gtk.ICON_SIZE_BUTTON)) self.but_ok.set_always_show_image(True) self.but_ok.add_accelerator('clicked', self.accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) self.win.set_default_response(gtk.RESPONSE_OK) self.win.connect('response', self.response) try: view = RPCExecute('model', 'res.user', 'get_preferences_fields_view') except RPCException: self.win.destroy() self.win = None return title = gtk.Label(_('Edit User Preferences')) title.show() self.win.vbox.pack_start(title, expand=False, fill=True) self.screen = Screen('res.user', mode=[]) # Reset readonly set automaticly by MODELACCESS self.screen.readonly = False self.screen.group.readonly = False self.screen.group.skip_model_access = True self.screen.add_view(view) self.screen.switch_view() self.screen.new(default=False) try: preferences = RPCExecute('model', 'res.user', 'get_preferences', False) except RPCException: self.win.destroy() self.win = None return self.screen.current_record.cancel() self.screen.current_record.set(preferences) self.screen.current_record.id = rpc._USER self.screen.current_record.validate(softvalidation=True) self.screen.display(set_cursor=True) self.screen.widget.show() self.win.vbox.pack_start(self.screen.widget) self.win.set_title(_('Preference')) width, height = self.parent.get_size() self.win.set_default_size(width, height) self.register() self.win.show()
def _parse_image(self, node, container, attributes): container.add( IconFactory.get_image(attributes['name'], gtk.ICON_SIZE_DIALOG), attributes)
def _new_remove_btn(self): but_remove = Gtk.Button() but_remove.add( IconFactory.get_image('tryton-remove', Gtk.IconSize.SMALL_TOOLBAR)) but_remove.set_relief(Gtk.ReliefStyle.NONE) return but_remove
def save(self, widget): parent = get_toplevel_window() dia = Gtk.Dialog( title=_('Image Size'), transient_for=parent, modal=True, destroy_with_parent=True) Main().add_window(dia) cancel_button = dia.add_button( set_underline(_("Cancel")), Gtk.ResponseType.CANCEL) cancel_button.set_image(IconFactory.get_image( 'tryton-cancel', Gtk.IconSize.BUTTON)) cancel_button.set_always_show_image(True) ok_button = dia.add_button( set_underline(_("OK")), Gtk.ResponseType.OK) ok_button.set_image(IconFactory.get_image( 'tryton-ok', Gtk.IconSize.BUTTON)) ok_button.set_always_show_image(True) dia.set_icon(TRYTON_ICON) dia.set_default_response(Gtk.ResponseType.OK) hbox = Gtk.HBox(spacing=3) dia.vbox.pack_start(hbox, expand=False, fill=True, padding=0) hbox.pack_start( Gtk.Label(label=_('Width:')), expand=False, fill=True, padding=0) spinwidth = Gtk.SpinButton() spinwidth.configure(Gtk.Adjustment( value=400.0, lower=0.0, upper=sys.maxsize, step_increment=1.0, page_increment=10.0), climb_rate=1, digits=0) spinwidth.set_numeric(True) spinwidth.set_activates_default(True) hbox.pack_start(spinwidth, expand=True, fill=True, padding=0) hbox.pack_start( Gtk.Label(label=_('Height:')), expand=False, fill=True, padding=0) spinheight = Gtk.SpinButton() spinheight.configure(Gtk.Adjustment( value=200.0, lower=0.0, upper=sys.maxsize, step_increment=1.0, page_increment=10.0), climb_rate=1, digits=0) spinheight.set_numeric(True) spinheight.set_activates_default(True) hbox.pack_start(spinheight, expand=True, fill=True, padding=0) dia.show_all() filter = Gtk.FileFilter() filter.set_name(_('PNG image (*.png)')) filter.add_mime_type('image/png') filter.add_pattern('*.png') while True: response = dia.run() width = spinwidth.get_value_as_int() height = spinheight.get_value_as_int() if response == Gtk.ResponseType.OK: filename = file_selection( _('Save As'), action=Gtk.FileChooserAction.SAVE, preview=False, filters=[filter]) if width and height and filename: if not filename.endswith('.png'): filename = filename + '.png' try: self.widgets['root'].export_png( filename, width, height) break except MemoryError: message( _('Image size too large.'), dia, Gtk.MessageType.ERROR) else: break parent.present() dia.destroy()