-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finishing up #220, still have to doc this
- Loading branch information
Showing
4 changed files
with
134 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# make some UI elements on the REPL | ||
|
||
import tulip | ||
|
||
def button_cb(e): | ||
obj = e.get_target_obj() | ||
print("label of button pressed is %s" % (obj.get_child(0).get_text())) | ||
|
||
def slider_cb(e): | ||
obj = e.get_target_obj() | ||
print("slider value is %d" % (obj.get_value())) | ||
|
||
def check_cb(e): | ||
obj = e.get_target_obj() | ||
print("checkbox value is %s" % (obj.get_state())) | ||
|
||
def text_cb(e): | ||
obj = e.get_target_obj() | ||
print("text value is %s" % (obj.get_text())) | ||
|
||
|
||
def run(screen): | ||
screen.bg_color = 9 | ||
|
||
screen.add(tulip.UILabel("hello it is a test"), x=200,y=200) | ||
screen.add(tulip.UIButton(text="Click me", fg_color=255, bg_color=200, callback=button_cb), x=600, y=200) | ||
screen.add(tulip.UIButton(text="here again", fg_color=255, bg_color=3, w=250, callback=button_cb), x=700, y=400) | ||
|
||
screen.add(tulip.UISlider(val=50, w=15, h=150, bar_color=151, handle_color=188, callback=slider_cb), x=300, y=400) | ||
screen.add(tulip.UISlider(val=50, w=400, h=15, bar_color=255, handle_color=0, callback=slider_cb), x=250, y=300) | ||
|
||
screen.add(tulip.UIText(text="12",fg_color=255,w=100,bg_color=0, font=tulip.lv.font_unscii_8, callback=text_cb), x=200, y=200) | ||
screen.add(tulip.UIText(placeholder="Type here", w=220, fg_color=255,bg_color=0, font=tulip.lv.font_unscii_8, callback=text_cb), x=400, y=100) | ||
|
||
screen.add(tulip.UICheckbox(text="Extra text", fg_color=255, bg_color = 0, callback=check_cb), x=400, y=400) | ||
screen.add(tulip.UICheckbox(fg_color=255, bg_color = 0, callback=check_cb), x=400, y=460) | ||
|
||
screen.handle_keyboard = True | ||
screen.keep_tfb = True | ||
screen.present() | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# editor.py | ||
# Tulip C editor wrapped in UIScreen. | ||
# One day (not today), we should re-write the editor in pure python here too (still using the TFB) | ||
# That will let us do LVGL stuff for saving/searching/etc | ||
|
||
import tulip | ||
|
||
class Editor(tulip.UIScreen): | ||
def __init__(self, filename): | ||
self.filename = filename | ||
# Make sure to turn off the offsets for the task bar | ||
super().__init__('edit', bg_color=36, keep_tfb=True, offset_x=0, offset_y=0) | ||
self.quit_callback = self.quit_editor_cb | ||
self.deactivate_callback = self.deactivate_editor_cb | ||
self.activate_callback = self.activate_editor_cb | ||
self.first_run = True | ||
self.present() | ||
|
||
def deactivate_editor_cb(self, screen): | ||
tulip.keyboard_callback() | ||
tulip.tfb_restore() | ||
# Fudge the repl line as it got eaten during the TFB restore. This will never be a problem, lol | ||
print(">>> ",end='') | ||
|
||
def quit_editor_cb(self, screen): | ||
tulip.keyboard_callback() | ||
tulip.deinit_editor() | ||
tulip.tfb_restore() | ||
|
||
def activate_editor_cb(self,screen): | ||
# Only load in the file on first run | ||
tulip.tfb_save() | ||
if(self.first_run): | ||
self.first_run = False | ||
if(self.filename is None): | ||
tulip.run_editor() | ||
else: | ||
tulip.run_editor(self.filename) | ||
|
||
tulip.keyboard_callback(tulip.key_editor) | ||
# The TFB switches over, but the REPL will print >>> after this runs, | ||
# overwriting the first line. So wait a bit and activate then | ||
# (This also means the >>> will print on the alternate TFB, so we have to fudge on reactivate) | ||
tulip.defer(tulip.activate_editor, 50) | ||
|
||
# Launch the tulip editor as a UIScreen | ||
def edit(filename=None): | ||
editor = Editor(filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters