2 # -*- coding: utf-8 -*-
4 #Copyright 2008-2010 Carl Gherardi
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
19 _
= L10n
.get_translation()
21 import xml
.dom
.minidom
22 from xml
.dom
.minidom
import Node
31 rewrite
= { 'general' : 'General', 'supported_databases' : 'Databases'
32 , 'import' : 'Import', 'hud_ui' : 'HUD'
33 , 'supported_sites' : 'Sites', 'supported_games' : 'Games'
34 , 'popup_windows' : 'Popup Windows', 'pu' : 'Window'
35 , 'pu_name' : 'Popup Name', 'pu_stat' : 'Stat'
36 , 'pu_stat_name' : 'Stat Name'
37 , 'aux_windows' : 'Auxiliary Windows', 'aw stud_mucked' : 'stud_mucked'
38 , 'aw mucked' : 'mucked', 'hhcs' : 'Hand History Converters'
39 , 'gui_cash_stats' : 'Ring Player Stats', 'field_type' : 'Field Type'
40 , 'col_title' : 'Column Heading', 'xalignment' : 'Left/Right Align'
41 , 'disp_all' : 'Show in Summaries', 'disp_posn' : 'Show in Position Stats'
42 , 'col_name' : 'Stat Name', 'field_format' : 'Format'
47 def __init__(self
, config
, mainwin
, dia
, parentwin
):
49 self
.main_window
= mainwin
51 self
.parent_window
= parentwin
#need to pass reference of parent, to set transient
53 self
.tree_box
= gtk
.ScrolledWindow()
54 self
.tree_box
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_AUTOMATIC
)
56 self
.dialog
.add(self
.tree_box
)
60 self
.configStore
= None
61 self
.configView
= None
66 self
.doc
= self
.config
.get_doc()
68 self
.configStore
= gtk
.TreeStore(gobject
.TYPE_PYOBJECT
, gobject
.TYPE_STRING
, gobject
.TYPE_STRING
)
69 self
.configView
= gtk
.TreeView(self
.configStore
)
70 self
.configView
.set_enable_tree_lines(True)
72 configColumn
= gtk
.TreeViewColumn(_("Setting"))
73 self
.configView
.append_column(configColumn
)
74 cRender
= gtk
.CellRendererText()
75 configColumn
.pack_start(cRender
, True)
76 configColumn
.add_attribute(cRender
, 'text', 1)
78 configColumn
= gtk
.TreeViewColumn(_("Value (double-click to change)"))
79 self
.configView
.append_column(configColumn
)
80 cRender
= gtk
.CellRendererText()
81 configColumn
.pack_start(cRender
, True)
82 configColumn
.add_attribute(cRender
, 'text', 2)
84 if self
.doc
.documentElement
.tagName
== 'FreePokerToolsConfig':
85 self
.configStore
.clear()
86 self
.root
= self
.configStore
.append( None, [self
.doc
.documentElement
, "fpdb", None] )
87 for elem
in self
.doc
.documentElement
.childNodes
:
88 iter = self
.addTreeRows(self
.root
, elem
)
90 self
.configView
.expand_row(self
.configStore
.get_path(self
.root
), False)
91 self
.configView
.connect("row-activated", self
.rowChosen
)
92 self
.configView
.show()
93 self
.tree_box
.add(self
.configView
)
97 def rewriteText(self
, s
):
104 def addTreeRows(self
, parent
, node
):
105 if (node
.nodeType
== node
.ELEMENT_NODE
):
106 (setting
, value
) = (node
.nodeName
, None)
107 elif (node
.nodeType
== node
.TEXT_NODE
):
108 # text nodes hold the whitespace (or whatever) between the xml elements, not used here
109 (setting
, value
) = ("TEXT: ["+node
.nodeValue
+"|"+node
.nodeValue
+"]", node
.data
)
111 (setting
, value
) = ("?? "+node
.nodeValue
, "type="+str(node
.nodeType
))
113 #iter = self.configStore.append( parent, [node.nodeValue, None] )
115 if node
.nodeType
!= node
.TEXT_NODE
and node
.nodeType
!= node
.COMMENT_NODE
:
117 iter = self
.configStore
.append( parent
, [node
, setting
, value
] )
118 if node
.hasAttributes():
119 for i
in xrange(node
.attributes
.length
):
120 localName
,updated
= self
.rewriteText( node
.attributes
.item(i
).localName
)
121 self
.configStore
.append( iter, [node
, localName
, node
.attributes
.item(i
).value
] )
122 if node
.attributes
.item(i
).localName
in ('site_name', 'game_name', 'stat_name', 'name', 'db_server', 'site', 'col_name'):
123 name
= " " + node
.attributes
.item(i
).value
125 label
,updated
= self
.rewriteText(setting
+name
)
126 if name
!= "" or updated
:
127 self
.configStore
.set_value(iter, 1, label
)
129 if node
.hasChildNodes():
130 for elem
in node
.childNodes
:
131 self
.addTreeRows(iter, elem
)
134 def rowChosen(self
, tview
, path
, something2
, data
=None):
135 # tview should= self.configStore
136 tmodel
= tview
.get_model()
137 iter = tmodel
.get_iter(path
)
138 if tmodel
.iter_has_child(iter):
139 # toggle children display
140 if tview
.row_expanded(path
):
141 tview
.collapse_row(tmodel
.get_path(iter))
143 tview
.expand_row(tmodel
.get_path(iter), False)
145 # display value and allow edit
146 name
= tmodel
.get_value( iter, 1 )
147 val
= tmodel
.get_value( iter, 2 )
148 dia_edit
= gtk
.Dialog(name
,
150 gtk
.DIALOG_MODAL | gtk
.DIALOG_DESTROY_WITH_PARENT
,
151 (gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
152 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
153 #dia_edit.set_default_size(350, 100)
157 entry
.set_width_chars(40)
158 dia_edit
.vbox
.pack_start(entry
, False, False, 0)
160 entry
.connect("activate", self
.__set
_entry
, dia_edit
)
161 response
= dia_edit
.run()
162 if response
== gtk
.RESPONSE_ACCEPT
:
164 new_val
= entry
.get_text()
165 tmodel
.set_value(iter, 2, new_val
)
166 tmodel
.get_value(iter, 0).setAttribute(name
, new_val
)
169 def __set_entry(self
, w
, dia
=None):
171 dia
.response(gtk
.RESPONSE_ACCEPT
)
173 if __name__
=="__main__":
175 config
= Configuration
.Config()
177 win
= gtk
.Window(gtk
.WINDOW_TOPLEVEL
)
178 win
.set_title(_("Test Preferences Dialog"))
179 win
.set_border_width(1)
180 win
.set_default_size(600, 500)
181 win
.set_resizable(True)
183 dia
= gtk
.Dialog(_("Preferences"),
185 gtk
.DIALOG_MODAL | gtk
.DIALOG_DESTROY_WITH_PARENT
,
186 (gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
187 gtk
.STOCK_SAVE
, gtk
.RESPONSE_ACCEPT
))
188 dia
.set_default_size(700, 500)
189 pw
=dia
#pass parent window
190 prefs
= GuiPrefs(config
, win
, dia
.vbox
,pw
)
192 if response
== gtk
.RESPONSE_ACCEPT
:
193 # save updated config