Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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)
    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)
Beispiel #5
0
def lv_event_callback(self, lv_obj, event):
    '''
    if event == lv.EVENT.VALUE_CHANGED:
    if event == lv.EVENT.REFRESH:
    if event == lv.EVENT.LEAVE:
    if event == lv.EVENT.INSERT:
    if event == lv.EVENT.APPLY:
    if event == lv.EVENT.CANCEL:
    if event == lv.EVENT.FOCUSED:
    if event == lv.EVENT.DEFOCUSED:
    '''

    point = lv.point_t()
    event_text = ''
    if event == lv.EVENT.CLICKED:
        event_text = 'clicked'
    if event == lv.EVENT.DRAG_BEGIN:
        event_text = 'drag begin'
    if event == lv.EVENT.DRAG_END:
        event_text = 'drag end'
    if event == lv.EVENT.DRAG_THROW_BEGIN:
        event_text = 'drag throw begin'
    if event == lv.EVENT.GESTURE:
        event_text = 'gesture'
    if event == lv.EVENT.KEY:
        event_text = 'key'
    if event == lv.EVENT.LONG_PRESSED:
        event_text = 'long pressed'
    if event == lv.EVENT.LONG_PRESSED_REPEAT:
        event_text = 'long pressed repeat'
    if event == lv.EVENT.PRESSED:
        event_text = 'pressed'
    if event == lv.EVENT.PRESSING:
        event_text = 'pressing'
    if event == lv.EVENT.PRESS_LOST:
        event_text = 'press lost'
    if event == lv.EVENT.RELEASED:
        event_text = 'released'
    if event == lv.EVENT.SHORT_CLICKED:
        event_text = 'short clicked'

    ptr = lv.indev_get_act()
    ptr.get_point(point)
    print(lv_obj, event_text, point)
Beispiel #6
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)
    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)