Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the first language page for the installer #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion config/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
"launch_without_root": false,
"default_language_code": "fr",
"locales_folder": "./locales",
"language_files": ["main_window", "popup", "general"]
"config_page": {
"language_live": {
"id": "language_live",
"icon": "./ui/gtk/img/ico/page1.png"
}
},
"language_files": ["main_window", "popup", "general", "language_live_page"]
}
25 changes: 25 additions & 0 deletions locales/en/LC_MESSAGES/language_live_page.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"X-Poedit-SourceCharset: UTF-8\n"

msgid "title"
msgstr "Live CD language configuration"

msgid "sidebar_title"
msgstr "Live CD language"

msgid "desc_language"
msgstr "Language :"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In English, there is no space before the punctuation like :, !, ?, etc.


msgid "desc_keyboard"
msgstr "Keyboard :"

msgid "input_keyboard"
msgstr "Try the keyboard here"

msgid "french"
msgstr "French"

msgid "english"
msgstr "English"
25 changes: 25 additions & 0 deletions locales/fr/LC_MESSAGES/language_live_page.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"X-Poedit-SourceCharset: UTF-8\n"

msgid "title"
msgstr "Configuration du langage de l'installeur"

msgid "sidebar_title"
msgstr "Langage de l'installeur"

msgid "desc_language"
msgstr "Langue :"

msgid "desc_keyboard"
msgstr "Clavier :"

msgid "input_keyboard"
msgstr "Essayez le clavier ici"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msgstr "Essayez le clavier ici"
msgstr "Essayer le clavier ici"


msgid "french"
msgstr "Français"

msgid "english"
msgstr "Anglais"
Binary file added ui/gtk/img/ico/page1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 129 additions & 2 deletions ui/gtk/main_window.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import gi
import threading

gi.require_version('Gtk', '3.0')

from gi.repository import Gdk, GObject, Gtk, GdkPixbuf
from gi.repository import Gdk, GObject, Gtk, GLib, GdkPixbuf
from ui.gtk.main_window_button import MainWindowButton
from egg.language_management import LanguageManagement
from ui.gtk.pages.page import Page
from ui.gtk.pages.language_live_page import LanguageLivePage


class Handler:
Expand All @@ -24,10 +28,27 @@ def load_component_main_window(self, config: dict) -> None:
def set_component(self, component_name: str, component: GObject.Object) -> None:
self._all_components[component_name] = component

def get_component(self, component_name: str) -> None:
def get_component(self, component_name: str) -> GObject:
return self._all_components[component_name]


class TitleLabel(Gtk.Label):
_page_id = None

def __init__(self, page_id: str, sidebar_title: str) -> None:
Gtk.Label.__init__(self)
self.set_label(sidebar_title)
self._page_id = page_id
self.set_halign(Gtk.Align.START)
self.get_style_context().add_class('dim-label')
self.set_property('margin', 6)
self.set_property('margin-start', 24)
self.set_property('margin-end', 24)

def get_page_id(self) -> str:
return self._page_id


class MainWindowGtk:

