From aecc70198e1b50e3289e39faa367f3213f129f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20G=C3=A1rate?= Date: Fri, 31 May 2024 17:36:44 +0200 Subject: [PATCH 1/4] launchers use new common window --- kratos.gid/apps/DEMLauncher/start.tcl | 52 +--------------- kratos.gid/apps/FluidLauncher/start.tcl | 54 +--------------- kratos.gid/apps/PfemLauncher/start.tcl | 46 +------------- kratos.gid/apps/ThermicLauncher/start.tcl | 51 +--------------- kratos.gid/kratos.tcl | 2 +- kratos.gid/scripts/Applications.tcl | 27 ++++++-- .../Controllers/ApplicationMarketWindow.tcl | 61 ++++++++++++++++++- 7 files changed, 88 insertions(+), 205 deletions(-) diff --git a/kratos.gid/apps/DEMLauncher/start.tcl b/kratos.gid/apps/DEMLauncher/start.tcl index c4d87e8af..276840edd 100644 --- a/kratos.gid/apps/DEMLauncher/start.tcl +++ b/kratos.gid/apps/DEMLauncher/start.tcl @@ -14,55 +14,7 @@ proc ::DemLauncher::Init { app } { proc ::DemLauncher::AppSelectorWindow { } { variable available_apps - set initwind $::spdAux::initwind - - set root [customlib::GetBaseRoot] - set nd [ [$root selectNodes "value\[@n='nDim'\]"] getAttribute v] - if { $nd ne "undefined" } { - # if {[apps::getActiveAppId] eq "Fluid"} { - # spdAux::SwitchDimAndCreateWindow $nd - # } - } { - [$root selectNodes "value\[@n='nDim'\]"] setAttribute v wait - - set initwind $::spdAux::application_window_id - spdAux::DestroyWindows - spdAux::RegisterWindow $initwind - set w $initwind - - InitWindow $w [_ "DEM applications"] Kratos "" "" 1 - set initwind $w - ttk::frame $w.top - ttk::label $w.top.title_text -text [_ "Select a DEM application"] - - ttk::frame $w.applications -relief ridge - set i 0 - foreach app $available_apps { - set img [::apps::getImgFrom $app] - set app_publicname [[::apps::getAppById $app] getPublicName] - set but [ttk::button $w.applications.img$app -image $img -command [list ::DemLauncher::ChangeAppTo $app] ] - bind $w.applications.img$app {::spdAux::PlaceInformationWindowByPath %W applications} - ttk::label $w.applications.text$app -text $app_publicname - grid $w.applications.img$app -column $i -row 0 - grid $w.applications.text$app -column $i -row 1 - incr i - } - grid $w.top - grid $w.top.title_text - - grid $w.applications - - # Information panel - set spdAux::info_main_window_text "" - ttk::labelframe $w.info -text " Information " -relief ridge - ttk::label $w.info.text -textvariable spdAux::info_main_window_text - grid $w.info.text - grid $w.info -sticky we - } + + spdAux::CreateLauncherWindow DemLauncher $available_apps } -proc ::DemLauncher::ChangeAppTo {appid} { - spdAux::deactiveApp DemLauncher - spdAux::SetSpatialDimmension undefined - apps::setActiveApp $appid -} diff --git a/kratos.gid/apps/FluidLauncher/start.tcl b/kratos.gid/apps/FluidLauncher/start.tcl index 989a7c2b1..4f8872b05 100644 --- a/kratos.gid/apps/FluidLauncher/start.tcl +++ b/kratos.gid/apps/FluidLauncher/start.tcl @@ -15,57 +15,5 @@ proc ::FluidLauncher::Init { app } { proc ::FluidLauncher::FluidAppSelectorWindow { } { variable available_apps - set root [customlib::GetBaseRoot] - set nd [ [$root selectNodes "value\[@n='nDim'\]"] getAttribute v] - if { $nd ne "undefined" } { - if {[apps::getActiveAppId] eq "Fluid"} { - spdAux::SwitchDimAndCreateWindow $nd - } - } { - [$root selectNodes "value\[@n='nDim'\]"] setAttribute v wait - - set initwind $::spdAux::application_window_id - spdAux::DestroyWindows - spdAux::RegisterWindow $initwind - - set w $initwind - - InitWindow $w [_ "Fluid applications"] Kratos "" "" 1 - set initwind $w - ttk::frame $w.top - ttk::label $w.top.title_text -text [_ "Select a fluid application"] - - ttk::frame $w.applications -relief ridge - set r 0 - set c 0 - set max_cols 3 - foreach app $available_apps { - set img [::apps::getImgFrom $app] - set app_publicname [[::apps::getAppById $app] getPublicName] - set but [ttk::button $w.applications.img$app -image $img -command [list ::FluidLauncher::ChangeAppTo $app] ] - bind $w.applications.img$app {::spdAux::PlaceInformationWindowByPath %W applications} - ttk::label $w.applications.text$app -text $app_publicname - grid $w.applications.img$app -column $r -row $c - grid $w.applications.text$app -column $r -row [expr $c + 1] - incr r - if {$r >= $max_cols} {incr c 2; set r 0} - } - grid $w.top - grid $w.top.title_text - - grid $w.applications - - # Information panel - set spdAux::info_main_window_text "" - ttk::labelframe $w.info -text " Information " -relief ridge - ttk::label $w.info.text -textvariable spdAux::info_main_window_text - grid $w.info.text - grid $w.info -sticky we - } -} - -proc ::FluidLauncher::ChangeAppTo {appid} { - spdAux::deactiveApp FluidLauncher - spdAux::SetSpatialDimmension undefined - apps::setActiveApp $appid + spdAux::CreateLauncherWindow FluidLauncher $available_apps [_ "Fluid applications"] [_ "Select a fluid application"] } diff --git a/kratos.gid/apps/PfemLauncher/start.tcl b/kratos.gid/apps/PfemLauncher/start.tcl index 191bc48bf..d6ed55553 100644 --- a/kratos.gid/apps/PfemLauncher/start.tcl +++ b/kratos.gid/apps/PfemLauncher/start.tcl @@ -15,49 +15,5 @@ proc ::PfemLauncher::Init { app } { proc ::PfemLauncher::AppSelectorWindow { } { variable available_apps - set root [customlib::GetBaseRoot] - set nd [ [$root selectNodes "value\[@n='nDim'\]"] getAttribute v] - if { $nd eq "undefined" } { - - [$root selectNodes "value\[@n='nDim'\]"] setAttribute v wait - - set initwind $::spdAux::application_window_id - spdAux::DestroyWindows - spdAux::RegisterWindow $initwind - - set w $initwind - InitWindow $w [_ "Pfem applications"] Kratos "" "" 1 - set initwind $w - ttk::frame $w.top - ttk::label $w.top.title_text -text [_ "Select a pfem application"] - - ttk::frame $w.applications -relief ridge - set i 0 - foreach app $available_apps { - set img [::apps::getImgFrom $app] - set app_publicname [[::apps::getAppById $app] getPublicName] - set but [ttk::button $w.applications.img$app -image $img -command [list ::PfemLauncher::ChangeAppTo $app] ] - bind $w.applications.img$app {::spdAux::PlaceInformationWindowByPath %W applications} - ttk::label $w.applications.text$app -text $app_publicname - grid $w.applications.img$app -column $i -row 0 - grid $w.applications.text$app -column $i -row 1 - incr i - } - grid $w.top - grid $w.top.title_text - grid $w.applications - - # Information panel - set spdAux::info_main_window_text "" - ttk::labelframe $w.info -text " Information " -relief ridge - ttk::label $w.info.text -textvariable spdAux::info_main_window_text - grid $w.info.text - grid $w.info -sticky we - } -} - -proc ::PfemLauncher::ChangeAppTo {appid} { - spdAux::deactiveApp PfemLauncher - spdAux::SetSpatialDimmension undefined - apps::setActiveApp $appid + spdAux::CreateLauncherWindow PfemLauncher $available_apps [_ "Pfem applications"] [_ "Select a Pfem application"] } diff --git a/kratos.gid/apps/ThermicLauncher/start.tcl b/kratos.gid/apps/ThermicLauncher/start.tcl index d5fd76a05..06a75380e 100644 --- a/kratos.gid/apps/ThermicLauncher/start.tcl +++ b/kratos.gid/apps/ThermicLauncher/start.tcl @@ -15,54 +15,5 @@ proc ::ThermicLauncher::Init { app } { proc ::ThermicLauncher::AppSelectorWindow { } { variable available_apps - set root [customlib::GetBaseRoot] - set nd [ [$root selectNodes "value\[@n='nDim'\]"] getAttribute v] - if { $nd ne "undefined" } { - # if {[apps::getActiveAppId] eq "Fluid"} { - # spdAux::SwitchDimAndCreateWindow $nd - # } - } { - [$root selectNodes "value\[@n='nDim'\]"] setAttribute v wait - - set initwind $::spdAux::application_window_id - spdAux::DestroyWindows - spdAux::RegisterWindow $initwind - set w $initwind - - InitWindow $w [_ "Thermic applications"] Kratos "" "" 1 - set initwind $w - ttk::frame $w.top - ttk::label $w.top.title_text -text [_ "Select a Thermic application"] - - ttk::frame $w.applications -relief ridge - set i 0 - foreach app $available_apps { - set img [::apps::getImgFrom $app] - set app_publicname [[::apps::getAppById $app] getPublicName] - set but [ttk::button $w.applications.img$app -image $img -command [list ::ThermicLauncher::ChangeAppTo $app] ] - bind $w.applications.img$app {::spdAux::PlaceInformationWindowByPath %W applications} - ttk::label $w.applications.text$app -text $app_publicname - grid $w.applications.img$app -column $i -row 0 - grid $w.applications.text$app -column $i -row 1 - incr i - } - grid $w.top - grid $w.top.title_text - - grid $w.applications - - # Information panel - set spdAux::info_main_window_text "" - ttk::labelframe $w.info -text " Information " -relief ridge - ttk::label $w.info.text -textvariable spdAux::info_main_window_text - grid $w.info.text - grid $w.info -sticky we - - } -} - -proc ::ThermicLauncher::ChangeAppTo {appid} { - spdAux::deactiveApp ThermicLauncher - spdAux::SetSpatialDimmension undefined - apps::setActiveApp $appid + spdAux::CreateLauncherWindow ThermicLauncher $available_apps [_ "Thermic applications"] [_ "Select a Thermic application"] } diff --git a/kratos.gid/kratos.tcl b/kratos.gid/kratos.tcl index 6fa599101..0372b1500 100644 --- a/kratos.gid/kratos.tcl +++ b/kratos.gid/kratos.tcl @@ -111,7 +111,7 @@ proc Kratos::Event_InitProblemtype { dir } { set activeapp_dom [spdAux::SetActiveAppFromDOM] if { $activeapp_dom == "" } { #open a window to allow the user select the app - after 500 [list spdAux::CreateWindow] + after 500 [list spdAux::CreateInitialApplicationsWindow] } } diff --git a/kratos.gid/scripts/Applications.tcl b/kratos.gid/scripts/Applications.tcl index d8dd43d9a..653b35785 100644 --- a/kratos.gid/scripts/Applications.tcl +++ b/kratos.gid/scripts/Applications.tcl @@ -73,6 +73,20 @@ proc apps::getAppById { id } { return $appR } +proc apps::appExists {id} { + variable appList + + set dir [file join $::Kratos::kratos_private(Path) apps $id] + set app_definition_file [file join $dir app.json] + # if the directory does not exist, do not load the app + if {[file exists $dir]} { + if {[file exists $app_definition_file]} { + return 1 + } + } + return 0 +} + proc apps::NewApp {appid publicname prefix} { variable appList set ap [App new $appid] @@ -305,11 +319,14 @@ oo::class create App { proc apps::LoadAppProperties {app} { set dir [file join $::Kratos::kratos_private(Path) apps [$app getName]] set app_definition_file [file join $dir app.json] - if {[file exists $app_definition_file]} { - set props [Kratos::ReadJsonDict $app_definition_file] - $app setProperties $props - } else { - W "MISSING app.json file for app [$app getName]" + # if the directory does not exist, do not load the app + if {[file exists $dir]} { + if {[file exists $app_definition_file]} { + set props [Kratos::ReadJsonDict $app_definition_file] + $app setProperties $props + } else { + W "MISSING app.json file for app [$app getName]" + } } } diff --git a/kratos.gid/scripts/Controllers/ApplicationMarketWindow.tcl b/kratos.gid/scripts/Controllers/ApplicationMarketWindow.tcl index 51325b9ee..391394dae 100644 --- a/kratos.gid/scripts/Controllers/ApplicationMarketWindow.tcl +++ b/kratos.gid/scripts/Controllers/ApplicationMarketWindow.tcl @@ -5,7 +5,7 @@ namespace eval ::spdAux { set application_window_id .gid.win_app_selection } -proc spdAux::CreateWindow {} { +proc spdAux::CreateInitialApplicationsWindow {} { variable initwind variable must_open_init_window variable application_window_id @@ -117,6 +117,65 @@ proc spdAux::CreateWindow {} { grid $w.info -columnspan 5 -sticky we } +proc spdAux::CreateLauncherWindow { current_launcher available_apps {window_text "Applications"} {action_text "Select an application"} } { + set initwind $::spdAux::initwind + + set root [customlib::GetBaseRoot] + set nd [ [$root selectNodes "value\[@n='nDim'\]"] getAttribute v] + if { $nd ne "undefined" } { + + } { + [$root selectNodes "value\[@n='nDim'\]"] setAttribute v wait + + set initwind $::spdAux::application_window_id + spdAux::DestroyWindows + spdAux::RegisterWindow $initwind + set w $initwind + + InitWindow $w $window_text Kratos "" "" 1 + set initwind $w + ttk::frame $w.top + ttk::label $w.top.title_text -text $action_text + ttk::frame $w.applications -relief ridge + set i 0 + set column 0 + set row 0 + foreach app $available_apps { + # check if app exists + if {![::apps::appExists $app]} {continue} + set img [::apps::getImgFrom $app] + set app_publicname [[::apps::getAppById $app] getPublicName] + set but [ttk::button $w.applications.img$app -image $img -command [list ::spdAux::ChangeAppTo $current_launcher $app] ] + bind $w.applications.img$app {::spdAux::PlaceInformationWindowByPath %W applications} + ttk::label $w.applications.text$app -text $app_publicname + grid $w.applications.img$app -column $column -row $row + grid $w.applications.text$app -column $column -row [expr $row +1] + incr i + incr column + if {$column >= 5} {set column 0; incr row; incr row} + } + grid $w.top + grid $w.top.title_text + + grid $w.applications + + # Information panel + set spdAux::info_main_window_text "" + ttk::labelframe $w.info -text " Information " -relief ridge + ttk::label $w.info.text -textvariable spdAux::info_main_window_text + grid $w.info.text + grid $w.info -sticky we + } + +} + +proc spdAux::ChangeAppTo {current_launcher appid} { + spdAux::deactiveApp $current_launcher + spdAux::SetSpatialDimmension undefined + apps::setActiveApp $appid +} + + proc spdAux::PlaceInformationWindowByPath {win_path what} { variable application_window_id set app_id [string trimleft $win_path $application_window_id.$what.img] From 16da9e8a624f55d7078003ee7fd4ee1d5c924eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20G=C3=A1rate?= Date: Fri, 31 May 2024 17:41:47 +0200 Subject: [PATCH 2/4] filter if app exists --- kratos.gid/scripts/Applications.tcl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kratos.gid/scripts/Applications.tcl b/kratos.gid/scripts/Applications.tcl index 653b35785..46a862d81 100644 --- a/kratos.gid/scripts/Applications.tcl +++ b/kratos.gid/scripts/Applications.tcl @@ -75,6 +75,10 @@ proc apps::getAppById { id } { proc apps::appExists {id} { variable appList + + if {[getAppById $id] eq ""} { + return 0 + } set dir [file join $::Kratos::kratos_private(Path) apps $id] set app_definition_file [file join $dir app.json] From dc1d3c07900051bae700e26cc853cf11680e352a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20G=C3=A1rate?= Date: Fri, 31 May 2024 17:53:53 +0200 Subject: [PATCH 3/4] prepare release py --- tools/create-release.bat | 5 ++++ tools/prepare-release-files.py | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tools/prepare-release-files.py diff --git a/tools/create-release.bat b/tools/create-release.bat index 73e20693c..842574d45 100644 --- a/tools/create-release.bat +++ b/tools/create-release.bat @@ -5,6 +5,11 @@ set VERSION=9.5.1 @REM set BRANCH=Release-%VERSION% @REM git branch %BRANCH% @REM git checkout %BRANCH% + + +@REM run python prepare-release-files.py +python prepare-release-files.py + cd .. mkdir dist set FOLDER=dist\kratos-%VERSION% diff --git a/tools/prepare-release-files.py b/tools/prepare-release-files.py new file mode 100644 index 000000000..fed9e1104 --- /dev/null +++ b/tools/prepare-release-files.py @@ -0,0 +1,43 @@ +# read the file kratos_default.spd, and parse it as xml +# then extract the version number + +import xml.etree.ElementTree as ET +import sys + +def get_version_number(file_name): + tree = ET.parse(file_name) + root = tree.getroot() + version = root.find('version').text + return version + +if __name__ == "__main__": + + file_name = "../kratos.gid/kratos_default.spd" + version = get_version_number(file_name) + print(version) + + # Get all the applications whose tag is appLink + tree = ET.parse(file_name) + root = tree.getroot() + applications = root.findall('.//appLink') + # create a list of applications, reading the field 'n' + + app_list = [] + for app in applications: + app_list.append(app.attrib['n']) + + print(app_list) + # if there is a folder in the folder apps whose name is not in the list, delete it + + folder_name = "../kratos.gid/apps" + import os + for folder in os.listdir(folder_name): + if folder not in app_list: + print("Deleting folder: ", folder) + import shutil + shutil.rmtree(folder_name + "/" + folder) + + # Ready + print("Ready to release version: ", version) + + \ No newline at end of file From 15e9ec1f184edaead903ab5673fa28dfec5e2ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20G=C3=A1rate?= Date: Fri, 31 May 2024 17:56:25 +0200 Subject: [PATCH 4/4] get version id --- tools/prepare-release-files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/prepare-release-files.py b/tools/prepare-release-files.py index fed9e1104..af87680eb 100644 --- a/tools/prepare-release-files.py +++ b/tools/prepare-release-files.py @@ -7,7 +7,7 @@ def get_version_number(file_name): tree = ET.parse(file_name) root = tree.getroot() - version = root.find('version').text + version = root.attrib['version'] return version if __name__ == "__main__":