Пример #1
0
 def extract_display_keyvalues(self):
     """ Updates the display values, based on current include files, layout """
     for counter in Common.keysegmentslist:
         self.dvalues[counter] = copy.copy(self.keyvalues[counter])
         if self.keycode in KeyDict.IgnoreKeys:
             continue
         if self.keyvalues[counter].getType() == Common.keyvaluetype.NOSYMBOL:
             for layout in activated_variants.keys():
                 for variant in activated_variants[layout].keys():
                     if activated_variants[layout][variant].has_key(self.keycode):
                         if activated_variants[layout][variant][self.keycode].has_key(counter):
                             self.dvalues_inherited[counter] = True
                             self.dvalues[counter] = copy.copy(activated_variants[layout][variant][self.keycode][counter])
         if self.dvalues[counter].getType() == Common.keyvaluetype.NOSYMBOL:
             self.dvalues_inherited[counter] = False
             self.dvalues[counter] = copy.copy(self.keyvalues[counter])
    def create_layout(self, layoutcode, layoutvariant, layoutcountry,
                      layoutname, layoutkeys):
        """ 
        Creates an lxml construct with the layout. 
        Makes use of KeyDict.included_files, KeyDict.activated_variants 
        """
        self.new_layout = etree.Element("layout", layoutname=layoutcode)

        self.symbols = etree.SubElement(self.new_layout, "symbols")

        self.mapoption = etree.SubElement(self.symbols, "mapoption")
        self.mapoption.text = "xkb_symbols"
        self.mapname = etree.SubElement(self.symbols, "mapname")
        self.mapname.text = layoutvariant
        self.mapmaterial = etree.SubElement(self.symbols, "mapmaterial")

        self.tokenname = etree.SubElement(self.mapmaterial, "tokenname")
        self.tokenname.attrib["name"] = layoutname
        for includefile in activated_variants.keys():
            for variant in activated_variants[includefile].keys():
                self.tokinclude = etree.SubElement(self.mapmaterial,
                                                   "tokeninclude")
                self.tokinclude.text = includefile + '(' + variant + ')'

        for keycodename in layoutkeys.keys():
            if keycodename in KeyDict.IgnoreKeys:
                #print "keycodename", keycodename, "is in ignorekeys"
                continue
            votes_empty = 0
            for counter in Common.keysegmentslist:
                if layoutkeys[keycodename].key.keyvalues[counter].getType(
                ) == Common.keyvaluetype.NOSYMBOL:
                    votes_empty += 1
            if votes_empty == len(Common.keysegmentslist):
                # print "Keycode", keycodename, "is empty, skipping"
                continue
            else:
                # print keycodename, "we only had", votes_empty, "votes,"
                for counter in Common.keysegmentslist:
                    pass
                    #print layoutkeys[keycodename].key.keyvalues[counter].getValue(),
                #print
            #print layoutkeys[keycodename].key.keyvalues[Common.keysegments.ONE].getValue()
            self.tokenkey = etree.SubElement(self.mapmaterial, "tokenkey")
            self.tokenkey.attrib["override"] = "False"

            self.keycodename = etree.SubElement(self.tokenkey, "keycodename")
            self.keycodename.text = keycodename
            self.keysymgroup = etree.SubElement(self.tokenkey, "keysymgroup")

            self.symbolsgroup = etree.SubElement(self.keysymgroup,
                                                 "symbolsgroup")

            # print "Counting elems in key:",
            for counter in Common.keysegmentslistreverse:
                max_index = counter
                if layoutkeys[keycodename].key.keyvalues[counter].getType(
                ) == Common.keyvaluetype.NOSYMBOL:
                    #print "O",
                    continue
                else:
                    break
            #print
            #print "Doing look between", Common.keysegments.ONE, "and", max_index
            for counter in range(Common.keysegments.ONE, max_index + 1):
                sym = etree.SubElement(self.symbolsgroup, "symbol")
                sym.text = layoutkeys[keycodename].key.keyvalues[
                    counter].getValue()
                if sym.text == "":
                    sym.text = "NoSymbol"

                # print "sym.text", sym.text
        return self.new_layout
    def create_layout(self, layoutcode, layoutvariant, layoutcountry, layoutname, layoutkeys):
        """ 
        Creates an lxml construct with the layout. 
        Makes use of KeyDict.included_files, KeyDict.activated_variants 
        """
        self.new_layout = etree.Element("layout", layoutname = layoutcode)

        self.symbols = etree.SubElement(self.new_layout, "symbols")

        self.mapoption = etree.SubElement(self.symbols, "mapoption")
        self.mapoption.text = "xkb_symbols"
        self.mapname = etree.SubElement(self.symbols, "mapname")
        self.mapname.text = layoutvariant
        self.mapmaterial = etree.SubElement(self.symbols, "mapmaterial")

        self.tokenname = etree.SubElement(self.mapmaterial, "tokenname")
        self.tokenname.attrib["name"] = layoutname
        for includefile in activated_variants.keys():
            for variant in activated_variants[includefile].keys():
                self.tokinclude = etree.SubElement(self.mapmaterial, "tokeninclude")
                self.tokinclude.text = includefile + '(' + variant + ')'

        for keycodename in layoutkeys.keys():
            if keycodename in KeyDict.IgnoreKeys:
                #print "keycodename", keycodename, "is in ignorekeys"
                continue
            votes_empty = 0
            for counter in Common.keysegmentslist:
                if layoutkeys[keycodename].key.keyvalues[counter].getType() == Common.keyvaluetype.NOSYMBOL:
                    votes_empty += 1
            if votes_empty == len(Common.keysegmentslist):
                # print "Keycode", keycodename, "is empty, skipping"
                continue
            else: 
                # print keycodename, "we only had", votes_empty, "votes,"
                for counter in Common.keysegmentslist:
                    pass
                    #print layoutkeys[keycodename].key.keyvalues[counter].getValue(),
                #print
            #print layoutkeys[keycodename].key.keyvalues[Common.keysegments.ONE].getValue()
            self.tokenkey = etree.SubElement(self.mapmaterial, "tokenkey")
            self.tokenkey.attrib["override"] = "False"

            self.keycodename = etree.SubElement(self.tokenkey, "keycodename")
            self.keycodename.text = keycodename
            self.keysymgroup = etree.SubElement(self.tokenkey, "keysymgroup")

            self.symbolsgroup = etree.SubElement(self.keysymgroup, "symbolsgroup")

            # print "Counting elems in key:",
            for counter in Common.keysegmentslistreverse:
                max_index = counter
                if layoutkeys[keycodename].key.keyvalues[counter].getType() == Common.keyvaluetype.NOSYMBOL:
                    #print "O",
                    continue
                else:
                    break
            #print
            #print "Doing look between", Common.keysegments.ONE, "and", max_index
            for counter in range(Common.keysegments.ONE, max_index + 1):
                sym = etree.SubElement(self.symbolsgroup, "symbol")
                sym.text = layoutkeys[keycodename].key.keyvalues[counter].getValue()
                if sym.text == "":
                    sym.text = "NoSymbol"

                # print "sym.text", sym.text
        return self.new_layout