~aleteoryx/tclircc

b8279c2d003cd7f1b2229dffef8878498eddee48 — aleteoryx a month ago 133ef83
more ui work
2 files changed, 54 insertions(+), 14 deletions(-)

M main.tcl
R uiMain.tcl => ui/main.tcl
M main.tcl => main.tcl +10 -3
@@ 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 <https://amehut.dev/~aleteoryx/tclircc>}
${log}::info "tclircc $version <https://amehut.dev/~aleteoryx/tclircc>"
${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

R uiMain.tcl => ui/main.tcl +44 -11
@@ 1,8 1,8 @@
#!/bin/env tclsh

set path [file dirname [dict get [info frame 0] file]]

variable toplevel_count 0
variable toplevel_tabs
variable toplevel_classes

package require logger
set log [logger::init tclircc::ui]


@@ 11,26 11,59 @@ ${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"

proc mkToplevel {varname {takefocus 0}} {
    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

  wm title $window "tclircc - $window"

  ### MENUBAR ###
  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 {
  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 v0.0.1" \
                  -message "tclircc $version" \
                  -detail "by Aleteoryx\nhttps://amehut.dev/~aleteoryx/tclircc\n\nThis software is in the public domain." \
                  -type ok }
                  -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
}

mkToplevel _
${log}::debug "ui init done!"