Ejemplo n.º 1
0
class SettingScrollOptionsWithOptions(SettingScrollOptions):
    """ showing a sub scroll options setting from a scroll option """
    def __init__(self, **kwargs):

        self.aSubOptions = []
        self.aSubOption = []
        self.subpopup = None
        self.uOption = None
        self.oSubScrollOptionsPopup = None
        self.register_event_type('on_release')
        super(SettingScrollOptionsWithOptions, self).__init__(**kwargs)
        for aSubOptions in kwargs["suboptions"]:
            self.aSubOptions.append(aSubOptions)
        if not len(self.aSubOptions) == len(self.options):
            Logger.debug(
                "Warning: SubScrollOptions do not match Scrolloptions")

    def _set_option(self, instance):
        """ called when the first option is selected """
        iIndex = self.GetSelectedIndex(instance)
        if iIndex <= len(self.aSubOptions):
            self.aSubOption = self.aSubOptions[iIndex]
            if len(self.aSubOption) > 0:
                self.uOption = instance.text
                self._create_subpopup(instance)
            else:
                self.value = '%s:%s' % (instance.text, '')
                self.popup.dismiss()
        else:
            self.value = '%s:%s' % (instance.text, '')
            self.popup.dismiss()

    def _set_suboption(self, instance):
        """ called, when the second option is selected """
        self.value = '%s:%s' % (self.uOption, instance.text)
        self.subpopup.dismiss()
        self.popup.dismiss()

    def GetSelectedIndex(self, instance):
        """ gets the selected option index """
        i = 0
        for option in self.options:
            if option == instance.text:
                return i
            i += 1
        return 0

    def _create_subpopup(self, instance):
        kwargs = {'title': self.uOption, 'options': self.aSubOption}
        self.oSubScrollOptionsPopup = ScrollOptionsPopUp(**kwargs)
        self.oSubScrollOptionsPopup.CreatePopup(self.value,
                                                self._set_suboption, None)
        self.subpopup = self.oSubScrollOptionsPopup.popup
Ejemplo n.º 2
0
class SettingActions(SettingScrollOptionsWithOptions):
    """ A setting class to select actions from the action list or from a codeset """
    def __init__(self, **kwargs):
        self.aCodesetCmds: List[str] = []
        self.oActionPopup: Union[Popup, None] = None
        self.oCodeSetActionsScrollOptionsPopup: Union[Popup, None] = None
        kwargs["options"] = [
            ReplaceVars("$lvar(742)"),
            ReplaceVars("$lvar(743)"),
            ReplaceVars("$lvar(744)")
        ]
        kwargs["suboptions"] = [["$ACTIONLISTSEND"], [
            "$ACTIONLIST"
        ], ["$FILELIST[%s]" % Globals.oPathCodesets.string]]
        super().__init__(**kwargs)

    def _set_suboption(self, instance: Widget) -> None:
        """ called, when the second option is selected """
        if instance.text.startswith('CODESET_'):
            self.subpopup.dismiss()
            self.popup.dismiss()
            self._ReadCodeset(instance.text)
            self._ShowCodesetCodesPopup(instance.text)
        else:
            self.value = instance.text
            self.subpopup.dismiss()
            self.popup.dismiss()

    def _set_suboptioncodesetaction(self, instance: Widget) -> None:
        """ called, when a codesetcode is selected """
        self.value = "SendCommand " + instance.text
        self.oActionPopup.dismiss()

    def _ReadCodeset(self, uFN: str) -> None:

        oXMLCode: Element
        uCmd: str
        del self.aCodesetCmds[:]
        try:
            oXMLCodeset: Element = LoadXMLFile(
                oFile=cFileName(Globals.oPathCodesets) + uFN)
            Orca_include(oXMLCodeset, orca_et_loader)
            if oXMLCodeset is not None:
                # First read imported codesets
                oXMLImports: Element = oXMLCodeset.find('imports')
                if oXMLImports is not None:
                    oXMLImportCodesets: Element = oXMLImports.find('codeset')
                    if oXMLImportCodesets is not None:
                        for oXMLCode in oXMLImportCodesets.findall('code'):
                            uCmd = GetXMLTextAttribute(oXMLNode=oXMLCode,
                                                       uTag='action',
                                                       bMandatory=False,
                                                       vDefault='')
                            if uCmd:
                                self.aCodesetCmds.append(uCmd)

                for oXMLCode in oXMLCodeset.findall('code'):
                    uCmd = GetXMLTextAttribute(oXMLNode=oXMLCode,
                                               uTag='action',
                                               bMandatory=False,
                                               vDefault='')
                    if uCmd:
                        self.aCodesetCmds.append(uCmd)

        except Exception as e:
            LogError(uMsg='Error Reading Codeset', oException=e)

    def _ShowCodesetCodesPopup(self, uFN: str) -> None:
        kwargs = {'title': uFN, 'options': sorted(self.aCodesetCmds)}
        self.oCodeSetActionsScrollOptionsPopup = ScrollOptionsPopUp(**kwargs)
        self.oCodeSetActionsScrollOptionsPopup.CreatePopup(
            self.value, self._set_suboptioncodesetaction, None)
        self.oActionPopup = self.oCodeSetActionsScrollOptionsPopup.popup
Ejemplo n.º 3
0
 def _ShowCodesetCodesPopup(self, uFN: str) -> None:
     kwargs = {'title': uFN, 'options': sorted(self.aCodesetCmds)}
     self.oCodeSetActionsScrollOptionsPopup = ScrollOptionsPopUp(**kwargs)
     self.oCodeSetActionsScrollOptionsPopup.CreatePopup(
         self.value, self._set_suboptioncodesetaction, None)
     self.oActionPopup = self.oCodeSetActionsScrollOptionsPopup.popup
Ejemplo n.º 4
0
 def _create_subpopup(self, instance):
     kwargs = {'title': self.uOption, 'options': self.aSubOption}
     self.oSubScrollOptionsPopup = ScrollOptionsPopUp(**kwargs)
     self.oSubScrollOptionsPopup.CreatePopup(self.value,
                                             self._set_suboption, None)
     self.subpopup = self.oSubScrollOptionsPopup.popup