示例#1
0
        def set_value(option):
            key = option.GetName()
            value = None

            if key in menu_definitions:
                value = menu_definitions[key]

                if not TextIsEmpty(value):
                    if option in self.opts_input:
                        option.SetValue(value)
                        return True

                    elif option in self.opts_choice:
                        if option.SetStringSelection(value):
                            return True

                    elif option in self.opts_list:
                        lst_categories = GetField(self, listid.CAT)

                        if key == lst_categories.GetName():
                            value = value.split(u';')

                            if value:
                                for X, val in enumerate(value):
                                    lst_categories.InsertStringItem(X, val)
                                return True

            return False
示例#2
0
    def Get(self, getModule=False):
        l_lines = [u'[Desktop Entry]']
        categories = []

        id_list = (
            inputid.VERSION,
            inputid.ENC,
            inputid.NAME,
            inputid.EXEC,
            inputid.DESCR,
            inputid.ICON,
            inputid.TYPE,
            inputid.TERM,
            inputid.NOTIFY,
            inputid.MIME,
            listid.CAT,
            inputid.CAT2,
            inputid.OTHER,
        )

        for ID in id_list:
            field = GetField(self, ID)

            if field:
                if isinstance(field, ErrorTuple):
                    Logger.Warn(__name__, field.GetMessage())

                    continue

                if ID == inputid.OTHER:
                    for INDEX in range(field.GetSectionCount()):
                        section = field.GetSection(INDEX)

                        if isinstance(section, CustomSection):
                            key = section.GetKey().strip()
                            value = section.GetValue().strip()

                elif ID in (listid.CAT, inputid.CAT2):
                    if ID == inputid.CAT2:
                        custom_cats = []

                        for C1 in field.GetValue().split(u','):
                            for C2 in C1.split(u';'):
                                if not TextIsEmpty(C2):
                                    custom_cats.append(C2.strip())

                        if GetField(self, chkid.CAT).GetValue():
                            for LABEL in reversed(custom_cats):
                                categories.insert(0, LABEL)

                        else:
                            for LABEL in custom_cats:
                                categories.append(LABEL)

                    else:
                        for LABEL in field.GetCheckedLabels():
                            categories.append(LABEL)

                else:
                    if isinstance(field, OutputField):
                        key = field.GetOutLabel()

                    else:
                        key = field.GetName()

                    value = wx.EmptyString

                    if isinstance(field, (
                            wx.TextCtrl,
                            OwnerDrawnComboBox,
                    )):
                        value = field.GetValue().strip()

                    elif isinstance(field, wx.CheckBox):
                        value = GS(field.GetValue()).lower()

                    elif isinstance(field, (
                            ListCtrlBase,
                            ListCtrl,
                    )):
                        value = u';'.join(field.GetListTuple())

                        if not value.endswith(u';'):
                            value = u'{};'.format(value)

                if not TextIsEmpty(key) and not TextIsEmpty(value):
                    l_lines.append(u'{}={}'.format(key, value))

        # FIXME: Categories should be organized manually by user
        if categories:
            categories = u';'.join(categories)
            if not categories.endswith(u';'):
                categories = u'{};'.format(categories)

            l_lines.append(u'Categories={}'.format(categories))

        l_text = u'\n'.join(l_lines)

        if getModule:
            # FIXME: 'MENU' needed?
            l_text = (__name__, l_text, u'MENU')

        return l_text