preferences.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. """
  2. @package gmodeler.preferences
  3. @brief wxGUI Graphical Modeler - preferences
  4. Classes:
  5. - preferences::PreferencesDialog
  6. - preferences::PropertiesDialog
  7. (C) 2010-2013 by the GRASS Development Team
  8. This program is free software under the GNU General Public License
  9. (>=v2). Read the file COPYING that comes with GRASS for details.
  10. @author Martin Landa <landa.martin gmail.com>
  11. """
  12. import wx
  13. import wx.lib.colourselect as csel
  14. from core import globalvar
  15. from gui_core.preferences import PreferencesBaseDialog
  16. from core.settings import UserSettings
  17. from gui_core.wrap import SpinCtrl, Button, StaticText, StaticBox, TextCtrl
  18. class PreferencesDialog(PreferencesBaseDialog):
  19. """User preferences dialog"""
  20. def __init__(
  21. self, parent, giface, settings=UserSettings, title=_("Modeler settings")
  22. ):
  23. PreferencesBaseDialog.__init__(
  24. self, parent=parent, giface=giface, title=title, settings=settings
  25. )
  26. # create notebook pages
  27. self._createGeneralPage(self.notebook)
  28. self._createActionPage(self.notebook)
  29. self._createDataPage(self.notebook)
  30. self._createLoopPage(self.notebook)
  31. self._createCommentPage(self.notebook)
  32. self.SetMinSize(self.GetBestSize())
  33. self.SetSize(self.size)
  34. def _createGeneralPage(self, notebook):
  35. """Create notebook page for action settings"""
  36. panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
  37. notebook.AddPage(page=panel, text=_("General"))
  38. # colors
  39. border = wx.BoxSizer(wx.VERTICAL)
  40. box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % _("Item properties"))
  41. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  42. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  43. row = 0
  44. gridSizer.Add(
  45. StaticText(parent=panel, id=wx.ID_ANY, label=_("Disabled:")),
  46. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  47. pos=(row, 0),
  48. )
  49. rColor = csel.ColourSelect(
  50. parent=panel,
  51. id=wx.ID_ANY,
  52. colour=self.settings.Get(group="modeler", key="disabled", subkey="color"),
  53. size=globalvar.DIALOG_COLOR_SIZE,
  54. )
  55. rColor.SetName("GetColour")
  56. self.winId["modeler:disabled:color"] = rColor.GetId()
  57. gridSizer.Add(
  58. rColor, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  59. )
  60. gridSizer.AddGrowableCol(0)
  61. sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  62. border.Add(
  63. sizer,
  64. proportion=0,
  65. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  66. border=3,
  67. )
  68. panel.SetSizer(border)
  69. return panel
  70. def _createActionPage(self, notebook):
  71. """Create notebook page for action settings"""
  72. panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
  73. notebook.AddPage(page=panel, text=_("Command"))
  74. # colors
  75. border = wx.BoxSizer(wx.VERTICAL)
  76. box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % _("Color"))
  77. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  78. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  79. row = 0
  80. gridSizer.Add(
  81. StaticText(parent=panel, id=wx.ID_ANY, label=_("Valid:")),
  82. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  83. pos=(row, 0),
  84. )
  85. vColor = csel.ColourSelect(
  86. parent=panel,
  87. id=wx.ID_ANY,
  88. colour=self.settings.Get(
  89. group="modeler", key="action", subkey=("color", "valid")
  90. ),
  91. size=globalvar.DIALOG_COLOR_SIZE,
  92. )
  93. vColor.SetName("GetColour")
  94. self.winId["modeler:action:color:valid"] = vColor.GetId()
  95. gridSizer.Add(
  96. vColor, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  97. )
  98. row += 1
  99. gridSizer.Add(
  100. StaticText(parent=panel, id=wx.ID_ANY, label=_("Invalid:")),
  101. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  102. pos=(row, 0),
  103. )
  104. iColor = csel.ColourSelect(
  105. parent=panel,
  106. id=wx.ID_ANY,
  107. colour=self.settings.Get(
  108. group="modeler", key="action", subkey=("color", "invalid")
  109. ),
  110. size=globalvar.DIALOG_COLOR_SIZE,
  111. )
  112. iColor.SetName("GetColour")
  113. self.winId["modeler:action:color:invalid"] = iColor.GetId()
  114. gridSizer.Add(
  115. iColor, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  116. )
  117. row += 1
  118. gridSizer.Add(
  119. StaticText(parent=panel, id=wx.ID_ANY, label=_("Running:")),
  120. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  121. pos=(row, 0),
  122. )
  123. rColor = csel.ColourSelect(
  124. parent=panel,
  125. id=wx.ID_ANY,
  126. colour=self.settings.Get(
  127. group="modeler", key="action", subkey=("color", "running")
  128. ),
  129. size=globalvar.DIALOG_COLOR_SIZE,
  130. )
  131. rColor.SetName("GetColour")
  132. self.winId["modeler:action:color:running"] = rColor.GetId()
  133. gridSizer.Add(
  134. rColor, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  135. )
  136. gridSizer.AddGrowableCol(0)
  137. sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  138. border.Add(
  139. sizer,
  140. proportion=0,
  141. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  142. border=3,
  143. )
  144. # size
  145. box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % _("Shape size"))
  146. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  147. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  148. row = 0
  149. gridSizer.Add(
  150. StaticText(parent=panel, id=wx.ID_ANY, label=_("Width:")),
  151. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  152. pos=(row, 0),
  153. )
  154. width = SpinCtrl(
  155. parent=panel,
  156. id=wx.ID_ANY,
  157. min=0,
  158. max=500,
  159. initial=self.settings.Get(
  160. group="modeler", key="action", subkey=("size", "width")
  161. ),
  162. )
  163. width.SetName("GetValue")
  164. self.winId["modeler:action:size:width"] = width.GetId()
  165. gridSizer.Add(
  166. width, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  167. )
  168. row += 1
  169. gridSizer.Add(
  170. StaticText(parent=panel, id=wx.ID_ANY, label=_("Height:")),
  171. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  172. pos=(row, 0),
  173. )
  174. height = SpinCtrl(
  175. parent=panel,
  176. id=wx.ID_ANY,
  177. min=0,
  178. max=500,
  179. initial=self.settings.Get(
  180. group="modeler", key="action", subkey=("size", "height")
  181. ),
  182. )
  183. height.SetName("GetValue")
  184. self.winId["modeler:action:size:height"] = height.GetId()
  185. gridSizer.Add(
  186. height, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  187. )
  188. gridSizer.AddGrowableCol(0)
  189. sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  190. border.Add(
  191. sizer,
  192. proportion=0,
  193. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  194. border=3,
  195. )
  196. panel.SetSizer(border)
  197. return panel
  198. def _createDataPage(self, notebook):
  199. """Create notebook page for data settings"""
  200. panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
  201. notebook.AddPage(page=panel, text=_("Data"))
  202. # colors
  203. border = wx.BoxSizer(wx.VERTICAL)
  204. box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % _("Type"))
  205. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  206. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  207. row = 0
  208. gridSizer.Add(
  209. StaticText(parent=panel, id=wx.ID_ANY, label=_("Raster:")),
  210. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  211. pos=(row, 0),
  212. )
  213. rColor = csel.ColourSelect(
  214. parent=panel,
  215. id=wx.ID_ANY,
  216. colour=self.settings.Get(
  217. group="modeler", key="data", subkey=("color", "raster")
  218. ),
  219. size=globalvar.DIALOG_COLOR_SIZE,
  220. )
  221. rColor.SetName("GetColour")
  222. self.winId["modeler:data:color:raster"] = rColor.GetId()
  223. gridSizer.Add(
  224. rColor, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  225. )
  226. row += 1
  227. gridSizer.Add(
  228. StaticText(parent=panel, id=wx.ID_ANY, label=_("3D raster:")),
  229. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  230. pos=(row, 0),
  231. )
  232. r3Color = csel.ColourSelect(
  233. parent=panel,
  234. id=wx.ID_ANY,
  235. colour=self.settings.Get(
  236. group="modeler", key="data", subkey=("color", "raster3d")
  237. ),
  238. size=globalvar.DIALOG_COLOR_SIZE,
  239. )
  240. r3Color.SetName("GetColour")
  241. self.winId["modeler:data:color:raster3d"] = r3Color.GetId()
  242. gridSizer.Add(
  243. r3Color, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  244. )
  245. row += 1
  246. gridSizer.Add(
  247. StaticText(parent=panel, id=wx.ID_ANY, label=_("Vector:")),
  248. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  249. pos=(row, 0),
  250. )
  251. vColor = csel.ColourSelect(
  252. parent=panel,
  253. id=wx.ID_ANY,
  254. colour=self.settings.Get(
  255. group="modeler", key="data", subkey=("color", "vector")
  256. ),
  257. size=globalvar.DIALOG_COLOR_SIZE,
  258. )
  259. vColor.SetName("GetColour")
  260. self.winId["modeler:data:color:vector"] = vColor.GetId()
  261. gridSizer.Add(
  262. vColor, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  263. )
  264. row += 1
  265. gridSizer.Add(
  266. StaticText(parent=panel, id=wx.ID_ANY, label=_("Table:")),
  267. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  268. pos=(row, 0),
  269. )
  270. tColor = csel.ColourSelect(
  271. parent=panel,
  272. id=wx.ID_ANY,
  273. colour=self.settings.Get(
  274. group="modeler", key="data", subkey=("color", "dbtable")
  275. ),
  276. size=globalvar.DIALOG_COLOR_SIZE,
  277. )
  278. tColor.SetName("GetColour")
  279. self.winId["modeler:data:color:dbtable"] = tColor.GetId()
  280. gridSizer.Add(
  281. tColor, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  282. )
  283. gridSizer.AddGrowableCol(0)
  284. sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  285. border.Add(
  286. sizer,
  287. proportion=0,
  288. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  289. border=3,
  290. )
  291. # size
  292. box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % _("Shape size"))
  293. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  294. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  295. row = 0
  296. gridSizer.Add(
  297. StaticText(parent=panel, id=wx.ID_ANY, label=_("Width:")),
  298. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  299. pos=(row, 0),
  300. )
  301. width = SpinCtrl(
  302. parent=panel,
  303. id=wx.ID_ANY,
  304. min=0,
  305. max=500,
  306. initial=self.settings.Get(
  307. group="modeler", key="data", subkey=("size", "width")
  308. ),
  309. )
  310. width.SetName("GetValue")
  311. self.winId["modeler:data:size:width"] = width.GetId()
  312. gridSizer.Add(
  313. width, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  314. )
  315. row += 1
  316. gridSizer.Add(
  317. StaticText(parent=panel, id=wx.ID_ANY, label=_("Height:")),
  318. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  319. pos=(row, 0),
  320. )
  321. height = SpinCtrl(
  322. parent=panel,
  323. id=wx.ID_ANY,
  324. min=0,
  325. max=500,
  326. initial=self.settings.Get(
  327. group="modeler", key="data", subkey=("size", "height")
  328. ),
  329. )
  330. height.SetName("GetValue")
  331. self.winId["modeler:data:size:height"] = height.GetId()
  332. gridSizer.Add(
  333. height, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  334. )
  335. gridSizer.AddGrowableCol(0)
  336. sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  337. border.Add(
  338. sizer,
  339. proportion=0,
  340. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  341. border=3,
  342. )
  343. panel.SetSizer(border)
  344. return panel
  345. def _createLoopPage(self, notebook):
  346. """Create notebook page for loop settings"""
  347. panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
  348. notebook.AddPage(page=panel, text=_("Loop"))
  349. # colors
  350. border = wx.BoxSizer(wx.VERTICAL)
  351. box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % _("Color"))
  352. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  353. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  354. row = 0
  355. gridSizer.Add(
  356. StaticText(parent=panel, id=wx.ID_ANY, label=_("Valid:")),
  357. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  358. pos=(row, 0),
  359. )
  360. vColor = csel.ColourSelect(
  361. parent=panel,
  362. id=wx.ID_ANY,
  363. colour=self.settings.Get(
  364. group="modeler", key="loop", subkey=("color", "valid")
  365. ),
  366. size=globalvar.DIALOG_COLOR_SIZE,
  367. )
  368. vColor.SetName("GetColour")
  369. self.winId["modeler:loop:color:valid"] = vColor.GetId()
  370. gridSizer.Add(
  371. vColor, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  372. )
  373. gridSizer.AddGrowableCol(0)
  374. sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  375. border.Add(
  376. sizer,
  377. proportion=0,
  378. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  379. border=3,
  380. )
  381. # size
  382. box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % _("Shape size"))
  383. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  384. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  385. row = 0
  386. gridSizer.Add(
  387. StaticText(parent=panel, id=wx.ID_ANY, label=_("Width:")),
  388. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  389. pos=(row, 0),
  390. )
  391. width = SpinCtrl(
  392. parent=panel,
  393. id=wx.ID_ANY,
  394. min=0,
  395. max=500,
  396. initial=self.settings.Get(
  397. group="modeler", key="loop", subkey=("size", "width")
  398. ),
  399. )
  400. width.SetName("GetValue")
  401. self.winId["modeler:loop:size:width"] = width.GetId()
  402. gridSizer.Add(
  403. width, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  404. )
  405. row += 1
  406. gridSizer.Add(
  407. StaticText(parent=panel, id=wx.ID_ANY, label=_("Height:")),
  408. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  409. pos=(row, 0),
  410. )
  411. height = SpinCtrl(
  412. parent=panel,
  413. id=wx.ID_ANY,
  414. min=0,
  415. max=500,
  416. initial=self.settings.Get(
  417. group="modeler", key="loop", subkey=("size", "height")
  418. ),
  419. )
  420. height.SetName("GetValue")
  421. self.winId["modeler:loop:size:height"] = height.GetId()
  422. gridSizer.Add(
  423. height, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  424. )
  425. gridSizer.AddGrowableCol(0)
  426. sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  427. border.Add(
  428. sizer,
  429. proportion=0,
  430. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  431. border=3,
  432. )
  433. panel.SetSizer(border)
  434. return panel
  435. def _createCommentPage(self, notebook):
  436. """Create notebook page for comment settings"""
  437. panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
  438. notebook.AddPage(page=panel, text=_("Comment"))
  439. # colors
  440. border = wx.BoxSizer(wx.VERTICAL)
  441. box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % _("Color"))
  442. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  443. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  444. row = 0
  445. gridSizer.Add(
  446. StaticText(parent=panel, id=wx.ID_ANY, label=_("Valid:")),
  447. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  448. pos=(row, 0),
  449. )
  450. vColor = csel.ColourSelect(
  451. parent=panel,
  452. id=wx.ID_ANY,
  453. colour=self.settings.Get(group="modeler", key="comment", subkey="color"),
  454. size=globalvar.DIALOG_COLOR_SIZE,
  455. )
  456. vColor.SetName("GetColour")
  457. self.winId["modeler:comment:color"] = vColor.GetId()
  458. gridSizer.Add(
  459. vColor, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  460. )
  461. gridSizer.AddGrowableCol(0)
  462. sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  463. border.Add(
  464. sizer,
  465. proportion=0,
  466. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  467. border=3,
  468. )
  469. # size
  470. box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % _("Shape size"))
  471. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  472. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  473. row = 0
  474. gridSizer.Add(
  475. StaticText(parent=panel, id=wx.ID_ANY, label=_("Width:")),
  476. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  477. pos=(row, 0),
  478. )
  479. width = SpinCtrl(
  480. parent=panel,
  481. id=wx.ID_ANY,
  482. min=0,
  483. max=500,
  484. initial=self.settings.Get(
  485. group="modeler", key="comment", subkey=("size", "width")
  486. ),
  487. )
  488. width.SetName("GetValue")
  489. self.winId["modeler:comment:size:width"] = width.GetId()
  490. gridSizer.Add(
  491. width, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  492. )
  493. row += 1
  494. gridSizer.Add(
  495. StaticText(parent=panel, id=wx.ID_ANY, label=_("Height:")),
  496. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  497. pos=(row, 0),
  498. )
  499. height = SpinCtrl(
  500. parent=panel,
  501. id=wx.ID_ANY,
  502. min=0,
  503. max=500,
  504. initial=self.settings.Get(
  505. group="modeler", key="comment", subkey=("size", "height")
  506. ),
  507. )
  508. height.SetName("GetValue")
  509. self.winId["modeler:comment:size:height"] = height.GetId()
  510. gridSizer.Add(
  511. height, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 1)
  512. )
  513. gridSizer.AddGrowableCol(0)
  514. sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  515. border.Add(
  516. sizer,
  517. proportion=0,
  518. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  519. border=3,
  520. )
  521. panel.SetSizer(border)
  522. return panel
  523. def OnApply(self, event):
  524. """Button 'Apply' pressed"""
  525. PreferencesBaseDialog.OnApply(self, event)
  526. self.parent.GetModel().Update()
  527. self.parent.GetCanvas().Refresh()
  528. def OnSave(self, event):
  529. """Button 'Save' pressed"""
  530. PreferencesBaseDialog.OnSave(self, event)
  531. self.parent.GetModel().Update()
  532. self.parent.GetCanvas().Refresh()
  533. class PropertiesDialog(wx.Dialog):
  534. """Model properties dialog"""
  535. def __init__(
  536. self,
  537. parent,
  538. id=wx.ID_ANY,
  539. title=_("Model properties"),
  540. size=(350, 400),
  541. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  542. ):
  543. wx.Dialog.__init__(self, parent, id, title, size=size, style=style)
  544. self.metaBox = StaticBox(
  545. parent=self, id=wx.ID_ANY, label=" %s " % _("Metadata")
  546. )
  547. self.cmdBox = StaticBox(parent=self, id=wx.ID_ANY, label=" %s " % _("Commands"))
  548. self.name = TextCtrl(parent=self, id=wx.ID_ANY, size=(300, 25))
  549. self.desc = TextCtrl(
  550. parent=self, id=wx.ID_ANY, style=wx.TE_MULTILINE, size=(300, 50)
  551. )
  552. self.author = TextCtrl(parent=self, id=wx.ID_ANY, size=(300, 25))
  553. # commands
  554. self.overwrite = wx.CheckBox(
  555. parent=self,
  556. id=wx.ID_ANY,
  557. label=_("Allow output files to overwrite existing files"),
  558. )
  559. self.overwrite.SetValue(
  560. UserSettings.Get(group="cmd", key="overwrite", subkey="enabled")
  561. )
  562. # buttons
  563. self.btnOk = Button(self, wx.ID_OK)
  564. self.btnCancel = Button(self, wx.ID_CANCEL)
  565. self.btnOk.SetDefault()
  566. self.btnOk.SetToolTip(_("Apply properties"))
  567. self.btnOk.SetDefault()
  568. self.btnCancel.SetToolTip(_("Close dialog and ignore changes"))
  569. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  570. self._layout()
  571. def _layout(self):
  572. metaSizer = wx.StaticBoxSizer(self.metaBox, wx.VERTICAL)
  573. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  574. gridSizer.Add(
  575. StaticText(parent=self, id=wx.ID_ANY, label=_("Name:")),
  576. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  577. pos=(0, 0),
  578. )
  579. gridSizer.Add(
  580. self.name,
  581. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  582. pos=(0, 1),
  583. )
  584. gridSizer.Add(
  585. StaticText(parent=self, id=wx.ID_ANY, label=_("Description:")),
  586. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  587. pos=(1, 0),
  588. )
  589. gridSizer.Add(
  590. self.desc,
  591. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  592. pos=(1, 1),
  593. )
  594. gridSizer.Add(
  595. StaticText(parent=self, id=wx.ID_ANY, label=_("Author(s):")),
  596. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  597. pos=(2, 0),
  598. )
  599. gridSizer.Add(
  600. self.author,
  601. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  602. pos=(2, 1),
  603. )
  604. gridSizer.AddGrowableCol(1)
  605. gridSizer.AddGrowableRow(1)
  606. metaSizer.Add(gridSizer, proportion=1, flag=wx.EXPAND)
  607. cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
  608. cmdSizer.Add(self.overwrite, flag=wx.EXPAND | wx.ALL, border=3)
  609. btnStdSizer = wx.StdDialogButtonSizer()
  610. btnStdSizer.AddButton(self.btnCancel)
  611. btnStdSizer.AddButton(self.btnOk)
  612. btnStdSizer.Realize()
  613. mainSizer = wx.BoxSizer(wx.VERTICAL)
  614. mainSizer.Add(metaSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  615. mainSizer.Add(
  616. cmdSizer,
  617. proportion=0,
  618. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  619. border=5,
  620. )
  621. mainSizer.Add(btnStdSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
  622. self.SetSizer(mainSizer)
  623. mainSizer.Fit(self)
  624. def OnCloseWindow(self, event):
  625. self.Hide()
  626. def GetValues(self):
  627. """Get values"""
  628. return {
  629. "name": self.name.GetValue(),
  630. "description": self.desc.GetValue(),
  631. "author": self.author.GetValue(),
  632. "overwrite": self.overwrite.IsChecked(),
  633. }
  634. def Init(self, prop):
  635. """Initialize dialog"""
  636. self.name.SetValue(prop["name"])
  637. self.desc.SetValue(prop["description"])
  638. self.author.SetValue(prop["author"])
  639. if "overwrite" in prop:
  640. self.overwrite.SetValue(prop["overwrite"])