예제 #1
0
 def _set_preferences(prefs):
     try:
         prefs = prefs()
     except RPCException:
         prefs = {}
     threads = []
     for target in (
             common.ICONFACTORY.load_icons,
             common.MODELACCESS.load_models,
             common.MODELHISTORY.load_history,
             common.VIEW_SEARCH.load_searches,
     ):
         t = threading.Thread(target=target)
         threads.append(t)
         t.start()
     for t in threads:
         t.join()
     if prefs and 'language_direction' in prefs:
         translate.set_language_direction(prefs['language_direction'])
         CONFIG['client.language_direction'] = \
             prefs['language_direction']
     self.sig_win_menu(prefs=prefs)
     for action_id in prefs.get('actions', []):
         Action.execute(action_id, {})
     self.set_title(prefs.get('status_bar', ''))
     if prefs and 'language' in prefs:
         translate.setlang(prefs['language'], prefs.get('locale'))
         if CONFIG['client.lang'] != prefs['language']:
             self.favorite_unset()
         CONFIG['client.lang'] = prefs['language']
     # Set placeholder after language is set to get correct translation
     self.global_search_entry.set_placeholder_text(_("Action"))
     CONFIG.save()
예제 #2
0
def main():
    CSS = b"""
    .readonly entry {
        background-color: @insensitive_bg_color;
    }
    .required entry {
        border-color: darker(@unfocused_borders);
    }
    .invalid entry, entry.invalid {
        border-color: @error_color;
    }
    """

    screen = Gdk.Screen.get_default()
    style_context = Gtk.StyleContext()
    provider = Gtk.CssProvider()
    provider.load_from_data(CSS)
    style_context.add_provider_for_screen(
        screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    theme_path = os.path.join(get_config_dir(), 'theme.css')
    if os.path.exists(theme_path):
        provider = Gtk.CssProvider()
        provider.load_from_path(theme_path)
        style_context.add_provider_for_screen(screen, provider,
                                              Gtk.STYLE_PROVIDER_PRIORITY_USER)

    def excepthook(type_, value, traceback_):
        common.error(str(value), ''.join(traceback.format_tb(traceback_)))

    sys.excepthook = excepthook

    CONFIG.parse()
    if CONFIG.arguments:
        url = CONFIG.arguments[0]
        urlp = urlparse(url)
        if urlp.scheme == 'tryton':
            urlp = urlparse('http' + url[6:])
            database, _ = (urlp.path[1:].split('/', 1) + [None])[:2]
            CONFIG['login.host'] = urlp.netloc
            CONFIG['login.db'] = database
            CONFIG['login.expanded'] = True
        else:
            CONFIG.arguments = []
    translate.set_language_direction(CONFIG['client.language_direction'])
    translate.setlang(CONFIG['client.lang'])
    common.ICONFACTORY.load_client_icons()
    if CONFIG.arguments or DBLogin().run():
        server = '%(hostname)s:%(port)s/%(database)s' % {
            'hostname': common.get_hostname(CONFIG['login.host']),
            'port': common.get_port(CONFIG['login.host']),
            'database': CONFIG['login.db'],
        }
        server = hashlib.md5(server.encode('utf-8')).hexdigest()
        application_id = 'org.tryton._' + server
        app = gui.Main(application_id=application_id,
                       flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
        app.run([sys.argv[0]] + CONFIG.arguments)
예제 #3
0
파일: main.py 프로젝트: masking/tryton
    def get_preferences(self, date=''):
        RPCContextReload()
        try:
            prefs = RPCExecute('model', 'res.user', 'get_preferences', False)
        except RPCException:
            prefs = {}

        threads = []
        for target in (
                common.IconFactory.load_icons,
                common.MODELACCESS.load_models,
                common.MODELHISTORY.load_history,
                common.VIEW_SEARCH.load_searches,
                ):
            t = threading.Thread(target=target)
            threads.append(t)
            t.start()
        for t in threads:
            t.join()
        if prefs and 'language_direction' in prefs:
            translate.set_language_direction(prefs['language_direction'])
            CONFIG['client.language_direction'] = \
                prefs['language_direction']
        self.sig_win_menu(prefs=prefs)
        for action_id in prefs.get('actions', []):
            Action.execute(action_id, {})
        # XXX: add connection date
        connection_date = date.strftime('%d/%m/%Y') if date else ''
        self.set_title(prefs.get('status_bar', ''), connection_date)
        # AKE: change bg color based on preferences
        color_bg = prefs.get('color_bg', None
            ) or os.environ.get('TRYTON_CLIENT_BG_COLOR', None)
        if color_bg:
            self.window.modify_bg(Gtk.StateType.NORMAL,
                Gdk.color_parse(color_bg))
        if prefs and 'language' in prefs:
            translate.setlang(prefs['language'], prefs.get('locale'))
            if CONFIG['client.lang'] != prefs['language']:
                self.favorite_unset()
            CONFIG['client.lang'] = prefs['language']
        # Set placeholder after language is set to get correct translation
        self.global_search_entry.set_placeholder_text(_("Action"))
        CONFIG.save()
예제 #4
0
 def __init__(self):
     CONFIG.parse()
     if CONFIG.arguments:
         url, = CONFIG.arguments
         urlp = urlparse(url)
         if urlp.scheme == 'tryton':
             urlp = urlparse('http' + url[6:])
             hostname = common.get_hostname(urlp.netloc)
             port = common.get_port(urlp.netloc)
             database, _ = (urlp.path[1:].split('/', 1) + [None])[:2]
             if IPCClient(hostname, port, database).write(url):
                 sys.exit(0)
             CONFIG['login.host'] = urlp.netloc
             CONFIG['login.db'] = database
             CONFIG['login.expanded'] = True
     translate.set_language_direction(CONFIG['client.language_direction'])
     translate.setlang(CONFIG['client.lang'])
     self.quit_client = (threading.Event()
                         if sys.platform == 'win32' else None)
     common.ICONFACTORY.load_client_icons()
예제 #5
0
파일: client.py 프로젝트: coopengo/tryton
 def __init__(self):
     CONFIG.parse()
     if CONFIG.arguments:
         url, = CONFIG.arguments
         urlp = urlparse(url)
         if urlp.scheme == "tryton":
             urlp = urlparse("http" + url[6:])
             hostname, port = (urlp.netloc.split(":", 1) + [CONFIG.defaults["login.port"]])[:2]
             database, _ = (urlp.path[1:].split("/", 1) + [None])[:2]
             if IPCClient(hostname, port, database).write(url):
                 sys.exit(0)
             CONFIG["login.server"] = hostname
             CONFIG["login.port"] = port
             CONFIG["login.db"] = database
             CONFIG["login.expanded"] = True
             CONFIG["proxy.active"] = False
     translate.set_language_direction(CONFIG["client.language_direction"])
     translate.setlang(CONFIG["client.lang"])
     self.quit_client = threading.Event() if sys.platform == "win32" else None
     common.ICONFACTORY.load_client_icons()
예제 #6
0
 def __init__(self):
     CONFIG.parse()
     if CONFIG.arguments:
         url, = CONFIG.arguments
         urlp = urlparse(url)
         if urlp.scheme == 'tryton':
             urlp = urlparse('http' + url[6:])
             hostname, port = (urlp.netloc.split(':', 1)
                     + [CONFIG.defaults['login.port']])[:2]
             database, _ = (urlp.path[1:].split('/', 1) + [None])[:2]
             if IPCClient(hostname, port, database).write(url):
                 sys.exit(0)
             CONFIG['login.server'] = hostname
             CONFIG['login.port'] = port
             CONFIG['login.db'] = database
             CONFIG['login.expanded'] = True
     translate.set_language_direction(CONFIG['client.language_direction'])
     translate.setlang(CONFIG['client.lang'])
     self.quit_client = (threading.Event()
         if sys.platform == 'win32' else None)
     common.ICONFACTORY.load_client_icons()
예제 #7
0
    def __init__(self):
        CONFIG.parse()
        if CONFIG.arguments:
            url, = CONFIG.arguments
            urlp = urlparse(url)
            if urlp.scheme == 'tryton':
                urlp = urlparse('http' + url[6:])
                hostname, port = (urlp.netloc.split(':', 1)
                        + [CONFIG.defaults['login.port']])[:2]
                database, _ = (urlp.path[1:].split('/', 1) + [None])[:2]
                if IPCClient(hostname, port, database).write(url):
                    sys.exit(0)
                CONFIG['login.server'] = hostname
                CONFIG['login.port'] = port
                CONFIG['login.db'] = database
                CONFIG['login.expanded'] = True
        logging.basicConfig()
        translate.set_language_direction(CONFIG['client.language_direction'])
        translate.setlang(CONFIG['client.lang'])
        loglevel = {
                'DEBUG': logging.DEBUG,
                'INFO': logging.INFO,
                'WARNING': logging.WARNING,
                'ERROR': logging.ERROR,
                'CRITICAL': logging.CRITICAL,
                }
        for logger in CONFIG['logging.logger'].split(','):
            if logger:
                log = logging.getLogger(logger)
                log.setLevel(loglevel[CONFIG['logging.level'].upper()])
        if CONFIG['logging.default']:
            logging.getLogger().setLevel(
                    loglevel[CONFIG['logging.default'].upper()])

        self.quit_client = (threading.Event()
            if sys.platform == 'win32' else None)
        common.ICONFACTORY.load_client_icons()
예제 #8
0
def main():
    CSS = b"""
    .readonly entry, .readonly text {
        background-color: @insensitive_bg_color;
    }
    .required entry, .required text {
        border-color: darker(@unfocused_borders);
    }
    .invalid entry, entry.invalid, .invalid text, text.invalid {
        border-color: @error_color;
    }
    label.required {
        font-weight: bold;
    }
    label.editable {
        font-style: italic;
    }
    .window-title, .wizard-title {
        background-color: white;
        font-size: large;
        font-weight: bold;
    }
    .window-title .status {
        font-size: medium;
        font-weight: normal;
    }
    """

    screen = Gdk.Screen.get_default()
    style_context = Gtk.StyleContext()
    provider = Gtk.CssProvider()
    # the line below injects CSS with higher priority than the custom theme
    # -> it overrides Coog theme behavior
    # provider.load_from_data(CSS)
    style_context.add_provider_for_screen(screen, provider,
                                          Gtk.STYLE_PROVIDER_PRIORITY_USER)
    theme_path = os.path.join(get_config_dir(), 'theme.css')
    if os.path.exists(theme_path):
        provider = Gtk.CssProvider()
        provider.load_from_path(theme_path)
        style_context.add_provider_for_screen(screen, provider,
                                              Gtk.STYLE_PROVIDER_PRIORITY_USER)

    def excepthook(type_, value, traceback_):
        common.error(value, ''.join(traceback.format_tb(traceback_)))

    sys.excepthook = excepthook

    CONFIG.parse()
    if CONFIG.arguments:
        url = CONFIG.arguments[0]
        urlp = urlparse(url)
        if urlp.scheme == 'tryton':
            urlp = urlparse('http' + url[6:])
            database, _ = (urlp.path[1:].split('/', 1) + [None])[:2]
            CONFIG['login.host'] = urlp.netloc
            CONFIG['login.db'] = database
            CONFIG['login.expanded'] = True
        else:
            CONFIG.arguments = []
    translate.set_language_direction(CONFIG['client.language_direction'])
    translate.setlang(CONFIG['client.lang'])
    if CONFIG.arguments or DBLogin().run():
        server = '%(hostname)s:%(port)s/%(database)s' % {
            'hostname': common.get_hostname(CONFIG['login.host']),
            'port': common.get_port(CONFIG['login.host']),
            'database': CONFIG['login.db'],
        }
        server = hashlib.md5(server.encode('utf-8')).hexdigest()
        application_id = 'org.tryton._' + server
        app = gui.Main(application_id=application_id,
                       flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
        app.run([sys.argv[0]] + CONFIG.arguments)