Example #1
0
    def pipWidgetCallback(self, inMessage, inWidget, inParam1, inParam2):
        if inMessage == xp.Message_CloseButtonPushed:
            xp.hideWidget(self.pipWindow['widgetID'])
            return 1

        if inMessage == xp.Msg_PushButtonPressed:
            if inParam1 == self.pipWindow['widgets']['button']:
                s = xp.getWidgetDescriptor(
                    self.pipWindow['widgets']['packages'])
                packages = list(filter(lambda x: x != '', re.split('[, ]+',
                                                                   s)))
                print("Looking to install packages: {}".format(packages))
                if packages:
                    xp.setWidgetDescriptor(
                        self.pipWindow['widgets']['error'],
                        "Looking to install packages: {}".format(
                            ' '.join(packages)))
                    found = False
                    for i in ('pip', 'pip3', 'pip.exe', 'pip3.exe'):
                        pip = os.path.join(sysconfig.get_paths()['scripts'], i)
                        if os.path.isfile(pip) and os.access(pip, os.X_OK):
                            found = True
                            cmd = [pip, 'install', '--user'] + packages
                            print("Calling pip as: {}".format(' '.join(cmd)))
                            try:
                                xp.setWidgetDescriptor(
                                    self.pipWindow['widgets']['error'],
                                    "Running pip... please wait.")
                                output = subprocess.check_output(
                                    cmd, stderr=subprocess.STDOUT)
                                xp.setWidgetDescriptor(
                                    self.pipWindow['widgets']['error'],
                                    "Execution complete.")
                                print("From pip:\n{}".format(
                                    output.decode('utf-8')))
                                output = output.decode('utf-8').split('\n')
                            except subprocess.CalledProcessError as e:
                                print("Calling pip failed: [{}]: {}".format(
                                    e.returncode, e.output.decode('utf-8')))
                                xp.setWidgetDescriptor(
                                    self.pipWindow['widgets']['error'],
                                    "Failed: Error while executing pip.")
                                output = e.output.decode('utf-8').split('\n')
                        if found:
                            popupWindow('PIP output', output)
                            break

                    if not found:
                        print("Could not find pip")
                        xp.setWidgetDescriptor(
                            self.pipWindow['widgets']['error'],
                            "Failed: Could not find pip.")

                xp.setWidgetDescriptor(self.pipWindow['widgets']['packages'],
                                       '')
            return 1

        return 0
Example #2
0
 def togglePip(self, inCommand, inPhase, inRefcon):
     if inPhase == xp.CommandBegin:
         if not self.pipWindow:
             self.pipWindow = self.createPipWindow()
         else:
             if xp.isWidgetVisible(self.pipWindow['widgetID']):
                 xp.hideWidget(self.pipWindow['widgetID'])
             else:
                 xp.showWidget(self.pipWindow['widgetID'])
     return 0
Example #3
0
    def aboutWidgetCallback(self, inMessage, inWidget, inParam1, inParam2):
        if inMessage == xp.Message_CloseButtonPushed:
            xp.hideWidget(self.aboutWindow['widgetID'])
            return 1

        if inMessage == xp.Msg_ButtonStateChanged:
            if inParam1 == self.aboutWindow['widgets']['beta']:
                self.config['beta'] = xp.getWidgetProperty(
                    inParam1, xp.Property_ButtonState, None) == 1
                xp.setWidgetDescriptor(self.aboutWindow['widgets']['currency'],
                                       self.get_currency())
                self.setUpdateMenu()

        if inMessage == xp.Msg_PushButtonPressed:
            if inParam1 == self.aboutWindow['widgets']['documentation']:
                webbrowser.open(
                    'https://xppython3.rtfd.io/en/latest/usage/installation_plugin.html'
                )
                return 1

            if inParam1 == self.aboutWindow['widgets']['support']:
                webbrowser.open(
                    'https://forums.x-plane.org/index.php?/forums/topic/225976-xppython3-now-available/'
                )
                return 1

            if inParam1 == self.aboutWindow['widgets']['plugin']:
                webbrowser.open(
                    'https://xppython3.rtfd.io/en/latest/development/index.html'
                )
                return 1

            if inParam1 == self.aboutWindow['widgets']['donate']:
                webbrowser.open(
                    'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=TA3EJ9VWFCH3N&source=url'
                )
                return 1

            if inParam1 == self.aboutWindow['widgets']['changelog']:
                webbrowser.open(
                    'https://xppython3.rtfd.io/en/latest/changelog.html')
                return 1
        return 0
Example #4
0
def popupCallback(inMessage, inWidget, inParam1, inParam2):
    if inMessage == xp.Message_CloseButtonPushed:
        xp.hideWidget(inWidget)
        return 1
    return 0