Esempio n. 1
0
 def cb(self, obj, event):
     # check event
     if event == lv.EVENT.DELETE:
         self.task.cancel()
     elif event == lv.EVENT.PRESSED:
         # get coords
         point = lv.point_t()
         indev = lv.indev_get_act()
         lv.indev_get_point(indev, point)
         self._press_start = point
     elif event == lv.EVENT.RELEASED:
         if len(self._text) <= self.MIN_SIZE or len(
                 self._text) > self.MAX_SIZE:
             self.toggle_fullscreen()
             return
         point = lv.point_t()
         indev = lv.indev_get_act()
         lv.indev_get_point(indev, point)
         # if swipe
         if (abs(self._press_start.x - point.x) +
                 abs(self._press_start.y - point.y) > 100):
             self.toggle_fullscreen()
             return
         if self.idx is None:
             self.idx = 0
             self.set_frame()
         else:
             self.idx = None
             self._set_text(self._text)
         self.updata_note()
Esempio n. 2
0
def feed_touch():
    point = lv.point_t()
    indev = lv.indev_get_act()
    lv.indev_get_point(indev, point)
    # now we can take bytes([point.x % 256, point.y % 256])
    # and feed it into hash digest
    t = time.ticks_cpu()
    random_data = t.to_bytes(4,'big') + bytes([point.x % 256, point.y % 256])
    rng.feed(random_data)
Esempio n. 3
0
def feed_touch():
    """
    Gets a point from the touchscreen 
    and feeds it to random number pool
    """
    point = lv.point_t()
    indev = lv.indev_get_act()
    lv.indev_get_point(indev, point)
    # now we can take bytes([point.x % 256, point.y % 256])
    # and feed it into hash digest
    t = time.ticks_cpu()
    random_data = t.to_bytes(4, 'big') + bytes([point.x % 256, point.y % 256])
    rng.feed(random_data)
