#!/usr/bin/python3

# Keyboard details window

import logging
import json
from os import path
import qrcode
import tempfile

import gi
from gi.repository import Gtk

from keyman_config import KeymanComUrl, _, secure_lookup
from keyman_config.accelerators import init_accel
from keyman_config.kmpmetadata import parsemetadata

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

# basics: keyboard name, package version, description
# other things: filename (of kmx), ,
#    OSK availability, documentation availability, package copyright
# also: supported languages, fonts
# from kmx?: keyboard version, encoding, layout type

# there is data in kmp.inf/kmp.json
# there is possibly data in kbid.json (downloaded from api)


class KeyboardDetailsView(Gtk.Dialog):
    # TODO Display all the information that is available
    #    especially what is displayed for Keyman on Windows
    # TODO clean up file once have what we want
    def __init__(self, parent, kmp):
        # kmp has name, version, packageID, area
        if "keyboard" in kmp["name"].lower():
            wintitle = kmp["name"]
        else:
            wintitle = _("{name} keyboard").format(name=kmp["name"])
        Gtk.Dialog.__init__(self, wintitle, parent)
        init_accel(self)

        self.set_border_width(6)

        packageDir = path.join(kmp['areapath'], kmp['packageID'])
        kmp_json = path.join(packageDir, "kmp.json")
        info, system, options, keyboards, files = parsemetadata(kmp_json)

        if info is None:
            # Dialog when invalid metadata
            self.add_button(_("_Close"), Gtk.ResponseType.CLOSE)
            grid = Gtk.Grid()
            self.get_content_area().pack_start(grid, True, True, 12)
            lbl_invalid_metadata = Gtk.Label()
            lbl_invalid_metadata.set_text(_("ERROR: Keyboard metadata is damaged.\nPlease \"Uninstall\" and then \"Install\" the keyboard."))
            lbl_invalid_metadata.set_halign(Gtk.Align.END)
            grid.add(lbl_invalid_metadata)
            self.resize(700, 200)
            self.show_all()
            return

        kbdata = None
        jsonfile = path.join(packageDir, kmp['packageID'] + ".json")
        if path.isfile(jsonfile):
            try:
                with open(jsonfile, "r") as read_file:
                    kbdata = json.load(read_file)
            except Exception as e:
                logging.warning('Exception %s reading %s %s', type(e), jsonfile, e.args)

        grid = Gtk.Grid()
        # grid.set_column_homogeneous(True)

        # kbdatapath = path.join("/usr/local/share/keyman", kmp["id"], kmp["id"] + ".json")

        # Package info

        lbl_pkg_name = Gtk.Label()
        lbl_pkg_name.set_text(_("Package name:   "))
        lbl_pkg_name.set_halign(Gtk.Align.END)
        grid.add(lbl_pkg_name)
        prevlabel = lbl_pkg_name
        label = Gtk.Label()
        if secure_lookup(info, 'name', 'description'):
            label.set_text(secure_lookup(info, 'name', 'description'))
        label.set_halign(Gtk.Align.START)
        label.set_selectable(True)
        grid.attach_next_to(label, lbl_pkg_name, Gtk.PositionType.RIGHT, 1, 1)

        lbl_pkg_id = Gtk.Label()
        lbl_pkg_id.set_text(_("Package id:   "))
        lbl_pkg_id.set_halign(Gtk.Align.END)
        grid.attach_next_to(lbl_pkg_id, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
        prevlabel = lbl_pkg_id
        label = Gtk.Label()
        if secure_lookup(kmp, 'packageID'):
            label.set_text(kmp['packageID'])
        label.set_halign(Gtk.Align.START)
        label.set_selectable(True)
        grid.attach_next_to(label, lbl_pkg_id, Gtk.PositionType.RIGHT, 1, 1)

        lbl_pkg_vrs = Gtk.Label()
        lbl_pkg_vrs.set_text(_("Package version:   "))
        lbl_pkg_vrs.set_halign(Gtk.Align.END)
        grid.attach_next_to(lbl_pkg_vrs, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
        prevlabel = lbl_pkg_vrs
        label = Gtk.Label()
        if secure_lookup(info, 'version', 'description'):
            label.set_text(secure_lookup(info, 'version', 'description'))
        label.set_halign(Gtk.Align.START)
        label.set_selectable(True)
        grid.attach_next_to(label, lbl_pkg_vrs, Gtk.PositionType.RIGHT, 1, 1)

        if secure_lookup(kbdata, 'description'):
            lbl_pkg_desc = Gtk.Label()
            lbl_pkg_desc.set_text(_("Package description:   "))
            lbl_pkg_desc.set_halign(Gtk.Align.END)
            grid.attach_next_to(lbl_pkg_desc, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
            prevlabel = lbl_pkg_desc
            label = Gtk.Label()
            label.set_text(kbdata['description'])
            label.set_halign(Gtk.Align.START)
            label.set_selectable(True)
            label.set_line_wrap(80)
            grid.attach_next_to(label, lbl_pkg_desc, Gtk.PositionType.RIGHT, 1, 1)

        if secure_lookup(info, "author"):
            lbl_pkg_auth = Gtk.Label()
            lbl_pkg_auth.set_text(_("Package author:   "))
            lbl_pkg_auth.set_halign(Gtk.Align.END)
            grid.attach_next_to(lbl_pkg_auth, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
            prevlabel = lbl_pkg_auth
            label = Gtk.Label()
            if secure_lookup(info, 'author', 'description'):
                label.set_text(secure_lookup(info, 'author', 'description'))
            label.set_halign(Gtk.Align.START)
            label.set_selectable(True)
            grid.attach_next_to(label, lbl_pkg_auth, Gtk.PositionType.RIGHT, 1, 1)

        if secure_lookup(info, "copyright"):
            lbl_pkg_cpy = Gtk.Label()
            lbl_pkg_cpy.set_text(_("Package copyright:   "))
            lbl_pkg_cpy.set_halign(Gtk.Align.END)
            grid.attach_next_to(lbl_pkg_cpy, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
            prevlabel = lbl_pkg_cpy
            label = Gtk.Label()
            if secure_lookup(info, 'copyright', 'description'):
                label.set_text(secure_lookup(info, 'copyright', 'description'))
            label.set_halign(Gtk.Align.START)
            label.set_selectable(True)
            grid.attach_next_to(label, lbl_pkg_cpy, Gtk.PositionType.RIGHT, 1, 1)

        # Padding and full width horizontal divider
        lbl_pad = Gtk.Label()
        lbl_pad.set_text("")
        lbl_pad.set_halign(Gtk.Align.END)
        grid.attach_next_to(lbl_pad, prevlabel, Gtk.PositionType.BOTTOM, 2, 1)
        prevlabel = lbl_pad

        divider_pkg = Gtk.HSeparator()
        grid.attach_next_to(divider_pkg, prevlabel, Gtk.PositionType.BOTTOM, 2, 1)
        prevlabel = divider_pkg

        # Keyboard info for each keyboard

        if keyboards:
            for kbd in keyboards:
                kbdata = None
                jsonfile = path.join(packageDir, kbd['id'] + ".json")
                if path.isfile(jsonfile):
                    try:
                        with open(jsonfile, "r") as read_file:
                            kbdata = json.load(read_file)
                    except Exception as e:
                        logging.warning('Exception %s reading %s %s', type(e), jsonfile, e.args)

                # start with padding
                lbl_pad = Gtk.Label()
                lbl_pad.set_text("")
                lbl_pad.set_halign(Gtk.Align.END)
                grid.attach_next_to(lbl_pad, prevlabel, Gtk.PositionType.BOTTOM, 2, 1)
                prevlabel = lbl_pad

                # show the icon somewhere

                lbl_kbd_file = Gtk.Label()
                lbl_kbd_file.set_text(_("Keyboard filename:   "))
                lbl_kbd_file.set_halign(Gtk.Align.END)
                grid.attach_next_to(lbl_kbd_file, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                prevlabel = lbl_kbd_file
                label = Gtk.Label()
                label.set_text(path.join(packageDir, kbd['id'] + ".kmx"))
                label.set_halign(Gtk.Align.START)
                label.set_selectable(True)
                grid.attach_next_to(label, lbl_kbd_file, Gtk.PositionType.RIGHT, 1, 1)

                if kbdata and secure_lookup(kbdata, 'id') != secure_lookup(kmp, 'packageID'):
                    lbl_kbd_name = Gtk.Label()
                    lbl_kbd_name.set_text(_("Keyboard name:   "))
                    lbl_kbd_name.set_halign(Gtk.Align.END)
                    grid.attach_next_to(lbl_kbd_name, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                    prevlabel = lbl_kbd_name
                    label = Gtk.Label()
                    if secure_lookup(kbdata, 'name'):
                        label.set_text(kbdata['name'])
                    label.set_halign(Gtk.Align.START)
                    label.set_selectable(True)
                    grid.attach_next_to(label, lbl_kbd_name, Gtk.PositionType.RIGHT, 1, 1)

                    lbl_kbd_id = Gtk.Label()
                    lbl_kbd_id.set_text(_("Keyboard id:   "))
                    lbl_kbd_id.set_halign(Gtk.Align.END)
                    grid.attach_next_to(lbl_kbd_id, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                    prevlabel = lbl_kbd_id
                    label = Gtk.Label()
                    if secure_lookup(kbdata, 'id'):
                        label.set_text(kbdata['id'])
                    label.set_halign(Gtk.Align.START)
                    label.set_selectable(True)
                    grid.attach_next_to(label, lbl_kbd_id, Gtk.PositionType.RIGHT, 1, 1)

                    lbl_kbd_vrs = Gtk.Label()
                    lbl_kbd_vrs.set_text(_("Keyboard version:   "))
                    lbl_kbd_vrs.set_halign(Gtk.Align.END)
                    grid.attach_next_to(lbl_kbd_vrs, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                    prevlabel = lbl_kbd_vrs
                    label = Gtk.Label()
                    if secure_lookup(kbdata, 'version'):
                        label.set_text(kbdata['version'])
                    label.set_halign(Gtk.Align.START)
                    label.set_selectable(True)
                    grid.attach_next_to(label, lbl_kbd_vrs, Gtk.PositionType.RIGHT, 1, 1)

                    if secure_lookup(info, "author"):
                        lbl_kbd_auth = Gtk.Label()
                        lbl_kbd_auth.set_text(_("Keyboard author:   "))
                        lbl_kbd_auth.set_halign(Gtk.Align.END)
                        grid.attach_next_to(lbl_kbd_auth, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                        prevlabel = lbl_kbd_auth
                        label = Gtk.Label()
                        if secure_lookup(kbdata, 'authorName'):
                            label.set_text(kbdata['authorName'])
                        label.set_halign(Gtk.Align.START)
                        label.set_selectable(True)
                        grid.attach_next_to(label, lbl_kbd_auth, Gtk.PositionType.RIGHT, 1, 1)

                    lbl_kbd_lic = Gtk.Label()
                    lbl_kbd_lic.set_text(_("Keyboard license:   "))
                    lbl_kbd_lic.set_halign(Gtk.Align.END)
                    grid.attach_next_to(lbl_kbd_lic, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                    prevlabel = lbl_kbd_lic
                    label = Gtk.Label()
                    if secure_lookup(kbdata, 'license'):
                        label.set_text(kbdata['license'])
                    label.set_halign(Gtk.Align.START)
                    label.set_selectable(True)
                    grid.attach_next_to(label, lbl_kbd_lic, Gtk.PositionType.RIGHT, 1, 1)

                    lbl_kbd_desc = Gtk.Label()
                    lbl_kbd_desc.set_text(_("Keyboard description:   "))
                    lbl_kbd_desc.set_halign(Gtk.Align.END)
                    grid.attach_next_to(lbl_kbd_desc, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                    prevlabel = lbl_kbd_desc
                    label = Gtk.Label()
                    if secure_lookup(kbdata, 'description'):
                        label.set_text(kbdata['description'])
                    label.set_halign(Gtk.Align.START)
                    label.set_selectable(True)
                    label.set_line_wrap(80)
                    grid.attach_next_to(label, lbl_kbd_desc, Gtk.PositionType.RIGHT, 1, 1)

                    # Padding and full width horizontal divider
                    lbl_pad = Gtk.Label()
                    lbl_pad.set_text("")
                    lbl_pad.set_halign(Gtk.Align.END)
                    grid.attach_next_to(lbl_pad, prevlabel, Gtk.PositionType.BOTTOM, 2, 1)
                    prevlabel = lbl_pad

                    divider_pkg = Gtk.HSeparator()
                    grid.attach_next_to(divider_pkg, prevlabel, Gtk.PositionType.BOTTOM, 2, 1)

                    # label7 = Gtk.Label()
                    # label7.set_text(_("On Screen Keyboard:   "))
                    # label7.set_halign(Gtk.Align.END)
                    # grid.attach_next_to(label7, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                    # prevlabel = label7
                    # # label = Gtk.Label()
                    # # label.set_text(secure_lookup(info, 'version', 'description'))
                    # # label.set_halign(Gtk.Align.START)
                    # # label.set_selectable(True)
                    # # grid.attach_next_to(label, label7, Gtk.PositionType.RIGHT, 1, 1)

                    # label8 = Gtk.Label()
                    # label8.set_text(_("Documentation:   "))
                    # label8.set_halign(Gtk.Align.END)
                    # grid.attach_next_to(label8, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                    # prevlabel = label8
                    # #TODO need to know which area keyboard is installed in to show this
                    # # label = Gtk.Label()
                    # # welcome_file = path.join("/usr/local/share/doc/keyman", kmp["id"], "welcome.htm")
                    # # if path.isfile(welcome_file):
                    # #     label.set_text(_("Installed"))
                    # # else:
                    # #     label.set_text(_("Not installed"))
                    # # label.set_halign(Gtk.Align.START)
                    # # label.set_selectable(True)
                    # # grid.attach_next_to(label, label8, Gtk.PositionType.RIGHT, 1, 1)

                    # label9 = Gtk.Label()
                    # # stored in kmx
                    # label9.set_text(_("Message:   "))
                    # label9.set_halign(Gtk.Align.END)
                    # grid.attach_next_to(label9, prevlabel, Gtk.PositionType.BOTTOM, 1, 1)
                    # prevlabel = label9
                    # label = Gtk.Label()
                    # label.set_line_wrap(True)
                    # label.set_text(
                    #     "This keyboard is distributed under the MIT license (MIT) as described somewhere")
                    # #label.set_text(kmp["description"])
                    # label.set_halign(Gtk.Align.START)
                    # label.set_selectable(True)
                    # grid.attach_next_to(label, label9, Gtk.PositionType.RIGHT, 1, 1)

        # Add an entire row of padding
        lbl_pad = Gtk.Label()
        lbl_pad.set_text("")
        lbl_pad.set_halign(Gtk.Align.END)
        grid.attach_next_to(lbl_pad, prevlabel, Gtk.PositionType.BOTTOM, 2, 1)
        prevlabel = lbl_pad

        # If it doesn't exist, generate QR code to share keyboard package
        path_qr = path.join(tempfile.gettempdir(), kmp['packageID'] + '_qrcode.png')
        url = KeymanComUrl + "/go/keyboard/" + kmp['packageID'] + "/share"
        if not path.isfile(path_qr):
            qr = qrcode.QRCode(
                version=1,
                error_correction=qrcode.constants.ERROR_CORRECT_H,
                box_size=4,
                border=4)
            qr.add_data(url)
            qr.make(fit=True)

            img = qr.make_image()
            img.save(path_qr)

        # Display QR Code, spanning 2 columns so it will be centered
        image = Gtk.Image()
        image.set_from_file(path_qr)
        grid.attach_next_to(image, prevlabel, Gtk.PositionType.BOTTOM, 2, 1)

        lbl_share_kbd = Gtk.Label()
        lbl_share_kbd.set_markup(_("Scan this code to load this keyboard\non another device or <a href='{uri}'>share online</a>").format(uri=url))
        lbl_share_kbd.set_halign(Gtk.Align.CENTER)
        lbl_share_kbd.set_line_wrap(True)
        grid.attach_next_to(lbl_share_kbd, image, Gtk.PositionType.BOTTOM, 2, 1)
        prevlabel = lbl_share_kbd

        self.add_button(_("_Close"), Gtk.ResponseType.CLOSE)

        self.get_content_area().pack_start(grid, True, True, 12)
        self.resize(800, 450)
        self.show_all()

[((18, 0, 18, 32), 'gi.require_version', 'gi.require_version', ({(18, 19, 18, 24): '"""Gtk"""', (18, 26, 18, 31): '"""3.0"""'}, {}), "('Gtk', '3.0')", False, 'import gi\n'), ((40, 8, 40, 51), 'gi.repository.Gtk.Dialog.__init__', 'Gtk.Dialog.__init__', ({(40, 28, 40, 32): 'self', (40, 34, 40, 42): 'wintitle', (40, 44, 40, 50): 'parent'}, {}), '(self, wintitle, parent)', False, 'from gi.repository import Gtk\n'), ((41, 8, 41, 24), 'keyman_config.accelerators.init_accel', 'init_accel', ({(41, 19, 41, 23): 'self'}, {}), '(self)', False, 'from keyman_config.accelerators import init_accel\n'), ((45, 21, 45, 65), 'os.path.join', 'path.join', ({(45, 31, 45, 46): "kmp['areapath']", (45, 48, 45, 64): "kmp['packageID']"}, {}), "(kmp['areapath'], kmp['packageID'])", False, 'from os import path\n'), ((46, 19, 46, 52), 'os.path.join', 'path.join', ({(46, 29, 46, 39): 'packageDir', (46, 41, 46, 51): '"""kmp.json"""'}, {}), "(packageDir, 'kmp.json')", False, 'from os import path\n'), ((47, 50, 47, 73), 'keyman_config.kmpmetadata.parsemetadata', 'parsemetadata', ({(47, 64, 47, 72): 'kmp_json'}, {}), '(kmp_json)', False, 'from keyman_config.kmpmetadata import parsemetadata\n'), ((63, 19, 63, 68), 'os.path.join', 'path.join', ({(63, 29, 63, 39): 'packageDir', (63, 41, 63, 67): "kmp['packageID'] + '.json'"}, {}), "(packageDir, kmp['packageID'] + '.json')", False, 'from os import path\n'), ((64, 11, 64, 32), 'os.path.isfile', 'path.isfile', ({(64, 23, 64, 31): 'jsonfile'}, {}), '(jsonfile)', False, 'from os import path\n'), ((71, 15, 71, 25), 'gi.repository.Gtk.Grid', 'Gtk.Grid', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((78, 23, 78, 34), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((83, 16, 83, 27), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((84, 11, 84, 53), 'keyman_config.secure_lookup', 'secure_lookup', ({(84, 25, 84, 29): 'info', (84, 31, 84, 37): '"""name"""', (84, 39, 84, 52): '"""description"""'}, {}), "(info, 'name', 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((90, 21, 90, 32), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((95, 16, 95, 27), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((96, 11, 96, 42), 'keyman_config.secure_lookup', 'secure_lookup', ({(96, 25, 96, 28): 'kmp', (96, 30, 96, 41): '"""packageID"""'}, {}), "(kmp, 'packageID')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((102, 22, 102, 33), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((107, 16, 107, 27), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((108, 11, 108, 56), 'keyman_config.secure_lookup', 'secure_lookup', ({(108, 25, 108, 29): 'info', (108, 31, 108, 40): '"""version"""', (108, 42, 108, 55): '"""description"""'}, {}), "(info, 'version', 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((114, 11, 114, 47), 'keyman_config.secure_lookup', 'secure_lookup', ({(114, 25, 114, 31): 'kbdata', (114, 33, 114, 46): '"""description"""'}, {}), "(kbdata, 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((127, 11, 127, 40), 'keyman_config.secure_lookup', 'secure_lookup', ({(127, 25, 127, 29): 'info', (127, 31, 127, 39): '"""author"""'}, {}), "(info, 'author')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((140, 11, 140, 43), 'keyman_config.secure_lookup', 'secure_lookup', ({(140, 25, 140, 29): 'info', (140, 31, 140, 42): '"""copyright"""'}, {}), "(info, 'copyright')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((154, 18, 154, 29), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((160, 22, 160, 38), 'gi.repository.Gtk.HSeparator', 'Gtk.HSeparator', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((325, 18, 325, 29), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((347, 16, 347, 27), 'gi.repository.Gtk.Image', 'Gtk.Image', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((351, 24, 351, 35), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((52, 19, 52, 29), 'gi.repository.Gtk.Grid', 'Gtk.Grid', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((54, 35, 54, 46), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((79, 30, 79, 51), 'keyman_config._', '_', ({(79, 32, 79, 50): '"""Package name:   """'}, {}), "('Package name:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((91, 28, 91, 47), 'keyman_config._', '_', ({(91, 30, 91, 46): '"""Package id:   """'}, {}), "('Package id:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((103, 29, 103, 53), 'keyman_config._', '_', ({(103, 31, 103, 52): '"""Package version:   """'}, {}), "('Package version:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((115, 27, 115, 38), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((120, 20, 120, 31), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((128, 27, 128, 38), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((133, 20, 133, 31), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((134, 15, 134, 59), 'keyman_config.secure_lookup', 'secure_lookup', ({(134, 29, 134, 33): 'info', (134, 35, 134, 43): '"""author"""', (134, 45, 134, 58): '"""description"""'}, {}), "(info, 'author', 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((141, 26, 141, 37), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((146, 20, 146, 31), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((147, 15, 147, 62), 'keyman_config.secure_lookup', 'secure_lookup', ({(147, 29, 147, 33): 'info', (147, 35, 147, 46): '"""copyright"""', (147, 48, 147, 61): '"""description"""'}, {}), "(info, 'copyright', 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((332, 28, 332, 49), 'tempfile.gettempdir', 'tempfile.gettempdir', ({}, {}), '()', False, 'import tempfile\n'), ((334, 15, 334, 35), 'os.path.isfile', 'path.isfile', ({(334, 27, 334, 34): 'path_qr'}, {}), '(path_qr)', False, 'from os import path\n'), ((335, 17, 339, 25), 'qrcode.QRCode', 'qrcode.QRCode', (), '', False, 'import qrcode\n'), ((358, 24, 358, 35), 'keyman_config._', '_', ({(358, 26, 358, 34): '"""_Close"""'}, {}), "('_Close')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((51, 28, 51, 39), 'keyman_config._', '_', ({(51, 30, 51, 38): '"""_Close"""'}, {}), "('_Close')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((55, 42, 55, 140), 'keyman_config._', '_', ({(55, 44, 55, 139): '"""ERROR: Keyboard metadata is damaged.\nPlease "Uninstall" and then "Install" the keyboard."""'}, {}), '("""ERROR: Keyboard metadata is damaged.\nPlease "Uninstall" and then "Install" the keyboard."""\n    )', False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((85, 27, 85, 69), 'keyman_config.secure_lookup', 'secure_lookup', ({(85, 41, 85, 45): 'info', (85, 47, 85, 53): '"""name"""', (85, 55, 85, 68): '"""description"""'}, {}), "(info, 'name', 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((109, 27, 109, 72), 'keyman_config.secure_lookup', 'secure_lookup', ({(109, 41, 109, 45): 'info', (109, 47, 109, 56): '"""version"""', (109, 58, 109, 71): '"""description"""'}, {}), "(info, 'version', 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((116, 34, 116, 62), 'keyman_config._', '_', ({(116, 36, 116, 61): '"""Package description:   """'}, {}), "('Package description:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((129, 34, 129, 57), 'keyman_config._', '_', ({(129, 36, 129, 56): '"""Package author:   """'}, {}), "('Package author:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((142, 33, 142, 59), 'keyman_config._', '_', ({(142, 35, 142, 58): '"""Package copyright:   """'}, {}), "('Package copyright:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((169, 27, 169, 69), 'os.path.join', 'path.join', ({(169, 37, 169, 47): 'packageDir', (169, 49, 169, 68): "kbd['id'] + '.json'"}, {}), "(packageDir, kbd['id'] + '.json')", False, 'from os import path\n'), ((170, 19, 170, 40), 'os.path.isfile', 'path.isfile', ({(170, 31, 170, 39): 'jsonfile'}, {}), '(jsonfile)', False, 'from os import path\n'), ((178, 26, 178, 37), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((186, 31, 186, 42), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((191, 24, 191, 35), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((39, 23, 39, 43), 'keyman_config._', '_', ({(39, 25, 39, 42): '"""{name} keyboard"""'}, {}), "('{name} keyboard')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((67, 29, 67, 49), 'json.load', 'json.load', ({(67, 39, 67, 48): 'read_file'}, {}), '(read_file)', False, 'import json\n'), ((135, 31, 135, 75), 'keyman_config.secure_lookup', 'secure_lookup', ({(135, 45, 135, 49): 'info', (135, 51, 135, 59): '"""author"""', (135, 61, 135, 74): '"""description"""'}, {}), "(info, 'author', 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((148, 31, 148, 78), 'keyman_config.secure_lookup', 'secure_lookup', ({(148, 45, 148, 49): 'info', (148, 51, 148, 62): '"""copyright"""', (148, 64, 148, 77): '"""description"""'}, {}), "(info, 'copyright', 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((187, 38, 187, 64), 'keyman_config._', '_', ({(187, 40, 187, 63): '"""Keyboard filename:   """'}, {}), "('Keyboard filename:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((192, 31, 192, 72), 'os.path.join', 'path.join', ({(192, 41, 192, 51): 'packageDir', (192, 53, 192, 71): "(kbd['id'] + '.kmx')"}, {}), "(packageDir, kbd['id'] + '.kmx')", False, 'from os import path\n'), ((198, 35, 198, 46), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((203, 28, 203, 39), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((204, 23, 204, 52), 'keyman_config.secure_lookup', 'secure_lookup', ({(204, 37, 204, 43): 'kbdata', (204, 45, 204, 51): '"""name"""'}, {}), "(kbdata, 'name')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((210, 33, 210, 44), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((215, 28, 215, 39), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((216, 23, 216, 50), 'keyman_config.secure_lookup', 'secure_lookup', ({(216, 37, 216, 43): 'kbdata', (216, 45, 216, 49): '"""id"""'}, {}), "(kbdata, 'id')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((222, 34, 222, 45), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((227, 28, 227, 39), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((228, 23, 228, 55), 'keyman_config.secure_lookup', 'secure_lookup', ({(228, 37, 228, 43): 'kbdata', (228, 45, 228, 54): '"""version"""'}, {}), "(kbdata, 'version')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((234, 23, 234, 52), 'keyman_config.secure_lookup', 'secure_lookup', ({(234, 37, 234, 41): 'info', (234, 43, 234, 51): '"""author"""'}, {}), "(info, 'author')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((247, 34, 247, 45), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((252, 28, 252, 39), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((253, 23, 253, 55), 'keyman_config.secure_lookup', 'secure_lookup', ({(253, 37, 253, 43): 'kbdata', (253, 45, 253, 54): '"""license"""'}, {}), "(kbdata, 'license')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((259, 35, 259, 46), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((264, 28, 264, 39), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((265, 23, 265, 59), 'keyman_config.secure_lookup', 'secure_lookup', ({(265, 37, 265, 43): 'kbdata', (265, 45, 265, 58): '"""description"""'}, {}), "(kbdata, 'description')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((273, 30, 273, 41), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((279, 34, 279, 50), 'gi.repository.Gtk.HSeparator', 'Gtk.HSeparator', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((352, 33, 352, 129), 'keyman_config._', '_', ({(352, 35, 352, 128): '"""Scan this code to load this keyboard\non another device or <a href=\'{uri}\'>share online</a>"""'}, {}), '("""Scan this code to load this keyboard\non another device or <a href=\'{uri}\'>share online</a>"""\n    )', False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((197, 30, 197, 57), 'keyman_config.secure_lookup', 'secure_lookup', ({(197, 44, 197, 50): 'kbdata', (197, 52, 197, 56): '"""id"""'}, {}), "(kbdata, 'id')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((197, 61, 197, 92), 'keyman_config.secure_lookup', 'secure_lookup', ({(197, 75, 197, 78): 'kmp', (197, 80, 197, 91): '"""packageID"""'}, {}), "(kmp, 'packageID')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((199, 42, 199, 64), 'keyman_config._', '_', ({(199, 44, 199, 63): '"""Keyboard name:   """'}, {}), "('Keyboard name:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((211, 40, 211, 60), 'keyman_config._', '_', ({(211, 42, 211, 59): '"""Keyboard id:   """'}, {}), "('Keyboard id:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((223, 41, 223, 66), 'keyman_config._', '_', ({(223, 43, 223, 65): '"""Keyboard version:   """'}, {}), "('Keyboard version:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((235, 39, 235, 50), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((240, 32, 240, 43), 'gi.repository.Gtk.Label', 'Gtk.Label', ({}, {}), '()', False, 'from gi.repository import Gtk\n'), ((241, 27, 241, 62), 'keyman_config.secure_lookup', 'secure_lookup', ({(241, 41, 241, 47): 'kbdata', (241, 49, 241, 61): '"""authorName"""'}, {}), "(kbdata, 'authorName')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((248, 41, 248, 66), 'keyman_config._', '_', ({(248, 43, 248, 65): '"""Keyboard license:   """'}, {}), "('Keyboard license:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((260, 42, 260, 71), 'keyman_config._', '_', ({(260, 44, 260, 70): '"""Keyboard description:   """'}, {}), "('Keyboard description:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n'), ((173, 37, 173, 57), 'json.load', 'json.load', ({(173, 47, 173, 56): 'read_file'}, {}), '(read_file)', False, 'import json\n'), ((236, 46, 236, 70), 'keyman_config._', '_', ({(236, 48, 236, 69): '"""Keyboard author:   """'}, {}), "('Keyboard author:   ')", False, 'from keyman_config import KeymanComUrl, _, secure_lookup\n')]