def create_widget(self): widget = Date() record = self.parent_widget.record field = self.parent_widget.field if record and field: format_ = field.date_format(record) widget.props.format = format_ widget.connect('key_press_event', self.parent_widget.send_modified) widget.connect('focus-out-event', lambda w, e: self.parent_widget._focus_out()) return widget
def create_widget(self): widget = add_operators(Date()) record = self.parent_widget.record field = self.parent_widget.field if record and field: format_ = field.date_format(record) widget.props.format = format_ widget.connect('key_press_event', self.parent_widget.send_modified) widget.connect('focus-out-event', lambda w, e: self.parent_widget._focus_out()) return widget
def __init__(self): # GTK Stuffs self.parent = common.get_toplevel_window() self.dialog = gtk.Dialog(title=_('Login'), parent=self.parent, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) self.dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.dialog.set_icon(TRYTON_ICON) tooltips = common.Tooltips() button_cancel = gtk.Button(_('_Cancel'), use_underline=True) img_cancel = gtk.Image() img_cancel.set_from_stock('gtk-cancel', gtk.ICON_SIZE_BUTTON) button_cancel.set_image(img_cancel) 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) img_connect = gtk.Image() img_connect.set_from_stock('tryton-connect', gtk.ICON_SIZE_BUTTON) self.button_connect.set_image(img_connect) 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(_(u'Profile:')) 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_button = gtk.Button(_('_Manage profiles'), 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) image = gtk.Image() image.set_from_stock('gtk-edit', gtk.ICON_SIZE_BUTTON) self.profile_button.set_image(image) 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(_('Host:')) 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(_('Database:')) 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(_("User name:")) 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(str=_('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.SafeConfigParser({'port': '8000'}) # JCA : Deactivate demo tryton database if os.path.exists(self.profile_cfg): self.profiles.read(self.profile_cfg) 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): # 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): # 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])