Esempio n. 4
0
 def on_word_click(self, obj, evt):
     if evt != lv.EVENT.RELEASED:
         return
     # get coordinates
     point = lv.point_t()
     indev = lv.indev_get_act()
     lv.indev_get_point(indev, point)
     # get offsets
     dx = point.x - obj.get_x()
     dy = point.y - obj.get_y()
     # get index
     idx = 12*int(dx > obj.get_width()//2) + int(12*dy/obj.get_height())
     self.change_word(idx)
Esempio n. 5
0
    def cb(self, obj, event):
        if event == lv.EVENT.PRESSING:
            feed_touch()
            c = obj.get_active_btn_text()
            if c is not None and len(c)<=2:
                self.hint.set_hidden(False)
                self.hint_lbl.set_text(c)
                point = lv.point_t()
                indev = lv.indev_get_act()
                lv.indev_get_point(indev, point)
                self.hint.set_pos(point.x-25, point.y-130)

        elif event == lv.EVENT.RELEASED:
            self.hint.set_hidden(True)

        if self.callback is not None:
            self.callback(obj, event)
Esempio n. 6
0
    def cb(obj, event):
        if event == lv.EVENT.PRESSING:
            c = obj.get_active_btn_text()
            if c is None:
                return
            if len(c)>2:
                key_hint.set_hidden(True)
                return
            key_hint.set_hidden(False)
            key_lbl.set_text(c)
            point = lv.point_t()
            indev = lv.indev_get_act()
            lv.indev_get_point(indev, point)
            key_hint.set_pos(point.x-25, point.y-130)

        elif event == lv.EVENT.RELEASED:
            key_hint.set_hidden(True)
            c = obj.get_active_btn_text()
            if c is None:
                return
            if c[0] == lv.SYMBOL.LEFT:
                ta.del_char()
            elif c == lv.SYMBOL.UP or c == lv.SYMBOL.DOWN:
                for i,ch in enumerate(CHARSET):
                    if ch.isalpha():
                        if c == lv.SYMBOL.UP:
                            CHARSET[i] = CHARSET[i].upper()
                        else:
                            CHARSET[i] = CHARSET[i].lower()
                    elif ch == lv.SYMBOL.UP:
                        CHARSET[i] = lv.SYMBOL.DOWN
                    elif ch == lv.SYMBOL.DOWN:
                        CHARSET[i] = lv.SYMBOL.UP
                btnm.set_map(CHARSET)
            elif c == "#@":
                btnm.set_map(CHARSET_EXTRA)
            elif c == "aA":
                btnm.set_map(CHARSET)
            elif c[0] == lv.SYMBOL.CLOSE:
                ta.set_text("")
            elif c[0] == lv.SYMBOL.OK:
                cb_continue(ta.get_text())
                ta.set_text("")
            else:
                ta.add_text(c)
Esempio n. 7
0
 def check(self):
     point = lv.point_t()
     indev = lv.indev_get_act()
     lv.indev_get_point(indev, point)
     self.circ_area.set_pos(point.x - CIRCLE_SIZE // 2,
                            point.y - CIRCLE_SIZE // 2)
Esempio n. 8
0
    def cb(obj, event):
        global words
        if event == lv.EVENT.PRESSING:
            c = obj.get_active_btn_text()
            if c is None:
                return
            if len(c)>1:
                key_hint.set_hidden(True)
                return
            key_hint.set_hidden(False)
            key_lbl.set_text(c)
            point = lv.point_t()
            indev = lv.indev_get_act()
            lv.indev_get_point(indev, point)
            key_hint.set_pos(point.x-25, point.y-130)
        elif event == lv.EVENT.RELEASED:
            key_hint.set_hidden(True)
            c = obj.get_active_btn_text()
            if c is None:
                return
            num = obj.get_active_btn()
            # if inactive button is clicked - return
            if obj.get_btn_ctrl(num,lv.btnm.CTRL.INACTIVE):
                return
            if c == lv.SYMBOL.LEFT+" Back":
                cb_back()
            elif c == lv.SYMBOL.LEFT:
                if len(words[-1]) > 0:
                    words[-1] = words[-1][:-1]
                elif len(words) > 0:
                    words = words[:-1]
                table_set_mnemonic(table, " ".join(words))
            elif c == "Next word":
                if words_lookup is not None and len(words[-1])>=2:
                    candidates = words_lookup(words[-1])
                    if len(candidates) == 1:
                        words[-1] = candidates[0]
                words.append("")
                table_set_mnemonic(table, " ".join(words))
            elif c == lv.SYMBOL.OK+" Done":
                pass
            else:
                if len(words) == 0:
                    words.append("")
                words[-1] = words[-1]+c.lower()
                table_set_mnemonic(table, " ".join(words))

            mnemonic = None
            if words_lookup is not None:
                btnm.set_btn_ctrl(28, lv.btnm.CTRL.INACTIVE)
                if len(words) > 0 and len(words[-1])>=2:
                    candidates = words_lookup(words[-1])
                    if len(candidates) == 1 or words[-1] in candidates:
                        btnm.clear_btn_ctrl(28, lv.btnm.CTRL.INACTIVE)
                        mnemonic = " ".join(words[:-1])
                        if len(candidates) == 1:
                            mnemonic += " "+candidates[0]
                        else:
                            mnemonic += " "+words[-1]
                else:
                    mnemonic = " ".join(words)
            else:
                mnemonic = " ".join(words)
            if mnemonic is None:
                return
            mnemonic = mnemonic.strip()
            if check_mnemonic is not None and mnemonic is not None:
                if check_mnemonic(mnemonic):
                    btnm.clear_btn_ctrl(29, lv.btnm.CTRL.INACTIVE)
                else:
                    btnm.set_btn_ctrl(29, lv.btnm.CTRL.INACTIVE)
            # if user was able to click this button then mnemonic is correct
            if c == lv.SYMBOL.OK+" Done":
                cb_continue(mnemonic)
Esempio n. 9
0
lv.scr_load(scr)


# create objects
def on_button(obj, event):
    print('on_button event')
    if event == lv.EVENT.CLICKED:
        print('button clicked!')


btn = lv.btn(lv.scr_act())
#btn.align(lv.scr_act(), lv.ALIGN.CENTER, 0, 0)
btn.set_pos(50, 50)
label = lv.label(btn)
label.set_text("Button")
btn.set_event_cb(on_button)

bar1 = lv.bar(lv.scr_act())
bar1.set_size(200, 30)
bar1.align(None, lv.ALIGN.CENTER, 0, 100)
bar1.set_anim_time(1000)
bar1.set_value(100, lv.ANIM.ON)

print('starting loop')
while True:
    if DEBUG:
        p = lv.point_t()
        lv.indev_get_point(lv.indev_get_next(lv.indev_t.cast(None)), p)
        print("x=%d, y=%d" % (p.x, p.y))
    pass