Skip to content

Commit

Permalink
Changes in extensions UI. Handle plugins dependence.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebengoechea authored and Mimoja committed Feb 21, 2021
1 parent f0c763e commit 0125113
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 35 deletions.
42 changes: 35 additions & 7 deletions de1plus/plugins.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@ proc create_plugin_namespace {plugin} {
set ::plugins::${plugin}::author {}
set ::plugins::${plugin}::contact {}
set ::plugins::${plugin}::version {}
set ::plugins::${plugin}::name {}
set ::plugins::${plugin}::description {}
set ::plugins::${plugin}::plugin_loaded 0
set ::plugins::${plugin}::plugin_preloaded 0
set ::plugins::${plugin}::plugin_loaded 0

array set ::plugins::${plugin}::settings {}
}

proc load_plugin_settings {plugin} {
create_plugin_namespace $plugin

set settings_file_contents [encoding convertfrom utf-8 [read_binary_file [plugin_settings_file $plugin]]]
msg "Settings file: $settings_file_contents"
if {[string length $settings_file_contents] != 0} {
array set [plugin_settings $plugin] $settings_file_contents
}
set fn [plugin_settings_file $plugin]
if { [file exists $fn] } {
set settings_file_contents [encoding convertfrom utf-8 [read_binary_file $fn]]
msg "Settings file: $settings_file_contents"
if {[string length $settings_file_contents] != 0} {
array set [plugin_settings $plugin] $settings_file_contents
}
} else {
msg "Settings file $fn not found"
}
}

