From c9874efe11b07ccd7e3f519a5548f1f0fefa4244 Mon Sep 17 00:00:00 2001 From: Alex Plotnikov Date: Wed, 6 Dec 2023 20:10:26 +0300 Subject: [PATCH] v1.2 --- aloupe.tcl | 55 +++++++++++++++++++++++++++++++++++++++------------- pkgIndex.tcl | 2 +- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/aloupe.tcl b/aloupe.tcl index b55409c..4029b28 100644 --- a/aloupe.tcl +++ b/aloupe.tcl @@ -1,20 +1,22 @@ #! /usr/bin/env tclsh -# _______________________________________________________________________ # -# -# This is a screen loupe. -# -# Scripted by Alex Plotnikov (https://aplsimple.github.io). -# -# See README.md for details. -# +########################################################### +# Name: aloupe.tcl +# Author: Alex Plotnikov (aplsimple@gmail.com) +# Date: Feb 26, 2021 +# Brief: Handles a screen loupe. # License: MIT. -# _______________________________________________________________________ # +########################################################### + +# _________________________ aloupe ________________________ # package require Tk +package provide aloupe 1.2 + namespace eval ::aloupe { variable solo [expr {[info exist ::argv0] && [file normalize $::argv0] eq [file normalize [info script]]}] } +if {$::aloupe::solo} {wm withdraw .} # _____ Remove installed (perhaps) packages used here _____ # @@ -41,18 +43,39 @@ if {$::aloupe::solo} { } } -package require treectrl -package require Img +# ________________________ Run solo at need _________________________ # -::msgcat::mcload [file join [file dirname [info script]] msgs] +proc ::aloupe::RunSolo {} { + # Runs aloupe as a sole Tcl script. + # When aloupe runs from tclkit, it may fail. So try it with tclsh deployed. -package provide aloupe 1.0 + set tclsh [auto_execok tclsh] + set tclexe [info nameofexecutable] + # tclsh may be sort of "tcl.sh" to run a tclkit + if {[file exists $tclsh] && [file size $tclsh]>1024 && $tclsh ne $tclexe} { + if {$::aloupe::solo} {set aar $::argv} {set aar {}} + exec -- $tclsh $::aloupe::aloupescript {*}$aar & + } else { + puts "aloupe: $::aloupe::runerr" + } + +} +set ::aloupe::aloupescript [info script] +set ::aloupe::starterr [catch {package require treectrl; package require Img} ::aloupe::runerr] +if {$::aloupe::solo && $::aloupe::starterr} { + ::aloupe::RunSolo + exit +} # ________________________ Variables _________________________ # +::msgcat::mcload [file join [file dirname [info script]] msgs] + namespace eval ::aloupe { variable filename {} namespace eval my { + variable HOMEDIR ~ + if {[info exists ::env(HOME)]} {set HOMEDIR $::env(HOME)} variable size 26 variable zoom 8 variable pause 0 @@ -70,7 +93,7 @@ namespace eval ::aloupe { -geometry "" \ -parent "" \ -save yes \ - -inifile "~/.config/aloupe.conf" \ + -inifile [file join $HOMEDIR .config aloupe.conf] \ -locale "" \ -apavedir "" \ -cs -2 \ @@ -595,6 +618,10 @@ proc ::aloupe::run {args} { # Runs the loupe. # args - options of the loupe + if {$::aloupe::starterr} { + RunSolo + return + } variable my::data variable my::size variable my::zoom diff --git a/pkgIndex.tcl b/pkgIndex.tcl index 102b9cb..099e34b 100644 --- a/pkgIndex.tcl +++ b/pkgIndex.tcl @@ -1,5 +1,5 @@ -package ifneeded aloupe 1.0 [list source [file join $dir aloupe.tcl]] +package ifneeded aloupe 1.2 [list source [file join $dir aloupe.tcl]] # A short intro (for Ruff! docs generator:)