Skip to content

Commit

Permalink
Update plugins to use new ui creation flow
Browse files Browse the repository at this point in the history
Signed-off-by: Mimoja <[email protected]>
  • Loading branch information
Mimoja committed Apr 12, 2021
1 parent 0425c55 commit 495b831
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 108 deletions.
105 changes: 51 additions & 54 deletions de1plus/plugins/DPx_Screen_Saver/plugin.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,71 @@
set plugin_name "DPx_Screen_Saver"

namespace eval ::plugins::${plugin_name} {
# These are shown in the plugin selection page
variable author "Damian"
variable contact "via Diaspora"
variable version 1.1
variable description "A plugin that allows users to select an alternate screen saver directory, for skins that don't already do so"
# These are shown in the plugin selection page
variable author "Damian"
variable contact "via Diaspora"
variable version 1.1
variable description "A plugin that allows users to select an alternate screen saver directory, for skins that don't already do so"

# preload is called on app start even if the plugin is disabled. Can be used to show
# dynamic informations on the settings overview. Please dont put logic here
# needs to return the page you want to be shown first
proc preload {} {
# Unique name per page
set page_name "DPx_SS_options"
proc build_ui {} {
# Unique name per page
set page_name "DPx_SS_options"

# Background image and "Done" button
add_de1_page "$page_name" "settings_message.png" "default"
add_de1_text $page_name 1280 1310 -text [translate "Done"] -font Helv_10_bold -fill "#fAfBff" -anchor "center"
add_de1_button $page_name {say [translate {Done}] $::settings(sound_button_in); page_to_show_when_off extensions; } 980 1210 1580 1410 ""
# Background image and "Done" button
add_de1_page "$page_name" "settings_message.png" "default"
add_de1_text $page_name 1280 1310 -text [translate "Done"] -font Helv_10_bold -fill "#fAfBff" -anchor "center"
add_de1_button $page_name {say [translate {Done}] $::settings(sound_button_in); page_to_show_when_off extensions; } 980 1210 1580 1410 ""

# Headline
add_de1_text $page_name 1280 300 -text [translate "DPx Screen Saver"] -font Helv_20_bold -width 1200 -fill "#444444" -anchor "center" -justify "center"
# Headline
add_de1_text $page_name 1280 300 -text [translate "DPx Screen Saver"] -font Helv_20_bold -width 1200 -fill "#444444" -anchor "center" -justify "center"

# The actual content. Here a list of all settings for this plugin
add_de1_variable $page_name 1280 600 -justify center -anchor "n" -font Helv_10 -fill "#444444" -textvariable {[::plugins::DPx_Screen_Saver::message]}
add_de1_button "$page_name" {say [translate {awake}] $::settings(sound_button_in); ::plugins::DPx_Screen_Saver::create_mysaver} 1000 450 1560 750
# The actual content. Here a list of all settings for this plugin
add_de1_variable $page_name 1280 600 -justify center -anchor "n" -font Helv_10 -fill "#444444" -textvariable {[::plugins::DPx_Screen_Saver::message]}
add_de1_button "$page_name" {say [translate {awake}] $::settings(sound_button_in); ::plugins::DPx_Screen_Saver::create_mysaver} 1000 450 1560 750

return $page_name
}

proc create_mysaver {} {
if {[file exists [homedir]/MySaver/${::screen_size_width}x${::screen_size_height}] != 1} {
set path [homedir]/MySaver/${::screen_size_width}x${::screen_size_height}
file mkdir $path
file attributes $path
return $page_name
}
}

proc message {args} {
if {[file exists [homedir]/MySaver/${::screen_size_width}x${::screen_size_height}] != 1} {
return "I could not find MySaver/${::screen_size_width}x${::screen_size_height} folder\r If you tap **HERE** I'll create them for you"
proc create_mysaver {} {
if {[file exists [homedir]/MySaver/${::screen_size_width}x${::screen_size_height}] != 1} {
set path [homedir]/MySaver/${::screen_size_width}x${::screen_size_height}
file mkdir $path
file attributes $path
}
}
set dir "[homedir]/MySaver/${::screen_size_width}x${::screen_size_height}"
set file_list [glob -nocomplain "$dir/*"]
if {[llength $file_list] == 0} {
return "I found your MySaver/${::screen_size_width}x${::screen_size_height} folder, but the folder is empty\r\rOnce you have added your image files, restart the app\r to direct the screen saver settings to your new images\r\rEnsure you use image files\r${::screen_size_width} pixels wide & ${::screen_size_height} pixels high\rso they fit your display correctly"
}
return "MySaver/${::screen_size_width}x${::screen_size_height} found with [llength $file_list] files\r\rAll looks good!"
}

proc check_MySaver_exists {args} {
set dir "[homedir]/MySaver"
set file_list [glob -nocomplain "$dir/*"]
if {[llength $file_list] != 0} {
set_de1_screen_saver_directory "[homedir]/MySaver"
proc message {args} {
if {[file exists [homedir]/MySaver/${::screen_size_width}x${::screen_size_height}] != 1} {
return "I could not find MySaver/${::screen_size_width}x${::screen_size_height} folder\r If you tap **HERE** I'll create them for you"
}
set dir "[homedir]/MySaver/${::screen_size_width}x${::screen_size_height}"
set file_list [glob -nocomplain "$dir/*"]
if {[llength $file_list] == 0} {
return "I found your MySaver/${::screen_size_width}x${::screen_size_height} folder, but the folder is empty\r\rOnce you have added your image files, restart the app\r to direct the screen saver settings to your new images\r\rEnsure you use image files\r${::screen_size_width} pixels wide & ${::screen_size_height} pixels high\rso they fit your display correctly"
}
return "MySaver/${::screen_size_width}x${::screen_size_height} found with [llength $file_list] files\r\rAll looks good!"
}
add_de1_button "saver sleep descaling cleaning" {say [translate {awake}] $::settings(sound_button_in); set_next_page off off; page_show off; start_idle; de1_send_waterlevel_settings; } 0 0 2560 1600

}
proc check_MySaver_exists {args} {
set dir "[homedir]/MySaver"
set file_list [glob -nocomplain "$dir/*"]
if {[llength $file_list] != 0} {
set_de1_screen_saver_directory "[homedir]/MySaver"
}
add_de1_button "saver sleep descaling cleaning" {say [translate {awake}] $::settings(sound_button_in); set_next_page off off; page_show off; start_idle; de1_send_waterlevel_settings; } 0 0 2560 1600

# This file will be sourced to display meta-data. Dont put any code into the
# general scope as there are no guarantees about when it will be run.
# For security reasons it is highly unlikely you will find the plugin in the
# official distribution if you are not beeing run from your main
# REQUIRED
}

proc main {} {
trace add execution load_skin leave ::plugins::DPx_Screen_Saver::check_MySaver_exists
# This file will be sourced to display meta-data. Dont put any code into the
# general scope as there are no guarantees about when it will be run.
# For security reasons it is highly unlikely you will find the plugin in the
# official distribution if you are not beeing run from your main
# REQUIRED

}
proc main {} {
trace add execution load_skin leave ::plugins::DPx_Screen_Saver::check_MySaver_exists
plugins gui DPx_Screen_Saver [build_ui]
}

}

92 changes: 46 additions & 46 deletions de1plus/plugins/DPx_Steam_Stop/plugin.tcl
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
set plugin_name "DPx_Steam_Stop"

namespace eval ::plugins::${plugin_name} {
# These are shown in the plugin selection page
variable author "Damian"
variable contact "via Diaspora"
variable version 1.1
variable description "This plugin will change stopping steam via the tablet\r- First tap will start gentle puffs\r- Second tap will end and purge"

proc DPx_start_idle {} {
proc ::start_idle {} {
msg "Tell DE1 to start to go IDLE (and stop whatever it is doing)"

if {[sdltk screensaver] == 1} {
sdltk screensaver off
}

if {$::de1(device_handle) == 0} {
update_de1_state "$::de1_state(Idle)\x0"
ble_connect_to_de1
return
}
# These are shown in the plugin selection page
variable author "Damian"
variable contact "via Diaspora"
variable version 1.1
variable description "This plugin will change stopping steam via the tablet\r- First tap will start gentle puffs\r- Second tap will end and purge"

proc DPx_start_idle {} {
proc ::start_idle {} {
msg "Tell DE1 to start to go IDLE (and stop whatever it is doing)"

if {[sdltk screensaver] == 1} {
sdltk screensaver off
}

if {$::settings(stress_test) == 1} {
# pressing stop on any step will stop the stress test
unset -nocomplain ::idle_next_step
}
set ::settings(flying) 0
if {$::de1_num_state($::de1(state)) == "Steam"} {

if {$::settings(steam_timeout) > 1} {
set ::DPx_steam_timer_backup $::settings(steam_timeout)
set ::settings(steam_timeout) 1
de1_send_steam_hotwater_settings
set ::DPx_puffs_on 1
if {$::de1(device_handle) == 0} {
update_de1_state "$::de1_state(Idle)\x0"
ble_connect_to_de1
return
}
if {$::DPx_puffs_on == 1} {
set ::settings(steam_timeout) $::DPx_steam_timer_backup
de1_send_steam_hotwater_settings
set ::DPx_puffs_on 0

if {$::settings(stress_test) == 1} {
# pressing stop on any step will stop the stress test
unset -nocomplain ::idle_next_step
}
set ::settings(flying) 0
if {$::de1_num_state($::de1(state)) == "Steam"} {

if {$::settings(steam_timeout) > 1} {
set ::DPx_steam_timer_backup $::settings(steam_timeout)
set ::settings(steam_timeout) 1
de1_send_steam_hotwater_settings
set ::DPx_puffs_on 1
return
}
if {$::DPx_puffs_on == 1} {
set ::settings(steam_timeout) $::DPx_steam_timer_backup
de1_send_steam_hotwater_settings
set ::DPx_puffs_on 0
}

}
de1_send_state "go idle" $::de1_state(Idle)
}
de1_send_state "go idle" $::de1_state(Idle)

if {[firmware_has_fan_sleep_bug] == 1} {
set_fan_temperature_threshold $::settings(fan_threshold)
}
if {[firmware_has_fan_sleep_bug] == 1} {
set_fan_temperature_threshold $::settings(fan_threshold)
}

if {$::android == 0} {
after 200 [list update_de1_state "$::de1_state(Idle)\x0"]
if {$::android == 0} {
after 200 [list update_de1_state "$::de1_state(Idle)\x0"]
}
}
}
}

proc main {} {
DPx_start_idle
}
proc main {} {
DPx_start_idle
}

}
8 changes: 3 additions & 5 deletions de1plus/plugins/example/plugin.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ namespace eval ::plugins::${plugin_name} {
variable description "Minimal plugin to showcase the interface of the plugin / extensions system."
variable name "Example Plugin"

# Always on entry point
proc preload {} {
return [build_ui]
}

proc build_ui {} {
variable settings

Expand Down Expand Up @@ -70,5 +65,8 @@ namespace eval ::plugins::${plugin_name} {

msg [namespace current] "Tracing function call"
trace add execution start_sleep leave ::plugins::example::on_function_called

# register gui
plugins gui example [build_ui]
}
}
3 changes: 2 additions & 1 deletion de1plus/plugins/log_upload/plugin.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace eval ::plugins::${plugin_name} {
}

# Paint settings screen
proc preload {} {
proc create_ui {} {

# Create settings if non-existant
if {[array size ::plugins::log_upload::settings] == 0} {
Expand Down Expand Up @@ -189,6 +189,7 @@ namespace eval ::plugins::${plugin_name} {
}

proc main {} {
plugins gui log_upload [create_ui]
}

}
3 changes: 2 additions & 1 deletion de1plus/plugins/visualizer_upload/plugin.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace eval ::plugins::${plugin_name} {
variable name "Upload to visualizer"

# Paint settings screen
proc preload {} {
proc create_ui {} {
set needs_save_settings 0

# Create settings if non-existant
Expand Down Expand Up @@ -235,6 +235,7 @@ namespace eval ::plugins::${plugin_name} {
}

proc main {} {
plugins gui visualizer_upload [create_ui]
::de1::event::listener::after_flow_complete_add \
[lambda {event_dict} {
::plugins::visualizer_upload::async_dispatch \
Expand Down
4 changes: 3 additions & 1 deletion de1plus/plugins/web_api/plugin.tcl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package require wibble
package require de1_machine

set plugin_name "web_api"

namespace eval ::wibble {}
namespace eval ::plugins::${plugin_name} {

variable author "Johanna Schander"
Expand All @@ -12,6 +12,8 @@ namespace eval ::plugins::${plugin_name} {
variable name "Web API"

proc main {} {
package require wibble

# Create settings if non-existant
if {[array size ::plugins::web_api::settings] == 0} {
array set ::plugins::web_api::settings {
Expand Down

0 comments on commit 495b831

Please sign in to comment.