From 5d243fccaea5cc735fd3c3ecf67e525e44e96f30 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Sun, 22 Jan 2017 14:11:20 -0600 Subject: [PATCH] start working on migrating codebase to python with qt webengine backend. --- .editorconfig | 3 + web-greeter/__init__.py | 0 web-greeter/bridge/Greeter.py | 159 +++++++++++++++++++++++++++++++++ web-greeter/bridge/__init__.py | 65 ++++++++++++++ web-greeter/greeter.py | 82 +++++++++++++++++ web-greeter/whither.yml | 31 +++++++ 6 files changed, 340 insertions(+) create mode 100644 web-greeter/__init__.py create mode 100644 web-greeter/bridge/Greeter.py create mode 100644 web-greeter/bridge/__init__.py create mode 100644 web-greeter/greeter.py create mode 100644 web-greeter/whither.yml diff --git a/.editorconfig b/.editorconfig index d16d726..5d97ae7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,3 +20,6 @@ max_line_length = 99 continuation_indent_size = 4 indent_brace_style = 1TBS curly_bracket_next_line = false + +[*.py] +indent_style = space diff --git a/web-greeter/__init__.py b/web-greeter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/web-greeter/bridge/Greeter.py b/web-greeter/bridge/Greeter.py new file mode 100644 index 0000000..161601f --- /dev/null +++ b/web-greeter/bridge/Greeter.py @@ -0,0 +1,159 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# LightDMGreeter.py +# +# Copyright © 2017 Antergos +# +# This file is part of Web Greeter. +# +# Web Greeter is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Web Greeter is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# The following additional terms are in effect as per Section 7 of the license: +# +# The preservation of all legal notices and author attributions in +# the material or in the Appropriate Legal Notices displayed +# by works containing it is required. +# +# You should have received a copy of the GNU General Public License +# along with Web Greeter; If not, see . + +# Standard Lib + +# 3rd-Party Libs +import gi +gi.require_version('LightDM', '1') +from gi.repository import LightDM +from PyQt5.QtCore import QVariant +from whither.bridge import BridgeObject, prop + +# This Application +from . import ( + language_to_dict, + layout_to_dict, + session_to_dict, + user_to_dict, +) + + +LightDMGreeter = LightDM.Greeter() +LightDMUserList = LightDM.UserList() + + +class Greeter(BridgeObject): + + def __init__(self, *args, **kwargs): + super().__init__(name='LightDMGreeter', *args, **kwargs) + + @prop(str) + def authentication_user(self): + return LightDMGreeter.get_authentication_user() or '' + + @prop(bool) + def autologin_guest(self): + return LightDMGreeter.get_autologin_guest_hint() + + @prop(int) + def autologin_timeout(self): + return LightDMGreeter.get_autologin_timeout_hint() + + @prop(str) + def autologin_user(self): + return LightDMGreeter.get_autologin_user_hint() + + @prop(bool) + def can_hibernate(self): + return LightDM.get_can_hibernate() + + @prop(bool) + def can_restart(self): + return LightDM.get_can_restart() + + @prop(bool) + def can_shutdown(self): + return LightDM.get_can_shutdown() + + @prop(bool) + def can_suspend(self): + return LightDM.get_can_suspend() + + @prop(str) + def default_session(self): + return LightDMGreeter.get_default_session_hint() + + @prop(bool) + def has_guest_account(self): + return LightDMGreeter.get_has_guest_account_hint() + + @prop(bool) + def hide_users(self): + return LightDMGreeter.get_hide_users_hint() + + @prop(str) + def hostname(self): + return LightDM.get_hostname() + + @prop(bool) + def in_authentication(self): + return LightDMGreeter.get_in_authentication() + + @prop(bool) + def is_authenticated(self): + return LightDMGreeter.get_is_authenticated() + + @prop(QVariant) + def language(self): + return language_to_dict(LightDM.get_language()) + + @prop(list) + def languages(self): + return [language_to_dict(lang) for lang in LightDM.get_languages()] + + @prop(QVariant) + def layout(self): + return layout_to_dict(LightDM.get_layout()) + + @prop(list) + def layouts(self): + return [layout_to_dict(layout) for layout in LightDM.get_layouts()] + + @prop(bool) + def lock_hint(self): + return LightDMGreeter.get_lock_hint() + + @prop(list) + def remote_sessions(self): + return [session_to_dict(session) for session in LightDM.get_remote_sessions()] + + @prop(bool) + def select_guest_hint(self): + return LightDMGreeter.get_select_guest_hint() + + @prop(str) + def select_user_hint(self): + return LightDMGreeter.get_select_user_hint() or '' + + @prop(list) + def sessions(self): + return [session_to_dict(session) for session in LightDM.get_sessions()] + + @prop(bool) + def show_manual_login_hint(self): + return LightDMGreeter.get_show_manual_login_hint() + + @prop(bool) + def show_remote_login_hint(self): + return LightDMGreeter.get_show_remote_login_hint() + + @prop(list) + def users(self): + return [user_to_dict(user) for user in LightDMUserList.get_users()] + diff --git a/web-greeter/bridge/__init__.py b/web-greeter/bridge/__init__.py new file mode 100644 index 0000000..85c6f2b --- /dev/null +++ b/web-greeter/bridge/__init__.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# __init__.py +# +# Copyright © 2017 Antergos +# +# This file is part of Web Greeter. +# +# Web Greeter is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Web Greeter is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# The following additional terms are in effect as per Section 7 of the license: +# +# The preservation of all legal notices and author attributions in +# the material or in the Appropriate Legal Notices displayed +# by works containing it is required. +# +# You should have received a copy of the GNU General Public License +# along with Web Greeter; If not, see . + + +def language_to_dict(lang): + return dict(code=lang.get_code(), name=lang.get_name(), territory=lang.get_territory()) + + +def layout_to_dict(layout): + return dict( + description=layout.get_description(), + name=layout.get_name(), + short_description=layout.get_short_description() + ) + + +def session_to_dict(session): + return dict( + comment=session.get_comment(), + key=session.get_key(), + name=session.get_name(), + type=session.get_session_type(), + ) + + +def user_to_dict(user): + return dict( + display_name=user.get_display_name(), + home_directory=user.get_home_directory(), + image=user.get_image(), + language=user.get_language(), + layout=user.get_layout(), + logged_in=user.get_logged_in(), + session=user.get_session(), + username=user.get_name(), + # ---->>> BEGIN DEPRECATED! <<<---- + name=user.get_name(), + real_name=user.get_real_name(), + # ---->>> END DEPRECATED! <<<---- + ) diff --git a/web-greeter/greeter.py b/web-greeter/greeter.py new file mode 100644 index 0000000..a5eddd1 --- /dev/null +++ b/web-greeter/greeter.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# greeter.py +# +# Copyright © 2017 Antergos +# +# This file is part of Web Greeter. +# +# Web Greeter is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Web Greeter is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# The following additional terms are in effect as per Section 7 of the license: +# +# The preservation of all legal notices and author attributions in +# the material or in the Appropriate Legal Notices displayed +# by works containing it is required. +# +# You should have received a copy of the GNU General Public License +# along with Web Greeter; If not, see . + +# Standard Lib +import configparser +import os + +# 3rd-Party Libs +from whither.app import App +from whither.base.data import AttributeDict + +# This Application +from bridge.Greeter import Greeter + + +BASE_DIR = os.path.dirname(os.path.realpath(__file__)) +CONFIG_FILE = os.path.join(BASE_DIR, 'whither.yml') + + +class WebGreeter(App): + _user_config = AttributeDict({}) + _greeter = None + + def __init__(self, *args, **kwargs): + super().__init__('WebGreeter', config_file=CONFIG_FILE, debug=True, *args, **kwargs) + self.get_and_save_user_config() + + self._greeter = Greeter() + self._web_container.bridge_objects = (self._greeter,) + + self._web_container.initialize_bridge_objects() + self.load_theme() + + def get_and_save_user_config(self): + config = configparser.ConfigParser() + + config.read('/etc/lightdm/web-greeter.conf') + + for section in config.sections(): + self._user_config[section] = {} + + for key in config[section]: + self._user_config[section][key] = config[section][key] + + def load_theme(self): + theme_url = 'file://{0}/{1}/index.html'.format( + self.config.themes_dir, + self._user_config.greeter.webkit_theme + ) + + self._web_container.load(theme_url) + + +if __name__ == '__main__': + greeter = WebGreeter() + + greeter.run() diff --git a/web-greeter/whither.yml b/web-greeter/whither.yml new file mode 100644 index 0000000..607c14e --- /dev/null +++ b/web-greeter/whither.yml @@ -0,0 +1,31 @@ +# Whither (Universal Linux Apps) Configuration +# The top-level keys in this file should be application names. This makes it possible to +# install multiple Whither-based apps on a single system, each with their own configuration. + +# App Name +WebGreeter: + # Whither's Config + whither: + # Unique identifier string (dbus-style) + app_id: com.antergos.web-greeter + toolkit: auto # auto|qt|gtk + # A valid URI for an HTML page that will be loaded when the app starts. + entry_point: + autoload: False + url: '' + window: + width: 1120 + height: 720 + initial_state: maximized # normal|maximized|minimized|fullscreen + # Whether or not the window should show standard titlebar and action buttons. + decorated: False + # Whether or not the window should stay on top of all other windows. + stays_on_top: False + title: Web Greeter for LightDM + icon: /usr/share/cnchi/data/icons/48x48/cnchi.png + toolbar: + enabled: False + + # App's Config + app: + themes_dir: /usr/share/lightdm-webkit/themes