TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG23.py
blob91e71d331d8356401e8171f06506cd131c67720c
1 # GemRB - Infinity Engine Emulator
2 # Copyright (C) 2003 The GemRB Project
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
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 General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #character generation, biography (GUICG23)
20 import GemRB
22 BioWindow = 0
23 EditControl = 0
25 def OnLoad ():
26 global BioWindow, EditControl
28 GemRB.LoadWindowPack ("GUICG", 640, 480)
29 BioWindow = GemRB.LoadWindow (23)
31 EditControl = BioWindow.GetControl (3)
32 BIO = GemRB.GetToken("BIO")
33 EditControl = EditControl.ConvertEdit (5)
34 EditControl.SetVarAssoc ("row", 0)
35 EditControl.SetStatus (IE_GUI_CONTROL_FOCUSED)
36 if BIO:
37 EditControl.SetText (BIO)
38 else:
39 EditControl.SetText (15882)
41 # done
42 OkButton = BioWindow.GetControl (1)
43 OkButton.SetText (11973)
45 ClearButton = BioWindow.GetControl (4)
46 ClearButton.SetText (34881)
48 # back
49 CancelButton = BioWindow.GetControl (2)
50 CancelButton.SetText (12896)
51 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
53 OkButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OkPress)
54 ClearButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClearPress)
55 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CancelPress)
56 BioWindow.SetVisible (WINDOW_VISIBLE)
57 return
59 def OkPress ():
60 global BioWindow, EditControl
62 row = 0
63 line = None
64 BioData = ""
66 #there is no way to get the entire TextArea content
67 #this hack retrieves the TextArea content row by row
68 #there is no way to know how much data is in the TextArea
69 while 1:
70 GemRB.SetVar ("row", row)
71 EditControl.SetVarAssoc ("row", row)
72 line = EditControl.QueryText ()
73 if len(line)<=0:
74 break
75 BioData += line+"\n"
76 row += 1
78 if BioWindow:
79 BioWindow.Unload ()
80 GemRB.SetNextScript ("CharGen9")
81 GemRB.SetToken ("BIO", BioData)
82 return
84 def CancelPress ():
85 if BioWindow:
86 BioWindow.Unload ()
87 GemRB.SetNextScript ("CharGen9")
88 return
90 def ClearPress ():
91 EditControl.SetText ("")
92 return