Exemple #1
0
import spacy
import numpy as np
import inflect
import language

np.random.seed(0)

lang = language.Language(phonemes={
    'V': 'AEIOU',
    'C': 'PTKMSL'
},
                         syll='CV',
                         wordlength=(3, 6))

nlp = spacy.load('en', tagger=False, parser=False, entity=False, matcher=False)


def load_words(filename):
    return [nlp(w) for w in open(filename).read().split("\n") if w.strip()]


nouns = load_words("nouns.txt")
verbs = load_words("verbs.txt")
adjectives = load_words("adjectives.txt")

for word in nouns + verbs + adjectives:
    assert word.vector.sum() != 0.0, word


def cosine(u, v):
    return np.dot(u, v) / (np.dot(u, u) * np.dot(v, v))**0.5
Exemple #2
0
    def __init__(self, app, cmd_line):
        Gtk.ApplicationWindow.__init__(self, title="Thus", application=app)

        # Check if we have administrative privileges
        if os.getuid() != 0:
            msg = _('This installer must be run with administrative privileges, '
                    'and cannot continue without them.')
            show.error(self, msg)
            sys.exit(1)

        # Check if we're already running
        tmp_running = "/tmp/.setup-running"
        if os.path.exists(tmp_running):
            logging.error(_("File '{0}' already exists.".format(tmp_running)))
            msg = _("You cannot run two instances of this installer.\n\n"
                    "If you are sure that the installer is not already running\n"
                    "you can run this installer using the --force option\n"
                    "or you can manually delete the offending file.\n\n"
                    "Offending file: '{0}'").format(tmp_running)
            show.error(self, msg)
            sys.exit(1)

        # workaround for dconf
        os.system("mkdir -p /root/.cache/dconf")
        os.system("chmod -R 777 /root/.cache")

        logging.info(_("Thus installer version {0}".format(info.THUS_VERSION)))

        self.settings = config.Settings()
        self.ui_dir = self.settings.get('ui')

        if not os.path.exists(self.ui_dir):
            thus_dir = os.path.join(os.path.dirname(__file__), './')
            self.settings.set('thus', thus_dir)

            ui_dir = os.path.join(os.path.dirname(__file__), 'ui/')
            self.settings.set('ui', ui_dir)

            data_dir = os.path.join(os.path.dirname(__file__), 'data/')
            self.settings.set('data', data_dir)

            self.ui_dir = self.settings.get('ui')

        '''if cmd_line.cache:
            logging.debug("Thus will use '{0}' as a source directory for cached xz packages".format(cmd_line.cache))
            self.settings.set('cache', cmd_line.cache)'''

        data_dir = self.settings.get('data')

        # For things we are not ready for users to test
        self.settings.set('z_hidden', cmd_line.z_hidden)

        self.ui = Gtk.Builder()
        path = os.path.join(self.ui_dir, "main_window.ui")
        self.ui.add_from_file(path)

        self.add(self.ui.get_object("main"))

        self.header = self.ui.get_object("header")

        self.logo = self.ui.get_object("logo")
        path = os.path.join(data_dir, "images", "manjaro", "manjaro-logo-mini.png")
        self.logo.set_from_file(path)

        self.title = self.ui.get_object("title")

        # To honor our css
        self.header.set_name("header")
        self.logo.set_name("logo")

        self.main_box = self.ui.get_object("main_box")

        self.progressbar = self.ui.get_object("main_progressbar")
        self.progressbar.set_name('process_progressbar')

        self.forward_button = self.ui.get_object("forward_button")
        self.exit_button = self.ui.get_object("exit_button")
        self.backwards_button = self.ui.get_object("backwards_button")

        # image1 = Gtk.Image.new_from_icon_name("go-next", Gtk.IconSize.LARGE_TOOLBAR)
        # self.forward_button.set_label("")
        # self.forward_button.set_image(image1)
        # self.forward_button.set_name('fwd_btn')
        # self.forward_button.set_always_show_image(True)
        # self.forward_button.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE))

        # image2 = Gtk.Image.new_from_icon_name("go-previous", Gtk.IconSize.LARGE_TOOLBAR)
        # self.backwards_button.set_label("")
        # self.backwards_button.set_image(image2)
        self.backwards_button.set_name('bk_btn')
        self.backwards_button.set_always_show_image(True)
        # self.backwards_button.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE))

        # Create a queue. Will be used to report pacman messages (pacman/pac.py)
        # to the main thread (installation/process.py)
        self.callback_queue = multiprocessing.JoinableQueue()

        '''# Save in config if we have to use aria2 to download pacman packages
        self.settings.set("use_aria2", cmd_line.aria2)
        if cmd_line.aria2:
            logging.info(_("Using Aria2 to download packages - EXPERIMENTAL"))'''

        # self.set_titlebar(self.header)

        # Prepare params dict to pass common parameters to all screens
        self.params = dict()
        self.params['title'] = self.title
        self.params['header'] = self.header
        self.params['ui_dir'] = self.ui_dir
        self.params['forward_button'] = self.forward_button
        self.params['exit_button'] = self.exit_button
        self.params['backwards_button'] = self.backwards_button
        self.params['callback_queue'] = self.callback_queue
        self.params['settings'] = self.settings
        self.params['main_progressbar'] = self.progressbar

        # self.params['disable_tryit'] = cmd_line.disable_tryit
        self.params['testing'] = cmd_line.testing

        # Just load the first two screens (the other ones will be loaded later)
        # We do this so the user has not to wait for all the screens to be loaded
        self.pages = dict()
        self.pages["language"] = language.Language(self.params)

        self.connect('delete-event', self.on_exit_button_clicked)
        self.connect('key-release-event', self.check_escape)

        self.ui.connect_signals(self)

        self.set_title(_("Manjaro Installer - Thus {0}".format(info.THUS_VERSION)))

        self.set_geometry()

        #self.set_position(Gtk.WindowPosition.CENTER)
        #self.set_resizable(False)
        #self.set_size_request(MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT)

        # Set window icon
        icon_path = os.path.join(data_dir, "images", "manjaro", "manjaro-icon.png")
        self.set_icon_from_file(icon_path)

        # Set the first page to show
        self.current_page = self.pages["language"]
        self.settings.set('timezone_start', True)

        self.main_box.add(self.current_page)

        # Use our css file (not in minimal, looks better without)
        # Sorry, not anymore thanks to gtk 3.16
        style_provider = Gtk.CssProvider()

        style_css = os.path.join(data_dir, "css", "gtk-style.css")

        with open(style_css, 'rb') as css:
            css_data = css.read()

        style_provider.load_from_data(css_data)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_USER
        )

        # Show main window
        self.show_all()

        self.current_page.prepare('forwards')

        # Hide backwards button
        self.backwards_button.hide()

        self.progressbar.set_fraction(0)
        self.progressbar_step = 0

        '''
        # Do not hide progress bar for minimal iso as it would break the widget alignment on language page.
        if not os.path.exists('/home/manjaro/.config/openbox'):
            # Hide progress bar
            self.progressbar.hide()
        '''

        with open(tmp_running, "w") as tmp_file:
            tmp_file.write("Thus {0}\n".format(1234))

        misc.gtk_refresh()
