Example #1
0
 def _on_current_password_changed(self, widget, event):
     self.infobar.hide()
     if self.current_password.get_text() != "":
         auth = PAM.pam()
         auth.start('passwd')
         auth.set_item(PAM.PAM_USER, GLib.get_user_name())
         auth.set_item(PAM.PAM_CONV, self.pam_conv)
         try:
             auth.authenticate()
             auth.acct_mgmt()
         except PAM.error as resp:
             self.current_password.set_icon_from_stock(
                 Gtk.EntryIconPosition.SECONDARY, Gtk.STOCK_DIALOG_WARNING)
             self.current_password.set_icon_tooltip_text(
                 Gtk.EntryIconPosition.SECONDARY, _("Wrong password"))
             self.current_password.set_tooltip_text(_("Wrong password"))
             self.correct_current_password = False
         except:
             print('Internal error')
         else:
             self.current_password.set_icon_from_stock(
                 Gtk.EntryIconPosition.SECONDARY, None)
             self.current_password.set_tooltip_text("")
             self.correct_current_password = True
             self.check_passwords()
Example #2
0
 def get_userinfo(self):
     dict = {}
     dict['username'] = GLib.get_user_name()
     dict['homedir'] = GLib.get_home_dir()
     dict['shell'] = GLib.getenv('SHELL')
     dict['lang'] = GLib.getenv('LANG')
     return dict['username'], dict['homedir'], dict['shell'], dict['lang']
Example #3
0
 def get_userinfo(self):
     dict = {}
     dict['username'] = GLib.get_user_name()
     dict['homedir'] = GLib.get_home_dir()
     dict['shell'] = GLib.getenv('SHELL')
     dict['lang'] =  GLib.getenv('LANG')
     return dict['username'], dict['homedir'],dict['shell'],dict['lang']
Example #4
0
def get_local_name(hostname=get_hostname()):
    local_name = "%s@%s" % (GLib.get_user_name(), hostname)
    real_name = GLib.get_real_name()
    if real_name is not None and real_name != "" and real_name != "Unknown":
        # according to glib's doc, it can actually return "Unknown"
        local_name = "%s - %s" % (real_name, local_name)
    return local_name
    def get_tty_vals(self):
        session_tty = None
        term_tty = None
        username = GLib.get_user_name()[:8]
        used_tty = []

        tty_output = subprocess.check_output(["w", "-h"]).decode("utf-8")
        for line in tty_output.split("\n"):
            if line.startswith(username):
                if "cinnamon-session" in line and "tty" in line:
                    session_tty = line.split()[1].replace("tty", "")
                    used_tty.append(session_tty)
                elif "tty" in line:
                    term_tty = line.split()[1].replace("tty", "")
            elif "tty" in line:
                used_tty.append(line.split()[1].replace("tty", ""))

        used_tty.sort()

        if term_tty == None:
            for i in range(1, 6):
                if str(i) not in used_tty:
                    term_tty = str(i)
                    break

        if term_tty == None:
            term_tty = "1"

        return [term_tty, session_tty]
Example #6
0
def get_user_name():
    name = GLib.get_user_name()

    utf8_name = None

    if name:
        utf8_name = nofail_locale_to_utf8(name)

    return utf8_name
Example #7
0
def get_user_name():
    name = GLib.get_user_name()

    utf8_name = None

    if name:
        utf8_name = nofail_locale_to_utf8(name)

    return utf8_name
Example #8
0
 def auth_PyPAM(self):
     auth = PAM.pam()
     auth.start('passwd')
     auth.set_item(PAM.PAM_USER, GLib.get_user_name())
     auth.set_item(PAM.PAM_CONV, self.pam_conv)
     try:
         auth.authenticate()
         auth.acct_mgmt()
         return True
     except PAM.error as resp:
         raise PasswordError("Invalid password")
Example #9
0
 def auth_PyPAM(self):
     auth = PAM.pam()
     auth.start('passwd')
     auth.set_item(PAM.PAM_USER, GLib.get_user_name())
     auth.set_item(PAM.PAM_CONV, self.pam_conv)
     try:
         auth.authenticate()
         auth.acct_mgmt()
         return True
     except PAM.error as resp:
         raise PasswordError("Invalid password")
Example #10
0
def user_can_lock():
    name = GLib.get_user_name()

    # KeyError is generated if group doesn't exist, ignore it and allow lock
    try:
        group = grp.getgrnam("nopasswdlogin")
        if name in group.gr_mem:
            return False
    except KeyError:
        pass

    return True
Example #11
0
def get_user_display_name():
    name = GLib.get_real_name()

    if not name or name == "Unknown":
        name = GLib.get_user_name()

    utf8_name = None

    if name:
        utf8_name = nofail_locale_to_utf8(name)

    return utf8_name
Example #12
0
def user_can_lock():
    name = GLib.get_user_name()

    # KeyError is generated if group doesn't exist, ignore it and allow lock
    try:
        group = grp.getgrnam("nopasswdlogin")
        if name in group.gr_mem:
            return False
    except KeyError:
        pass

    return True
Example #13
0
def get_user_display_name():
    name = GLib.get_real_name()

    if not name or name == "Unknown":
        name = GLib.get_user_name()

    utf8_name = None

    if name:
        utf8_name = nofail_locale_to_utf8(name)

    return utf8_name
Example #14
0
 def _on_current_password_changed(self, widget, event):
     self.infobar.hide()
     if self.current_password.get_text() != "":
         auth = PAM.pam()
         auth.start('passwd')
         auth.set_item(PAM.PAM_USER, GLib.get_user_name())
         auth.set_item(PAM.PAM_CONV, self.pam_conv)
         try:
             auth.authenticate()
             auth.acct_mgmt()
         except PAM.error, resp:
             self.current_password.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, Gtk.STOCK_DIALOG_WARNING)
             self.current_password.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, _("Wrong password"))
             self.correct_current_password = False
         except:
Example #15
0
    def _ensure_proxy(klass):
        if klass._proxy is None:
            system_bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
            accounts = Gio.DBusProxy.new_sync(system_bus, 0, None,
                                              klass._INTERFACE_NAME,
                                              '/org/freedesktop/Accounts',
                                              klass._INTERFACE_NAME, None)

            user_path = accounts.FindUserByName('(s)', GLib.get_user_name())

            klass._proxy = Gio.DBusProxy.new_sync(
                system_bus, 0, None, klass._INTERFACE_NAME, user_path,
                'org.freedesktop.Accounts.User', None)
            klass._props = Gio.DBusProxy.new_sync(
                system_bus, 0, None, klass._INTERFACE_NAME, user_path,
                'org.freedesktop.DBus.Properties', None)
Example #16
0
    def __init__(self):
        Clip.__init__(self)

        self.table = EasyTable(items=(
                        (Gtk.Label(label=_('Current user:'******'Home directory:')),
                         Gtk.Label(label=GLib.get_home_dir())),
                        (Gtk.Label(label=_('Shell:')),
                         Gtk.Label(label=GLib.getenv('SHELL'))),
                        (Gtk.Label(label=_('Language:')),
                         Gtk.Label(label=GLib.getenv('LANG')))),
                        xpadding=12, ypadding=2)

        self.add_content(self.table)

        self.show_all()
Example #17
0
    def __init__(self):
        Clip.__init__(self)

        self.table = EasyTable(items=((Gtk.Label(label=_('Current user:'******'Home directory:')),
                                       Gtk.Label(label=GLib.get_home_dir())),
                                      (Gtk.Label(label=_('Shell:')),
                                       Gtk.Label(label=GLib.getenv('SHELL'))),
                                      (Gtk.Label(label=_('Language:')),
                                       Gtk.Label(label=GLib.getenv('LANG')))),
                               xpadding=12,
                               ypadding=2)

        self.add_content(self.table)

        self.show_all()
Example #18
0
import re
import argparse
import shlex
import os
import subprocess
from gi.repository import Gtk, GLib

import psutil
old_psutil_format = isinstance(psutil.Process.username, property)

import light_locker_xfsync

''' Settings window for the light-locker '''

username = GLib.get_user_name()


screensaver_managers = {
    'xfce4-power-manager': (_("Xfce Power Manager"), "xfce4-power-manager -c")
}


