config.tcl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. #!/usr/bin/env tclsh
  2. #
  3. # Copyright (c) 2015-2017 OpenIndex.de
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. # THE SOFTWARE.
  22. #
  23. package require inifile
  24. namespace eval ::support::Config {
  25. variable ABOUT
  26. variable GUI
  27. variable GUI_FONT_BUTTON
  28. variable GUI_FONT_CHECKBUTTON
  29. variable GUI_FONT_ENTRY
  30. variable GUI_FONT_LABEL
  31. variable GUI_FONT_TITLE
  32. variable GUI_FONT_SUBTITLE
  33. variable GUI_FONT_STATUS
  34. variable SESSION
  35. proc configure {filename} {
  36. variable ABOUT
  37. variable GUI
  38. variable SESSION
  39. if {[array exists ABOUT] == 0} {
  40. array set ABOUT {}
  41. }
  42. if {[array exists GUI] == 0} {
  43. array set GUI {}
  44. }
  45. if {[array exists SESSION] == 0} {
  46. array set SESSION {}
  47. }
  48. set ini [::ini::open $filename -encoding "utf-8" "r"]
  49. #foreach section [::ini::sections $ini] {
  50. # puts "SECTION: $section"
  51. # foreach key [::ini::keys $ini $section] {
  52. # set value [::ini::value $ini $section $key]
  53. # puts "> $key = $value"
  54. # }
  55. #}
  56. # load global configurations for Mac OS X
  57. configureSection $ini "about" ABOUT
  58. configureSection $ini "gui" GUI
  59. configureSection $ini "session" SESSION
  60. # load additional configurations for Mac OS X
  61. if {[::support::utils::is_darwin]} {
  62. configureSection $ini "about-darwin" ABOUT
  63. configureSection $ini "gui-darwin" GUI
  64. configureSection $ini "session-darwin" SESSION
  65. }
  66. # load additional configurations for Linux
  67. if {[::support::utils::is_linux]} {
  68. configureSection $ini "about-linux" ABOUT
  69. configureSection $ini "gui-linux" GUI
  70. configureSection $ini "session-linux" SESSION
  71. }
  72. # load additional configurations for Windows
  73. if {[::support::utils::is_windows]} {
  74. configureSection $ini "about-windows" ABOUT
  75. configureSection $ini "gui-windows" GUI
  76. configureSection $ini "session-windows" SESSION
  77. }
  78. ::ini::close $ini
  79. }
  80. proc configureSection {ini section target} {
  81. variable $target
  82. if {[::ini::exists $ini $section] != 1} {
  83. return
  84. }
  85. #puts $target
  86. foreach key [::ini::keys $ini $section] {
  87. set value [::ini::value $ini $section $key]
  88. #puts "CONFIG $section / $key / $value"
  89. set var [format "%s(%s)" $target $key]
  90. #puts $var
  91. set $var $value
  92. #set $target($key) $value
  93. #eval "set $target(\$key) $value"
  94. #eval "set $var $value"
  95. }
  96. }
  97. proc getAboutValue {key {defaultValue ""}} {
  98. variable ABOUT
  99. set value $defaultValue
  100. if {[info exists ABOUT($key)]} {
  101. set value [string trim $ABOUT($key)]
  102. if {$value == ""} {
  103. set value $defaultValue
  104. }
  105. }
  106. return $value
  107. }
  108. proc getGuiButtonFont {} {
  109. variable GUI_FONT_BUTTON
  110. if {![info exists GUI_FONT_BUTTON]} {
  111. set GUI_FONT_BUTTON [font create \
  112. -family [getGuiValue "button-font-family" "TkDefaultFont"] \
  113. -size [getGuiValue "button-font-size" "9"] \
  114. -weight [getGuiValue "button-font-weight" "normal"]]
  115. }
  116. return $GUI_FONT_BUTTON
  117. }
  118. proc getGuiButtonOptions {} {
  119. set options {}
  120. lappend options "-background"
  121. lappend options [getGuiValue "button-background" "white"]
  122. lappend options "-activebackground"
  123. lappend options [getGuiValue "button-background-active" "#eeeeee"]
  124. lappend options "-foreground"
  125. lappend options [getGuiValue "button-foreground" "#333333"]
  126. lappend options "-activeforeground"
  127. lappend options [getGuiValue "button-foreground-active" "black"]
  128. lappend options "-disabledforeground"
  129. lappend options [getGuiValue "button-foreground-disabled" "#cccccc"]
  130. lappend options "-font"
  131. lappend options [getGuiButtonFont]
  132. #lappend options "-cursor"
  133. #lappend options "hand1"
  134. return $options
  135. }
  136. proc getGuiCheckbuttonFont {} {
  137. variable GUI_FONT_CHECKBUTTON
  138. if {![info exists GUI_FONT_CHECKBUTTON]} {
  139. set GUI_FONT_CHECKBUTTON [font create \
  140. -family [getGuiValue "checkbutton-font-family" "TkDefaultFont"] \
  141. -size [getGuiValue "checkbutton-font-size" "9"] \
  142. -weight [getGuiValue "checkbutton-font-weight" "normal"]]
  143. }
  144. return $GUI_FONT_CHECKBUTTON
  145. }
  146. proc getGuiCheckbuttonOptions {} {
  147. set options {}
  148. lappend options "-background"
  149. lappend options [getGuiValue "checkbutton-background" "white"]
  150. lappend options "-activebackground"
  151. lappend options [getGuiValue "checkbutton-background-active" "#eeeeee"]
  152. lappend options "-foreground"
  153. lappend options [getGuiValue "checkbutton-foreground" "#333333"]
  154. lappend options "-activeforeground"
  155. lappend options [getGuiValue "checkbutton-foreground-active" "black"]
  156. lappend options "-font"
  157. lappend options [getGuiCheckbuttonFont]
  158. lappend options "-borderwidth"
  159. lappend options 0
  160. lappend options "-highlightthickness"
  161. lappend options 0
  162. #lappend options "-cursor"
  163. #lappend options "hand1"
  164. return $options
  165. }
  166. proc getGuiEntryFont {} {
  167. variable GUI_FONT_ENTRY
  168. if {![info exists GUI_FONT_ENTRY]} {
  169. set GUI_FONT_ENTRY [font create \
  170. -family [getGuiValue "entry-font-family" "TkTextFont"] \
  171. -size [getGuiValue "entry-font-size" "10"] \
  172. -weight [getGuiValue "entry-font-weight" "normal"]]
  173. }
  174. return $GUI_FONT_ENTRY
  175. }
  176. proc getGuiEntryOptions {} {
  177. set options {}
  178. lappend options "-background"
  179. lappend options [getGuiValue "entry-background" "white"]
  180. lappend options "-disabledbackground"
  181. lappend options [getGuiValue "entry-background-disabled" "#e0e0e0"]
  182. lappend options "-readonlybackground"
  183. lappend options [getGuiValue "entry-background-readonly" "#f0f0f0"]
  184. lappend options "-foreground"
  185. lappend options [getGuiValue "entry-foreground" "black"]
  186. lappend options "-disabledforeground"
  187. lappend options [getGuiValue "entry-foreground-disabled" "#999999"]
  188. lappend options "-font"
  189. lappend options [getGuiEntryFont]
  190. #lappend options "-cursor"
  191. #lappend options "hand1"
  192. return $options
  193. }
  194. proc getGuiLabelFont {} {
  195. variable GUI_FONT_LABEL
  196. if {![info exists GUI_FONT_LABEL]} {
  197. set GUI_FONT_LABEL [font create \
  198. -family [getGuiValue "label-font-family" "TkDefaultFont"] \
  199. -size [getGuiValue "label-font-size" "9"] \
  200. -weight [getGuiValue "label-font-weight" "normal"]]
  201. }
  202. return $GUI_FONT_LABEL
  203. }
  204. proc getGuiLabelOptions {} {
  205. set options {}
  206. lappend options "-background"
  207. lappend options [getGuiValue "label-background" "white"]
  208. lappend options "-foreground"
  209. lappend options [getGuiValue "label-foreground" "black"]
  210. lappend options "-disabledforeground"
  211. lappend options [getGuiValue "label-foreground-disabled" "#cccccc"]
  212. lappend options "-font"
  213. lappend options [getGuiLabelFont]
  214. #lappend options "-cursor"
  215. #lappend options "hand1"
  216. return $options
  217. }
  218. proc getGuiStatusFont {} {
  219. variable GUI_FONT_STATUS
  220. if {![info exists GUI_FONT_STATUS]} {
  221. set GUI_FONT_STATUS [font create \
  222. -family [getGuiValue "status-font-family" "TkDefaultFont"] \
  223. -size [getGuiValue "status-font-size" "9"] \
  224. -weight [getGuiValue "status-font-weight" "normal"]]
  225. }
  226. return $GUI_FONT_STATUS
  227. }
  228. proc getGuiStatusOptions {} {
  229. set options {}
  230. lappend options "-background"
  231. lappend options [getGuiValue "status-background" "#f0f0f0"]
  232. lappend options "-foreground"
  233. lappend options [getGuiValue "status-foreground" "black"]
  234. lappend options "-disabledforeground"
  235. lappend options [getGuiValue "status-foreground-disabled" "#c0c0c0"]
  236. lappend options "-font"
  237. lappend options [getGuiStatusFont]
  238. #lappend options "-cursor"
  239. #lappend options "hand1"
  240. return $options
  241. }
  242. proc getGuiSubtitleFont {} {
  243. variable GUI_FONT_SUBTITLE
  244. if {![info exists GUI_FONT_SUBTITLE]} {
  245. set GUI_FONT_SUBTITLE [font create \
  246. -family [getGuiValue "subtitle-font-family" "TkCaptionFont"] \
  247. -size [getGuiValue "subtitle-font-size" "10"] \
  248. -weight [getGuiValue "subtitle-font-weight" "bold"]]
  249. }
  250. return $GUI_FONT_SUBTITLE
  251. }
  252. proc getGuiSubtitleOptions {} {
  253. set options {}
  254. lappend options "-background"
  255. lappend options [getGuiValue "subtitle-background" "white"]
  256. lappend options "-foreground"
  257. lappend options [getGuiValue "subtitle-foreground" "black"]
  258. lappend options "-disabledforeground"
  259. lappend options [getGuiValue "subtitle-foreground-disabled" "#cccccc"]
  260. lappend options "-font"
  261. lappend options [getGuiSubtitleFont]
  262. #lappend options "-cursor"
  263. #lappend options "hand1"
  264. return $options
  265. }
  266. proc getGuiTitleFont {} {
  267. variable GUI_FONT_TITLE
  268. if {![info exists GUI_FONT_TITLE]} {
  269. set GUI_FONT_TITLE [font create \
  270. -family [getGuiValue "title-font-family" "TkCaptionFont"] \
  271. -size [getGuiValue "title-font-size" "12"] \
  272. -weight [getGuiValue "title-font-weight" "bold"]]
  273. }
  274. return $GUI_FONT_TITLE
  275. }
  276. proc getGuiTitleOptions {} {
  277. set options {}
  278. lappend options "-background"
  279. lappend options [getGuiValue "title-background" "white"]
  280. lappend options "-foreground"
  281. lappend options [getGuiValue "title-foreground" "black"]
  282. lappend options "-disabledforeground"
  283. lappend options [getGuiValue "title-foreground-disabled" "#cccccc"]
  284. lappend options "-font"
  285. lappend options [getGuiTitleFont]
  286. #lappend options "-cursor"
  287. #lappend options "hand1"
  288. return $options
  289. }
  290. proc getGuiValue {key {defaultValue ""}} {
  291. variable GUI
  292. set value $defaultValue
  293. if {[info exists GUI($key)]} {
  294. set value [string trim $GUI($key)]
  295. if {$value == ""} {
  296. set value $defaultValue
  297. }
  298. }
  299. return $value
  300. }
  301. proc getSessionValue {key {defaultValue ""}} {
  302. variable SESSION
  303. set value $defaultValue
  304. if {[info exists SESSION($key)]} {
  305. set value [string trim $SESSION($key)]
  306. if {$value == ""} {
  307. set value $defaultValue
  308. }
  309. }
  310. return $value
  311. }
  312. }