Exemple #3
0
import os
import xbmcgui
import xbmc
import string

__scriptname__ = "OpenSubtitles"
__author__ = "Leo"
__url__ = ""
__svn_url__ = ""
__credits__ = "Leo"
__version__ = "1.0"

BASE_RESOURCE_PATH = os.path.join(os.getcwd().replace(";", ""), "resources")
sys.path.append(os.path.join(BASE_RESOURCE_PATH, "lib"))
import language
__language__ = language.Language().localized

if (__name__ == "__main__"):

    import gui
    window = "main"

    search_string = ""
    path_string = ""
    type = "file"
    if len(sys.argv) > 1:
        tmp_string = sys.argv[1]
        tmp_string.strip()
        path_string = tmp_string[tmp_string.find("[PATH]") +
                                 len("[PATH]"):tmp_string.find("[/PATH]")]
        if (tmp_string.find("[MOVIE]") > -1):
Exemple #4
0
    def __init__(self):
        ## This allows to translate all py texts (not the glade ones)
        #gettext.textdomain(APP_NAME)
        #gettext.bindtextdomain(APP_NAME, LOCALE_DIR)
        #
        #locale_code, encoding = locale.getdefaultlocale()
        #lang = gettext.translation(APP_NAME, LOCALE_DIR, [locale_code], None, True)
        #lang.install()
        #
        ## With this we can use _("string") to translate
        #gettext.install(APP_NAME, localedir=LOCALE_DIR, codeset=None, names=[locale_code])

        # Check if we have administrative privileges
        if os.getuid() != 0:
            show.fatal_error(
                _('This installer must be run with administrative'
                  ' privileges and cannot continue without them.'))

        setup_logging()

        # Check if we're already running
        tmp_running = "/tmp/.setup-running"
        if os.path.exists(tmp_running):
            show.error(
                _('You cannot run two instances of this installer.\n\n'
                  'If you are sure that another installer is not already running\n'
                  'you can manually delete the file %s\n'
                  'and run this installer again.') % tmp_running)
            sys.exit(1)

        super().__init__()

        # workaround for dconf
        os.system("mkdir -p /root/.cache/dconf")
        os.system("chmod -R 777 /root/.cache")

        logging.info(_("Thus installer version %s"), info.THUS_VERSION)

        current_process = multiprocessing.current_process()
        logging.debug("[%d] %s started", current_process.pid,
                      current_process.name)

        self.settings = config.Settings()

        thus_dir = os.path.join(os.path.dirname(__file__), './')
        if os.path.exists(thus_dir):
            self.settings.set('thus', thus_dir)
        else:
            thus_dir = self.settings.get('thus')

        ui_dir = os.path.join(os.path.dirname(__file__), 'ui/')
        if os.path.exists(ui_dir):
            self.settings.set('ui', ui_dir)
        else:
            ui_dir = self.settings.get('ui')

        data_dir = os.path.join(os.path.dirname(__file__), 'data/')
        if os.path.exists(data_dir):
            self.settings.set('data', data_dir)
        else:
            data_dir = self.settings.get('data')

        if os.path.exists("/sys/firmware/efi"):
            self.settings.set('efi', True)

        self.ui = Gtk.Builder()
        self.ui.add_from_file(ui_dir + "thus.ui")

        self.add(self.ui.get_object("main"))

        self.header = self.ui.get_object("header")

        self.forward_button = self.ui.get_object("forward_button")

        self.logo = self.ui.get_object("logo")

        logo_dir = os.path.join(data_dir, "manjaro-logo-mini.png")

        self.logo.set_from_file(logo_dir)

        self.title = self.ui.get_object("title")

        # To honor our css
        self.title.set_name("header")
        self.logo.set_name("header")

        self.main_box = self.ui.get_object("main_box")
        self.progressbar = self.ui.get_object("progressbar1")

        self.forward_button = self.ui.get_object("forward_button")
        self.exit_button = self.ui.get_object("exit_button")
        self.backwards_button = self.ui.get_object("backwards_button")

        # Create a queue. Will be used to report pacman messages (pac.py)
        # to the main thread (installer_*.py)
        self.callback_queue = multiprocessing.JoinableQueue()

        # Load all pages
        # (each one is a screen, a step in the install process)

        self.pages = dict()

        params = dict()
        params['title'] = self.title
        params['forward_button'] = self.forward_button
        params['backwards_button'] = self.backwards_button
        params['exit_button'] = self.exit_button
        params['callback_queue'] = self.callback_queue
        params['settings'] = self.settings
        params['main_progressbar'] = self.ui.get_object('progressbar1')
        params['alternate_package_list'] = ""
        params['testing'] = cmd_line.testing

        self.pages["language"] = language.Language(params)
        self.pages["location"] = location.Location(params)
        self.pages["check"] = check.Check(params)
        self.pages["keymap"] = keymap.Keymap(params)
        self.pages["timezone"] = timezone.Timezone(params)
        self.pages["installation_ask"] = installation_ask.InstallationAsk(
            params)
        self.pages[
            "installation_automatic"] = installation_automatic.InstallationAutomatic(
                params)
        self.pages[
            "installation_alongside"] = installation_alongside.InstallationAlongside(
                params)
        self.pages[
            "installation_advanced"] = installation_advanced.InstallationAdvanced(
                params)
        self.pages["user_info"] = user_info.UserInfo(params)
        self.pages["slides"] = slides.Slides(params)

        self.connect("delete-event", Gtk.main_quit)
        self.ui.connect_signals(self)

        self.set_title(_('Manjaro Installer'))
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_resizable(False)
        self.set_size_request(MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT)

        # Set window icon
        icon_dir = os.path.join(data_dir, 'manjaro-icon.png')

        self.set_icon_from_file(icon_dir)

        # Set the first page to show
        self.current_page = self.pages["language"]

        self.main_box.add(self.current_page)

        # Header style testing

        style_provider = Gtk.CssProvider()

        style_css = os.path.join(data_dir, "css", "gtk-style.css")

        with open(style_css, 'rb') as css:
            css_data = css.read()

        style_provider.load_from_data(css_data)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        # Show main window
        self.show_all()

        self.current_page.prepare('forwards')

        # Hide backwards button
        self.backwards_button.hide()

        # Hide titlebar but show border decoration
        self.get_window().set_accept_focus(True)
        #self.get_window().set_decorations(Gdk.WMDecoration.BORDER)

        # Hide progress bar as it's value is zero
        self.progressbar.set_fraction(0)
        self.progressbar.hide()
        self.progressbar_step = 1.0 / (len(self.pages) - 2)

        with open(tmp_running, "w") as tmp_file:
            tmp_file.write("Thus %d\n" % 1234)

        GLib.timeout_add(1000,
                         self.pages["slides"].manage_events_from_cb_queue)