proc save_plugin_settings {plugin} {
Expand All @@ -44,15 +51,19 @@ proc save_plugin_settings {plugin} {
proc source_plugin {plugin} {
load_plugin_settings $plugin
source "[homedir]/[plugin_directory]/$plugin/plugin.tcl"
set ::plugins::${plugin}::plugin_loaded 1
}

proc plugin_preload {plugin} {
if { [plugin_preloaded $plugin] } {
return
}

if {[catch {
source_plugin $plugin
if {[info proc ::plugins::${plugin}::preload] != ""} {
set ::plugins::${plugin}::ui_entry [::plugins::${plugin}::preload]
}
set ::plugins::${plugin}::plugin_preloaded 1
} err] != 0} {
catch {
info_page [subst {[translate "The plugin $plugin could not be sourced for metadata"]\n\n$err}] [translate "Ok"]
Expand All @@ -61,8 +72,13 @@ proc plugin_preload {plugin} {
}

proc load_plugin {plugin} {
if { [plugin_loaded $plugin] } {
return
}

if {[catch {
::plugins::${plugin}::main
set ::plugins::${plugin}::plugin_loaded 1
} err] != 0} {
catch {
# remove from enabled plugins
Expand All @@ -83,6 +99,18 @@ proc plugin_enabled {plugin} {
return false
}

proc plugin_available {plugin} {
return [expr {[lsearch [available_plugins] $plugin] >= 0}]
}

proc plugin_preloaded {plugin} {
return [expr {[info exists ::plugins::${plugin}::plugin_preloaded] && [subst \$::plugins::${plugin}::plugin_preloaded] == 1}]
}

proc plugin_loaded {plugin} {
return [expr {[info exists ::plugins::${plugin}::plugin_loaded] && [subst \$::plugins::${plugin}::plugin_loaded] == 1}]
}

proc toggle_plugin {plugin} {
if {[plugin_enabled $plugin]} {
set new [lsearch -inline -all -not -exact $::settings(enabled_plugins) $plugin]
Expand Down
2 changes: 1 addition & 1 deletion de1plus/plugins/example/plugin.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc ::plugins::${plugin_name}::preload {} {
# 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); fill_extensions_listbox; page_to_show_when_off extensions; set_extensions_scrollbar_dimensions} 980 1210 1580 1410 ""
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 "Example Plugin"] -font Helv_20_bold -width 1200 -fill "#444444" -anchor "center" -justify "center"
Expand Down
2 changes: 1 addition & 1 deletion de1plus/plugins/visualizer_upload/plugin.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc ::plugins::${plugin_name}::preload {} {
# 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); save_plugin_settings visualizer_upload; fill_extensions_listbox; page_to_show_when_off extensions; set_extensions_scrollbar_dimensions} 980 1210 1580 1410 ""
add_de1_button $page_name {say [translate {Done}] $::settings(sound_button_in); save_plugin_settings visualizer_upload; page_to_show_when_off extensions; } 980 1210 1580 1410 ""

# Headline
add_de1_text $page_name 1280 300 -text [translate "Visualizer Upload"] -font Helv_20_bold -width 1200 -fill "#444444" -anchor "center" -justify "center"
Expand Down
60 changes: 34 additions & 26 deletions de1plus/vars.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -2280,26 +2280,43 @@ proc fill_languages_listbox {} {
}

proc highlight_extension {} {
set stepnum [$::extensions_widget curselection]
set stepnum [$::extensions_widget curselection]
if {$stepnum == ""} {
set ::extension_highlighted -1
return
}
if { [info exists ::extension_highlighted] } {
if { $::extension_highlighted == $stepnum } {
set plugin [lindex [available_plugins] $stepnum]
toggle_plugin $plugin

fill_extensions_listbox
$::extensions_widget selection set $stepnum
make_current_listbox_item_blue $::extensions_widget
return
} else {
set ::extension_highlighted $stepnum
}
} else {
set ::extension_highlighted $stepnum
}

set plugin [lindex [available_plugins] $stepnum ]

source_plugin $plugin
# ENRIQUE: Why needed, already done at startup??? COMMENTED
#source_plugin $plugin
set description ""

if {[info proc ::plugins::${plugin}::preload] != ""} {
set description [translate "Configurable: Yes"]
canvas_show "$::extensions_settings $::extensions_settings_button"
} else {
set description [translate "Configurable: No"]
canvas_hide "$::extensions_settings $::extensions_settings_button"
}

foreach {name value} { "Version: " version "Author: " author "Contact: " contact "" description} {
foreach {name value} { "Version: " version "Author: " author "Contact: " contact "\n" description} {
set conf [set ::plugins::${plugin}::${value}]
if { $conf != {} } {
set description "$description\n[translate $name]$conf"
append description "[translate $name]$conf\n"
}
}
.can itemconfigure $::extensions_metadata -text $description
Expand All @@ -2310,27 +2327,10 @@ proc highlight_extension {} {

}

proc extension_toggle {} {
set stepnum [$::extensions_widget curselection]
if {$stepnum == ""} {
borg toast [translate "No Extensions selected"]
return
}

set plugin [lindex [available_plugins] $stepnum]

toggle_plugin $plugin

fill_extensions_listbox
$::extensions_widget selection set $stepnum;
make_current_listbox_item_blue $::extensions_widget
}


proc fill_plugin_settings {} {
set stepnum [$::extensions_widget curselection]
if {$stepnum == ""} {
borg toast [translate "No Extensions selected"]
borg toast [translate "No extension selected"]
return
}

Expand Down Expand Up @@ -2366,14 +2366,22 @@ proc fill_extensions_listbox {} {
set p "\u2610 "
}
}

if { [info exists ::plugins::${plugin}::name ] && [subst \$::plugins::${plugin}::name] ne "" } {
set plugin_name [subst \$::plugins::${plugin}::name]
} else {
set plugin_name $plugin
}

$widget insert $cnt "$p $plugin"
$widget insert $cnt "$p $plugin_name"
incr cnt
}

$::extensions_widget yview $current

if {$stepnum != ""} {
if {$stepnum == ""} {
canvas_hide "$::extensions_settings $::extensions_settings_button"
} else {
$::extensions_widget selection set $stepnum;
make_current_listbox_item_blue $::extensions_widget
}
Expand Down

0 comments on commit 0125113

Please sign in to comment.