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 _update_popup_menu(self, tbutton, menu, keyword): for item in menu.get_children(): if getattr(item, '_update_action', False): menu.remove(item) buttons = [ b for b in self.screen.get_buttons() if keyword == b.attrs.get('keyword', 'action') ] if buttons and menu.get_children(): separator = Gtk.SeparatorMenuItem() separator._update_action = True menu.add(separator) for button in buttons: menuitem = Gtk.MenuItem(label=set_underline( button.attrs.get('string', _('Unknown'))), use_underline=True) menuitem.connect('activate', lambda m, attrs: self.screen.button(attrs), button.attrs) menuitem._update_action = True menu.add(menuitem) kw_plugins = [] for plugin in plugins.MODULES: for plugin_spec in plugin.get_plugins(self.model): name, func = plugin_spec[:2] try: plugin_keyword = plugin_spec[2] except IndexError: plugin_keyword = 'action' if keyword != plugin_keyword: continue kw_plugins.append((name, func)) if kw_plugins: separator = Gtk.SeparatorMenuItem() separator._update_action = True menu.add(separator) for name, func in kw_plugins: menuitem = Gtk.MenuItem(label=set_underline(name)) menuitem.set_use_underline(True) menuitem.connect( 'activate', lambda m, func: func({ 'model': self.screen.model_name, 'model_context': (self.screen.context_screen.model_name if self.screen.context_screen else None), 'id': (self.screen.current_record.id if self.screen.current_record else None), 'ids': [r.id for r in self.screen.selected_records], 'paths': self.screen.selected_paths, }), func) menuitem._update_action = True menu.add(menuitem)
def _parse_field(self, node, attributes): name = attributes['name'] if name and name == self.exclude_field: self.container.add(None, attributes) return widget = self.WIDGETS[attributes['widget']](self.view, attributes) self.view.widgets[name].append(widget) if widget.expand: attributes.setdefault('yexpand', True) attributes.setdefault('yfill', True) if attributes.get('height') or attributes.get('width'): widget.widget.set_size_request(int(attributes.get('width', -1)), int(attributes.get('height', -1))) widget.widget.set_halign( get_align(attributes.get('xalign', 0.5), bool(attributes.get('xexpand', True)))) widget.widget.set_valign( get_align(attributes.get('yalign', 0.5), bool(attributes.get('yexpand')))) self.container.add(widget.widget, attributes) if name in self._mnemonics and widget.mnemonic_widget: label = self._mnemonics.pop(name) label.set_label(set_underline(label.get_label())) label.set_use_underline(True) label.set_mnemonic_widget(widget.mnemonic_widget)
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: ICONFACTORY.register_icon(attributes['icon']) icon = gtk.Image() icon.set_from_stock(attributes['icon'], gtk.ICON_SIZE_SMALL_TOOLBAR) tab_box.pack_start(icon) 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 parse(self, node, container=None): if not container: node_attrs = node_attributes(node) container = Container.constructor( int(node_attrs.get('col', 4)), node_attrs.get('homogeneous', False)) mnemonics = {} for node in node.childNodes: if node.nodeType != node.ELEMENT_NODE: continue node_attrs = node_attributes(node) for b_field in ('readonly', 'homogeneous'): if b_field in node_attrs: node_attrs[b_field] = bool(int(node_attrs[b_field])) for i_field in ('yexpand', 'yfill', 'xexpand', 'xfill', 'colspan', 'position'): if i_field in node_attrs: node_attrs[i_field] = int(node_attrs[i_field]) parser = getattr(self, '_parse_%s' % node.tagName) widget = parser(node, container, node_attrs) if not widget: continue name = node_attrs.get('name') if node.tagName == 'label' and name: mnemonics[name] = widget if node.tagName == 'field': if name in mnemonics and widget.mnemonic_widget: label = mnemonics.pop(name) label.set_label(set_underline(label.get_label())) label.set_use_underline(True) label.set_mnemonic_widget(widget.mnemonic_widget) return container
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 add_line(self, key): key_schema = self.field.keys[key] self.fields[key] = DICT_ENTRIES[key_schema['type_']](key, self) field = self.fields[key] text = key_schema['string'] + _(':') label = Gtk.Label( label=set_underline(text), use_underline=True, halign=Gtk.Align.END) self.grid.attach_next_to( label, None, Gtk.PositionType.BOTTOM, 1, 1) label.set_mnemonic_widget(field.widget) label.show() hbox = Gtk.HBox(hexpand=True) hbox.pack_start( field.widget, expand=field.expand, fill=field.fill, padding=0) self.grid.attach_next_to( hbox, label, Gtk.PositionType.RIGHT, 1, 1) hbox.show_all() remove_but = self._new_remove_btn() self.tooltips.set_tip(remove_but, _('Remove "%s"') % key_schema['string']) self.grid.attach_next_to( remove_but, hbox, Gtk.PositionType.RIGHT, 1, 1) remove_but.connect('clicked', self._sig_remove, key) remove_but.show_all() self.rows[key] = [label, hbox, remove_but] self.buttons[key] = remove_but
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 switch_view(self, widget): self.screen.switch_view() mnemonic_widget = self.screen.current_view.mnemonic_widget string = self.attrs.get('string', '') if mnemonic_widget: string = set_underline(string) self.title.set_mnemonic_widget(mnemonic_widget) self.title.set_label(string)
def __init__(self, view, attrs): super(DictWidget, self).__init__(view, attrs) self.schema_model = attrs['schema_model'] self.keys = {} 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 = PlaceholderEntry() 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) img_add = gtk.Image() img_add.set_from_stock('tryton-list-add', gtk.ICON_SIZE_SMALL_TOOLBAR) img_add.set_alignment(0.5, 0.5) self.but_add.add(img_add) 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 add_line(self, key): key_schema = self.field.keys[key] self.fields[key] = DICT_ENTRIES[key_schema['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 = _(':') + key_schema['string'] else: text = key_schema['string'] + _(':') label = gtk.Label(set_underline(text)) label.set_use_underline(True) label.set_alignment(1., .5) self.table.attach(label, 0, 1, n_rows - 1, n_rows, xoptions=gtk.FILL, yoptions=False, xpadding=4, ypadding=4) 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=4, ypadding=3) alignment.show_all() if not self.attrs.get('no_command', 0.0): remove_but = self._new_remove_btn() self.tooltips.set_tip(remove_but, _('Remove "%s"') % key_schema['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] else: self.rows[key] = [label, alignment]
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 switch_view(self, widget): self.screen.switch_view() # ABD: Specific, keep colors self.color_set(self.color_name) mnemonic_widget = self.screen.current_view.mnemonic_widget string = self.attrs.get('string', '') if mnemonic_widget: string = set_underline(string) self.title.set_mnemonic_widget(mnemonic_widget) self.title.set_label(string)
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 __init__(self, view, attrs): super().__init__(view, attrs) self.widget = Gtk.HBox() self.mnemonic_widget = self.button = Gtk.LinkButton() self.button.set_label(set_underline(attrs['string'])) self.button.set_use_underline(True) self.button.set_alignment(0, 0.5) self.widget.pack_start( self.button, expand=False, fill=False, padding=0) if attrs.get('translate'): self.widget.pack_start( self.translate_button(), expand=False, fill=False, padding=0)
def _create_popup_menu(self, widget, keyword, actions, special_action): menu = Gtk.Menu() menu.connect('deactivate', self._popup_menu_hide, widget) widget.connect('toggled', self._update_popup_menu, menu, keyword) for action in actions: new_action = action.copy() if special_action == 'print': new_action['direct_print'] = True menuitem = Gtk.MenuItem(label=set_underline(action['name'])) menuitem.set_use_underline(True) menuitem.connect('activate', self._popup_menu_selected, widget, new_action, keyword) menu.add(menuitem) return menu
def _parse_field(self, node, attributes): name = attributes['name'] if name and name == self.exclude_field: self.container.add(None, attributes) return # RSE Display more useful info when trying to display unexisting field if 'widget' not in attributes: raise Exception('Unknown field %s' % attributes['name']) widget = self.WIDGETS[attributes['widget']](self.view, attributes) self.view.widgets[name].append(widget) if attributes.get('group'): group = attributes['group'] if widget.expand: attributes.setdefault('yexpand', True) attributes.setdefault('yfill', True) if attributes.get('height') or attributes.get('width'): widget.widget.set_size_request(int(attributes.get('width', -1)), int(attributes.get('height', -1))) widget.widget.set_halign( get_align(attributes.get('xalign', 0.5), bool(attributes.get('xexpand', True)))) widget.widget.set_valign( get_align(attributes.get('yalign', 0.5), bool(attributes.get('yexpand')))) self.container.add(widget.widget, attributes) if name in self._mnemonics and widget.mnemonic_widget: label = self._mnemonics.pop(name) label.set_label(set_underline(label.get_label())) label.set_use_underline(True) label.set_mnemonic_widget(widget.mnemonic_widget)
def __init__(self): # Fake windows to avoid warning about Dialog without transient self._window = Gtk.Window() self.dialog = Gtk.Dialog(title="Tryton - " + _('Login'), modal=True) self.dialog.set_transient_for(self._window) self.dialog.set_icon(TRYTON_ICON) self.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) self.dialog.set_resizable(False) tooltips = common.Tooltips() button_cancel = Gtk.Button(label=_('_Cancel'), use_underline=True) tooltips.set_tip(button_cancel, _('Cancel connection to the Tryton server')) self.dialog.add_action_widget(button_cancel, Gtk.ResponseType.CANCEL) self.button_connect = Gtk.Button(label=_('C_onnect'), use_underline=True) self.button_connect.get_style_context().add_class( Gtk.STYLE_CLASS_SUGGESTED_ACTION) self.button_connect.set_can_default(True) tooltips.set_tip(self.button_connect, _('Connect the Tryton server')) self.dialog.add_action_widget(self.button_connect, Gtk.ResponseType.OK) self.dialog.set_default_response(Gtk.ResponseType.OK) alignment = Gtk.Alignment(yalign=0, yscale=0, xscale=1) grid = Gtk.Grid(column_spacing=3, row_spacing=3) alignment.add(grid) self.dialog.vbox.pack_start(alignment, expand=True, fill=True, padding=0) image = Gtk.Image() image.set_from_file(os.path.join(PIXMAPS_DIR, 'tryton.png')) image.set_valign(Gtk.Align.START) overlay = Gtk.Overlay() overlay.add(image) label = Gtk.Label(label='<span color="white">%s</span>' % __version__, use_markup=True) label.props.halign = Gtk.Align.END label.props.valign = Gtk.Align.START label.props.margin_right = 10 label.props.margin_top = 5 overlay.add_overlay(label) grid.attach(overlay, 0, 0, 3, 1) self.profile_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_BOOLEAN) self.combo_profile = Gtk.ComboBox(hexpand=True) cell = Gtk.CellRendererText() self.combo_profile.pack_start(cell, expand=True) self.combo_profile.add_attribute(cell, 'text', 0) self.combo_profile.add_attribute(cell, 'sensitive', 1) self.combo_profile.set_model(self.profile_store) self.combo_profile.connect('changed', self.profile_changed) self.profile_label = Gtk.Label(label=set_underline(_('Profile:')), use_underline=True, halign=Gtk.Align.END) self.profile_label.set_mnemonic_widget(self.combo_profile) self.profile_button = Gtk.Button(label=set_underline(_('Manage...')), use_underline=True) self.profile_button.connect('clicked', self.profile_manage) grid.attach(self.profile_label, 0, 1, 1, 1) grid.attach(self.combo_profile, 1, 1, 1, 1) grid.attach(self.profile_button, 2, 1, 1, 1) self.expander = Gtk.Expander() self.expander.set_label(_('Host / Database information')) self.expander.connect('notify::expanded', self.expand_hostspec) grid.attach(self.expander, 0, 2, 3, 1) self.label_host = Gtk.Label(label=set_underline(_('Host:')), use_underline=True, halign=Gtk.Align.END) self.entry_host = Gtk.Entry(hexpand=True) self.entry_host.connect_after('focus-out-event', self.clear_profile_combo) self.entry_host.set_activates_default(True) self.label_host.set_mnemonic_widget(self.entry_host) grid.attach(self.label_host, 0, 3, 1, 1) grid.attach(self.entry_host, 1, 3, 2, 1) self.label_database = Gtk.Label(label=set_underline(_('Database:')), use_underline=True, halign=Gtk.Align.END) self.entry_database = Gtk.Entry(hexpand=True) self.entry_database.connect_after('focus-out-event', self.clear_profile_combo) self.entry_database.set_activates_default(True) self.label_database.set_mnemonic_widget(self.entry_database) grid.attach(self.label_database, 0, 4, 1, 1) grid.attach(self.entry_database, 1, 4, 2, 1) self.entry_login = Gtk.Entry(hexpand=True) self.entry_login.set_activates_default(True) grid.attach(self.entry_login, 1, 5, 2, 1) label_username = Gtk.Label(label=set_underline(_("User name:")), use_underline=True, halign=Gtk.Align.END, margin=3) label_username.set_mnemonic_widget(self.entry_login) grid.attach(label_username, 0, 5, 1, 1) # Date stuff if CONFIG['login.date']: self.label_date = Gtk.Label(label=set_underline(_("Date:")), use_underline=True, halign=Gtk.Align.END) grid.attach(self.label_date, 0, 6, 1, 1) self.entry_date = Date() self.entry_date.props.format = '%d/%m/%Y' self.entry_date.props.value = datetime.date.today() grid.attach(self.entry_date, 1, 6, 2, 1) # Profile information self.profile_cfg = os.path.join(get_config_dir(), 'profiles.cfg') self.profiles = configparser.ConfigParser() if not os.path.exists(self.profile_cfg): short_version = '.'.join(__version__.split('.', 2)[:2]) name = 'demo%s.tryton.org' % short_version self.profiles.add_section(name) self.profiles.set(name, 'host', name) self.profiles.set(name, 'database', 'demo%s' % short_version) self.profiles.set(name, 'username', 'demo') else: try: self.profiles.read(self.profile_cfg) except configparser.ParsingError: logger.error("Fail to parse profiles.cfg", exc_info=True) for section in self.profiles.sections(): active = all( self.profiles.has_option(section, option) for option in ('host', 'database')) self.profile_store.append([section, active])
def __init__(self, view, attrs): super(One2Many, self).__init__(view, attrs) self.widget = Gtk.Frame() self.widget.set_shadow_type(Gtk.ShadowType.NONE) self.widget.get_accessible().set_name(attrs.get('string', '')) vbox = Gtk.VBox(homogeneous=False, spacing=2) self.widget.add(vbox) self._readonly = True self._required = False self._position = 0 self._length = 0 self.title_box = hbox = Gtk.HBox(homogeneous=False, spacing=0) hbox.set_border_width(2) self.title = Gtk.Label(label=set_underline(attrs.get('string', '')), use_underline=True, halign=Gtk.Align.START) hbox.pack_start(self.title, expand=True, fill=True, padding=0) hbox.pack_start(Gtk.VSeparator(), expand=False, fill=True, padding=0) tooltips = common.Tooltips() but_switch = Gtk.Button(can_focus=False) tooltips.set_tip(but_switch, _('Switch')) but_switch.connect('clicked', self.switch_view) but_switch.add( common.IconFactory.get_image('tryton-switch', Gtk.IconSize.SMALL_TOOLBAR)) but_switch.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(but_switch, expand=False, fill=False, padding=0) self.but_pre = Gtk.Button(can_focus=False) tooltips.set_tip(self.but_pre, _('Previous')) self.but_pre.connect('clicked', self._sig_previous) self.but_pre.add( common.IconFactory.get_image('tryton-back', Gtk.IconSize.SMALL_TOOLBAR)) self.but_pre.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(self.but_pre, expand=False, fill=False, padding=0) self.label = Gtk.Label(label='(0,0)') hbox.pack_start(self.label, expand=False, fill=False, padding=0) self.but_next = Gtk.Button(can_focus=False) tooltips.set_tip(self.but_next, _('Next')) self.but_next.connect('clicked', self._sig_next) self.but_next.add( common.IconFactory.get_image('tryton-forward', Gtk.IconSize.SMALL_TOOLBAR)) self.but_next.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(self.but_next, expand=False, fill=False, padding=0) hbox.pack_start(Gtk.VSeparator(), expand=False, fill=True, padding=0) self.focus_out = True self.wid_completion = None if attrs.get('add_remove'): self.wid_text = Gtk.Entry() self.wid_text.set_placeholder_text(_('Search')) self.wid_text.set_property('width_chars', 13) self.wid_text.connect('focus-out-event', self._focus_out) hbox.pack_start(self.wid_text, expand=True, fill=True, padding=0) if int(self.attrs.get('completion', 1)): self.wid_completion = get_completion(search=self.read_access, create=self.create_access) self.wid_completion.connect('match-selected', self._completion_match_selected) self.wid_completion.connect('action-activated', self._completion_action_activated) self.wid_text.set_completion(self.wid_completion) self.wid_text.connect('changed', self._update_completion) self.but_add = Gtk.Button(can_focus=False) tooltips.set_tip(self.but_add, _('Add existing record')) self.but_add.connect('clicked', self._sig_add) self.but_add.add( common.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) self.but_remove = Gtk.Button(can_focus=False) tooltips.set_tip(self.but_remove, _('Remove selected record')) self.but_remove.connect('clicked', self._sig_remove, True) self.but_remove.add( common.IconFactory.get_image('tryton-remove', Gtk.IconSize.SMALL_TOOLBAR)) self.but_remove.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(self.but_remove, expand=False, fill=False, padding=0) hbox.pack_start(Gtk.VSeparator(), expand=False, fill=True, padding=0) self.but_new = Gtk.Button(can_focus=False) tooltips.set_tip(self.but_new, _('Create a new record')) self.but_new.connect('clicked', self._sig_new) self.but_new.add( common.IconFactory.get_image('tryton-create', Gtk.IconSize.SMALL_TOOLBAR)) self.but_new.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(self.but_new, expand=False, fill=False, padding=0) self.but_open = Gtk.Button(can_focus=False) tooltips.set_tip(self.but_open, _('Edit selected record')) self.but_open.connect('clicked', self._sig_edit) self.but_open.add( common.IconFactory.get_image('tryton-open', Gtk.IconSize.SMALL_TOOLBAR)) self.but_open.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(self.but_open, expand=False, fill=False, padding=0) self.but_del = Gtk.Button(can_focus=False) tooltips.set_tip(self.but_del, _('Delete selected record')) self.but_del.connect('clicked', self._sig_remove, False) self.but_del.add( common.IconFactory.get_image('tryton-delete', Gtk.IconSize.SMALL_TOOLBAR)) self.but_del.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(self.but_del, expand=False, fill=False, padding=0) self.but_undel = Gtk.Button(can_focus=False) tooltips.set_tip(self.but_undel, _('Undelete selected record <Ins>')) self.but_undel.connect('clicked', self._sig_undelete) self.but_undel.add( common.IconFactory.get_image('tryton-undo', Gtk.IconSize.SMALL_TOOLBAR)) self.but_undel.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(self.but_undel, expand=False, fill=False, padding=0) tooltips.enable() frame = Gtk.Frame() frame.add(hbox) frame.set_shadow_type(Gtk.ShadowType.OUT) vbox.pack_start(frame, expand=False, fill=True, padding=0) model = attrs['relation'] breadcrumb = list(self.view.screen.breadcrumb) breadcrumb.append(attrs.get('string') or common.MODELNAME.get(model)) self.screen = Screen(model, mode=attrs.get('mode', 'tree,form').split(','), view_ids=attrs.get('view_ids', '').split(','), views_preload=attrs.get('views', {}), order=attrs.get('order'), row_activate=self._on_activate, exclude_field=attrs.get('relation_field', None), limit=None, breadcrumb=breadcrumb) self.screen.pre_validate = bool(int(attrs.get('pre_validate', 0))) self.screen.windows.append(self) vbox.pack_start(self.screen.widget, expand=True, fill=True, padding=0) self.title.set_mnemonic_widget( self.screen.current_view.mnemonic_widget) self.screen.widget.connect('key_press_event', self.on_keypress) if self.attrs.get('add_remove'): self.wid_text.connect('key_press_event', self.on_keypress) but_switch.props.sensitive = self.screen.number_of_views > 1
def __init__(self, model, callback, sel_multi=True, context=None, domain=None, order=None, view_ids=None, views_preload=None, new=True, title='', exclude_field=None): NoModal.__init__(self) if view_ids is None: view_ids = [] if views_preload is None: views_preload = {} self.domain = domain or [] self.context = context or {} self.order = order self.view_ids = view_ids self.views_preload = views_preload self.sel_multi = sel_multi self.callback = callback self.title = title self.exclude_field = exclude_field self.win = Gtk.Dialog( title=_('Search'), transient_for=self.parent, destroy_with_parent=True) Main().add_window(self.win) self.win.set_icon(TRYTON_ICON) self.win.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) self.win.set_default_response(Gtk.ResponseType.APPLY) self.win.connect('response', self.response) self.win.set_default_size(*self.default_size()) 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(common.IconFactory.get_image( 'tryton-cancel', Gtk.IconSize.BUTTON)) self.but_cancel.set_always_show_image(True) self.but_find = self.win.add_button( set_underline(_("Search")), Gtk.ResponseType.APPLY) self.but_find.set_image(common.IconFactory.get_image( 'tryton-search', Gtk.IconSize.BUTTON)) self.but_find.set_always_show_image(True) if new and common.MODELACCESS[model]['create']: self.but_new = self.win.add_button( set_underline(_("New")), Gtk.ResponseType.ACCEPT) self.but_new.set_image(common.IconFactory.get_image( 'tryton-create', Gtk.IconSize.BUTTON)) self.but_new.set_always_show_image(True) self.but_new.set_accel_path('<tryton>/Form/New', self.accel_group) self.but_ok = self.win.add_button( set_underline(_("OK")), Gtk.ResponseType.OK) self.but_ok.set_image(common.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) hbox = Gtk.HBox() hbox.show() self.win.vbox.pack_start(hbox, expand=False, fill=True, padding=0) self.win.vbox.pack_start( Gtk.HSeparator(), expand=False, fill=True, padding=0) self.screen = Screen(model, domain=domain, mode=['tree'], order=order, context=context, view_ids=view_ids, views_preload=views_preload, row_activate=self.sig_activate, readonly=True) self.view = self.screen.current_view # Prevent to set tree_state self.screen.tree_states_done.add(id(self.view)) sel = self.view.treeview.get_selection() self.win.set_title(_('Search %s') % self.title) if not sel_multi: sel.set_mode(Gtk.SelectionMode.SINGLE) else: sel.set_mode(Gtk.SelectionMode.MULTIPLE) self.win.vbox.pack_start( self.screen.widget, expand=True, fill=True, padding=0) self.screen.widget.show() self.model_name = model self.register()
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, view, attrs): super(Many2Many, self).__init__(view, attrs) self.widget = Gtk.Frame() self.widget.set_shadow_type(Gtk.ShadowType.NONE) self.widget.get_accessible().set_name(attrs.get('string', '')) vbox = Gtk.VBox(homogeneous=False, spacing=5) self.widget.add(vbox) self._readonly = True self._required = False self._position = 0 hbox = Gtk.HBox(homogeneous=False, spacing=0) hbox.set_border_width(2) self.title = Gtk.Label(label=set_underline(attrs.get('string', '')), use_underline=True, halign=Gtk.Align.START) hbox.pack_start(self.title, expand=True, fill=True, padding=0) hbox.pack_start(Gtk.VSeparator(), expand=False, fill=True, padding=0) tooltips = common.Tooltips() self.wid_text = Gtk.Entry() self.wid_text.set_placeholder_text(_('Search')) self.wid_text.set_property('width_chars', 13) self.wid_text.connect('focus-out-event', self._focus_out) self.focus_out = True hbox.pack_start(self.wid_text, expand=True, fill=True, padding=0) if int(self.attrs.get('completion', 1)): self.wid_completion = get_completion(search=self.read_access, create=self.create_access) self.wid_completion.connect('match-selected', self._completion_match_selected) self.wid_completion.connect('action-activated', self._completion_action_activated) 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) tooltips.set_tip(self.but_add, _('Add existing record')) self.but_add.connect('clicked', self._sig_add) self.but_add.add( common.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) self.but_remove = Gtk.Button(can_focus=False) tooltips.set_tip(self.but_remove, _('Remove selected record')) self.but_remove.connect('clicked', self._sig_remove) self.but_remove.add( common.IconFactory.get_image('tryton-remove', Gtk.IconSize.SMALL_TOOLBAR)) self.but_remove.set_relief(Gtk.ReliefStyle.NONE) hbox.pack_start(self.but_remove, expand=False, fill=False, padding=0) tooltips.enable() frame = Gtk.Frame() frame.add(hbox) frame.set_shadow_type(Gtk.ShadowType.OUT) vbox.pack_start(frame, expand=False, fill=True, padding=0) self.screen = Screen(attrs['relation'], view_ids=attrs.get('view_ids', '').split(','), mode=['tree'], views_preload=attrs.get('views', {}), order=attrs.get('order'), row_activate=self._on_activate, readonly=True, limit=None) self.screen.windows.append(self) vbox.pack_start(self.screen.widget, expand=True, fill=True, padding=0) self.title.set_mnemonic_widget( self.screen.current_view.mnemonic_widget) self.screen.widget.connect('key_press_event', self.on_keypress) self.wid_text.connect('key_press_event', self.on_keypress)
def __init__(self): # Fake windows to avoid warning about Dialog without transient self._window = gtk.Window() self.dialog = gtk.Dialog(title=_('Login'), flags=gtk.DIALOG_MODAL) self.dialog.set_transient_for(self._window) self.dialog.set_icon(TRYTON_ICON) self.dialog.set_position(gtk.WIN_POS_CENTER_ALWAYS) tooltips = common.Tooltips() button_cancel = gtk.Button(_('_Cancel'), use_underline=True) tooltips.set_tip(button_cancel, _('Cancel connection to the Tryton server')) self.dialog.add_action_widget(button_cancel, gtk.RESPONSE_CANCEL) self.button_connect = gtk.Button(_('C_onnect'), use_underline=True) self.button_connect.get_style_context().add_class( Gtk.STYLE_CLASS_SUGGESTED_ACTION) self.button_connect.set_can_default(True) tooltips.set_tip(self.button_connect, _('Connect the Tryton server')) self.dialog.add_action_widget(self.button_connect, gtk.RESPONSE_OK) self.dialog.set_default_response(gtk.RESPONSE_OK) alignment = gtk.Alignment(yalign=0, yscale=0, xscale=1) self.table_main = gtk.Table(3, 3, False) self.table_main.set_border_width(0) self.table_main.set_row_spacings(3) self.table_main.set_col_spacings(3) alignment.add(self.table_main) self.dialog.vbox.pack_start(alignment, True, True, 0) image = gtk.Image() image.set_from_file(os.path.join(PIXMAPS_DIR, 'tryton.png')) image.set_alignment(0.5, 1) ebox = gtk.EventBox() ebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#1b2019")) ebox.add(image) self.table_main.attach(ebox, 0, 3, 0, 1, ypadding=2) self.profile_store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_BOOLEAN) self.combo_profile = gtk.ComboBox() cell = gtk.CellRendererText() self.combo_profile.pack_start(cell, True) self.combo_profile.add_attribute(cell, 'text', 0) self.combo_profile.add_attribute(cell, 'sensitive', 1) self.combo_profile.set_model(self.profile_store) self.combo_profile.connect('changed', self.profile_changed) self.profile_label = gtk.Label(set_underline(_('Profile:'))) self.profile_label.set_use_underline(True) self.profile_label.set_justify(gtk.JUSTIFY_RIGHT) self.profile_label.set_alignment(1, 0.5) self.profile_label.set_padding(3, 3) self.profile_label.set_mnemonic_widget(self.combo_profile) self.profile_button = gtk.Button(set_underline(_('Manage...')), use_underline=True) self.profile_button.connect('clicked', self.profile_manage) self.table_main.attach(self.profile_label, 0, 1, 1, 2, xoptions=gtk.FILL) self.table_main.attach(self.combo_profile, 1, 2, 1, 2) self.table_main.attach(self.profile_button, 2, 3, 1, 2, xoptions=gtk.FILL) self.expander = gtk.Expander() self.expander.set_label(_('Host / Database information')) self.expander.connect('notify::expanded', self.expand_hostspec) self.table_main.attach(self.expander, 0, 3, 3, 4) self.label_host = gtk.Label(set_underline(_('Host:'))) self.label_host.set_use_underline(True) self.label_host.set_justify(gtk.JUSTIFY_RIGHT) self.label_host.set_alignment(1, 0.5) self.label_host.set_padding(3, 3) self.entry_host = gtk.Entry() self.entry_host.connect_after('focus-out-event', self.clear_profile_combo) self.entry_host.set_activates_default(True) self.label_host.set_mnemonic_widget(self.entry_host) self.table_main.attach(self.label_host, 0, 1, 4, 5, xoptions=gtk.FILL) self.table_main.attach(self.entry_host, 1, 3, 4, 5) self.label_database = gtk.Label(set_underline(_('Database:'))) self.label_database.set_use_underline(True) self.label_database.set_justify(gtk.JUSTIFY_RIGHT) self.label_database.set_alignment(1, 0.5) self.label_database.set_padding(3, 3) self.entry_database = gtk.Entry() self.entry_database.connect_after('focus-out-event', self.clear_profile_combo) self.entry_database.set_activates_default(True) self.label_database.set_mnemonic_widget(self.entry_database) self.table_main.attach(self.label_database, 0, 1, 5, 6, xoptions=gtk.FILL) self.table_main.attach(self.entry_database, 1, 3, 5, 6) self.entry_login = gtk.Entry() self.entry_login.set_activates_default(True) self.table_main.attach(self.entry_login, 1, 3, 6, 7) label_username = gtk.Label(set_underline(_("User name:"))) label_username.set_use_underline(True) label_username.set_alignment(1, 0.5) label_username.set_padding(3, 3) label_username.set_mnemonic_widget(self.entry_login) self.table_main.attach(label_username, 0, 1, 6, 7, xoptions=gtk.FILL) # Date stuff if CONFIG['login.date']: self.label_date = gtk.Label() self.label_date.set_text('Date:') self.label_date.set_justify(gtk.JUSTIFY_RIGHT) self.label_date.set_alignment(1, .5) self.label_date.set_padding(3, 3) self.table_main.attach(self.label_date, 0, 1, 8, 9, xoptions=gtk.FILL) self.entry_date = Date() self.entry_date.props.format = '%d/%m/%Y' self.entry_date.props.value = datetime.date.today() self.table_main.attach(self.entry_date, 1, 3, 8, 9) # Profile informations self.profile_cfg = os.path.join(get_config_dir(), 'profiles.cfg') self.profiles = configparser.ConfigParser() if not os.path.exists(self.profile_cfg): short_version = '.'.join(__version__.split('.', 2)[:2]) name = 'demo%s.tryton.org' % short_version self.profiles.add_section(name) self.profiles.set(name, 'host', name) self.profiles.set(name, 'database', 'demo%s' % short_version) self.profiles.set(name, 'username', 'demo') else: try: self.profiles.read(self.profile_cfg) except configparser.ParsingError: logger.error("Fail to parse profiles.cfg", exc_info=True) for section in self.profiles.sections(): active = all(self.profiles.has_option(section, option) for option in ('host', 'database')) self.profile_store.append([section, active])
def __init__(self, screen, callback, view_type='form', new=False, many=0, domain=None, context=None, save_current=False, title='', rec_name=None): tooltips = common.Tooltips() NoModal.__init__(self) self.screen = screen self.callback = callback self.many = many self.domain = domain self.context = context self.save_current = save_current self.title = title self.prev_view = self.screen.current_view self.screen.screen_container.alternate_view = True self.screen.switch_view(view_type=view_type) if self.screen.current_view.view_type != view_type: self.destroy() return if new: self.screen.new(rec_name=rec_name) self.win = gtk.Dialog(_('Link'), 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.win.set_deletable(False) self.win.connect('delete-event', lambda *a: True) self.win.connect('close', self.close) self.win.connect('delete-event', self.delete_event) self.win.connect('response', self.response) allocation = self.parent.get_allocation() width, height, = allocation.width, allocation.height if self.parent != self.sensible_widget: width = max(width - 150, 0) height = max(height - 150, 0) self.win.set_default_size(width, height) self.accel_group = gtk.AccelGroup() self.win.add_accel_group(self.accel_group) readonly = self.screen.readonly or self.screen.group.readonly self.but_ok = None self.but_new = None self._initial_value = None if view_type == 'form': if new: label, icon = _("Delete"), 'tryton-delete' else: label, icon = _("Cancel"), 'tryton-cancel' self._initial_value = self.screen.current_record.get_eval() self.but_cancel = self.win.add_button(set_underline(label), gtk.RESPONSE_CANCEL) self.but_cancel.set_image( common.IconFactory.get_image(icon, gtk.ICON_SIZE_BUTTON)) self.but_cancel.set_always_show_image(True) if new and self.many: self.but_new = self.win.add_button(set_underline(_("New")), gtk.RESPONSE_ACCEPT) self.but_new.set_image( common.IconFactory.get_image('tryton-create', gtk.ICON_SIZE_BUTTON)) self.but_new.set_always_show_image(True) self.but_new.set_accel_path('<tryton>/Form/New', self.accel_group) if self.save_current: self.but_ok = gtk.Button(_('_Save'), use_underline=True) self.but_ok.set_image( common.IconFactory.get_image('tryton-save', gtk.ICON_SIZE_BUTTON)) self.but_ok.set_always_show_image(True) self.but_ok.set_accel_path('<tryton>/Form/Save', self.accel_group) self.but_ok.set_can_default(True) self.but_ok.show() self.win.add_action_widget(self.but_ok, gtk.RESPONSE_OK) if not new: self.but_ok.props.sensitive = False else: self.but_ok = self.win.add_button(set_underline(_("OK")), gtk.RESPONSE_OK) self.but_ok.set_image( common.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.set_title(self.title) title = gtk.Label() title.modify_font(pango.FontDescription("bold 12")) title.set_label(common.ellipsize(self.title, 80)) tooltips.set_tip(title, self.title) title.set_padding(20, 3) title.set_alignment(0.0, 0.5) title.set_size_request(0, -1) # Allow overflow title.set_max_width_chars(1) title.set_ellipsize(pango.ELLIPSIZE_END) title.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) title.show() hbox = gtk.HBox() hbox.pack_start(title, expand=True, fill=True) hbox.show() frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_ETCHED_IN) frame.add(hbox) frame.show() eb = gtk.EventBox() eb.add(frame) eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) eb.show() self.win.vbox.pack_start(eb, expand=False, fill=True, padding=3) if view_type == 'tree': hbox = gtk.HBox(homogeneous=False, spacing=0) access = common.MODELACCESS[screen.model_name] but_switch = gtk.Button() tooltips.set_tip(but_switch, _('Switch')) but_switch.connect('clicked', self.switch_view) but_switch.add( common.IconFactory.get_image('tryton-switch', gtk.ICON_SIZE_SMALL_TOOLBAR)) but_switch.set_relief(gtk.RELIEF_NONE) hbox.pack_start(but_switch, expand=False, fill=False) self.but_pre = gtk.Button() tooltips.set_tip(self.but_pre, _('Previous')) self.but_pre.connect('clicked', self._sig_previous) self.but_pre.add( common.IconFactory.get_image('tryton-back', gtk.ICON_SIZE_SMALL_TOOLBAR)) self.but_pre.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_pre, expand=False, fill=False) self.label = gtk.Label('(0,0)') hbox.pack_start(self.label, expand=False, fill=False) self.but_next = gtk.Button() tooltips.set_tip(self.but_next, _('Next')) self.but_next.connect('clicked', self._sig_next) self.but_next.add( common.IconFactory.get_image('tryton-forward', gtk.ICON_SIZE_SMALL_TOOLBAR)) self.but_next.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_next, expand=False, fill=False) hbox.pack_start(gtk.VSeparator(), expand=False, fill=True) if domain is not None: self.wid_text = gtk.Entry() self.wid_text.set_property('width_chars', 13) self.wid_text.connect('activate', self._sig_activate) self.wid_text.connect('focus-out-event', self._focus_out) hbox.pack_start(self.wid_text, expand=True, fill=True) self.but_add = gtk.Button() tooltips.set_tip(self.but_add, _('Add')) self.but_add.connect('clicked', self._sig_add) self.but_add.add( common.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) if not access['read'] or readonly: self.but_add.set_sensitive(False) self.but_remove = gtk.Button() tooltips.set_tip(self.but_remove, _('Remove <Del>')) self.but_remove.connect('clicked', self._sig_remove, True) self.but_remove.add( common.IconFactory.get_image('tryton-remove', gtk.ICON_SIZE_SMALL_TOOLBAR)) self.but_remove.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_remove, expand=False, fill=False) if not access['read'] or readonly: self.but_remove.set_sensitive(False) hbox.pack_start(gtk.VSeparator(), expand=False, fill=True) self.but_new = gtk.Button() tooltips.set_tip(self.but_new, _('Create a new record <F3>')) self.but_new.connect('clicked', self._sig_new) self.but_new.add( common.IconFactory.get_image('tryton-create', gtk.ICON_SIZE_SMALL_TOOLBAR)) self.but_new.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_new, expand=False, fill=False) if not access['create'] or readonly: self.but_new.set_sensitive(False) self.but_del = gtk.Button() tooltips.set_tip(self.but_del, _('Delete selected record <Del>')) self.but_del.connect('clicked', self._sig_remove, False) self.but_del.add( common.IconFactory.get_image('tryton-delete', gtk.ICON_SIZE_SMALL_TOOLBAR)) self.but_del.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_del, expand=False, fill=False) if not access['delete'] or readonly: self.but_del.set_sensitive(False) self.but_undel = gtk.Button() tooltips.set_tip(self.but_undel, _('Undelete selected record <Ins>')) self.but_undel.connect('clicked', self._sig_undelete) self.but_undel.add( common.IconFactory.get_image('tryton-undo', gtk.ICON_SIZE_SMALL_TOOLBAR)) self.but_undel.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_undel, expand=False, fill=False) if not access['delete'] or readonly: self.but_undel.set_sensitive(False) but_switch.props.sensitive = screen.number_of_views > 1 tooltips.enable() alignment = gtk.Alignment(1.0) alignment.add(hbox) alignment.show_all() self.win.vbox.pack_start(alignment, expand=False, fill=True) scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroll.set_placement(gtk.CORNER_TOP_LEFT) scroll.set_shadow_type(gtk.SHADOW_NONE) scroll.show() self.win.vbox.pack_start(scroll, expand=True, fill=True) scroll.add(self.screen.screen_container.alternate_viewport) self.create_info_bar() self.win.vbox.pack_start(self.info_bar, False, True) if view_type == 'tree': self.screen.signal_connect(self, 'record-message', self._sig_label) self.screen.screen_container.alternate_viewport.connect( 'key-press-event', self.on_keypress) if self.save_current and not new: self.screen.signal_connect(self, 'record-message', self.activate_save) self.screen.signal_connect(self, 'record-modified', self.activate_save) self.register() self.show() self.screen.display() self.screen.current_view.set_cursor()
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 create_toolbar(self, toolbars): gtktoolbar = super(Form, self).create_toolbar(toolbars) attach_btn = self.buttons['attach'] attach_btn.drag_dest_set(Gtk.DestDefaults.ALL, [ Gtk.TargetEntry.new('text/uri-list', 0, 0), Gtk.TargetEntry.new('text/plain', 0, 0), ], Gdk.DragAction.MOVE | Gdk.DragAction.COPY) attach_btn.connect('drag_data_received', self.attach_drag_data_received) iconstock = { 'print': 'tryton-print', 'action': 'tryton-launch', 'relate': 'tryton-link', 'email': 'tryton-email', 'open': 'tryton-print-open', } for action_type, special_action, action_name, tooltip in ( ('action', 'action', _('Action'), _('Launch action')), ('relate', 'relate', _('Relate'), _('Open related records')), (None, ) * 4, ('print', 'open', _('Report'), _('Open report')), ('print', 'email', _('E-Mail'), _('E-Mail report')), ('print', 'print', _('Print'), _('Print report')), ): if action_type is not None: tbutton = Gtk.ToggleToolButton() tbutton.set_icon_widget( common.IconFactory.get_image(iconstock.get(special_action), Gtk.IconSize.LARGE_TOOLBAR)) tbutton.set_label(action_name) tbutton._menu = self._create_popup_menu( tbutton, action_type, toolbars[action_type], special_action) tbutton.connect('toggled', self.action_popup) self.tooltips.set_tip(tbutton, tooltip) self.buttons[special_action] = tbutton if action_type != 'action': tbutton._can_be_sensitive = bool( tbutton._menu.get_children()) else: tbutton = Gtk.SeparatorToolItem() gtktoolbar.insert(tbutton, -1) exports = toolbars['exports'] if exports: tbutton = self.buttons['open'] tbutton._can_be_sensitive = True menu = tbutton._menu if menu.get_children(): menu.add(Gtk.SeparatorMenuItem()) # Coog: move available exports to a submenu exports_menuitem = Gtk.MenuItem(set_underline('Exports')) exports_menuitem.set_use_underline(True) menu.add(exports_menuitem) submenu = Gtk.Menu() exports_menuitem.set_submenu(submenu) for export in exports: menuitem = Gtk.MenuItem(set_underline(export['name'])) menuitem.set_use_underline(True) menuitem.connect('activate', self.do_export, export) submenu.add(menuitem) gtktoolbar.insert(Gtk.SeparatorToolItem(), -1) url_button = Gtk.ToggleToolButton() url_button.set_icon_widget( common.IconFactory.get_image('tryton-public', Gtk.IconSize.LARGE_TOOLBAR)) url_button.set_label(_('_Copy URL')) url_button.set_use_underline(True) self.tooltips.set_tip(url_button, _('Copy URL into clipboard')) url_button._menu = url_menu = Gtk.Menu() url_menuitem = Gtk.MenuItem() url_menuitem.connect('activate', self.url_copy) url_menu.add(url_menuitem) url_menu.show_all() url_menu.connect('deactivate', self._popup_menu_hide, url_button) url_button.connect('toggled', self.url_set, url_menuitem) url_button.connect('toggled', self.action_popup) self.buttons['copy_url'] = url_button gtktoolbar.insert(url_button, -1) quick_actions = toolbars.get('quick_actions', []) if quick_actions: gtktoolbar.insert(Gtk.SeparatorToolItem(), -1) for quick_action in quick_actions: icon = quick_action.get('icon.', {}).get('rec_name') if not icon: icon = 'tryton-executable' # prevent problem with variables scopes in lambda # cf. https://docs.python.org/3/faq/programming.html# # why-do-lambdas-defined-in-a-loop-with-different-values # -all-return-the-same-result def make_func(n, *args): return lambda z: n(*args) # Fix for #8825 common.IconFactory.register_icon(icon) qbutton = Gtk.ToolButton() qbutton.set_icon_widget( common.IconFactory.get_image(icon, Gtk.IconSize.LARGE_TOOLBAR)) qbutton.set_label(quick_action['name']) qbutton.connect( 'clicked', make_func(self._action, quick_action, 'quick_actions')) self.tooltips.set_tip(qbutton, _(quick_action['name'])) gtktoolbar.insert(qbutton, -1) return gtktoolbar
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 __init__(self, parent, profile_store, profiles, callback): self.profiles = profiles self.current_database = None self.old_profile, self.current_profile = None, None self.db_cache = None self.updating_db = False # GTK Stuffs self.parent = parent self.dialog = Gtk.Dialog(title=_('Profile Editor'), transient_for=parent, modal=True, destroy_with_parent=True) self.ok_button = self.dialog.add_button(set_underline(_("Close")), Gtk.ResponseType.CLOSE) self.dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) self.dialog.set_icon(TRYTON_ICON) tooltips = common.Tooltips() hpaned = Gtk.HPaned() vbox_profiles = Gtk.VBox(homogeneous=False, spacing=6) self.cell = Gtk.CellRendererText() self.cell.set_property('editable', True) self.cell.connect('editing-started', self.edit_started) self.profile_tree = Gtk.TreeView() self.profile_tree.set_model(profile_store) self.profile_tree.insert_column_with_attributes(-1, _('Profile'), self.cell, text=0) self.profile_tree.connect('cursor-changed', self.profile_selected) scroll = Gtk.ScrolledWindow() scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scroll.add(self.profile_tree) self.add_button = Gtk.Button() self.add_button.set_image( common.IconFactory.get_image('tryton-add', Gtk.IconSize.BUTTON)) tooltips.set_tip(self.add_button, _("Add new profile")) self.add_button.connect('clicked', self.profile_create) self.remove_button = Gtk.Button() self.remove_button.set_image( common.IconFactory.get_image('tryton-remove', Gtk.IconSize.BUTTON)) tooltips.set_tip(self.remove_button, _("Remove selected profile")) self.remove_button.get_style_context().add_class( Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION) self.remove_button.connect('clicked', self.profile_delete) bbox = Gtk.ButtonBox() bbox.pack_start(self.remove_button, expand=True, fill=True, padding=0) bbox.pack_start(self.add_button, expand=True, fill=True, padding=0) vbox_profiles.pack_start(scroll, expand=True, fill=True, padding=0) vbox_profiles.pack_start(bbox, expand=False, fill=True, padding=0) hpaned.add1(vbox_profiles) grid = Gtk.Grid(column_spacing=3, row_spacing=3) host = Gtk.Label(label=set_underline(_('Host:')), use_underline=True, halign=Gtk.Align.END) self.host_entry = Gtk.Entry(hexpand=True) self.host_entry.connect('focus-out-event', self.display_dbwidget) self.host_entry.connect('changed', self.update_profiles, 'host') self.host_entry.set_activates_default(True) host.set_mnemonic_widget(self.host_entry) grid.attach(host, 0, 1, 1, 1) grid.attach(self.host_entry, 1, 1, 1, 1) database = Gtk.Label(label=set_underline(_('Database:')), use_underline=True, halign=Gtk.Align.END) self.database_entry = Gtk.Entry() self.database_entry.connect('changed', self.dbentry_changed) self.database_entry.connect('changed', self.update_profiles, 'database') self.database_entry.set_activates_default(True) self.database_label = Gtk.Label(valign=Gtk.Align.START) self.database_label.set_use_markup(True) self.database_combo = Gtk.ComboBoxText() self.database_combo.connect('changed', self.dbcombo_changed) self.database_progressbar = Gtk.ProgressBar() self.database_progressbar.set_text(_('Fetching databases list')) db_box = Gtk.VBox(homogeneous=True, hexpand=True) db_box.pack_start(self.database_entry, expand=True, fill=True, padding=0) db_box.pack_start(self.database_combo, expand=True, fill=True, padding=0) db_box.pack_start(self.database_label, expand=True, fill=True, padding=0) db_box.pack_start(self.database_progressbar, expand=True, fill=True, padding=0) # Compute size_request of box in order to prevent "form jumping" width, height = 0, 0 for child in db_box.get_children(): request = child.get_preferred_size()[0] width = max(width, request.width) height = max(height, request.height) db_box.set_size_request(width, height) grid.attach(database, 0, 2, 1, 1) grid.attach(db_box, 1, 2, 1, 1) username = Gtk.Label(label=set_underline(_('Username:'******'changed', self.update_profiles, 'username') username.set_mnemonic_widget(self.username_entry) self.username_entry.set_activates_default(True) grid.attach(username, 0, 3, 1, 1) grid.attach(self.username_entry, 1, 3, 1, 1) hpaned.add2(grid) hpaned.set_position(250) self.dialog.vbox.pack_start(hpaned, expand=True, fill=True, padding=0) self.dialog.set_default_size(640, 350) self.dialog.set_default_response(Gtk.ResponseType.CLOSE) self.dialog.connect('close', lambda *a: False) self.dialog.connect('response', self.response) self.callback = callback
def create_toolbar(self, toolbars): gtktoolbar = super(Form, self).create_toolbar(toolbars) attach_btn = self.buttons['attach'] attach_btn.drag_dest_set(Gtk.DestDefaults.ALL, [ Gtk.TargetEntry.new('text/uri-list', 0, 0), Gtk.TargetEntry.new('text/plain', 0, 0), ], Gdk.DragAction.MOVE | Gdk.DragAction.COPY) attach_btn.connect('drag_data_received', self.attach_drag_data_received) iconstock = { 'print': 'tryton-print', 'action': 'tryton-launch', 'relate': 'tryton-link', 'email': 'tryton-email', 'open': 'tryton-open', } for action_type, special_action, action_name, tooltip in ( ('action', 'action', _('Action'), _('Launch action')), ('relate', 'relate', _('Relate'), _('Open related records')), (None, ) * 4, ('print', 'open', _('Report'), _('Open report')), ('print', 'email', _('E-Mail'), _('E-Mail report')), ('print', 'print', _('Print'), _('Print report')), ): if action_type is not None: tbutton = Gtk.ToggleToolButton() tbutton.set_icon_widget( common.IconFactory.get_image(iconstock.get(special_action), Gtk.IconSize.LARGE_TOOLBAR)) tbutton.set_label(action_name) tbutton._menu = self._create_popup_menu( tbutton, action_type, toolbars[action_type], special_action) tbutton.connect('toggled', self.action_popup) self.tooltips.set_tip(tbutton, tooltip) self.buttons[special_action] = tbutton if action_type != 'action': tbutton._can_be_sensitive = bool( tbutton._menu.get_children()) else: tbutton = Gtk.SeparatorToolItem() gtktoolbar.insert(tbutton, -1) exports = toolbars['exports'] if exports: tbutton = self.buttons['open'] tbutton._can_be_sensitive = True menu = tbutton._menu if menu.get_children(): menu.add(Gtk.SeparatorMenuItem()) for export in exports: menuitem = Gtk.MenuItem(set_underline(export['name'])) menuitem.set_use_underline(True) menuitem.connect('activate', self.do_export, export) menu.add(menuitem) gtktoolbar.insert(Gtk.SeparatorToolItem(), -1) url_button = Gtk.ToggleToolButton() url_button.set_icon_widget( common.IconFactory.get_image('tryton-public', Gtk.IconSize.LARGE_TOOLBAR)) url_button.set_label(_('_Copy URL')) url_button.set_use_underline(True) self.tooltips.set_tip(url_button, _('Copy URL into clipboard')) url_button._menu = url_menu = Gtk.Menu() url_menuitem = Gtk.MenuItem() url_menuitem.connect('activate', self.url_copy) url_menu.add(url_menuitem) url_menu.show_all() url_menu.connect('deactivate', self._popup_menu_hide, url_button) url_button.connect('toggled', self.url_set, url_menuitem) url_button.connect('toggled', self.action_popup) self.buttons['copy_url'] = url_button gtktoolbar.insert(url_button, -1) return gtktoolbar
def __init__(self, view, attrs): super(One2Many, self).__init__(view, attrs) self.widget = gtk.Frame() self.widget.set_shadow_type(gtk.SHADOW_NONE) self.widget.get_accessible().set_name(attrs.get('string', '')) vbox = gtk.VBox(homogeneous=False, spacing=2) self.widget.add(vbox) self._readonly = True self._required = False self._position = 0 self._length = 0 self.title_box = hbox = gtk.HBox(homogeneous=False, spacing=0) hbox.set_border_width(2) self.title = gtk.Label(set_underline(attrs.get('string', ''))) self.title.set_use_underline(True) self.title.set_alignment(0.0, 0.5) hbox.pack_start(self.title, expand=True, fill=True) hbox.pack_start(gtk.VSeparator(), expand=False, fill=True) tooltips = common.Tooltips() but_switch = gtk.Button() tooltips.set_tip(but_switch, _('Switch')) but_switch.connect('clicked', self.switch_view) img_switch = gtk.Image() img_switch.set_from_stock('tryton-fullscreen', gtk.ICON_SIZE_SMALL_TOOLBAR) img_switch.set_alignment(0.5, 0.5) but_switch.add(img_switch) but_switch.set_relief(gtk.RELIEF_NONE) hbox.pack_start(but_switch, expand=False, fill=False) self.but_pre = gtk.Button() tooltips.set_tip(self.but_pre, _('Previous')) self.but_pre.connect('clicked', self._sig_previous) img_pre = gtk.Image() img_pre.set_from_stock('tryton-go-previous', gtk.ICON_SIZE_SMALL_TOOLBAR) img_pre.set_alignment(0.5, 0.5) self.but_pre.add(img_pre) self.but_pre.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_pre, expand=False, fill=False) self.label = gtk.Label('(0,0)') hbox.pack_start(self.label, expand=False, fill=False) self.but_next = gtk.Button() tooltips.set_tip(self.but_next, _('Next')) self.but_next.connect('clicked', self._sig_next) img_next = gtk.Image() img_next.set_from_stock('tryton-go-next', gtk.ICON_SIZE_SMALL_TOOLBAR) img_next.set_alignment(0.5, 0.5) self.but_next.add(img_next) self.but_next.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_next, expand=False, fill=False) hbox.pack_start(gtk.VSeparator(), expand=False, fill=True) self.focus_out = True self.wid_completion = None if attrs.get('add_remove'): self.wid_text = gtk.Entry() self.wid_text.set_placeholder_text(_('Search')) self.wid_text.set_property('width_chars', 13) self.wid_text.connect('focus-out-event', self._focus_out) hbox.pack_start(self.wid_text, expand=True, fill=True) if int(self.attrs.get('completion', 1)): access = common.MODELACCESS[attrs['relation']] self.wid_completion = get_completion( search=access['read'] and access['write'], create=attrs.get('create', True) and access['create']) self.wid_completion.connect('match-selected', self._completion_match_selected) self.wid_completion.connect('action-activated', self._completion_action_activated) self.wid_text.set_completion(self.wid_completion) self.wid_text.connect('changed', self._update_completion) self.but_add = gtk.Button() tooltips.set_tip(self.but_add, _('Add existing record')) self.but_add.connect('clicked', self._sig_add) img_add = gtk.Image() img_add.set_from_stock('tryton-list-add', gtk.ICON_SIZE_SMALL_TOOLBAR) img_add.set_alignment(0.5, 0.5) self.but_add.add(img_add) self.but_add.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_add, expand=False, fill=False) self.but_remove = gtk.Button() tooltips.set_tip(self.but_remove, _('Remove selected record')) self.but_remove.connect('clicked', self._sig_remove, True) img_remove = gtk.Image() img_remove.set_from_stock('tryton-list-remove', gtk.ICON_SIZE_SMALL_TOOLBAR) img_remove.set_alignment(0.5, 0.5) self.but_remove.add(img_remove) self.but_remove.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_remove, expand=False, fill=False) hbox.pack_start(gtk.VSeparator(), expand=False, fill=True) self.but_new = gtk.Button() tooltips.set_tip(self.but_new, _('Create a new record <F3>')) self.but_new.connect('clicked', self._sig_new) img_new = gtk.Image() img_new.set_from_stock('tryton-new', gtk.ICON_SIZE_SMALL_TOOLBAR) img_new.set_alignment(0.5, 0.5) self.but_new.add(img_new) self.but_new.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_new, expand=False, fill=False) self.but_open = gtk.Button() tooltips.set_tip(self.but_open, _('Edit selected record <F2>')) self.but_open.connect('clicked', self._sig_edit) img_open = gtk.Image() img_open.set_from_stock('tryton-open', gtk.ICON_SIZE_SMALL_TOOLBAR) img_open.set_alignment(0.5, 0.5) self.but_open.add(img_open) self.but_open.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_open, expand=False, fill=False) self.but_del = gtk.Button() tooltips.set_tip(self.but_del, _('Delete selected record <Del>')) self.but_del.connect('clicked', self._sig_remove, False) img_del = gtk.Image() img_del.set_from_stock('tryton-delete', gtk.ICON_SIZE_SMALL_TOOLBAR) img_del.set_alignment(0.5, 0.5) self.but_del.add(img_del) self.but_del.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_del, expand=False, fill=False) self.but_undel = gtk.Button() tooltips.set_tip(self.but_undel, _('Undelete selected record <Ins>')) self.but_undel.connect('clicked', self._sig_undelete) img_undel = gtk.Image() img_undel.set_from_stock('tryton-undo', gtk.ICON_SIZE_SMALL_TOOLBAR) img_undel.set_alignment(0.5, 0.5) self.but_undel.add(img_undel) self.but_undel.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_undel, expand=False, fill=False) if attrs.get('add_remove'): hbox.set_focus_chain([self.wid_text]) else: hbox.set_focus_chain([]) tooltips.enable() frame = gtk.Frame() frame.add(hbox) frame.set_shadow_type(gtk.SHADOW_OUT) vbox.pack_start(frame, expand=False, fill=True) self.screen = Screen(attrs['relation'], mode=attrs.get('mode', 'tree,form').split(','), view_ids=attrs.get('view_ids', '').split(','), views_preload=attrs.get('views', {}), row_activate=self._on_activate, exclude_field=attrs.get('relation_field', None), limit=None) self.screen.pre_validate = bool(int(attrs.get('pre_validate', 0))) self.screen.signal_connect(self, 'record-message', self._sig_label) vbox.pack_start(self.screen.widget, expand=True, fill=True) self.title.set_mnemonic_widget( self.screen.current_view.mnemonic_widget) self.screen.widget.connect('key_press_event', self.on_keypress) if self.attrs.get('add_remove'): self.wid_text.connect('key_press_event', self.on_keypress) but_switch.props.sensitive = self.screen.number_of_views > 1