class LightLockerSettings:
    '''Light Locker Settings application class.'''

    def __init__(self):
        '''Initialize the Light Locker Settings application.'''
        self.systemwide_desktop_file = \
            "/etc/xdg/autostart/light-locker.desktop"
        self.user_desktop_file = os.path.join(os.path.expanduser('~'),
Example #19
0
 def auth_pam(self):
     if not pam.authenticate(GLib.get_user_name(), self.current_password.get_text(), 'passwd'):
         raise PasswordError("Invalid password")
Example #20
0
 def auth_pam(self):
     if not pam.pam().authenticate(GLib.get_user_name(), self.current_password.get_text(), 'passwd'):
         raise PasswordError("Invalid password")
Example #21
0
    def __init__(self):

        # load our glade ui file in
        self.builder = Gtk.Builder()
        self.builder.set_translation_domain("mintlocale")
        self.builder.add_from_file('/usr/lib/linuxmint/mintLocale/mintLocale.ui')
        
        self.window = self.builder.get_object( "main_window" )
               
        self.builder.get_object("main_window").connect("destroy", Gtk.main_quit)        
                              
        # set up larger components.
        self.builder.get_object("main_window").set_title(_("Language Settings"))
        self.builder.get_object("main_window").connect("destroy", Gtk.main_quit)
        
        self.locale_button = PictureChooserButton(num_cols=2, button_picture_size=16, has_button_label=True)
        self.region_button = PictureChooserButton(num_cols=2, button_picture_size=16, has_button_label=True)
      
        self.locale_system_wide_button = Gtk.Button()
        self.locale_system_wide_button.set_label(_("Apply System-Wide"))
        self.locale_system_wide_button.connect("clicked", self.button_system_language_clicked)

        self.locale_install_button = Gtk.Button()
        self.locale_install_button.set_label(_("Install / Remove Languages..."))
        self.locale_install_button.connect("clicked", self.button_install_remove_clicked)      

        self.system_label = Gtk.Label()
        self.install_label = Gtk.Label()

        bg = SectionBg()
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        bg.add(vbox)
        
        language_section = Section(_("Language"))
        label = "%s\n<small><i><span foreground='#3C3C3C'>%s</span></i></small>" % (_("Language"), _("Language, interface, date and time..."))
        language_section.add(self.make_group(label, self.locale_button))
        label = "%s\n<small><i><span foreground='#3C3C3C'>%s</span></i></small>" % (_("Region"), _("Numbers, currency, addresses, measurement..."))
        language_section.add(self.make_group(label, self.region_button))        
        vbox.add(language_section)
        
        vbox.add(Gtk.Separator.new(Gtk.Orientation.HORIZONTAL))

        
        self.im_combo = Gtk.ComboBox()  
        model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
        cell = Gtk.CellRendererText()
        self.im_combo.pack_start(cell, True)
        self.im_combo.add_attribute(cell, 'text', IM_NAME)
        self.im_combo.set_model(model)

        self.ImConfig = ImConfig()
        im_section = Section(_("Input method"))

        label = Gtk.Label()
        label.set_markup("<small><i><span foreground='#3C3C3C'>%s</span></i></small>" % (_("Input methods are used to write symbols and characters which are not present on the keyboard. They are useful to write in Chinese, Japanese, Korean, Thai, Vietnamese...")))
        label.set_line_wrap(True)
        im_section.add(label)
                
        im_section.add(self.make_group(_("Input method"), self.im_combo))
        
        self.ibus_label = Gtk.Label()
        self.ibus_label.set_line_wrap(True)
        self.ibus_button = Gtk.Button()        
        self.ibus_button.connect('clicked', self.install_im, 'ibus')

        self.fcitx_label = Gtk.Label()
        self.fcitx_label.set_line_wrap(True)
        self.fcitx_button = Gtk.Button()
        self.fcitx_button.connect('clicked', self.install_im, 'fcitx')

        self.scim_label = Gtk.Label()
        self.scim_label.set_line_wrap(True)
        self.scim_button = Gtk.Button()
        self.scim_button.connect('clicked', self.install_im, 'scim')

        self.uim_label = Gtk.Label()       
        self.uim_label.set_line_wrap(True)
        self.uim_button = Gtk.Button()
        self.uim_button.connect('clicked', self.install_im, 'uim')

        vbox.add(im_section)
        
        self.im_combo.connect("changed", self.on_combobox_input_method_changed)

        self.builder.get_object("box1").pack_start(bg, True, True, 6)

        bg.show_all()       
        
        self.pam_environment_path = os.path.join(GLib.get_home_dir(), ".pam_environment")
        self.dmrc_path = os.path.join(GLib.get_home_dir(), ".dmrc")
        self.dmrc = ConfigParser.ConfigParser()
        self.dmrc.optionxform=str # force case sensitivity on ConfigParser
        self.dmrc.read(self.dmrc_path)
        if not self.dmrc.has_section('Desktop'):
            self.dmrc.add_section('Desktop')

        current_user = GLib.get_user_name()        

        self.current_language = None        
        dmrc_language = None
        env_language = os.environ['LANG']        
        
        if self.dmrc.has_option('Desktop', 'Language'):
            dmrc_language = self.dmrc.get('Desktop', 'Language')
        
        if dmrc_language is not None:
            self.current_language = dmrc_language
        else:
            self.current_language = env_language

        print "User language in .dmrc: %s" % dmrc_language
        print "User language in $LANG: %s" % env_language
        print "Current language: %s" % self.current_language

        self.current_region = None
        pam_region = None
        env_region = os.environ['LC_NUMERIC']

        if os.path.exists(self.pam_environment_path):
            with open(self.pam_environment_path, 'r') as pam_file:
                for line in pam_file:
                    line = line.strip()
                    if line.startswith("LC_NUMERIC="):
                        pam_region = line.split("=")[1]             

        if pam_region is not None:
            self.current_region = pam_region
        else:
            self.current_region = env_region

        print "User region in .pam_environment: %s" % pam_region
        print "User language in $LC_NUMERIC: %s" % env_region
        print "Current region: %s" % self.current_region

        self.build_lang_list()
        self.set_system_locale()
        self.set_num_installed()

        self.accountService = AccountsService.UserManager.get_default().get_user(current_user)
        self.accountService.connect('notify::is-loaded', self.accountservice_ready)
        self.accountService.connect('changed::', self.accountservice_changed)

        groups = grp.getgrall()
        for group in groups:
            (name, pw, gid, mem) = group
            if name in ("adm", "sudo"):
                for user in mem:
                    if current_user == user:                        
                        language_section.add(self.make_group(self.system_label, self.locale_system_wide_button))        
                        language_section.add(self.make_group(self.install_label, self.locale_install_button)) 
                        language_section.show_all()
                        im_section.add(self.make_group(self.ibus_label, self.ibus_button))
                        im_section.add(self.make_group(self.fcitx_label, self.fcitx_button))
                        im_section.add(self.make_group(self.scim_label, self.scim_button))
                        im_section.add(self.make_group(self.uim_label, self.uim_button))
                        im_section.show_all()
                        break

        self.read_im_info()
        self.check_input_methods()
Example #22
0
 def GetRemoteMachineInfo(self, request, context):
     return warp_pb2.RemoteMachineInfo(display_name=GLib.get_real_name(),
                                       user_name=GLib.get_user_name())
Example #23
0
    def __init__(self):

        # Determine path to system locale-config
        self.locale_path=''

        if os.path.exists('/etc/default/locale'):
            self.locale_path='/etc/default/locale'
        else:
            self.locale_path='/etc/locale.conf'

        # Prepare the APT cache
        if IS_DEBIAN:
            self.cache = apt.Cache()
        self.cache_updated = False

        # load our glade ui file in
        self.builder = Gtk.Builder()
        self.builder.set_translation_domain("mintlocale")
        self.builder.add_from_file('/usr/share/linuxmint/mintlocale/mintlocale.ui')

        self.window = self.builder.get_object("main_window")
        self.window.set_title(_("Language Settings"))
        self.window.connect("destroy", Gtk.main_quit)
        XApp.set_window_icon_name(self.window, "preferences-desktop-locale")

        self.toolbar = Gtk.Toolbar()
        self.toolbar.get_style_context().add_class("primary-toolbar")
        self.builder.get_object("box1").pack_start(self.toolbar, False, False, 0)


        size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

        self.locale_button = PictureChooserButton(num_cols=2, button_picture_size=BUTTON_FLAG_SIZE, has_button_label=True)
        size_group.add_widget(self.locale_button)
        self.region_button = PictureChooserButton(num_cols=2, button_picture_size=BUTTON_FLAG_SIZE, has_button_label=True)
        size_group.add_widget(self.region_button)

        self.locale_system_wide_button = Gtk.Button()
        self.locale_system_wide_button.set_label(_("Apply System-Wide"))
        self.locale_system_wide_button.connect("clicked", self.button_system_language_clicked)
        size_group.add_widget(self.locale_system_wide_button)

        self.locale_install_button = Gtk.Button()
        self.locale_install_button.set_label(_("Install / Remove Languages..."))
        self.locale_install_button.connect("clicked", self.button_install_remove_clicked)
        size_group.add_widget(self.locale_install_button)

        self.system_label = Gtk.Label()
        self.install_label = Gtk.Label()

        page = SettingsPage()
        self.builder.get_object("box1").pack_start(page, True, True, 0)

        language_settings = page.add_section()

        label = Gtk.Label.new()
        label.set_markup("<b>%s</b>\n<small>%s</small>" % (_("Language"), _("Language, interface, date and time...")))
        row = SettingsRow(label, self.locale_button)
        language_settings.add_row(row)

        label = Gtk.Label.new()
        label.set_markup("<b>%s</b>\n<small>%s</small>" % (_("Region"), _("Numbers, currency, addresses, measurement...")))
        row = SettingsRow(label, self.region_button)
        language_settings.add_row(row)

        self.system_row = SettingsRow(self.system_label, self.locale_system_wide_button)
        self.system_row.set_no_show_all(True)
        language_settings.add_row(self.system_row)

        self.install_row = SettingsRow(self.install_label, self.locale_install_button)
        self.install_row.set_no_show_all(True)
        if IS_DEBIAN:
            language_settings.add_row(self.install_row)

        self.pam_environment_path = os.path.join(GLib.get_home_dir(), ".pam_environment")
        self.dmrc_path = os.path.join(GLib.get_home_dir(), ".dmrc")
        self.dmrc = configparser.ConfigParser()
        self.dmrc.optionxform = str  # force case sensitivity on ConfigParser
        self.dmrc.read(self.dmrc_path)
        if not self.dmrc.has_section('Desktop'):
            self.dmrc.add_section('Desktop')

        current_user = GLib.get_user_name()

        self.current_language = None
        dmrc_language = None
        env_language = os.environ['LANG']

        if self.dmrc.has_option('Desktop', 'Language'):
            dmrc_language = self.dmrc.get('Desktop', 'Language')

        if dmrc_language is not None:
            self.current_language = dmrc_language
        else:
            self.current_language = env_language

        print("User language in .dmrc: %s" % dmrc_language)
        print("User language in $LANG: %s" % env_language)
        print("Current language: %s" % self.current_language)

        if 'LC_NUMERIC' in os.environ:
            self.current_region = os.environ['LC_NUMERIC']
        else:
            self.current_region = self.current_language

        if os.path.exists(self.pam_environment_path):
            with codecs.open(self.pam_environment_path, 'r', encoding='UTF-8') as pam_file:
                for line in pam_file:
                    line = line.strip()
                    if line.startswith("LC_NUMERIC="):
                        self.current_region = line.split("=")[1].replace("\"", "").replace("'", "").strip()

        print("Current region: %s" % self.current_region)

        # Replace utf8 with UTF-8 (lightDM GTK greeter messes that up)
        self.current_language = self.current_language.replace(".utf8", ".UTF-8")
        self.current_region = self.current_region.replace(".utf8", ".UTF-8")

        self.build_lang_list()
        self.set_system_locale()
        self.set_num_installed()

        self.accountService = AccountsService.UserManager.get_default().get_user(current_user)
        self.accountService.connect('notify::is-loaded', self.accountservice_ready)
        self.accountService.connect('changed::', self.accountservice_changed)

        groups = grp.getgrall()
        for group in groups:
            (name, pw, gid, mem) = group
            if name in ("adm", "sudo", "wheel", "root"):
                for user in mem:
                    if current_user == user:
                        self.system_row.set_no_show_all(False)
                        self.install_row.set_no_show_all(False)
                        language_settings.show_all()
                        break

        self.window.show_all()
Example #24
0
    def __init__(self):

        # load our glade ui file in
        self.builder = Gtk.Builder()
        self.builder.set_translation_domain("mintlocale")
        self.builder.add_from_file(
            '/usr/lib/linuxmint/mintLocale/mintLocale.ui')

        self.window = self.builder.get_object("main_window")

        self.builder.get_object("main_window").connect("destroy",
                                                       Gtk.main_quit)

        # set up larger components.
        self.builder.get_object("main_window").set_title(
            _("Language Settings"))

        toolbar = Gtk.Toolbar()
        toolbar.get_style_context().add_class("primary-toolbar")
        self.builder.get_object("box1").pack_start(toolbar, False, False, 0)

        stack = Gtk.Stack()
        stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
        stack.set_transition_duration(150)
        self.builder.get_object("box1").pack_start(stack, True, True, 0)

        stack_switcher = Gtk.StackSwitcher()
        stack_switcher.set_stack(stack)

        tool_item = Gtk.ToolItem()
        tool_item.set_expand(True)
        tool_item.get_style_context().add_class("raised")
        toolbar.insert(tool_item, 0)
        switch_holder = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        switch_holder.set_border_width(1)
        tool_item.add(switch_holder)
        switch_holder.pack_start(stack_switcher, True, True, 0)
        stack_switcher.set_halign(Gtk.Align.CENTER)
        toolbar.show_all()

        size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

        self.locale_button = PictureChooserButton(num_cols=2,
                                                  button_picture_size=16,
                                                  has_button_label=True)
        size_group.add_widget(self.locale_button)
        self.region_button = PictureChooserButton(num_cols=2,
                                                  button_picture_size=16,
                                                  has_button_label=True)
        size_group.add_widget(self.region_button)

        self.locale_system_wide_button = Gtk.Button()
        self.locale_system_wide_button.set_label(_("Apply System-Wide"))
        self.locale_system_wide_button.connect(
            "clicked", self.button_system_language_clicked)
        size_group.add_widget(self.locale_system_wide_button)

        self.locale_install_button = Gtk.Button()
        self.locale_install_button.set_label(
            _("Install / Remove Languages..."))
        self.locale_install_button.connect("clicked",
                                           self.button_install_remove_clicked)
        size_group.add_widget(self.locale_install_button)

        self.system_label = Gtk.Label()
        self.install_label = Gtk.Label()

        page = SettingsPage()
        stack.add_titled(page, "language", _("Language"))

        language_settings = page.add_section(_("Language"))

        row = SettingsRow(self.locale_button)
        label = Gtk.Label.new()
        label.set_markup(
            "<b>%s</b>\n<small>%s</small>" %
            (_("Language"), _("Language, interface, date and time...")))
        row.add_label(label)
        language_settings.add_row(row)

        row = SettingsRow(self.region_button)
        label = Gtk.Label.new()
        label.set_markup(
            "<b>%s</b>\n<small>%s</small>" %
            (_("Region"), _("Numbers, currency, addresses, measurement...")))
        row.add_label(label)
        language_settings.add_row(row)

        self.system_row = SettingsRow(self.locale_system_wide_button)
        self.system_row.add_label(self.system_label)
        self.system_row.set_no_show_all(True)
        language_settings.add_row(self.system_row)

        self.install_row = SettingsRow(self.locale_install_button)
        self.install_row.add_label(self.install_label)
        self.install_row.set_no_show_all(True)
        language_settings.add_row(self.install_row)

        page = SettingsPage()
        stack.add_titled(page, "input settings", _("Input method"))

        size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

        self.im_combo = Gtk.ComboBox()
        model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
        cell = Gtk.CellRendererText()
        self.im_combo.pack_start(cell, True)
        self.im_combo.add_attribute(cell, 'text', IM_NAME)
        self.im_combo.set_model(model)
        size_group.add_widget(self.im_combo)

        self.ImConfig = ImConfig()

        label = Gtk.Label()
        label.set_markup("<small><i>%s</i></small>" % (_(
            "Input methods are used to write symbols and characters which are not present on the keyboard. They are useful to write in Chinese, Japanese, Korean, Thai, Vietnamese..."
        )))
        label.set_line_wrap(True)
        page.add(label)

        self.input_settings = page.add_section(_("Input method"))

        row = SettingsRow(self.im_combo)
        label = Gtk.Label(_("Input method"))
        row.add_label(label)
        self.input_settings.add_row(row)

        self.ibus_label = Gtk.Label()
        self.ibus_label.set_line_wrap(True)
        self.ibus_button = Gtk.Button()
        size_group.add_widget(self.ibus_button)
        self.ibus_button.connect('clicked', self.install_im, 'ibus')
        self.ibus_row = SettingsRow(self.ibus_button)
        self.ibus_row.add_label(self.ibus_label)
        self.ibus_row.set_no_show_all(True)
        self.input_settings.add_row(self.ibus_row)

        self.fcitx_label = Gtk.Label()
        self.fcitx_label.set_line_wrap(True)
        self.fcitx_button = Gtk.Button()
        size_group.add_widget(self.fcitx_button)
        self.fcitx_button.connect('clicked', self.install_im, 'fcitx')
        self.fcitx_row = SettingsRow(self.fcitx_button)
        self.fcitx_row.add_label(self.fcitx_label)
        self.fcitx_row.set_no_show_all(True)
        self.input_settings.add_row(self.fcitx_row)

        self.scim_label = Gtk.Label()
        self.scim_label.set_line_wrap(True)
        self.scim_button = Gtk.Button()
        size_group.add_widget(self.scim_button)
        self.scim_button.connect('clicked', self.install_im, 'scim')
        self.scim_row = SettingsRow(self.scim_button)
        self.scim_row.add_label(self.scim_label)
        self.scim_row.set_no_show_all(True)
        self.input_settings.add_row(self.scim_row)

        self.uim_label = Gtk.Label()
        self.uim_label.set_line_wrap(True)
        self.uim_button = Gtk.Button()
        size_group.add_widget(self.uim_button)
        self.uim_button.connect('clicked', self.install_im, 'uim')
        self.uim_row = SettingsRow(self.uim_button)
        self.uim_row.add_label(self.uim_label)
        self.uim_row.set_no_show_all(True)
        self.input_settings.add_row(self.uim_row)

        self.gcin_label = Gtk.Label()
        self.gcin_label.set_line_wrap(True)
        self.gcin_button = Gtk.Button()
        size_group.add_widget(self.gcin_button)
        self.gcin_button.connect('clicked', self.install_im, 'gcin')
        self.gcin_row = SettingsRow(self.gcin_button)
        self.gcin_row.add_label(self.gcin_label)
        self.gcin_row.set_no_show_all(True)
        self.input_settings.add_row(self.gcin_row)

        self.im_loaded = False  # don't react to im changes until we're fully loaded (we're loading that combo asynchronously)
        self.im_combo.connect("changed", self.on_combobox_input_method_changed)

        stack.show_all()

        self.pam_environment_path = os.path.join(GLib.get_home_dir(),
                                                 ".pam_environment")
        self.dmrc_path = os.path.join(GLib.get_home_dir(), ".dmrc")
        self.dmrc = ConfigParser.ConfigParser()
        self.dmrc.optionxform = str  # force case sensitivity on ConfigParser
        self.dmrc.read(self.dmrc_path)
        if not self.dmrc.has_section('Desktop'):
            self.dmrc.add_section('Desktop')

        current_user = GLib.get_user_name()

        self.current_language = None
        dmrc_language = None
        env_language = os.environ['LANG']

        if self.dmrc.has_option('Desktop', 'Language'):
            dmrc_language = self.dmrc.get('Desktop', 'Language')

        if dmrc_language is not None:
            self.current_language = dmrc_language
        else:
            self.current_language = env_language

        print "User language in .dmrc: %s" % dmrc_language
        print "User language in $LANG: %s" % env_language
        print "Current language: %s" % self.current_language

        if 'LC_NUMERIC' in os.environ:
            self.current_region = os.environ['LC_NUMERIC']
        else:
            self.current_region = self.current_language

        if os.path.exists(self.pam_environment_path):
            with open(self.pam_environment_path, 'r') as pam_file:
                for line in pam_file:
                    line = line.strip()
                    if line.startswith("LC_NUMERIC="):
                        self.current_region = line.split("=")[1].replace(
                            "\"", "").replace("'", "").strip()

        print "Current region: %s" % self.current_region

        # Replace utf8 with UTF-8 (lightDM GTK greeter messes that up)
        self.current_language = self.current_language.replace(
            ".utf8", ".UTF-8")
        self.current_region = self.current_region.replace(".utf8", ".UTF-8")

        self.build_lang_list()
        self.set_system_locale()
        self.set_num_installed()

        self.accountService = AccountsService.UserManager.get_default(
        ).get_user(current_user)
        self.accountService.connect('notify::is-loaded',
                                    self.accountservice_ready)
        self.accountService.connect('changed::', self.accountservice_changed)

        groups = grp.getgrall()
        for group in groups:
            (name, pw, gid, mem) = group
            if name in ("adm", "sudo"):
                for user in mem:
                    if current_user == user:
                        self.system_row.set_no_show_all(False)
                        self.install_row.set_no_show_all(False)
                        language_settings.show_all()
                        self.ibus_row.set_no_show_all(False)
                        self.fcitx_row.set_no_show_all(False)
                        self.scim_row.set_no_show_all(False)
                        self.uim_row.set_no_show_all(False)
                        self.gcin_row.set_no_show_all(False)
                        self.input_settings.hide()
                        break

        self.read_im_info()
        self.check_input_methods()
Example #25
0
def get_user_name():
    name = GLib.get_real_name()
    if name == "":
        name = GLib.get_user_name()
    return name
Example #26
0
#!/usr/bin/python3

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk, WebKit2, GLib

HISTORY_FILE = '/home/' + GLib.get_user_name() + '/.fullhistory.html'
HOME_PAGE = "https://ya.ru"


def on_destroy(win):
    Gtk.main_quit()


def op_page(url):
    urlent.set_text(url)
    webvw.load_uri(url)


def op_history(bttn):
    op_page('file://' + HISTORY_FILE)


def on_load_changed(webvw, event):
    url = webvw.get_uri()
    hist_file = open(HISTORY_FILE, 'a+')
    hist_file.writelines('* <a href="' + url + '">' + url + '</a></br>')
    hist_file.close()

import argparse
import shlex
import os
import subprocess
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib, Gio

import psutil
old_psutil_format = isinstance(psutil.Process.username, property)

import light_locker_xfsync

''' Settings window for the light-locker '''

username = GLib.get_user_name()


screensaver_managers = {
    'xfce4-power-manager': (_("Xfce Power Manager"), "xfce4-power-manager -c")
}


class LightLockerSettings:
    '''Light Locker Settings application class.'''

    def __init__(self):
        '''Initialize the Light Locker Settings application.'''
        self.light_locker_keyfile = None
        self.screensaver_keyfile = None
Example #28
0
def _make_installconfig(script, osobj, unattended_data, arch, hostname, url):
    """
    Build a Libosinfo.InstallConfig instance
    """
    def get_timezone():
        TZ_FILE = "/etc/localtime"
        localtime = Gio.File.new_for_path(TZ_FILE)
        if not localtime.query_exists():
            return None
        info = localtime.query_info(Gio.FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
                                    Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)
        if not info:
            return None
        target = info.get_symlink_target()
        if not target:
            return None
        tokens = target.split("zoneinfo/")
        if not tokens or len(tokens) < 2:
            return None
        return tokens[1]

    def get_language():
        names = GLib.get_language_names()
        if not names or len(names) < 2:
            return None
        return names[1]

    config = Libosinfo.InstallConfig()

    # Set user login and name based on the one from the system
    config.set_user_login(GLib.get_user_name())
    config.set_user_realname(GLib.get_real_name())

    # Set user-password.
    # In case it's required and not passed, just raise a RuntimeError.
    if script.requires_user_password() and not unattended_data.user_password:
        raise RuntimeError(
            _("%s requires the user-password to be set.") % osobj.name)
    config.set_user_password(
        unattended_data.user_password if unattended_data.user_password else "")

    # Set the admin-password:
    # In case it's required and not passed, just raise a RuntimeError.
    if script.requires_admin_password() and not unattended_data.admin_password:
        raise RuntimeError(
            _("%s requires the admin-password to be set.") % osobj.name)
    config.set_admin_password(unattended_data.admin_password
                              if unattended_data.admin_password else "")

    # Set the target disk.
    # virtiodisk is the preferred way, in case it's supported, otherwise
    # just fallback to scsi.
    #
    # Note: this is linux specific and will require some changes whenever
    # support for Windows will be added.
    tgt = "/dev/vda" if osobj.supports_virtiodisk() else "/dev/sda"
    config.set_target_disk(tgt)

    # Set hardware architecture and hostname
    config.set_hardware_arch(arch)
    config.set_hostname(hostname)

    # Try to guess the timezone from '/etc/localtime', in case it's not
    # possible 'America/New_York' will be used.
    timezone = get_timezone()
    if timezone:
        config.set_l10n_timezone(timezone)
    else:
        logging.warning(
            _("'America/New_York' timezone will be used for this "
              "unattended installation."))

    # Try to guess to language and keyboard layout from the system's
    # language.
    #
    # This method has flows as it's quite common to have language and
    # keyboard layout not matching. Otherwise, there's no easy way to guess
    # the keyboard layout without relying on a set of APIs of an specific
    # Desktop Environment.
    language = get_language()
    if language:
        config.set_l10n_language(language)
        config.set_l10n_keyboard(language)
    else:
        logging.warning(
            _("'en_US' will be used as both language and keyboard layout "
              "for unattended installation."))

    if url:
        config.set_installation_url(url)  # pylint: disable=no-member

    logging.debug("InstallScriptConfig created with the following params:")
    logging.debug("username: %s", config.get_user_login())
    logging.debug("realname: %s", config.get_user_realname())
    logging.debug("user password: %s", config.get_user_password())
    logging.debug("admin password: %s", config.get_admin_password())
    logging.debug("target disk: %s", config.get_target_disk())
    logging.debug("hardware arch: %s", config.get_hardware_arch())
    logging.debug("hostname: %s", config.get_hostname())
    logging.debug("timezone: %s", config.get_l10n_timezone())
    logging.debug("language: %s", config.get_l10n_language())
    logging.debug("keyboard: %s", config.get_l10n_keyboard())
    logging.debug("url: %s", config.get_installation_url())  # pylint: disable=no-member

    return config
Example #29
0
    def on_module_selected(self):
        if not self.loaded:
            print "Loading User module"

            page = SettingsPage()
            self.sidePage.add_widget(page)

            settings = page.add_section(_("Account details"))

            self.face_button = PictureChooserButton(num_cols=4, button_picture_size=64, menu_pictures_size=64)
            self.face_button.set_alignment(0.0, 0.5)
            self.face_button.set_tooltip_text(_("Click to change your picture"))

            self.face_photo_menuitem = Gtk.MenuItem.new_with_label(_("Take a photo..."))
            self.face_photo_menuitem.connect('activate', self._on_face_photo_menuitem_activated)

            self.face_browse_menuitem = Gtk.MenuItem.new_with_label(_("Browse for more pictures..."))
            self.face_browse_menuitem.connect('activate', self._on_face_browse_menuitem_activated)

            face_dirs = ["/usr/share/cinnamon/faces"]
            for face_dir in face_dirs:
                if os.path.exists(face_dir):
                    pictures = sorted(os.listdir(face_dir))
                    for picture in pictures:
                        path = os.path.join(face_dir, picture)
                        self.face_button.add_picture(path, self._on_face_menuitem_activated)

            widget = SettingsWidget()
            label = Gtk.Label.new(_("Picture"))
            widget.pack_start(label, False, False, 0)
            widget.pack_end(self.face_button, False, False, 0)
            settings.add_row(widget)

            size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

            widget = SettingsWidget()
            label = Gtk.Label.new(_("Name"))
            widget.pack_start(label, False, False, 0)
            self.realname_entry = EditableEntry()
            size_group.add_widget(self.realname_entry)
            self.realname_entry.connect("changed", self._on_realname_changed)
            self.realname_entry.set_tooltip_text(_("Click to change your name"))
            widget.pack_end(self.realname_entry, False, False, 0)
            settings.add_row(widget)

            widget = SettingsWidget()
            label = Gtk.Label.new(_("Password"))
            widget.pack_start(label, False, False, 0)
            password_mask = Gtk.Label.new(u'\u2022\u2022\u2022\u2022\u2022\u2022')
            password_mask.set_alignment(0.9, 0.5)
            self.password_button = Gtk.Button()
            size_group.add_widget(self.password_button)
            self.password_button.add(password_mask)
            self.password_button.set_relief(Gtk.ReliefStyle.NONE)
            self.password_button.set_tooltip_text(_("Click to change your password"))
            self.password_button.connect('activate', self._on_password_button_clicked)
            self.password_button.connect('released', self._on_password_button_clicked)
            widget.pack_end(self.password_button, False, False, 0)
            settings.add_row(widget)

            current_user = GLib.get_user_name()
            self.accountService = AccountsService.UserManager.get_default().get_user(current_user)
            self.accountService.connect('notify::is-loaded', self.load_user_info)

            self.face_button.add_separator()

            # Video devices assumed to be webcams
            import glob
            webcam_detected = len(glob.glob("/dev/video*")) > 0

            if webcam_detected:
                self.face_button.add_menuitem(self.face_photo_menuitem)

            self.face_button.add_menuitem(self.face_browse_menuitem)
Example #30
0
    def __init__(self):

        # Determine path to system locale-config
        self.locale_path = ''

        if os.path.exists('/etc/default/locale'):
            self.locale_path = '/etc/default/locale'
        else:
            self.locale_path = '/etc/locale.conf'

        # Prepare the APT cache
        if IS_DEBIAN:
            self.cache = apt.Cache()
        self.cache_updated = False

        # load our glade ui file in
        self.builder = Gtk.Builder()
        self.builder.set_translation_domain("mintlocale")
        self.builder.add_from_file(
            '/usr/share/linuxmint/mintlocale/mintlocale.ui')

        self.window = self.builder.get_object("main_window")
        self.window.set_title(_("Language Settings"))
        self.window.connect("destroy", Gtk.main_quit)
        XApp.set_window_icon_name(self.window, "preferences-desktop-locale")

        self.scale = self.window.get_scale_factor()

        self.toolbar = Gtk.Toolbar()
        self.toolbar.get_style_context().add_class("primary-toolbar")
        self.builder.get_object("box1").pack_start(self.toolbar, False, False,
                                                   0)

        size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

        self.locale_button = PictureChooserButton(num_cols=2,
                                                  has_button_label=True,
                                                  scale=self.scale)
        size_group.add_widget(self.locale_button)
        self.region_button = PictureChooserButton(num_cols=2,
                                                  has_button_label=True,
                                                  scale=self.scale)
        size_group.add_widget(self.region_button)
        self.time_button = PictureChooserButton(num_cols=2,
                                                has_button_label=True,
                                                scale=self.scale)
        size_group.add_widget(self.time_button)

        self.locale_system_wide_button = Gtk.Button()
        self.locale_system_wide_button.set_label(_("Apply System-Wide"))
        self.locale_system_wide_button.connect(
            "clicked", self.button_system_language_clicked)
        size_group.add_widget(self.locale_system_wide_button)

        self.locale_install_button = Gtk.Button()
        self.locale_install_button.set_label(
            _("Install / Remove Languages..."))
        self.locale_install_button.connect("clicked",
                                           self.button_install_remove_clicked)
        size_group.add_widget(self.locale_install_button)

        self.system_label = Gtk.Label()
        self.install_label = Gtk.Label()

        page = SettingsPage()
        self.builder.get_object("box1").pack_start(page, True, True, 0)

        language_settings = page.add_section()

        label = Gtk.Label.new()
        label.set_markup("<b>%s</b>\n<small>%s</small>" %
                         (_("Language"), _("Language, interface...")))
        row = SettingsRow(label, self.locale_button)
        language_settings.add_row(row)

        label = Gtk.Label.new()
        label.set_markup(
            "<b>%s</b>\n<small>%s</small>" %
            (_("Region"), _("Numbers, currency, addresses, measurement...")))
        row = SettingsRow(label, self.region_button)
        language_settings.add_row(row)

        label = Gtk.Label.new()
        label.set_markup("<b>%s</b>\n<small>%s</small>" %
                         (_("Time format"), _("Date and time...")))
        row = SettingsRow(label, self.time_button)
        language_settings.add_row(row)

        self.system_row = SettingsRow(self.system_label,
                                      self.locale_system_wide_button)
        self.system_row.set_no_show_all(True)
        language_settings.add_row(self.system_row)

        self.install_row = SettingsRow(self.install_label,
                                       self.locale_install_button)
        self.install_row.set_no_show_all(True)
        if IS_DEBIAN:
            language_settings.add_row(self.install_row)

        self.pam_environment_path = os.path.join(GLib.get_home_dir(),
                                                 ".pam_environment")
        self.xsessionrc_path = os.path.join(GLib.get_home_dir(), ".xsessionrc")
        self.dmrc_path = os.path.join(GLib.get_home_dir(), ".dmrc")
        self.dmrc = configparser.ConfigParser()
        self.dmrc.optionxform = str  # force case sensitivity on ConfigParser
        self.dmrc.read(self.dmrc_path)
        if not self.dmrc.has_section('Desktop'):
            self.dmrc.add_section('Desktop')

        current_user = GLib.get_user_name()

        self.current_language = None
        dmrc_language = None
        env_language = os.environ['LANG']

        if self.dmrc.has_option('Desktop', 'Language'):
            dmrc_language = self.dmrc.get('Desktop', 'Language')

        if dmrc_language is not None:
            self.current_language = dmrc_language
        else:
            self.current_language = env_language

        print("User language in .dmrc: %s" % dmrc_language)
        print("User language in $LANG: %s" % env_language)
        print("Current language: %s" % self.current_language)

        if 'LC_NUMERIC' in os.environ:
            self.current_region = os.environ['LC_NUMERIC']
        else:
            self.current_region = self.current_language

        if 'LC_TIME' in os.environ:
            self.current_time = os.environ['LC_TIME']
        else:
            self.current_time = self.current_language

        if os.path.exists(self.pam_environment_path):
            with codecs.open(self.pam_environment_path, 'r',
                             encoding='UTF-8') as pam_file:
                for line in pam_file:
                    line = line.strip()
                    if line.startswith("LC_NUMERIC="):
                        self.current_region = line.split("=")[1].replace(
                            "\"", "").replace("'", "").strip()
                    if line.startswith("LC_TIME="):
                        self.current_time = line.split("=")[1].replace(
                            "\"", "").replace("'", "").strip()

        print("Current region: %s" % self.current_region)
        print("Current time: %s" % self.current_time)

        # Replace utf8 with UTF-8 (lightDM GTK greeter messes that up)
        self.current_language = self.current_language.replace(
            ".utf8", ".UTF-8")
        self.current_region = self.current_region.replace(".utf8", ".UTF-8")
        self.current_time = self.current_time.replace(".utf8", ".UTF-8")

        self.build_lang_list()
        self.set_system_locale()
        self.set_num_installed()

        self.accountService = AccountsService.UserManager.get_default(
        ).get_user(current_user)
        self.accountService.connect('notify::is-loaded',
                                    self.accountservice_ready)

        groups = grp.getgrall()
        for group in groups:
            (name, pw, gid, mem) = group
            if name in ("adm", "sudo", "wheel", "root"):
                for user in mem:
                    if current_user == user:
                        self.system_row.set_no_show_all(False)
                        self.install_row.set_no_show_all(False)
                        language_settings.show_all()
                        break

        self.window.show_all()
Example #31
0
    def on_module_selected(self):
        if not self.loaded:
            print "Loading User module"

            self.face_button = PictureChooserButton(num_cols=4,
                                                    button_picture_size=96,
                                                    menu_pictures_size=64)
            self.face_button.set_alignment(0.0, 0.5)
            self.face_button.set_tooltip_text(
                _("Click to change your picture"))

            self.face_photo_menuitem = Gtk.MenuItem.new_with_label(
                _("Take a photo..."))
            self.face_photo_menuitem.connect(
                'activate', self._on_face_photo_menuitem_activated)

            self.face_browse_menuitem = Gtk.MenuItem.new_with_label(
                _("Browse for more pictures..."))
            self.face_browse_menuitem.connect(
                'activate', self._on_face_browse_menuitem_activated)

            face_dirs = ["/usr/share/cinnamon/faces"]
            for face_dir in face_dirs:
                if os.path.exists(face_dir):
                    pictures = sorted(os.listdir(face_dir))
                    for picture in pictures:
                        path = os.path.join(face_dir, picture)
                        self.face_button.add_picture(
                            path, self._on_face_menuitem_activated)

            self.realname_entry = EditableEntry()
            self.realname_entry.connect("changed", self._on_realname_changed)
            self.realname_entry.set_tooltip_text(
                _("Click to change your name"))

            table = Gtk.Table.new(3, 2, False)
            table.set_row_spacings(8)
            table.set_col_spacings(15)
            self.sidePage.add_widget(table)

            label_picture = Gtk.Label.new(_("Picture:"))
            label_picture.set_alignment(1, 0.5)
            label_picture.get_style_context().add_class("dim-label")
            table.attach(label_picture, 0, 1, 0, 1)

            password_mask = Gtk.Label.new(
                u'\u2022\u2022\u2022\u2022\u2022\u2022')
            password_mask.set_alignment(0.0, 0.5)
            self.password_button = Gtk.Button()
            self.password_button.add(password_mask)
            self.password_button.set_relief(Gtk.ReliefStyle.NONE)
            self.password_button.set_tooltip_text(
                _("Click to change your password"))
            self.password_button.connect('activate',
                                         self._on_password_button_clicked)
            self.password_button.connect('released',
                                         self._on_password_button_clicked)

            label_name = Gtk.Label.new(_("Name:"))
            label_name.set_alignment(1, 0.5)
            label_name.get_style_context().add_class("dim-label")
            table.attach(label_name, 0, 1, 1, 2)

            label_name = Gtk.Label.new(_("Password:"******"dim-label")
            table.attach(label_name, 0, 1, 2, 3)

            box = Gtk.Box()
            box.pack_start(self.face_button, False, False, 0)
            table.attach(box,
                         1,
                         2,
                         0,
                         1,
                         xoptions=Gtk.AttachOptions.EXPAND
                         | Gtk.AttachOptions.FILL)
            table.attach(self.realname_entry,
                         1,
                         2,
                         1,
                         2,
                         xoptions=Gtk.AttachOptions.EXPAND
                         | Gtk.AttachOptions.FILL)
            table.attach(self.password_button,
                         1,
                         2,
                         2,
                         3,
                         xoptions=Gtk.AttachOptions.EXPAND
                         | Gtk.AttachOptions.FILL)

            current_user = GLib.get_user_name()
            self.accountService = AccountsService.UserManager.get_default(
            ).get_user(current_user)
            self.accountService.connect('notify::is-loaded',
                                        self.load_user_info)

            self.face_button.add_separator()

            webcam_detected = False
            try:
                import cv
                capture = cv.CaptureFromCAM(-1)
                for i in range(10):
                    img = cv.QueryFrame(capture)
                    if img != None:
                        webcam_detected = True
            except Exception, detail:
                print detail

            if (webcam_detected):
                self.face_button.add_menuitem(self.face_photo_menuitem)
                self.face_button.add_menuitem(self.face_browse_menuitem)
            else:
                self.face_button.add_menuitem(self.face_browse_menuitem)
Example #32
0
    def __init__(self):

        # load our glade ui file in
        self.builder = Gtk.Builder()
        self.builder.set_translation_domain("mintlocale")
        self.builder.add_from_file('/usr/lib/linuxmint/mintLocale/mintLocale.ui')
        
        self.window = self.builder.get_object( "main_window" )
               
        self.builder.get_object("main_window").connect("destroy", Gtk.main_quit)        
                              
        # set up larger components.
        self.builder.get_object("main_window").set_title(_("Language Settings"))

        toolbar = Gtk.Toolbar()
        toolbar.get_style_context().add_class("primary-toolbar")
        self.builder.get_object("box1").pack_start(toolbar, False, False, 0)

        stack = Gtk.Stack()
        stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
        stack.set_transition_duration(150)
        self.builder.get_object("box1").pack_start(stack, True, True, 0)

        stack_switcher = Gtk.StackSwitcher()
        stack_switcher.set_stack(stack)

        tool_item = Gtk.ToolItem()
        tool_item.set_expand(True)
        tool_item.get_style_context().add_class("raised")
        toolbar.insert(tool_item, 0)
        switch_holder = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        switch_holder.set_border_width(1)
        tool_item.add(switch_holder)
        switch_holder.pack_start(stack_switcher, True, True, 0)
        stack_switcher.set_halign(Gtk.Align.CENTER)
        toolbar.show_all()
        
        size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

        self.locale_button = PictureChooserButton(num_cols=2, button_picture_size=16, has_button_label=True)
        size_group.add_widget(self.locale_button)
        self.region_button = PictureChooserButton(num_cols=2, button_picture_size=16, has_button_label=True)
        size_group.add_widget(self.region_button)

        self.locale_system_wide_button = Gtk.Button()
        self.locale_system_wide_button.set_label(_("Apply System-Wide"))
        self.locale_system_wide_button.connect("clicked", self.button_system_language_clicked)
        size_group.add_widget(self.locale_system_wide_button)

        self.locale_install_button = Gtk.Button()
        self.locale_install_button.set_label(_("Install / Remove Languages..."))
        self.locale_install_button.connect("clicked", self.button_install_remove_clicked)      
        size_group.add_widget(self.locale_install_button)

        self.system_label = Gtk.Label()
        self.install_label = Gtk.Label()

        page = SettingsPage()
        stack.add_titled(page, "language", _("Language"))

        language_settings = page.add_section(_("Language"))

        row = SettingsRow(self.locale_button)
        label = Gtk.Label.new()
        label.set_markup("<b>%s</b>\n<small>%s</small>" % (_("Language"), _("Language, interface, date and time...")))
        row.add_label(label)
        language_settings.add_row(row)

        row = SettingsRow(self.region_button)
        label = Gtk.Label.new()
        label.set_markup("<b>%s</b>\n<small>%s</small>" % (_("Region"), _("Numbers, currency, addresses, measurement...")))
        row.add_label(label)
        language_settings.add_row(row)

        self.system_row = SettingsRow(self.locale_system_wide_button)
        self.system_row.add_label(self.system_label)
        self.system_row.set_no_show_all(True)
        language_settings.add_row(self.system_row)

        self.install_row = SettingsRow(self.locale_install_button)
        self.install_row.add_label(self.install_label)
        self.install_row.set_no_show_all(True)
        language_settings.add_row(self.install_row)

        page = SettingsPage()
        stack.add_titled(page, "input settings", _("Input method"))

        size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)
        
        self.im_combo = Gtk.ComboBox()  
        model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
        cell = Gtk.CellRendererText()
        self.im_combo.pack_start(cell, True)
        self.im_combo.add_attribute(cell, 'text', IM_NAME)
        self.im_combo.set_model(model)
        size_group.add_widget(self.im_combo)

        self.ImConfig = ImConfig()

        label = Gtk.Label()
        label.set_markup("<small><i>%s</i></small>" % (_("Input methods are used to write symbols and characters which are not present on the keyboard. They are useful to write in Chinese, Japanese, Korean, Thai, Vietnamese...")))
        label.set_line_wrap(True)
        page.add(label)

        self.input_settings = page.add_section(_("Input method"))

        row = SettingsRow(self.im_combo)
        label = Gtk.Label(_("Input method"))
        row.add_label(label)
        self.input_settings.add_row(row)
        
        self.ibus_label = Gtk.Label()
        self.ibus_label.set_line_wrap(True)
        self.ibus_button = Gtk.Button()
        size_group.add_widget(self.ibus_button)        
        self.ibus_button.connect('clicked', self.install_im, 'ibus')
        self.ibus_row = SettingsRow(self.ibus_button)
        self.ibus_row.add_label(self.ibus_label)
        self.ibus_row.set_no_show_all(True)
        self.input_settings.add_row(self.ibus_row)

        self.fcitx_label = Gtk.Label()
        self.fcitx_label.set_line_wrap(True)
        self.fcitx_button = Gtk.Button()
        size_group.add_widget(self.fcitx_button)
        self.fcitx_button.connect('clicked', self.install_im, 'fcitx')
        self.fcitx_row = SettingsRow(self.fcitx_button)
        self.fcitx_row.add_label(self.fcitx_label)
        self.fcitx_row.set_no_show_all(True)
        self.input_settings.add_row(self.fcitx_row)

        self.scim_label = Gtk.Label()
        self.scim_label.set_line_wrap(True)
        self.scim_button = Gtk.Button()
        size_group.add_widget(self.scim_button)
        self.scim_button.connect('clicked', self.install_im, 'scim')
        self.scim_row = SettingsRow(self.scim_button)
        self.scim_row.add_label(self.scim_label)
        self.scim_row.set_no_show_all(True)
        self.input_settings.add_row(self.scim_row)

        self.uim_label = Gtk.Label()       
        self.uim_label.set_line_wrap(True)
        self.uim_button = Gtk.Button()
        size_group.add_widget(self.uim_button)
        self.uim_button.connect('clicked', self.install_im, 'uim')
        self.uim_row = SettingsRow(self.uim_button)
        self.uim_row.add_label(self.uim_label)
        self.uim_row.set_no_show_all(True)
        self.input_settings.add_row(self.uim_row)

        self.gcin_label = Gtk.Label()       
        self.gcin_label.set_line_wrap(True)
        self.gcin_button = Gtk.Button()
        size_group.add_widget(self.gcin_button)
        self.gcin_button.connect('clicked', self.install_im, 'gcin')
        self.gcin_row = SettingsRow(self.gcin_button)
        self.gcin_row.add_label(self.gcin_label)
        self.gcin_row.set_no_show_all(True)
        self.input_settings.add_row(self.gcin_row)

        self.im_loaded = False # don't react to im changes until we're fully loaded (we're loading that combo asynchronously)
        self.im_combo.connect("changed", self.on_combobox_input_method_changed)

        stack.show_all()       
        
        self.pam_environment_path = os.path.join(GLib.get_home_dir(), ".pam_environment")
        self.dmrc_path = os.path.join(GLib.get_home_dir(), ".dmrc")
        self.dmrc = ConfigParser.ConfigParser()
        self.dmrc.optionxform=str # force case sensitivity on ConfigParser
        self.dmrc.read(self.dmrc_path)
        if not self.dmrc.has_section('Desktop'):
            self.dmrc.add_section('Desktop')

        current_user = GLib.get_user_name()        

        self.current_language = None        
        dmrc_language = None
        env_language = os.environ['LANG']        
        
        if self.dmrc.has_option('Desktop', 'Language'):
            dmrc_language = self.dmrc.get('Desktop', 'Language')
        
        if dmrc_language is not None:
            self.current_language = dmrc_language
        else:
            self.current_language = env_language

        print "User language in .dmrc: %s" % dmrc_language
        print "User language in $LANG: %s" % env_language
        print "Current language: %s" % self.current_language
                
        if 'LC_NUMERIC' in os.environ:
            self.current_region = os.environ['LC_NUMERIC']
        else:
            self.current_region = self.current_language
        
        if os.path.exists(self.pam_environment_path):
            with open(self.pam_environment_path, 'r') as pam_file:
                for line in pam_file:
                    line = line.strip()
                    if line.startswith("LC_NUMERIC="):
                        self.current_region = line.split("=")[1].replace("\"", "").replace("'", "").strip()

        print "Current region: %s" % self.current_region

        # Replace utf8 with UTF-8 (lightDM GTK greeter messes that up)
        self.current_language = self.current_language.replace(".utf8", ".UTF-8")
        self.current_region = self.current_region.replace(".utf8", ".UTF-8")

        self.build_lang_list()
        self.set_system_locale()
        self.set_num_installed()

        self.accountService = AccountsService.UserManager.get_default().get_user(current_user)
        self.accountService.connect('notify::is-loaded', self.accountservice_ready)
        self.accountService.connect('changed::', self.accountservice_changed)

        groups = grp.getgrall()
        for group in groups:
            (name, pw, gid, mem) = group
            if name in ("adm", "sudo"):
                for user in mem:
                    if current_user == user:                        
                        self.system_row.set_no_show_all(False)        
                        self.install_row.set_no_show_all(False)
                        language_settings.show_all()
                        self.ibus_row.set_no_show_all(False)
                        self.fcitx_row.set_no_show_all(False)
                        self.scim_row.set_no_show_all(False)
                        self.uim_row.set_no_show_all(False)
                        self.gcin_row.set_no_show_all(False)
                        self.input_settings.hide()
                        break

        self.read_im_info()
        self.check_input_methods()
Example #33
0
    def on_module_selected(self):
        if not self.loaded:
            print "Loading User module"

            self.face_button = Gtk.Button()
            self.face_image = Gtk.Image()
            self.face_button.set_image(self.face_image)
            self.face_image.set_from_file(
                "/usr/share/cinnamon/faces/user-generic.png")
            self.face_button.set_alignment(0.0, 0.5)
            self.face_button.set_tooltip_text(
                _("Click to change your picture"))

            self.menu = Gtk.Menu()

            self.face_photo_menuitem = Gtk.MenuItem.new_with_label(
                _("Take a photo..."))
            self.face_photo_menuitem.connect(
                'activate', self._on_face_photo_menuitem_activated)

            self.separator = Gtk.SeparatorMenuItem()
            self.face_browse_menuitem = Gtk.MenuItem.new_with_label(
                _("Browse for more pictures..."))
            self.face_browse_menuitem.connect(
                'activate', self._on_face_browse_menuitem_activated)
            self.face_button.connect("button-release-event", self.menu_display)

            self.row = 0
            col = 0
            num_cols = 4
            face_dirs = ["/usr/share/cinnamon/faces"]
            for face_dir in face_dirs:
                if os.path.exists(face_dir):
                    pictures = sorted(os.listdir(face_dir))
                    for picture in pictures:
                        path = os.path.join(face_dir, picture)
                        file = Gio.File.new_for_path(path)
                        file_icon = Gio.FileIcon(file=file)
                        image = Gtk.Image.new_from_gicon(
                            file_icon, Gtk.IconSize.DIALOG)
                        menuitem = Gtk.MenuItem()
                        menuitem.add(image)
                        menuitem.connect('activate',
                                         self._on_face_menuitem_activated,
                                         path)
                        self.menu.attach(menuitem, col, col + 1, self.row,
                                         self.row + 1)
                        col = (col + 1) % num_cols
                        if (col == 0):
                            self.row = self.row + 1

            self.realname_entry = EditableEntry()
            self.realname_entry.connect("changed", self._on_realname_changed)
            self.realname_entry.set_tooltip_text(
                _("Click to change your name"))

            table = Gtk.Table.new(3, 2, False)
            table.set_row_spacings(8)
            table.set_col_spacings(15)
            self.sidePage.add_widget(table)

            label_picture = Gtk.Label.new(_("Picture:"))
            label_picture.set_alignment(1, 0.5)
            label_picture.get_style_context().add_class("dim-label")
            table.attach(label_picture, 0, 1, 0, 1)

            password_mask = Gtk.Label.new(
                u'\u2022\u2022\u2022\u2022\u2022\u2022')
            password_mask.set_alignment(0.0, 0.5)
            self.password_button = Gtk.Button()
            self.password_button.add(password_mask)
            self.password_button.set_relief(Gtk.ReliefStyle.NONE)
            self.password_button.set_tooltip_text(
                _("Click to change your password"))
            self.password_button.connect('activate',
                                         self._on_password_button_clicked)
            self.password_button.connect('released',
                                         self._on_password_button_clicked)

            label_name = Gtk.Label.new(_("Name:"))
            label_name.set_alignment(1, 0.5)
            label_name.get_style_context().add_class("dim-label")
            table.attach(label_name, 0, 1, 1, 2)

            label_name = Gtk.Label.new(_("Password:"******"dim-label")
            table.attach(label_name, 0, 1, 2, 3)

            box = Gtk.Box()
            box.pack_start(self.face_button, False, False, 0)
            table.attach(box,
                         1,
                         2,
                         0,
                         1,
                         xoptions=Gtk.AttachOptions.EXPAND
                         | Gtk.AttachOptions.FILL)
            table.attach(self.realname_entry,
                         1,
                         2,
                         1,
                         2,
                         xoptions=Gtk.AttachOptions.EXPAND
                         | Gtk.AttachOptions.FILL)
            table.attach(self.password_button,
                         1,
                         2,
                         2,
                         3,
                         xoptions=Gtk.AttachOptions.EXPAND
                         | Gtk.AttachOptions.FILL)

            current_user = GLib.get_user_name()
            self.accountService = AccountsService.UserManager.get_default(
            ).get_user(current_user)
            self.accountService.connect('notify::is-loaded',
                                        self.load_user_info)

            self.row = self.row + 1
            self.menu.attach(self.separator, 0, 4, self.row, self.row + 1)

            webcam_detected = False
            try:
                import cv
                capture = cv.CaptureFromCAM(-1)
                for i in range(10):
                    img = cv.QueryFrame(capture)
                    if img != None:
                        webcam_detected = True
            except Exception, detail:
                print detail

            if (webcam_detected):
                self.menu.attach(self.face_photo_menuitem, 0, 4, self.row + 1,
                                 self.row + 2)
                self.menu.attach(self.face_browse_menuitem, 0, 4, self.row + 2,
                                 self.row + 3)
            else:
                self.menu.attach(self.face_browse_menuitem, 0, 4, self.row + 1,
                                 self.row + 2)
Example #34
0
def get_user_email():
    return "{}@{}".format(GLib.get_user_name(), GLib.get_host_name())
Example #35
0
    def __init__(self, show_input_methods):

        # Determine path to system locale-config
        self.locale_path = ''

        if os.path.exists('/etc/default/locale'):
            self.locale_path = '/etc/default/locale'
        else:
            self.locale_path = '/etc/locale.conf'

        # Prepare the APT cache
        if IS_DEBIAN:
            self.cache = apt.Cache()
        self.cache_updated = False

        self.pam_environment_path = os.path.join(GLib.get_home_dir(),
                                                 ".pam_environment")
        self.dmrc_path = os.path.join(GLib.get_home_dir(), ".dmrc")
        self.dmrc = configparser.ConfigParser()
        self.dmrc.optionxform = str  # force case sensitivity on ConfigParser
        self.dmrc.read(self.dmrc_path)
        if not self.dmrc.has_section('Desktop'):
            self.dmrc.add_section('Desktop')

        current_user = GLib.get_user_name()

        self.current_language = None
        dmrc_language = None
        env_language = os.environ['LANG']

        if self.dmrc.has_option('Desktop', 'Language'):
            dmrc_language = self.dmrc.get('Desktop', 'Language')

        if dmrc_language is not None:
            self.current_language = dmrc_language
        else:
            self.current_language = env_language

        print("User language in .dmrc: %s" % dmrc_language)
        print("User language in $LANG: %s" % env_language)
        print("Current language: %s" % self.current_language)

        if 'LC_NUMERIC' in os.environ:
            self.current_region = os.environ['LC_NUMERIC']
        else:
            self.current_region = self.current_language

        if os.path.exists(self.pam_environment_path):
            with codecs.open(self.pam_environment_path, 'r',
                             encoding='UTF-8') as pam_file:
                for line in pam_file:
                    line = line.strip()
                    if line.startswith("LC_NUMERIC="):
                        self.current_region = line.split("=")[1].replace(
                            "\"", "").replace("'", "").strip()

        print("Current region: %s" % self.current_region)

        # Replace utf8 with UTF-8 (lightDM GTK greeter messes that up)
        self.current_language = self.current_language.replace(
            ".utf8", ".UTF-8")
        self.current_region = self.current_region.replace(".utf8", ".UTF-8")

        subprocess.call([
            'set-default-locale', self.locale_path, self.current_language,
            self.current_region
        ])
Example #36
0
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Strings to be used in UI.

import gettext
from gettext import gettext as _
from gi.repository import GLib

gettext.textdomain("gmailwatcher")

# String constants
icon_name = 'gmailwatcher'

# Messages Tuple of (Title, Description)
username = GLib.get_real_name().split()[0]
username = username == 'Unknown' and GLib.get_user_name() or username

no_account = (
        _("Add an account"),
        _("Hey %s, I don't have any accounts to watch over right now."
           "Please add a gmail or google apps account and I'll let you "
           "know about any new messages.") % username
        )

quit = (
        _("ZZZzzzz..."),
        _("If you need me again, you can find me by clicking "
          "the messaging icon in the top panel.")
        )

start = (
        _("Gmail Watcher"),
Example #37
0
    def on_module_selected(self):
        if not self.loaded:
            print "Loading User module"
       
            self.face_button = Gtk.Button()
            self.face_image = Gtk.Image()  
            self.face_button.set_image(self.face_image)
            self.face_image.set_from_file("/usr/share/cinnamon/faces/user-generic.png")      
            self.face_button.set_alignment(0.0, 0.5)
            self.face_button.set_tooltip_text(_("Click to change your picture"))

            self.menu = Gtk.Menu()

            self.face_photo_menuitem = Gtk.MenuItem.new_with_label(_("Take a photo..."))
            self.face_photo_menuitem.connect('activate', self._on_face_photo_menuitem_activated)         

            self.separator = Gtk.SeparatorMenuItem()
            self.face_browse_menuitem = Gtk.MenuItem.new_with_label(_("Browse for more pictures..."))       
            self.face_browse_menuitem.connect('activate', self._on_face_browse_menuitem_activated)         
            self.face_button.connect("button-release-event", self.menu_display)

            self.row = 0
            col = 0       
            num_cols = 4
            face_dirs = ["/usr/share/cinnamon/faces"]
            for face_dir in face_dirs:
                if os.path.exists(face_dir):
                    pictures = sorted(os.listdir(face_dir))
                    for picture in pictures:
                        path = os.path.join(face_dir, picture)            
                        file = Gio.File.new_for_path(path)
                        file_icon = Gio.FileIcon(file=file)
                        image = Gtk.Image.new_from_gicon (file_icon, Gtk.IconSize.DIALOG)            
                        menuitem = Gtk.MenuItem()
                        menuitem.add(image)
                        menuitem.connect('activate', self._on_face_menuitem_activated, path)
                        self.menu.attach(menuitem, col, col+1, self.row, self.row+1)            
                        col = (col+1) % num_cols            
                        if (col == 0):
                            self.row = self.row + 1
           
            self.realname_entry = EditableEntry()
            self.realname_entry.connect("changed", self._on_realname_changed)
            self.realname_entry.set_tooltip_text(_("Click to change your name"))
            
            table = Gtk.Table.new(3, 2, False)
            table.set_row_spacings(8)
            table.set_col_spacings(15)        
            self.sidePage.add_widget(table)
            
            label_picture = Gtk.Label.new(_("Picture:"))
            label_picture.set_alignment(1, 0.5)
            label_picture.get_style_context().add_class("dim-label")
            table.attach(label_picture, 0, 1, 0, 1)

            password_mask = Gtk.Label.new(u'\u2022\u2022\u2022\u2022\u2022\u2022')        
            password_mask.set_alignment(0.0, 0.5)
            self.password_button = Gtk.Button()
            self.password_button.add(password_mask)
            self.password_button.set_relief(Gtk.ReliefStyle.NONE)
            self.password_button.set_tooltip_text(_("Click to change your password"))
            self.password_button.connect('activate', self._on_password_button_clicked)
            self.password_button.connect('released', self._on_password_button_clicked)
            
            label_name = Gtk.Label.new(_("Name:"))
            label_name.set_alignment(1, 0.5)
            label_name.get_style_context().add_class("dim-label")                        
            table.attach(label_name, 0, 1, 1, 2)

            label_name = Gtk.Label.new(_("Password:"******"dim-label")                        
            table.attach(label_name, 0, 1, 2, 3)
            
            box = Gtk.Box()
            box.pack_start(self.face_button, False, False, 0)        
            table.attach(box, 1, 2, 0, 1, xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)
            table.attach(self.realname_entry, 1, 2, 1, 2, xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)
            table.attach(self.password_button, 1, 2, 2, 3, xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)        

            current_user = GLib.get_user_name()
            self.accountService = AccountsService.UserManager.get_default().get_user(current_user)
            self.accountService.connect('notify::is-loaded', self.load_user_info)       

            self.row = self.row + 1
            self.menu.attach(self.separator, 0, 4, self.row, self.row+1)    

            webcam_detected = False
            try:
                import cv
                capture = cv.CaptureFromCAM(-1)
                for i in range(10):
                    img = cv.QueryFrame(capture)
                    if img != None:
                        webcam_detected = True
            except Exception, detail:
                print detail

            if (webcam_detected):
                self.menu.attach(self.face_photo_menuitem, 0, 4, self.row+1, self.row+2)
                self.menu.attach(self.face_browse_menuitem, 0, 4, self.row+2, self.row+3)
            else:
                self.menu.attach(self.face_browse_menuitem, 0, 4, self.row+1, self.row+2)
Example #38
0
    def __init__(self, content_box):
        keywords = _("user, account, information, details")
        advanced = False
        sidePage = SidePage(_("Account details"),
                            "user.svg",
                            keywords,
                            advanced,
                            content_box,
                            module=self)
        self.sidePage = sidePage
        self.name = "user"
        self.category = "prefs"

        self.face_button = Gtk.Button()
        self.face_image = Gtk.Image()
        self.face_button.set_image(self.face_image)
        self.face_image.set_from_file(
            "/usr/share/sagarmatha/faces/user-generic.png")
        self.face_button.set_alignment(0.0, 0.5)
        self.face_button.set_tooltip_text(_("Click to change your picture"))

        self.menu = Gtk.Menu()
        self.webcam_presence_checked = False  # Only check for the presence of the webcam the first time the module is selected

        self.face_photo_menuitem = Gtk.MenuItem(_("Take a photo..."))
        self.face_photo_menuitem.connect(
            'activate', self._on_face_photo_menuitem_activated)

        self.separator = Gtk.SeparatorMenuItem()
        self.face_browse_menuitem = Gtk.MenuItem(
            _("Browse for more pictures..."))
        self.face_browse_menuitem.connect(
            'activate', self._on_face_browse_menuitem_activated)
        self.face_button.connect("button-release-event", self.menu_display)

        self.row = 0
        col = 0
        num_cols = 4
        face_dirs = ["/usr/share/sagarmatha/faces"]
        for face_dir in face_dirs:
            if os.path.exists(face_dir):
                pictures = sorted(os.listdir(face_dir))
                for picture in pictures:
                    path = os.path.join(face_dir, picture)
                    file = Gio.File.new_for_path(path)
                    file_icon = Gio.FileIcon().new(file)
                    image = Gtk.Image.new_from_gicon(file_icon,
                                                     Gtk.IconSize.DIALOG)
                    menuitem = Gtk.MenuItem()
                    menuitem.add(image)
                    menuitem.connect('activate',
                                     self._on_face_menuitem_activated, path)
                    self.menu.attach(menuitem, col, col + 1, self.row,
                                     self.row + 1)
                    col = (col + 1) % num_cols
                    if (col == 0):
                        self.row = self.row + 1

        self.realname_entry = EditableEntry()
        self.sidePage.add_widget(self.realname_entry, False)
        self.realname_entry.connect("changed", self._on_realname_changed)
        self.realname_entry.set_tooltip_text(_("Click to change your name"))

        table = Gtk.Table(3, 2)
        table.set_row_spacings(8)
        table.set_col_spacings(15)
        self.sidePage.add_widget(table, False)

        label_picture = Gtk.Label(_("Picture:"))
        label_picture.set_alignment(1, 0.5)
        label_picture.get_style_context().add_class("dim-label")
        table.attach(label_picture, 0, 1, 0, 1)

        password_mask = Gtk.Label(u'\u2022\u2022\u2022\u2022\u2022\u2022')
        password_mask.set_alignment(0.0, 0.5)
        self.password_button = Gtk.Button()
        self.password_button.add(password_mask)
        self.password_button.set_relief(Gtk.ReliefStyle.NONE)
        self.password_button.set_tooltip_text(
            _("Click to change your password"))
        self.password_button.connect('activate',
                                     self._on_password_button_clicked)
        self.password_button.connect('released',
                                     self._on_password_button_clicked)

        label_name = Gtk.Label(_("Name:"))
        label_name.set_alignment(1, 0.5)
        label_name.get_style_context().add_class("dim-label")
        table.attach(label_name, 0, 1, 1, 2)

        label_name = Gtk.Label(_("Password:"******"dim-label")
        table.attach(label_name, 0, 1, 2, 3)

        box = Gtk.Box()
        box.pack_start(self.face_button, False, False, 0)
        table.attach(box,
                     1,
                     2,
                     0,
                     1,
                     xoptions=Gtk.AttachOptions.EXPAND
                     | Gtk.AttachOptions.FILL)
        table.attach(self.realname_entry,
                     1,
                     2,
                     1,
                     2,
                     xoptions=Gtk.AttachOptions.EXPAND
                     | Gtk.AttachOptions.FILL)
        table.attach(self.password_button,
                     1,
                     2,
                     2,
                     3,
                     xoptions=Gtk.AttachOptions.EXPAND
                     | Gtk.AttachOptions.FILL)

        current_user = GLib.get_user_name()
        self.accountService = AccountsService.UserManager.get_default(
        ).get_user(current_user)
        self.accountService.connect('notify::is-loaded', self.load_user_info)
Example #39
0
    def on_module_selected(self):
        if not self.loaded:
            print("Loading User module")

            page = SettingsPage()
            self.sidePage.add_widget(page)

            settings = page.add_section(_("Account details"))

            self.scale = self.window.get_scale_factor()

            self.face_button = PictureChooserButton(num_cols=4,
                                                    button_picture_size=64,
                                                    menu_pictures_size=64 *
                                                    self.scale,
                                                    keep_square=True)
            self.face_button.set_alignment(0.0, 0.5)
            self.face_button.set_tooltip_text(
                _("Click to change your picture"))

            self.face_photo_menuitem = Gtk.MenuItem.new_with_label(
                _("Take a photo..."))
            self.face_photo_menuitem.connect(
                'activate', self._on_face_photo_menuitem_activated)

            self.face_browse_menuitem = Gtk.MenuItem.new_with_label(
                _("Browse for more pictures..."))
            self.face_browse_menuitem.connect(
                'activate', self._on_face_browse_menuitem_activated)

            face_dirs = ["/usr/share/cinnamon/faces"]
            for face_dir in face_dirs:
                if os.path.exists(face_dir):
                    pictures = sorted(os.listdir(face_dir))
                    for picture in pictures:
                        path = os.path.join(face_dir, picture)
                        self.face_button.add_picture(
                            path, self._on_face_menuitem_activated)

            widget = SettingsWidget()
            label = Gtk.Label.new(_("Picture"))
            widget.pack_start(label, False, False, 0)
            widget.pack_end(self.face_button, False, False, 0)
            settings.add_row(widget)

            size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

            widget = SettingsWidget()
            label = Gtk.Label.new(_("Name"))
            widget.pack_start(label, False, False, 0)
            self.realname_entry = EditableEntry()
            size_group.add_widget(self.realname_entry)
            self.realname_entry.connect("changed", self._on_realname_changed)
            self.realname_entry.set_tooltip_text(
                _("Click to change your name"))
            widget.pack_end(self.realname_entry, False, False, 0)
            settings.add_row(widget)

            widget = SettingsWidget()
            label = Gtk.Label.new(_("Password"))
            widget.pack_start(label, False, False, 0)
            password_mask = Gtk.Label.new(
                '\u2022\u2022\u2022\u2022\u2022\u2022')
            password_mask.set_alignment(0.9, 0.5)
            self.password_button = Gtk.Button()
            size_group.add_widget(self.password_button)
            self.password_button.add(password_mask)
            self.password_button.set_relief(Gtk.ReliefStyle.NONE)
            self.password_button.set_tooltip_text(
                _("Click to change your password"))
            self.password_button.connect('activate',
                                         self._on_password_button_clicked)
            self.password_button.connect('released',
                                         self._on_password_button_clicked)
            widget.pack_end(self.password_button, False, False, 0)
            settings.add_row(widget)

            current_user = GLib.get_user_name()
            self.accountService = AccountsService.UserManager.get_default(
            ).get_user(current_user)
            self.accountService.connect('notify::is-loaded',
                                        self.load_user_info)

            self.face_button.add_separator()

            # Video devices assumed to be webcams
            import glob
            webcam_detected = len(glob.glob("/dev/video*")) > 0

            if webcam_detected:
                self.face_button.add_menuitem(self.face_photo_menuitem)

            self.face_button.add_menuitem(self.face_browse_menuitem)
Example #40
0
    def on_module_selected(self):
        if not self.loaded:
            print "Loading User module"

            page = SettingsPage()
            self.sidePage.add_widget(page)

            settings = page.add_section(_("Account details"))

            self.face_button = PictureChooserButton(num_cols=4,
                                                    button_picture_size=64,
                                                    menu_pictures_size=64)
            self.face_button.set_alignment(0.0, 0.5)
            self.face_button.set_tooltip_text(
                _("Click to change your picture"))

            self.face_photo_menuitem = Gtk.MenuItem.new_with_label(
                _("Take a photo..."))
            self.face_photo_menuitem.connect(
                'activate', self._on_face_photo_menuitem_activated)

            self.face_browse_menuitem = Gtk.MenuItem.new_with_label(
                _("Browse for more pictures..."))
            self.face_browse_menuitem.connect(
                'activate', self._on_face_browse_menuitem_activated)

            face_dirs = ["/usr/share/cinnamon/faces"]
            for face_dir in face_dirs:
                if os.path.exists(face_dir):
                    pictures = sorted(os.listdir(face_dir))
                    for picture in pictures:
                        path = os.path.join(face_dir, picture)
                        self.face_button.add_picture(
                            path, self._on_face_menuitem_activated)

            widget = SettingsWidget()
            label = Gtk.Label.new(_("Picture"))
            widget.pack_start(label, False, False, 0)
            widget.pack_end(self.face_button, False, False, 0)
            settings.add_row(widget)

            size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

            widget = SettingsWidget()
            label = Gtk.Label.new(_("Name"))
            widget.pack_start(label, False, False, 0)
            self.realname_entry = EditableEntry()
            size_group.add_widget(self.realname_entry)
            self.realname_entry.connect("changed", self._on_realname_changed)
            self.realname_entry.set_tooltip_text(
                _("Click to change your name"))
            widget.pack_end(self.realname_entry, False, False, 0)
            settings.add_row(widget)

            widget = SettingsWidget()
            label = Gtk.Label.new(_("Password"))
            widget.pack_start(label, False, False, 0)
            password_mask = Gtk.Label.new(
                u'\u2022\u2022\u2022\u2022\u2022\u2022')
            password_mask.set_alignment(0.9, 0.5)
            self.password_button = Gtk.Button()
            size_group.add_widget(self.password_button)
            self.password_button.add(password_mask)
            self.password_button.set_relief(Gtk.ReliefStyle.NONE)
            self.password_button.set_tooltip_text(
                _("Click to change your password"))
            self.password_button.connect('activate',
                                         self._on_password_button_clicked)
            self.password_button.connect('released',
                                         self._on_password_button_clicked)
            widget.pack_end(self.password_button, False, False, 0)
            settings.add_row(widget)

            current_user = GLib.get_user_name()
            self.accountService = AccountsService.UserManager.get_default(
            ).get_user(current_user)
            self.accountService.connect('notify::is-loaded',
                                        self.load_user_info)

            self.face_button.add_separator()

            webcam_detected = False
            try:
                import cv
                capture = cv.CaptureFromCAM(-1)
                for i in range(10):
                    img = cv.QueryFrame(capture)
                    if img != None:
                        webcam_detected = True
            except Exception, detail:
                print detail

            if (webcam_detected):
                self.face_button.add_menuitem(self.face_photo_menuitem)
                self.face_button.add_menuitem(self.face_browse_menuitem)
            else:
                self.face_button.add_menuitem(self.face_browse_menuitem)
Example #41
0
    def __init__(self, content_box):
        keywords = _("user, account, information, details")
        advanced = False
        sidePage = SidePage(_("Account details"), "user.svg", keywords, advanced, content_box, module=self)
        self.sidePage = sidePage
        self.name = "user"
        self.category = "prefs"
        self.comment = _("Change your user preferences and password")
                
        self.face_button = Gtk.Button()
        self.face_image = Gtk.Image()  
        self.face_button.set_image(self.face_image)
        self.face_image.set_from_file("/usr/share/cinnamon/faces/user-generic.png")      
        self.face_button.set_alignment(0.0, 0.5)
        self.face_button.set_tooltip_text(_("Click to change your picture"))

        self.menu = Gtk.Menu()
        self.webcam_presence_checked = False # Only check for the presence of the webcam the first time the module is selected

        self.face_photo_menuitem = Gtk.MenuItem(_("Take a photo..."))
        self.face_photo_menuitem.connect('activate', self._on_face_photo_menuitem_activated)         

        self.separator = Gtk.SeparatorMenuItem()
        self.face_browse_menuitem = Gtk.MenuItem(_("Browse for more pictures..."))       
        self.face_browse_menuitem.connect('activate', self._on_face_browse_menuitem_activated)         
        self.face_button.connect("button-release-event", self.menu_display)

        self.row = 0
        col = 0       
        num_cols = 4
        face_dirs = ["/usr/share/cinnamon/faces"]
        for face_dir in face_dirs:
            if os.path.exists(face_dir):
                pictures = sorted(os.listdir(face_dir))
                for picture in pictures:
                    path = os.path.join(face_dir, picture)            
                    file = Gio.File.new_for_path(path)
                    file_icon = Gio.FileIcon().new(file)
                    image = Gtk.Image.new_from_gicon (file_icon, Gtk.IconSize.DIALOG)            
                    menuitem = Gtk.MenuItem()
                    menuitem.add(image)
                    menuitem.connect('activate', self._on_face_menuitem_activated, path)
                    self.menu.attach(menuitem, col, col+1, self.row, self.row+1)            
                    col = (col+1) % num_cols            
                    if (col == 0):
                        self.row = self.row + 1
       
        self.realname_entry = EditableEntry()
        self.sidePage.add_widget(self.realname_entry, False)         
        self.realname_entry.connect("changed", self._on_realname_changed)
        self.realname_entry.set_tooltip_text(_("Click to change your name"))
        
        table = Gtk.Table(3, 2)
        table.set_row_spacings(8)
        table.set_col_spacings(15)        
        self.sidePage.add_widget(table, False)
        
        label_picture = Gtk.Label(_("Picture:"))
        label_picture.set_alignment(1, 0.5)
        label_picture.get_style_context().add_class("dim-label")
        table.attach(label_picture, 0, 1, 0, 1)

        password_mask = Gtk.Label(u'\u2022\u2022\u2022\u2022\u2022\u2022')        
        password_mask.set_alignment(0.0, 0.5)
        self.password_button = Gtk.Button()
        self.password_button.add(password_mask)
        self.password_button.set_relief(Gtk.ReliefStyle.NONE)
        self.password_button.set_tooltip_text(_("Click to change your password"))
        self.password_button.connect('activate', self._on_password_button_clicked)
        self.password_button.connect('released', self._on_password_button_clicked)
        
        label_name = Gtk.Label(_("Name:"))
        label_name.set_alignment(1, 0.5)
        label_name.get_style_context().add_class("dim-label")                        
        table.attach(label_name, 0, 1, 1, 2)

        label_name = Gtk.Label(_("Password:"******"dim-label")                        
        table.attach(label_name, 0, 1, 2, 3)
        
        box = Gtk.Box()
        box.pack_start(self.face_button, False, False, 0)        
        table.attach(box, 1, 2, 0, 1, xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)
        table.attach(self.realname_entry, 1, 2, 1, 2, xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)
        table.attach(self.password_button, 1, 2, 2, 3, xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)        

        current_user = GLib.get_user_name()
        self.accountService = AccountsService.UserManager.get_default().get_user(current_user)
        self.accountService.connect('notify::is-loaded', self.load_user_info)    
Example #42
0
 def _get_computer_user_name() -> str:
     from gi.repository import GLib
     return GLib.get_user_name()
Example #43
0
    def GetRemoteMachineInfo(self, request, context):
        logging.debug("Server RPC: GetRemoteMachineInfo from '%s'" %
                      request.readable_name)

        return warp_pb2.RemoteMachineInfo(display_name=GLib.get_real_name(),
                                          user_name=GLib.get_user_name())
Example #44
0
    def __init__(self):

        # load our glade ui file in
        self.builder = Gtk.Builder()
        self.builder.add_from_file('/usr/lib/linuxmint/mintLocale/mintLocale.ui')
        self.window = self.builder.get_object( "main_window" )
               
        self.builder.get_object("main_window").connect("destroy", Gtk.main_quit)

        self.treeview = self.builder.get_object("treeview_language_list")
                              
        # set up larger components.
        self.builder.get_object("main_window").set_title(_("Language Settings"))
        self.builder.get_object("main_window").connect("destroy", Gtk.main_quit)
        self.builder.get_object("button_close").connect("clicked", Gtk.main_quit)
        self.builder.get_object("button_system_language").connect("clicked", self.button_system_language_clicked)
        self.builder.get_object("button_install_remove").connect("clicked", self.button_install_remove_clicked)

        ren = Gtk.CellRendererPixbuf()
        column = Gtk.TreeViewColumn("Flags", ren)
        column.add_attribute(ren, "pixbuf", 2)
        ren.set_property('ypad', 5)
        ren.set_property('xpad', 10)
        self.treeview.append_column(column)

        ren = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn("Languages", ren)
        column.add_attribute(ren, "text", 0)
        self.treeview.append_column(column)
        
        self.pam_environment_path = os.path.join(GLib.get_home_dir(), ".pam_environment")
        self.dmrc_path = os.path.join(GLib.get_home_dir(), ".dmrc")
        self.dmrc = ConfigParser.ConfigParser()
        self.dmrc.read(self.dmrc_path)
        if not self.dmrc.has_section('Desktop'):
            self.dmrc.add_section('Desktop')

        current_user = GLib.get_user_name()        

        self.current_language = None
        dmrc_language = None
        env_language = os.environ['LANG']
        
        if self.dmrc.has_option('Desktop', 'Language'):
            dmrc_language = self.dmrc.get('Desktop', 'Language')
        
        if dmrc_language is not None:
            self.current_language = dmrc_language
        else:
            self.current_language = env_language

        print "User language in .dmrc: %s" % dmrc_language
        print "User language in $LANG: %s" % env_language
        print "Current language: %s" % self.current_language

        self.build_lang_list()
        self.set_system_locale()
        self.set_num_installed()

        self.accountService = AccountsService.UserManager.get_default().get_user(current_user)
        self.accountService.connect('notify::is-loaded', self.accountservice_ready)
        self.accountService.connect('changed::', self.accountservice_changed)

        groups = grp.getgrall()
        for group in groups:
            (name, pw, gid, mem) = group
            if name in ("adm", "sudo"):
                for user in mem:
                    if current_user == user:
                        self.builder.get_object("separator").show()
                        self.builder.get_object("button_system_language").show()
                        self.builder.get_object("button_install_remove").show()
Example #45
0
    def on_module_selected(self):
        if not self.loaded:
            print "Loading User module"
       
            self.face_button = PictureChooserButton(num_cols=4, button_picture_size=48, menu_pictures_size=96)
            self.face_button.set_alignment(0.0, 0.5)
            self.face_button.set_tooltip_text(_("Click to change your picture"))

            self.face_photo_menuitem = Gtk.MenuItem.new_with_label(_("Take a photo..."))
            self.face_photo_menuitem.connect('activate', self._on_face_photo_menuitem_activated)         

            self.face_browse_menuitem = Gtk.MenuItem.new_with_label(_("Browse for more pictures..."))       
            self.face_browse_menuitem.connect('activate', self._on_face_browse_menuitem_activated)
           
            face_dirs = ["/usr/share/cinnamon/faces"]
            for face_dir in face_dirs:
                if os.path.exists(face_dir):                    
                    pictures = sorted(os.listdir(face_dir))
                    for picture in pictures:
                        path = os.path.join(face_dir, picture)
                        self.face_button.add_picture(path, self._on_face_menuitem_activated)
           
            self.realname_entry = EditableEntry()
            self.realname_entry.connect("changed", self._on_realname_changed)
            self.realname_entry.set_tooltip_text(_("Click to change your name"))
            
            table = Gtk.Table.new(3, 2, False)
            table.set_row_spacings(8)
            table.set_col_spacings(15)        
            self.sidePage.add_widget(table)
            
            label_picture = Gtk.Label.new(_("Picture:"))
            label_picture.set_alignment(1, 0.5)
            label_picture.get_style_context().add_class("dim-label")
            table.attach(label_picture, 0, 1, 0, 1)

            password_mask = Gtk.Label.new(u'\u2022\u2022\u2022\u2022\u2022\u2022')        
            password_mask.set_alignment(0.0, 0.5)
            self.password_button = Gtk.Button()
            self.password_button.add(password_mask)
            self.password_button.set_relief(Gtk.ReliefStyle.NONE)
            self.password_button.set_tooltip_text(_("Click to change your password"))
            self.password_button.connect('activate', self._on_password_button_clicked)
            self.password_button.connect('released', self._on_password_button_clicked)
            
            label_name = Gtk.Label.new(_("Name:"))
            label_name.set_alignment(1, 0.5)
            label_name.get_style_context().add_class("dim-label")                        
            table.attach(label_name, 0, 1, 1, 2)

            label_name = Gtk.Label.new(_("Password:"******"dim-label")                        
            table.attach(label_name, 0, 1, 2, 3)
            
            box = Gtk.Box()
            box.pack_start(self.face_button, False, False, 0)        
            table.attach(box, 1, 2, 0, 1, xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)
            table.attach(self.realname_entry, 1, 2, 1, 2, xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)
            table.attach(self.password_button, 1, 2, 2, 3, xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)        

            current_user = GLib.get_user_name()
            self.accountService = AccountsService.UserManager.get_default().get_user(current_user)
            self.accountService.connect('notify::is-loaded', self.load_user_info)       

            self.face_button.add_separator()

            webcam_detected = False
            try:
                import cv
                capture = cv.CaptureFromCAM(-1)
                for i in range(10):
                    img = cv.QueryFrame(capture)
                    if img != None:
                        webcam_detected = True
            except Exception, detail:
                print detail

            if (webcam_detected):
                self.face_button.add_menuitem(self.face_photo_menuitem)
                self.face_button.add_menuitem(self.face_browse_menuitem)
            else:
                self.face_button.add_menuitem(self.face_browse_menuitem)