Beispiel #1
0
class KeyinScreen(Screen):
    def on_enter(self):
        self.txt = TextInput(size_hint=(.5, .1),
                             pos_hint={
                                 'center_x': .5,
                                 'center_y': .6
                             },
                             id="id",
                             keyboard_mode='managed',
                             unfocus_on_touch=True)
        self.txt.bind(focus=self.on_focus)
        self.txt.bind(on_touch_up=self.on_touch_up)
        self.add_widget(self.txt)

    def on_focus(self, instance, value):
        if value:
            self.kb = Keyboard("number", self.txt)
        else:
            instance.hide_keyboard()
            return False

    def on_touch_up(self, *args):
        touch = args[0]
        print("touch", *touch.pos)
        if not self.txt.collide_point(*touch.pos):
            print('touched outside keyboard')
            self.txt.focus = False
            Window.release_keyboard(self.kb)
        return super(TextInput, self.txt).on_touch_up(touch)

    def unlock(self):
        string = self.txt.text
        print(string)
        unlocked = Storage().manual_unlock(string)
        self.manager.current = 'rest'
Beispiel #2
0
class TInput(DAQWidget):

	def __init__(self, **kwargs):

		super(TInput, self).__init__(**kwargs)
		
		self.box = BoxLayout(orientation='vertical', padding=[5,10])
		self.button = Button(text='send!')
		self.inp = TextInput(multiline=False)
		self.box.add_widget(self.inp)
		self.box.add_widget(self.button)

		self.set_widget(self.box)

		self.button.bind(on_press=self.button_clicked)
		self.mqueued = False

		self.inp.bind(on_text_validate=self.on_enter)
		self.text = ''

	def on_touch_down(self, event):
		if(self.inp.collide_point(*event.pos)):
			self.inp.on_touch_down(event)
			return True
		elif(self.button.collide_point(*event.pos)):
			self.button.on_touch_down(event)
			return True
		return False

	def button_clicked(self, arg):
		self.mqueued = True
		self.text = self.inp.text
		self.inp.text = ''

	def get_text(self):
		return self.text

	def on_enter(self, val):
		self.mqueued = True
		self.text = self.inp.text
		self.inp.text = ''
Beispiel #3
0
class LoginScreen(Screen):
    def on_enter(self):
        self.username = TextInput(size_hint=(.4, .1),
                                  pos_hint={
                                      'center_x': .6,
                                      'center_y': .7
                                  },
                                  id="username",
                                  keyboard_mode='managed',
                                  unfocus_on_touch=True)
        self.username.bind(focus=self.on_focus)
        self.username.bind(
            on_touch_up=lambda *args: self.on_touch_up('username'))
        self.add_widget(self.username)

        self.password = TextInput(size_hint=(.4, .1),
                                  pos_hint={
                                      'center_x': .6,
                                      'center_y': .5
                                  },
                                  id="password",
                                  keyboard_mode='managed',
                                  unfocus_on_touch=True)

        self.password.bind(focus=self.on_focus)
        self.password.bind(
            on_touch_up=lambda *args: self.on_touch_up('password'))
        self.add_widget(self.password)

    def on_focus(self, instance, value):
        print('instance:', instance)
        if value:
            if instance == self.username:
                self.u_kb = Keyboard("text", instance)
            elif instance == self.password:
                self.p_kb = Keyboard("text", instance)
        else:
            instance.release()
            return False

    def on_touch_up(self, *args):
        print(*args)
        touch = args[0]
        if hasattr(args, 'mode'):
            mode = args.mode
            print('mode: ', mode)
            if mode == "username":
                if not self.username.collide_point(*touch.pos):
                    print('touched outside keyboard')
                    self.username.focus = False
                    self.u_kb.submit()
                return super(TextInput, self.txt).on_touch_up(touch)
            elif mode == "password":
                if not self.password.collide_point(*touch.pos):
                    print('touched outside keyboard')
                    self.password.focus = False
                    self.p_kb.submit()
                return super(TextInput, self.txt).on_touch_up(touch)

    def login(self, username, password):
        loader = LoadingPopup()
        header = {'Content-Type': 'application/json'}
        data = {'username': username, 'password': password}
        req = requests.post(config.URL + '/api/user/login',
                            headers=header,
                            json=data)
        print(req)
        if (req.status_code == requests.codes.ok):
            loader.stop_t()
            popup = Popup(title="Success",
                          content=Label(text="Logged in!",
                                        font_size=18,
                                        color=(0, 0, 0, 1)),
                          size_hint=(None, None),
                          size=(400, 400))
            popup.open()
            self.manager.current = 'main'