Exemple #5
0
    def __init__(self):
       
        # This allows to translate all py texts (not the glade ones)
        gettext.textdomain(APP)
        gettext.bindtextdomain(APP, DIR)

        locale_code, encoding = locale.getdefaultlocale()
        lang = gettext.translation (APP, DIR, [locale_code], None, True)
        lang.install()

        # With this we can use _("string") to translate
        gettext.install(APP, localedir=DIR, codeset=None, names=[locale_code])

        if os.getuid() != 0:
            show.fatal_error(_('This installer must be run with administrative'
                         ' privileges, and cannot continue without them.'))
        
        # check if we're already running
        tmp_running = "/tmp/.setup-running"
        if os.path.exists(tmp_running):
            show.error(_('You cannot run two instances of this installer.\n\n'
                          'If you are sure that the installer is not already running\n'
                          'you can manually delete the file %s\n'
                          'and run this installer again.') % tmp_running)
            sys.exit(1)
                
        super().__init__()
        
        self.settings = config.Settings()

        self.ui_dir = self.settings.get("UI_DIR")

        if not os.path.exists(self.ui_dir):
            cnchi_dir = os.path.join(os.path.dirname(__file__), './')
            self.settings.set("CNCHI_DIR", cnchi_dir)
            
            ui_dir = os.path.join(os.path.dirname(__file__), 'ui/')
            self.settings.set("UI_DIR", ui_dir)
            
            data_dir = os.path.join(os.path.dirname(__file__), 'data/')
            self.settings.set("DATA_DIR", data_dir)
            
            self.ui_dir = self.settings.get("UI_DIR")
            
        # set enabled desktops
        self.settings.set("desktops", _desktops)

        self.ui = Gtk.Builder()
        self.ui.add_from_file(self.ui_dir + "cnchi.ui")

        self.add(self.ui.get_object("main"))

        self.header = self.ui.get_object("box5")

        self.forward_button = self.ui.get_object("forward_button")

        self.logo = self.ui.get_object("logo")

        logo_dir = os.path.join(self.settings.get("DATA_DIR"), "antergos-logo-mini.png")
                                
        self.logo.set_from_file(logo_dir)

        self.title = self.ui.get_object("title")

        # To honor our css
        self.title.set_name("header")
        self.logo.set_name("header")

        self.main_box = self.ui.get_object("main_box")
        self.progressbar = self.ui.get_object("progressbar1")

        self.forward_button = self.ui.get_object("forward_button")
        self.exit_button = self.ui.get_object("exit_button")
        self.backwards_button = self.ui.get_object("backwards_button")
        
        # Create a queue. Will be used to report pacman messages (pac.py)
        # to the main thread (installer_*.py)
        #self.callback_queue = queue.Queue(0)
        # Doing some tests with a LIFO queue
        #self.callback_queue = queue.LifoQueue(0)
        self.callback_queue = Queue()

        # save in config if we have to use aria2 to download pacman packages
        self.settings.set("use_aria2", _use_aria2)
        if _use_aria2:
            log.debug(_("Cnchi will use pm2ml and aria2 to download packages - EXPERIMENTAL"))

        # load all pages
        # (each one is a screen, a step in the install process)

        self.pages = dict()

        params = dict()
        params['title'] = self.title
        params['ui_dir'] = self.ui_dir
        params['forward_button'] = self.forward_button
        params['backwards_button'] = self.backwards_button
        params['exit_button'] = self.exit_button
        params['callback_queue'] = self.callback_queue
        params['settings'] = self.settings
        params['alternate_package_list'] = _alternate_package_list
        params['enable_alongside'] = _enable_alongside
        
        if len(_alternate_package_list) > 0:
            log.debug(_("Using '%s' file as package list") % _alternate_package_list)
        
        self.pages["welcome"] = welcome.Welcome(params)
        self.pages["language"] = language.Language(params)
        self.pages["location"] = location.Location(params)
        self.pages["check"] = check.Check(params)
        self.pages["desktop"] = desktop.DesktopAsk(params)
        self.pages["keymap"] = keymap.Keymap(params)
        self.pages["timezone"] = timezone.Timezone(params)
        self.pages["installation_ask"] = installation_ask.InstallationAsk(params)
        self.pages["installation_automatic"] = installation_automatic.InstallationAutomatic(params)
        self.pages["installation_alongside"] = installation_alongside.InstallationAlongside(params)
        self.pages["installation_advanced"] = installation_advanced.InstallationAdvanced(params)
        self.pages["user_info"] = user_info.UserInfo(params)
        self.pages["slides"] = slides.Slides(params)

        self.connect("delete-event", Gtk.main_quit)
        self.ui.connect_signals(self)

        self.set_title(_('Antergos Installer'))
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_resizable(False)
        self.set_size_request(_main_window_width, _main_window_height);

        # set window icon
        icon_dir = os.path.join(self.settings.get("DATA_DIR"), 'antergos-icon.png')
        
        self.set_icon_from_file(icon_dir)

        # set the first page to show
        self.current_page = self.pages["welcome"]

        self.main_box.add(self.current_page)

        # Header style testing
        style_provider = Gtk.CssProvider()

        style_css = os.path.join(self.settings.get("DATA_DIR"), "css", "gtk-style.css")

        with open(style_css, 'rb') as css:
            css_data = css.read()

        style_provider.load_from_data(css_data)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), style_provider,     
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )

        # show main window
        self.show_all()

        self.current_page.prepare('forwards')

        # hide backwards button
        self.backwards_button.hide()

        # Hide titlebar but show border decoration
        self.get_window().set_accept_focus(True)
        self.get_window().set_decorations(Gdk.WMDecoration.BORDER)
        
        # hide progress bar as it's value is zero
        self.progressbar.set_fraction(0)
        self.progressbar.hide()
        self.progressbar_step = 1.0 / (len(self.pages) - 2)

        # we drop privileges, but where we should do it? before this? ¿?
        misc.drop_privileges()

        with open(tmp_running, "wt") as tmp_file:
            tmp_file.write("Cnchi %d\n" % 1234)

        GLib.timeout_add(100, self.pages["slides"].manage_events_from_cb_queue)
