Ejemplo n.º 1
0
    def connect(self):
        def success(*args):
            for callback in self.connect_callback:
                callback()

        def error(error):
            for callback in self.error_callback:
                callback(error)

        async_call(context.api.authenticate, success, error)
Ejemplo n.º 2
0
    def handle_select(self, event):
        jlist = event.source
        if event.valueIsAdjusting:
            return None
        selected_idx = jlist.getSelectedIndex()
        if selected_idx < 0 or selected_idx > len(self.programs):
            return None

        slug = self.programs[selected_idx].slug
        async_call(lambda: context.api.get_program_details(slug),
                   self.load_program_details)
Ejemplo n.º 3
0
    def update_status(self):
        self.status.set("Updating...", bg=Color(0xCCCCCC))

        def set_username(hunter):
            txt = "Connected as {}".format(hunter.username)
            self.status.set(txt, Color(0x006400), Color.WHITE)

        def set_error(error):
            txt = "Disconnected  - {}".format(error.message)
            self.status.set(txt, Color(0xB80000), Color.WHITE)

        async_call(context.api.get_user, set_username, set_error)
Ejemplo n.º 4
0
    def display_program_list(self, programs):
        self.programs = programs

        model = DefaultListModel()
        for program in programs:
            model.addElement(program)

        self.JprogramList.setModel(model)
        self.JprogramList.setCellRenderer(ProgramRenderer())

        if self.programs:
            async_call(
                lambda: context.api.get_program_details(self.programs[0].slug),
                self.load_program_details,
            )
        else:
            self.splitPane.setRightComponent(JPanel())
Ejemplo n.º 5
0
    def __init__(self):
        self.setLayout(GridBagLayout())
        self.setBorder(make_title_border("API"))
        self.setAlignmentX(JPanel.LEFT_ALIGNMENT)

        self.status = StatusText(25)
        self.add(JLabel("Status :"), gridx=0)
        self.add(self.status, gridx=1)

        self.version = StatusText(25)
        self.version.set(context.version, bg=Color.GRAY)
        self.add(JLabel("Version :"), gridx=0)
        self.add(self.version, gridx=1)

        settings = context.settings

        txt_url = JTextField(25)
        txt_url.setText(settings.load("apiurl", "https://api.yeswehack.com/"))
        self.add(JLabel("API URL :"), gridx=0)
        self.add(txt_url, gridx=1)

        combo_auth = JComboBox((AuthMethod.anonymous, AuthMethod.email_pass))
        combo_auth.setSelectedItem(
            settings.load("auth_method", AuthMethod.anonymous))
        combo_auth.addActionListener(
            CallbackActionListener(self.auth_method_changed))

        self.add(JLabel("Authentication :"), gridx=0)
        self.add(combo_auth, gridx=1)

        txt_mail = JTextField(25)
        txt_mail.setText(settings.load("email"))
        self.add(JLabel("Email :"), gridx=0)
        self.add(txt_mail, gridx=1)

        txt_pass = JPasswordField(25)
        txt_pass.setText(settings.load("password"))
        self.add(JLabel("Password :"******"remember", True))
        self.add(JLabel("Remember password :"******"Connect")
        btn_connect.addActionListener(CallbackActionListener(self.submit))
        self.add(btn_connect, gridx=1, anchor=EAST)

        self.inputs = {
            "apiurl": txt_url,
            "auth_method": combo_auth,
            "email": txt_mail,
            "password": txt_pass,
            "remember": check_remember,
            "connect": btn_connect,
        }

        self.setMaximumSize(self.getPreferredSize())

        self.auth_method_changed()
        async_call(self.update_status)
Ejemplo n.º 6
0
 def load_program_list(self):
     # fetch and display program async
     async_call(context.api.get_programs, self.display_program_list,
                self.display_error)