def __init__(self, locale_general: LanguageManagement, config_general: dict, config_main_window: dict) -> None:
Expand Down Expand Up @@ -63,12 +84,118 @@ def __init__(self, locale_general: LanguageManagement, config_general: dict, con
ltr = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT
self._component.get_component('main_window_right_stack').set_transition_type(ltr)
self._settings.set_property('gtk-application-prefer-dark-theme', True)
self.register_all_pages()
self.load_lang()
self.update_page()

self._component.get_component('main_window_prev_btn').connect('clicked', lambda x: self.prev_page_btn())
self._component.get_component('main_window_next_btn').connect('clicked', lambda x: self.next_page_btn())
self._component.get_component('main_window').show_all()
GLib.idle_add(self.prepare_all_long_tasks_page)

def set_title(self, message: str) -> None:
self._component.get_component('main_window_header_right_label').set_halign(Gtk.Align.START)
self._component.get_component('main_window_header_right_label').set_label(
u'<span font-size=\'x-large\'>{}</span>'.format(message))

def register_all_pages(self) -> None:
all_pages = [
LanguageLivePage(self._locale_general, self._config_general)
]
# Add pages in the stack
for current_page in all_pages:
current_page.load_win(self)
self._component.get_component('main_window_right_stack').add_named(
current_page._components.get_component('general_box'), current_page.get_page_id())
self._component.get_component('main_window_left_list_text_box').pack_start(
TitleLabel(current_page.get_page_id(), current_page.get_page_sidebar_title()), False, False, 0)
self._pages.append(current_page)

def current_page(self) -> Page:
return self._pages[self._page_index]

def load_lang(self) -> None:
component = self._component.get_component('main_window_left_list_text_box')
for label in component.get_children():
component.remove(label)

# Load pages labels with the current on the left box
for current_page in self._pages:
label_in_box = TitleLabel(current_page.get_page_id(), current_page.get_page_sidebar_title())
if label_in_box.get_page_id() == self.current_page().get_page_id():
label_in_box.get_style_context().remove_class('dim-label')
else:
label_in_box.get_style_context().add_class('dim-label')
self._component.get_component('main_window_left_list_text_box').pack_start(label_in_box, False,
False, 0)
current_page.refresh_ui_language()
self._component.get_component('main_window_left_list_text_box').show_all()

self.set_title(self.current_page().get_page_title())
self._component.get_component('main_window_prev_btn').set_label(
self._locale_general.translate_msg('main_window', 'bot_right_prev_btn'))
self._component.get_component('main_window_next_btn').set_label(
self._locale_general.translate_msg('main_window', 'bot_right_next_btn'))
self._component.get_component('main_window_header_right_quit_btn').set_label(
self._locale_general.translate_msg('main_window', 'top_right_quit_btn'))

def next_page_btn(self) -> None:
idx = self._page_index + 1
if idx >= len(self._pages):
return
self._page_index = idx
self.update_page()

def prev_page_btn(self) -> None:
idx = self._page_index - 1
if idx < 0:
return
self._page_index = idx
self.update_page()

def update_page(self) -> None:
self.set_title(self.current_page().get_page_title())
self.set_button_action_visibility(MainWindowButton.NEXT, self._page_index != len(self._pages) - 1)
self.set_button_action_visibility(MainWindowButton.PREV, self._page_index != 0)
self.set_button_visibility(MainWindowButton.NEXT, self._page_index == len(self._pages) - 1)
self.set_button_visibility(MainWindowButton.PREV, self._page_index == 0)

self.current_page().load_page()
# Update the current page icon
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(self.current_page().get_page_icon(), 50, 50, False)
self._component.get_component('main_window_top_left_logo').set_from_pixbuf(pixbuf)

# Update the current highlight page label
for label in self._component.get_component('main_window_left_list_text_box').get_children():
if label.get_page_id() == self.current_page().get_page_id():
label.get_style_context().remove_class('dim-label')
else:
label.get_style_context().add_class('dim-label')
self._component.get_component('main_window_right_stack').set_visible_child_name(
self.current_page().get_page_id())

def set_button_action_visibility(self, button: MainWindowButton, status: bool) -> None:
self._component.get_component(button.value).set_sensitive(status)

def set_button_visibility(self, button: MainWindowButton, hidden: bool) -> None:
if hidden:
self._component.get_component(button.value).hide()
else:
self._component.get_component(button.value).show_all()

def init_background_tasks(self) -> None:
for page in self._pages:
try:
page.long_task()
except Exception as e:
pass

def prepare_all_long_tasks_page(self) -> bool:
self.set_button_action_visibility(MainWindowButton.NEXT, False)
thread = threading.Thread(target=self.init_background_tasks)
thread.daemon = True
thread.start()
return False

def launch(self) -> None:
Gtk.main()
6 changes: 6 additions & 0 deletions ui/gtk/main_window_button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum


class MainWindowButton(Enum):
NEXT = 'main_window_next_btn'
PREV = 'main_window_prev_btn'
Empty file added ui/gtk/pages/__init__.py
Empty file.
Loading