Skip to content

Commit

Permalink
Merge pull request #16 from 4LT/config-line-items
Browse files Browse the repository at this point in the history
Line item configuration
  • Loading branch information
4LT authored Mar 17, 2024
2 parents 7f2ff32 + 2e1ecf2 commit a9aab18
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pectin"
version = "0.0.3"
version = "0.1.0"
edition = "2021"
authors = ["Seth Rader"]
license = "CC0-1.0 OR MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn main() -> Result<(), String> {
let mut done = false;

while !done {
std::thread::sleep(Duration::from_millis(1000 / 60));
std::thread::sleep(Duration::from_millis(1000 / 120));
interp.update().map_err(|e| e.to_string())?;
let root_cmd =
interp.eval("info commands .").map_err(|e| e.to_string())?;
Expand Down
114 changes: 108 additions & 6 deletions src/pectin.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ proc getConfigPath {} {
variable dir

if {[string first win32- [platform::identify]] == 0} {
set dir [file join $::env(USERPROFILE) "AppData/Roaming"]
set dir [file join $::env(USERPROFILE) "AppData/Local"]
} else {
set dir [file join $::env(HOME) ".config"]
}
Expand Down Expand Up @@ -84,6 +84,14 @@ proc populateMaps {treeView config mapList} {
$treeView delete $child
}

variable hideRegexes {}

dict for {regex hide} [dict get $::config hideLineItems] {
if {$hide} {
lappend hideRegexes $regex
}
}

foreach map $mapList {
set failureOnly [dict get $config failureOnly]

Expand All @@ -102,9 +110,20 @@ proc populateMaps {treeView config mapList} {
variable anyFail 0

dict for {key val} $report {
set condition [lindex $val 0]
variable condition [lindex $val 0]

# TODO: Why isn't hide already unset? Tcl Bug?
catch {unset hide}

if {$failureOnly && $condition != "fail"} {
variable hide 0

foreach regex $hideRegexes {
if {[regexp -- $regex $key]} {
set hide 1
}
}

if {$hide || ($failureOnly && $condition != "fail")} {
continue
}

Expand Down Expand Up @@ -361,11 +380,87 @@ proc openAbout {} {
wm minsize .about [scaleDim 500] [scaleDim 600]
}

proc lineItemClick {checkBtn regex} {
variable hide [expr ![$checkBtn instate selected]]
dict set ::config hideLineItems $regex $hide
refreshConfig
}

proc newLineItem {winName text regex} {
ttk::checkbutton $winName -text $text\
-command [list lineItemClick $winName $regex]
$winName state !alternate
variable hide [lineItemHidden $regex]

if {$hide} {
$winName state !selected
} else {
$winName state selected
}

return $winName
}

proc lineItemHidden {itemRegex} {
variable hide

if {[catch {dict get $::config hideLineItems $itemRegex} hide]} {
set hide 0
}

return $hide
}

proc createConfigLineItems {} {
toplevel .config -padx 10

grid [ttk::frame .config.toppad -height 10] -sticky nesw

variable checkNum 0
variable checks {
{"Changelevel to/from start" "Changelevel"}
{"Lighting" "Lighting"}
{"Intermission cameras" "Intermission Count"}
{"Map title set" "Title"}
{"Music track" "Track No\\."}
{"BSP version" "Version"}
{"VIS present" "Vis"}
{"Empty targets" ".* Target"}
}

foreach check $checks {
variable text [lindex $check 0]
variable regex [lindex $check 1]
variable winName .config.check${checkNum}
grid $winName [newLineItem $winName $text $regex] -sticky w
incr checkNum
}

grid [ttk::button .config.ok -text "Ok"\
-command closeConfigLineItems] -sticky e -pady 10

configureBackground .config
update
closeConfigLineItems
}

proc closeConfigLineItems {} {
wm forget .config
}

proc openConfigLineItems {} {
wm manage .config
wm title .config "Pectin - Configuration"
wm protocol .config WM_DELETE_WINDOW closeConfigLineItems
wm resizable .config 0 0
}

readConfig

option add *Menu.tearOff 0
menu .m
menu .m.file
menu .m.options
menu .m.help

.m.file add command -label "Open Map(s)..." -underline 0 -accelerator "Ctrl+O"\
Expand All @@ -376,10 +471,13 @@ menu .m.help
.m.file add command -label "Exit" -underline 1 -accelerator "Alt+F4"\
-command closePectin

.m.options add command -label Configure -command openConfigLineItems

.m.help add command -label About -underline 0 -accelerator "F1"\
-command openAbout

.m add cascade -label File -underline 0 -menu .m.file
.m add cascade -label Options -underline 0 -menu .m.options
.m add cascade -label Help -underline 0 -menu .m.help
. configure -menu .m

Expand All @@ -404,20 +502,24 @@ bind .maps <<TreeviewClose>> {cacheMapExpand .maps 0}

.scrolly configure -command {.maps yview}

ttk::checkbutton .filter -text "Show failures only" -padding {8 8 8 8}\
-command failureFilterUpdate
ttk::checkbutton .filter -text "Show failures only" -command failureFilterUpdate
.filter state !alternate

if {[dict get $::config failureOnly]} {
.filter state selected
}

grid .filter -sticky ew -columnspan 2
grid .filter -sticky w -columnspan 2 -padx 8 -pady 8
grid .maps .scrolly -sticky nesw
grid columnconfigure . 0 -weight 1
grid rowconfigure . 1 -weight 1

configureBackground .

wm minsize . [scaleDim 500] [scaleDim 500]

createAbout
createConfigLineItems

wm title . Pectin
wm client . Pectin
Expand Down

0 comments on commit a9aab18

Please sign in to comment.