import struct
import binascii
from operator import itemgetter
import itertools
import collections
import language

try:
    from Crypto.Cipher import AES
    from Crypto.Util import Counter
except ImportError:
    from Cryptodome.Cipher import AES
    from Cryptodome.Util import Counter
import os

english = language.Language()


def find_key_and_decrypt_fixed_xor(message: bytes):
    """
    Devise some method for "scoring" a piece of English plaintext. Character frequency is a good metric.
    Evaluate each output and choose the one with the best score.
    """

    scores = list()
    for key in range(0, 256):
        try:
            decrypted = decrypt_xor(message, bytes([key]))
            score = english.score_text(decrypted)
            if score > 0:
                scores.append((key, english.score_text(decrypted), decrypted))
Exemple #7
0
    def __init__(self, app, cmd_line):
        Gtk.ApplicationWindow.__init__(self, title="Cnchi", application=app)

        self._main_window_width = 875
        self._main_window_height = 550

        logging.info("Cnchi installer version %s", info.CNCHI_VERSION)

        self.settings = config.Settings()
        self.ui_dir = self.settings.get('ui')

        if not os.path.exists(self.ui_dir):
            cnchi_dir = os.path.join(os.path.dirname(__file__), './')
            self.settings.set('cnchi', cnchi_dir)

            ui_dir = os.path.join(os.path.dirname(__file__), 'ui/')
            self.settings.set('ui', ui_dir)

            data_dir = os.path.join(os.path.dirname(__file__), 'data/')
            self.settings.set('data', data_dir)

            self.ui_dir = self.settings.get('ui')

        # By default, always try to use local /var/cache/pacman/pkg
        xz_cache = ["/var/cache/pacman/pkg"]

        # Check command line
        if cmd_line.cache and cmd_line.cache not in xz_cache:
            xz_cache.append(cmd_line.cache)

        # Log cache dirs
        for xz in xz_cache:
            logging.debug(
                "Cnchi will use '%s' as a source for cached xz packages", xz)

        # Store cache dirs in config
        self.settings.set('xz_cache', xz_cache)

        data_dir = self.settings.get('data')

        # For things we are not ready for users to test
        self.settings.set('z_hidden', cmd_line.z_hidden)

        # a11y
        self.settings.set('a11y', cmd_line.a11y)

        # Set enabled desktops
        if self.settings.get('z_hidden'):
            self.settings.set('desktops', desktop_info.DESKTOPS_DEV)
        elif self.settings.get('a11y'):
            self.settings.set('desktops', desktop_info.DESKTOPS_A11Y)
        else:
            self.settings.set('desktops', desktop_info.DESKTOPS)

        if cmd_line.environment:
            my_desktop = cmd_line.environment.lower()
            if my_desktop in desktop_info.DESKTOPS:
                self.settings.set('desktop', my_desktop)
                self.settings.set('desktop_ask', False)
                logging.debug("Cnchi will install the %s desktop environment",
                              my_desktop)

        self.ui = Gtk.Builder()
        path = os.path.join(self.ui_dir, "cnchi.ui")
        self.ui.add_from_file(path)

        self.add(self.ui.get_object("main"))

        self.header_ui = Gtk.Builder()
        path = os.path.join(self.ui_dir, "header.ui")
        self.header_ui.add_from_file(path)
        self.header = self.header_ui.get_object("header")

        self.logo = self.header_ui.get_object("logo")
        path = os.path.join(data_dir, "images", "antergos",
                            "antergos-logo-mini2.png")
        self.logo.set_from_file(path)

        # To honor our css
        self.header.set_name("header")
        self.logo.set_name("logo")

        self.main_box = self.ui.get_object("main_box")
        # self.main_box.set_property('width_request', 800)

        self.progressbar = self.ui.get_object("main_progressbar")
        self.progressbar.set_name('process_progressbar')
        # a11y
        self.progressbar.set_can_focus(False)

        self.forward_button = self.header_ui.get_object("forward_button")
        self.backwards_button = self.header_ui.get_object("backwards_button")

        # atk_set_image_description(self.forward_button, _("Next step"))
        # atk_set_image_description(self.backwards_button, _("Previous step"))
        # atk_set_object_description(self.forward_button, _("Next step"))
        # atk_set_object_description(self.backwards_button, _("Previous step"))

        self.forward_button.set_name('fwd_btn')
        self.forward_button.set_always_show_image(True)

        self.backwards_button.set_name('bk_btn')
        self.backwards_button.set_always_show_image(True)

        # a11y
        if cmd_line.a11y:
            self.forward_button.set_label(_("Next"))
            self.backwards_button.set_label(_("Back"))

        # Create a queue. Will be used to report pacman messages
        # (pacman/pac.py) to the main thread (installation/process.py)
        self.callback_queue = multiprocessing.JoinableQueue()

        # This list will have all processes (rankmirrors, autotimezone...)
        self.process_list = []

        if cmd_line.packagelist:
            self.settings.set('alternate_package_list', cmd_line.packagelist)
            logging.info("Using '%s' file as package list",
                         self.settings.get('alternate_package_list'))

        self.set_titlebar(self.header)

        # Prepare params dict to pass common parameters to all screens
        self.params = dict()
        self.params['main_window'] = self
        self.params['header'] = self.header
        self.params['ui_dir'] = self.ui_dir
        self.params['forward_button'] = self.forward_button
        self.params['backwards_button'] = self.backwards_button
        self.params['callback_queue'] = self.callback_queue
        self.params['settings'] = self.settings
        self.params['main_progressbar'] = self.progressbar
        self.params['process_list'] = self.process_list

        self.params['checks_are_optional'] = cmd_line.no_check
        self.params['disable_tryit'] = cmd_line.disable_tryit
        self.params['a11y'] = cmd_line.a11y

        # Just load the first two screens (the other ones will be loaded later)
        # We do this so the user has not to wait for all the screens to be
        # loaded
        self.pages = dict()
        self.pages["welcome"] = welcome.Welcome(self.params)

        if os.path.exists('/home/reborn/.config/openbox'):
            # In minimal iso, load language screen now
            self.pages["language"] = language.Language(self.params)

            # Fix bugy Gtk window size when using Openbox
            self._main_window_width = 750
            self._main_window_height = 450

        self.connect('delete-event', self.on_exit_button_clicked)
        self.connect('key-release-event', self.on_key_release)

        self.ui.connect_signals(self)
        self.header_ui.connect_signals(self)

        nil, major, minor = info.CNCHI_VERSION.split('.')
        name = 'Cnchi '
        title_string = "{0} {1}.{2}.{3}".format(name, nil, major, minor)
        self.set_title(title_string)
        self.header.set_title(title_string)
        self.header.set_subtitle(_("Reborn Installer"))
        self.header.set_show_close_button(True)
        self.tooltip_string = "{0} {1}.{2}.{3}".format(name, nil, major, minor)
        self.header.forall(self.header_for_all_callback, self.tooltip_string)

        self.set_geometry()

        # Set window icon
        icon_path = os.path.join(data_dir, "images", "antergos",
                                 "antergos-icon.png")
        self.set_icon_from_file(icon_path)

        # Set the first page to show

        # If minimal iso is detected, skip the welcome page.
        if os.path.exists('/home/reborn/.config/openbox'):
            self.current_page = self.pages["language"]
            self.settings.set('timezone_start', True)
        else:
            self.current_page = self.pages["welcome"]

        self.main_box.add(self.current_page)

        # Use our css file
        style_provider = Gtk.CssProvider()

        style_css = os.path.join(data_dir, "css", "gtk-style.css")

        with open(style_css, 'rb') as css:
            css_data = css.read()

        style_provider.load_from_data(css_data)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_USER)

        # Show main window
        self.show_all()

        self.current_page.prepare('forwards')

        # Hide backwards button
        self.backwards_button.hide()

        self.progressbar.set_fraction(0)
        self.progressbar_step = 0

        # Do not hide progress bar for minimal iso as it would break
        # the widget alignment on language page.
        if not os.path.exists('/home/reborn/.config/openbox'):
            # Hide progress bar
            self.progressbar.hide()

        self.set_focus(None)

        misc.gtk_refresh()
