From b8279c2d003cd7f1b2229dffef8878498eddee48 Mon Sep 17 00:00:00 2001 From: aleteoryx Date: Wed, 6 Nov 2024 22:15:23 -0500 Subject: [PATCH] more ui work --- main.tcl | 13 +++++++--- ui/main.tcl | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ uiMain.tcl | 36 ---------------------------- 3 files changed, 79 insertions(+), 39 deletions(-) create mode 100644 ui/main.tcl delete mode 100644 uiMain.tcl diff --git a/main.tcl b/main.tcl index 7c3c86b..6ba70c1 100755 --- a/main.tcl +++ b/main.tcl @@ -1,20 +1,27 @@ #!/bin/env tclsh set path [file dirname [dict get [info frame 0] file]] +set version v0.0.1 package require Thread package require logger set log [logger::init tclircc::main] -${log}::info {tclircc 0.0.1 } +${log}::info "tclircc $version " ${log}::info "running from $path" -${log}::debug "starting ui thread" +${log}::debug "starting ui thread..." set ui_thread [thread::create -preserved] -if {[thread::send $ui_thread [list source "$path[file separator]/uiMain.tcl"] result] == 1} { +thread::send $ui_thread [list variable path $path version $version] +if {[thread::send $ui_thread [list source "$path[file separator]ui[file separator]main.tcl"] result] == 1} { ${log}::critical "couldn't start ui thread: $result" exit -1 } +${log}::debug "started ui thread." + +${log}::debug "opening main window..." +thread::send $ui_thread {mk_toplevel name; return $name} mainwin +${log}::debug "main window opened: $mainwin" ${log}::info "entering event loop" vwait nil diff --git a/ui/main.tcl b/ui/main.tcl new file mode 100644 index 0000000..6ffd943 --- /dev/null +++ b/ui/main.tcl @@ -0,0 +1,69 @@ +#!/bin/env tclsh + +variable toplevel_count 0 +variable toplevel_tabs +variable toplevel_classes + +package require logger +set log [logger::init tclircc::ui] + +${log}::debug "loading tk" +package require Tk +wm withdraw . +# TODO: tray handling +# use tktray on linux, use TWAPI on windows (packaged with magicsplat) + +proc tab_update {window} { + variable toplevel_tabs + + if ![llength [set toplevel_tabs($window)]] { + destroy $window.tabs + destroy $window.msg1 $window.msg2 + + wm title $window "tclircc" + + label $window.msg1 -text "No tabs open!" + label $window.msg2 -text "Use the titlebar to open a new tab." + + pack configure $window.msg1 -side top -pady {20 10} + pack configure $window.msg2 -side top -pady {10 50} -padx {50} + } +} + +proc mk_toplevel {varname {takefocus 0}} { + variable toplevel_count + variable toplevel_tabs + variable version + upvar $varname window + set window .win$toplevel_count + toplevel $window -takefocus $takefocus + incr toplevel_count + + ### MENUBAR ### + menu $window.menu + $window configure -menu "$window.menu" + + menu $window.menu.conn + menu $window.menu.irc + menu $window.menu.plugin + + menu $window.menu.me + $window.menu.me add command -label "About" -command [subst { + tk_messageBox -title "About tclircc" \ + -message "tclircc $version" \ + -detail "by Aleteoryx\nhttps://amehut.dev/~aleteoryx/tclircc\n\nThis software is in the public domain." \ + -type ok \ + -parent $window }] + + $window.menu add cascade -label "chat" -menu $window.menu.irc + $window.menu add cascade -label "connection" -menu $window.menu.conn + $window.menu add cascade -label "plugins" -menu $window.menu.plugin + $window.menu add cascade -label "tclircc" -menu $window.menu.me + + ### TABS ### + set toplevel_tabs($window) {} + + tab_update $window +} + +${log}::debug "ui init done!" diff --git a/uiMain.tcl b/uiMain.tcl deleted file mode 100644 index fa2c4a4..0000000 --- a/uiMain.tcl +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/env tclsh - -set path [file dirname [dict get [info frame 0] file]] - -variable toplevel_count 0 - -package require logger -set log [logger::init tclircc::ui] - -${log}::debug "loading tk" -package require Tk -wm withdraw . -# TODO: tray handling - -proc mkToplevel {varname {takefocus 0}} { - variable toplevel_count - upvar $varname window - set window .win$toplevel_count - toplevel $window -takefocus $takefocus - incr toplevel_count - - wm title $window "tclircc - $window" - - menu $window.menu - menu $window.menu.me - $window configure -menu "$window.menu" - - $window.menu add cascade -label "tclircc" -menu $window.menu.me - $window.menu.me add command -label "About" -command { - tk_messageBox -title "About tclircc" \ - -message "tclircc v0.0.1" \ - -detail "by Aleteoryx\nhttps://amehut.dev/~aleteoryx/tclircc\n\nThis software is in the public domain." \ - -type ok } -} - -mkToplevel _ -- 2.45.2