Ejemplo n.º 1
0
 def activate_lockscreen(self):
     if not self.context.request_exclusive():
         logger.info("Can't get exclusive access!")
         return False  #Couldn't get exclusive access!
     screens = self.get_screens()
     self.locked = True
     c = Canvas(self.o)
     c.centered_text("Locked")
     remove_left_failsafe(self.i)
     if self.showing_other_context:
         self.context.request_context_start(self.showing_other_context)
     while self.locked:
         key = None
         if self.showing_other_context:
             key = self.contextscreen.wait_loop(self.showing_other_context)
         else:
             c.display()
         lockscreen_obj = screens.get(settings["name"], KeyScreen)
         args = settings.get("args", [])
         kwargs = settings.get("kwargs", {})
         lockscreen = lockscreen_obj(self.i, self.o, *args, **kwargs)
         lockscreen.wait_loop(last_key=key)
         logger.info("Lockscreen triggered")
         self.locked = lockscreen.activate()
         logger.info("Finished, restarting loop")
     self.context.rescind_exclusive()
     if self.showing_other_context:
         pass  # stop the context that we might've started? idk
Ejemplo n.º 2
0
 def test_howto_example_drawing_basics(self):
     """tests the first canvas example from howto"""
     test_image = get_image("canvas_1.png")
     o = get_mock_output()
     c = Canvas(o, name=c_name)
     c.point((1, 2))
     c.point( ( (2, 1), (2, 3), (3, 4) ) )
     c.display() # Shouldn't throw an exception
     assert(imgs_are_equal(c.get_image(), test_image))
Ejemplo n.º 3
0
def draw_field():
	c = Canvas(o)
	c.rectangle((0, 0, width-1, height-1))
	c.point(snake)
	if not(applex and appley):
		create_apple()
	if level == 1:		# We draw the apple
		c.point([(applex, appley-1),									# the leaf
			(applex-1, appley),(applex, appley),(applex+1, appley),	# the top half
			(applex-1, appley+1),(applex, appley+1),(applex+1, appley+1)]) # the lower half
	else:
		c.point((applex, appley))
	c.display() 		# Display the canvas on the screen
Ejemplo n.º 4
0
def show(lines):
    if len(lines) < 4:
        max = len(lines)
    else:
        max = 4
    index = values.get_index()
    if index == 1:
        index = 2  # row 3
    c = Canvas(o)
    for n in range(max):
        y = n * char_height
        c.text(lines[n], (0, y), font=font1)
        if n == index and blink.isSet():  # row 0 or 3 && blink
            c.invert_rect(
                (127 - 8, y + char_height - 4, 127, y + char_height - 1))
    c.display()
Ejemplo n.º 5
0
 def test_screen(self):
     # Testing the screen - drawing a "crosshair" to test screen edges and lines
     c = Canvas(self.o)
     c.line((0, 0, 10, 0))
     c.line(("-1", 0, "-10", 0))
     c.line((0, "-1", 10, "-1"))
     c.line(("-1", "-1", "-10", "-1"))
     c.line((0, 0, 0, 10))
     c.line((0, "-1", 0, "-10"))
     c.line(("-1", 10, "-1", 0))
     c.line(("-1", "-1", "-1", "-10"))
     c.line((0, 0, "-1", "-1"))
     c.line((0, "-1", "-1", 0))
     eh = ExitHelper(self.i, ["KEY_ENTER", "KEY_LEFT"]).start()
     c.display()
     sleep(1)
     for x in range(30):
         if eh.do_run():
             if x % 10 == 0:
                 c.invert()
                 c.display()
             sleep(0.1)
         else:
             break
     # Filling the screen (still using the same ExitHelper)
     c = Canvas(self.o)
     for x in range(60):
         if eh.do_run():
             if x % 20 == 0:
                 c.invert()
                 c.display()
             sleep(0.1)
         else:
             break
Ejemplo n.º 6
0
class DrawingBoard(BaseUIElement):
    far_move_len = 10

    def __init__(self, i, o):
        BaseUIElement.__init__(self, i, o, "Drawing app's drawing board", override_left=False)
        self.reset()
        # horrible hack that makes the refresh rate decent on both ZP and emulator ;-P
        self.sleep_time = 0.1 if is_emulator() else 0.01
        self.view_wrappers = []

    def idle_loop(self):
        self.display_tool_image()
        sleep(self.sleep_time)

    @to_be_foreground
    def display_tool_image(self):
        image = self.tool.get_current_image()
        for wrapper in self.view_wrappers:
            image = wrapper(image)
        self.o.display_image(image)

    def add_view_wrapper(self, wrapper):
        self.view_wrappers.append(wrapper)

    def reset(self):
        self.coords = [0, 0]
        self.field = Canvas(self.o)
        self.tool = PointTool(self)

    def on_enter(self):
        self.tool.on_enter()

    def load_image(self, image):
        self.field.load_image(image)

    def update_image(self, image):
        self.field.load_image(image)
        self.refresh()

    def move_up(self):
        y = self.coords[1]
        if y > 1:
            self.coords[1] = y - 1
            self.refresh()

    def move_down(self):
        y = self.coords[1]
        if y < self.field.height-1:
            self.coords[1] = y + 1
            self.refresh()

    def move_left(self):
        x = self.coords[0]
        if x > 1:
            self.coords[0] = x - 1
            self.refresh()

    def move_right(self):
        x = self.coords[0]
        if x < self.field.width-1:
            self.coords[0] = x + 1
            self.refresh()

    def move_far_up(self):
        y = self.coords[1]
        if y > self.far_move_len:
            self.coords[1] = y - self.far_move_len
        else:
            self.coords[1] = 0
        self.refresh()

    def move_far_down(self):
        y = self.coords[1]
        if y < self.field.height-(self.far_move_len+1):
            self.coords[1] = y + self.far_move_len
        else:
            self.coords[1] = self.field_height-1
        self.refresh()

    def move_far_left(self):
        x = self.coords[0]
        if x > self.far_move_len:
            self.coords[0] = x - self.far_move_len
        else:
            self.coords[0] = 0
        self.refresh()

    def move_far_right(self):
        x = self.coords[0]
        if x < self.field.width-(self.far_move_len+1):
            self.coords[0] = x + self.far_move_len
        else:
            self.coords[0] = self.field_width-1
        self.refresh()

    def tool_settings(self):
        pass

    def back(self):
        self.deactivate()

    def pick_tools(self):
        lb_contents = ToolBucket().get_tools()
        choice = Listbox(lb_contents, self.i, self.o, "Drawing app tool picker listbox").activate()
        if choice:
            self.tool = choice(self)

    def generate_keymap(self):
        return {
            "KEY_UP": "move_up",
            "KEY_DOWN": "move_down",
            "KEY_LEFT": "move_left",
            "KEY_RIGHT": "move_right",
            "KEY_2": "move_far_up",
            "KEY_8": "move_far_down",
            "KEY_4": "move_far_left",
            "KEY_6": "move_far_right",
            "KEY_ENTER": "on_enter",
            "KEY_F3": self.tool_settings,
            "KEY_F1": "back",
            "KEY_F2": self.pick_tools}

    @to_be_foreground
    def refresh(self):
        self.field.display()
Ejemplo n.º 7
0
def show_centered_text(text, delay=1):
	c = Canvas(o)
	c.centered_text(text)
	c.display()
	if delay:
		sleep(delay)