From e789988b05d5e80f27313dcd3dbff13780250656 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Thu, 13 Mar 2025 20:11:18 +0100 Subject: [PATCH] add `user_startup_commands` variable that may contain tcl code to be executed after any new window creation. Useful to have custom bindings / menu / buttons in all windows. --- src/xinit.c | 2 ++ src/xschem.tcl | 9 +++++++++ src/xschemrc | 11 +++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/xinit.c b/src/xinit.c index 8ffe0f5c..ff9e9835 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1666,6 +1666,7 @@ static void create_new_window(int *window_count, const char *noconfirm, const ch tclvareval("set_bindings ", window_path[n], NULL); tclvareval("set_replace_key_binding ", window_path[n], NULL); tclvareval("save_ctx ", window_path[n], NULL); + tcleval("eval_user_startup_commands"); /* restore previous context, * because the Expose event after new window creation does a context switch prev win -> new win * @@ -2892,6 +2893,7 @@ int Tcl_AppInit(Tcl_Interp *inter) if(has_x) { tclsetintvar("tctx::max_new_windows", MAX_NEW_WINDOWS); tcleval("pack_widgets; set_bindings .drw"); + tcleval("eval_user_startup_commands"); } fs=tclgetintvar("fullscreen"); diff --git a/src/xschem.tcl b/src/xschem.tcl index 77d498b2..3f2844f5 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -9355,6 +9355,15 @@ proc source_user_tcl_files {} { } } +proc eval_user_startup_commands {} { + global user_startup_commands + if {[info exists user_startup_commands]} { + if {[catch {uplevel #0 $user_startup_commands} res]} { + puts "executing $user_startup_commands:\n\n$res" + } + } +} + proc eval_postinit_commands {} { global postinit_commands if {[info exists postinit_commands]} { diff --git a/src/xschemrc b/src/xschemrc index 8bcacf06..41516e38 100644 --- a/src/xschemrc +++ b/src/xschemrc @@ -540,6 +540,17 @@ # } # } +########################################################################### +#### TCL COMMANDS TO BE EXECUTED AFTER ANY NEW WINDOW CREATION +########################################################################### +#### this hook is useful to execute user UI code (like event binding, +#### new buttons / menu entries etc). +# set user_startup_commands { +# bind [xschem get current_win_path] { +# puts Hello +# } +# } + ########################################################################### #### TCL COMMANDS TO BE EXECUTED AFTER GENERATING NETLIST ###########################################################################