Exemple #8
0
    def __init__(self, app, cmd_line):
        Gtk.ApplicationWindow.__init__(self, title="Cnchi", application=app)

        self.MAIN_WINDOW_WIDTH = 875
        self.MAIN_WINDOW_HEIGHT = 550

        logging.info("Cnchi installer version %s", info.CNCHI_VERSION)

        self.settings = config.Settings()
        self.ui_dir = self.settings.get('ui')

        if not os.path.exists(self.ui_dir):
            cnchi_dir = os.path.join(os.path.dirname(__file__), './')
            self.settings.set('cnchi', cnchi_dir)

            ui_dir = os.path.join(os.path.dirname(__file__), 'ui/')
            self.settings.set('ui', ui_dir)

            data_dir = os.path.join(os.path.dirname(__file__), 'data/')
            self.settings.set('data', data_dir)

            self.ui_dir = self.settings.get('ui')

        if cmd_line.cache:
            logging.debug(
                "Cnchi will use '%s' as a source directory for cached xz packages",
                cmd_line.cache)
            self.settings.set('cache', cmd_line.cache)

        data_dir = self.settings.get('data')

        # For things we are not ready for users to test
        self.settings.set('z_hidden', cmd_line.z_hidden)

        # Set enabled desktops
        if self.settings.get('z_hidden'):
            self.settings.set("desktops", desktop_info.DESKTOPS_DEV)
        else:
            self.settings.set("desktops", desktop_info.DESKTOPS)

        if cmd_line.environment:
            desktop = cmd_line.environment.lower()
            if desktop in desktop_info.DESKTOPS:
                self.settings.set('desktop', desktop)
                self.settings.set('desktop_ask', False)
                logging.debug("Cnchi will install the %s desktop environment",
                              desktop)

        self.ui = Gtk.Builder()
        path = os.path.join(self.ui_dir, "cnchi.ui")
        self.ui.add_from_file(path)

        self.add(self.ui.get_object("main"))

        self.header_ui = Gtk.Builder()
        path = os.path.join(self.ui_dir, "header.ui")
        self.header_ui.add_from_file(path)
        self.header = self.header_ui.get_object("header")

        self.logo = self.header_ui.get_object("logo")
        path = os.path.join(data_dir, "images", "antergos",
                            "antergos-logo-mini2.png")
        self.logo.set_from_file(path)

        # To honor our css
        self.header.set_name("header")
        self.logo.set_name("logo")

        self.main_box = self.ui.get_object("main_box")
        # self.main_box.set_property('width_request', 800)

        self.progressbar = self.ui.get_object("main_progressbar")
        self.progressbar.set_name('process_progressbar')

        self.forward_button = self.header_ui.get_object("forward_button")
        self.backwards_button = self.header_ui.get_object("backwards_button")

        atk_set_image_description(self.forward_button, _("Next step"))
        atk_set_image_description(self.backwards_button, _("Previous step"))

        self.forward_button.set_name('fwd_btn')
        self.forward_button.set_always_show_image(True)

        self.backwards_button.set_name('bk_btn')
        self.backwards_button.set_always_show_image(True)

        # Create a queue. Will be used to report pacman messages (pacman/pac.py)
        # to the main thread (installation/process.py)
        self.callback_queue = multiprocessing.JoinableQueue()

        # This list will have all processes (rankmirrors, autotimezone...)
        self.process_list = []

        # Save in config which download method we have to use
        if cmd_line.download_module:
            self.settings.set("download_module", cmd_line.download_module)
        else:
            # Use requests by default
            self.settings.set("download_module", 'requests')

        logging.info("Using %s to download packages",
                     self.settings.get("download_module"))

        if cmd_line.packagelist:
            self.settings.set('alternate_package_list', cmd_line.packagelist)
            logging.info("Using '%s' file as package list",
                         self.settings.get('alternate_package_list'))

        self.set_titlebar(self.header)

        # Prepare params dict to pass common parameters to all screens
        self.params = dict()
        self.params['main_window'] = self
        self.params['header'] = self.header
        self.params['ui_dir'] = self.ui_dir
        self.params['forward_button'] = self.forward_button
        self.params['backwards_button'] = self.backwards_button
        self.params['callback_queue'] = self.callback_queue
        self.params['settings'] = self.settings
        self.params['main_progressbar'] = self.progressbar
        self.params['process_list'] = self.process_list

        self.params['checks_are_optional'] = cmd_line.no_check
        self.params['disable_tryit'] = cmd_line.disable_tryit
        self.params['disable_rank_mirrors'] = cmd_line.disable_rank_mirrors
        self.params['testing'] = cmd_line.testing

        # Just load the first two screens (the other ones will be loaded later)
        # We do this so the user has not to wait for all the screens to be loaded
        self.pages = dict()
        self.pages["welcome"] = welcome.Welcome(self.params)

        if os.path.exists('/home/antergos/.config/openbox'):
            # In minimal iso, load language screen now
            self.pages["language"] = language.Language(self.params)

            # Fix bugy Gtk window size when using Openbox
            self.MAIN_WINDOW_WIDTH = 750
            self.MAIN_WINDOW_HEIGHT = 450

        self.connect('delete-event', self.on_exit_button_clicked)
        self.connect('key-release-event', self.check_escape)

        self.ui.connect_signals(self)
        self.header_ui.connect_signals(self)

        title = "Cnchi {0}".format(info.CNCHI_VERSION)
        self.set_title(title)
        self.header.set_title(title)
        self.header.set_subtitle(_("Antergos Installer"))
        self.header.set_show_close_button(True)

        self.set_geometry()

        # Set window icon
        icon_path = os.path.join(data_dir, "images", "antergos",
                                 "antergos-icon.png")
        self.set_icon_from_file(icon_path)

        # Set the first page to show

        # If minimal iso is detected, skip the welcome page.
        if os.path.exists('/home/antergos/.config/openbox'):
            self.current_page = self.pages["language"]
            self.settings.set('timezone_start', True)
        else:
            self.current_page = self.pages["welcome"]

        self.main_box.add(self.current_page)

        # Use our css file
        style_provider = Gtk.CssProvider()

        style_css = os.path.join(data_dir, "css", "gtk-style.css")

        with open(style_css, 'rb') as css:
            css_data = css.read()

        style_provider.load_from_data(css_data)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_USER)

        # Show main window
        self.show_all()

        self.current_page.prepare('forwards')

        # Hide backwards button
        self.backwards_button.hide()

        self.progressbar.set_fraction(0)
        self.progressbar_step = 0

        # Do not hide progress bar for minimal iso as it would break the widget alignment on language page.
        if not os.path.exists('/home/antergos/.config/openbox'):
            # Hide progress bar
            self.progressbar.hide()

        misc.gtk_refresh()