1 ## This file is part of Crapvine.
3 ## Copyright (C) 2007 Andrew Sayman <lorien420@myrealbox.com>
5 ## Crapvine is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or
8 ## (at your option) any later version.
10 ## Crapvine is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
22 from template
import Template
24 class NumberAsTextWithTemporaryAttributeBox
:
25 __glade_xml_file
= configuration
.get_number_as_text_with_temporary_attribute_box_xml_file_path()
26 def __init__(self
, menu_name
, display_name
, tmp_name
, overlord
, character
):
27 self
.xml
= gtk
.glade
.XML(self
.__glade
_xml
_file
, 'numberastextwithtemporaryattribute')
28 self
.vbox
= self
.xml
.get_widget('numberastextwithtemporaryattribute')
29 self
.display
= self
.xml
.get_widget('display')
30 self
.label
= self
.xml
.get_widget('lblNumberAsTextWithTemporaryAttributeName')
31 self
.permanent
= self
.xml
.get_widget('permanent')
32 self
.temporary
= self
.xml
.get_widget('temporary')
33 self
.menu_name
= menu_name
34 self
.display_name
= display_name
35 self
.temporary_name
= tmp_name
36 self
.overlord
= overlord
37 self
.character
= character
39 self
.label
.set_label(self
.display_name
.capitalize())
40 self
.permanent
.set_value(float(self
.character
[self
.display_name
]))
41 self
.temporary
.set_value(float(self
.character
[self
.temporary_name
]))
42 self
.__update
_special
_display
()
44 self
.xml
.signal_autoconnect({
45 'on_permanent_value_changed' : self
.on_permanent_value_changed
,
46 'on_temporary_value_changed' : self
.on_temporary_value_changed
49 def add_menu_item(self
, menu_item
):
50 self
.entry
.set_text(menu_item
.name
)
52 def on_permanent_value_changed(self
, entry
):
53 self
.character
[self
.display_name
] = entry
.get_text()
54 self
.__update
_special
_display
()
55 def on_temporary_value_changed(self
, entry
):
56 self
.character
[self
.temporary_name
] = entry
.get_text()
57 self
.__update
_special
_display
()
59 def __update_special_display(self
):
60 prm_val
= int(round(float(self
.character
[self
.display_name
])))
61 tmp_val
= int(round(float(self
.character
[self
.temporary_name
])))
62 rep_str
= Template
.temporary_tally_str(prm_val
, tmp_val
, wrap
=10)
63 self
.display
.set_label(rep_str
)