comparison orpg/tools/orpg_settings.py @ 66:c54768cffbd4 ornery-dev

Traipse Dev 'OpenRPG' {090818-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc''s main goal is to offer more advanced features and enhance the productivity of the user. Update Summary: *Unstable* This is the first wave of Code Refinement updates. Includes new material from Core Beta; new debugger material (partially implemented), beginnings of switch to etree, TerminalWriter, and a little more. open_rpg has been renamed to component; functioning now as component.get(), component.add(), component.delete(). This version has known bugs, specifically with the gametree and nodes. I think the XML files where not removed during testing of Core and switching back.
author sirebral
date Tue, 18 Aug 2009 06:33:37 -0500
parents 4840657c23c5
children d1aff41c031b
comparison
equal deleted inserted replaced
65:4840657c23c5 66:c54768cffbd4
25 # 25 #
26 # Description: classes for orpg settings 26 # Description: classes for orpg settings
27 # 27 #
28 28
29 from orpg.orpg_windows import * 29 from orpg.orpg_windows import *
30 import orpg.dirpath 30 from orpg.orpgCore import component
31 from orpg.dirpath import dir_struct
31 from rgbhex import * 32 from rgbhex import *
32 import sys 33 import sys
33 import os 34 import os
35 from orpg.orpg_xml import xml
34 36
35 class orpgSettings: 37 class orpgSettings:
36 def __init__(self): 38 def __init__(self):
37 self.validate = open_rpg.get_component("validate") 39 self.validate = component.get("validate")
38 self.xml = open_rpg.get_component("xml") 40 component.add('xml', xml)
39 self.log = open_rpg.get_component("log") 41 self.xml = component.get("xml")
42 self.orpgLog = component.get("log")
40 self.changes = [] 43 self.changes = []
41 self.validate.config_file("settings.xml","default_settings.xml") 44 self.validate.config_file("settings.xml","default_settings.xml")
42 self.filename = orpg.dirpath.dir_struct["user"] + "settings.xml" 45 self.filename = dir_struct["user"] + "settings.xml"
43 temp_file = open(self.filename) 46 temp_file = open(self.filename)
44 txt = temp_file.read() 47 txt = temp_file.read()
45 temp_file.close() 48 temp_file.close()
49
46 self.xml_dom = self.xml.parseXml(txt) 50 self.xml_dom = self.xml.parseXml(txt)
47 51
48 if self.xml_dom is None: self.rebuildSettings() 52 if self.xml_dom is None: self.rebuildSettings()
49 self.xml_dom = self.xml_dom._get_documentElement() 53 self.xml_dom = self.xml_dom._get_documentElement()
50 54
51 def rebuildSettings(self): 55 def rebuildSettings(self):
52 self.log.log("Settings file has be corrupted, rebuilding settings.", ORPG_INFO, True) 56 self.orpgLog.log("Settings file has be corrupted, rebuilding settings.", ORPG_INFO, True)
53 try: os.remove(self.filename) 57 try: os.remove(self.filename)
54 except: pass 58 except: pass
55 59
56 self.validate.config_file("settings.xml","default_settings.xml") 60 self.validate.config_file("settings.xml","default_settings.xml")
57 temp_file = open(self.filename) 61 temp_file = open(self.filename)
139 def __init__(self, parent): 143 def __init__(self, parent):
140 wx.Dialog.__init__(self,parent,-1,"OpenRPG Preferences", 144 wx.Dialog.__init__(self,parent,-1,"OpenRPG Preferences",
141 wx.DefaultPosition,size = wx.Size(-1,-1), 145 wx.DefaultPosition,size = wx.Size(-1,-1),
142 style=wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION) 146 style=wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION)
143 self.Freeze() 147 self.Freeze()
144 self.validate = open_rpg.get_component("validate") 148 self.validate = component.get("validate")
145 self.settings = open_rpg.get_component("settings") 149 self.settings = component.get("settings")
146 self.chat = open_rpg.get_component("chat") 150 self.chat = component.get("chat")
147 self.changes = [] 151 self.changes = []
148 self.SetMinSize((545,500)) 152 self.SetMinSize((545,500))
149 self.tabber = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON) 153 self.tabber = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON)
150 self.build_gui() 154 self.build_gui()
151 self.tabber.SetSelection(0) 155 self.tabber.SetSelection(0)
167 (w,h) = self.GetClientSizeTuple() 171 (w,h) = self.GetClientSizeTuple()
168 self.winsizer.SetDimension(0,0,w,h-25) 172 self.winsizer.SetDimension(0,0,w,h-25)
169 173
170 def build_gui(self): 174 def build_gui(self):
171 self.validate.config_file("settings.xml","default_settings.xml") 175 self.validate.config_file("settings.xml","default_settings.xml")
172 filename = open_rpg.get_component("dir_struct")["user"] + "settings.xml" 176 filename = dir_struct["user"] + "settings.xml"
173 temp_file = open(filename) 177 temp_file = open(filename)
174 temp_file.close() 178 temp_file.close()
175 children = self.settings.xml_dom._get_childNodes() 179 children = self.settings.xml_dom._get_childNodes()
176 for c in children: self.build_window(c,self.tabber) 180 for c in children: self.build_window(c,self.tabber)
177 181
213 temp_wnd = settings_grid(parent_wnd, settings, self.changes) 217 temp_wnd = settings_grid(parent_wnd, settings, self.changes)
214 return temp_wnd 218 return temp_wnd
215 219
216 def onOk(self, evt): 220 def onOk(self, evt):
217 #This will write the settings back to the XML 221 #This will write the settings back to the XML
218 self.session = open_rpg.get_component("session") 222 self.session = component.get("session")
219 tabbedwindows = open_rpg.get_component("tabbedWindows") 223 tabbedwindows = component.get("tabbedWindows")
220 new = [] 224 new = []
221 for wnd in tabbedwindows: 225 for wnd in tabbedwindows:
222 try: 226 try:
223 style = wnd.GetWindowStyleFlag() 227 style = wnd.GetWindowStyleFlag()
224 new.append(wnd) 228 new.append(wnd)
225 except: pass 229 except: pass
226 tabbedwindows = new 230 tabbedwindows = new
227 open_rpg.add_component("tabbedWindows", tabbedwindows) 231 component.add("tabbedWindows", tabbedwindows)
228 rgbconvert = RGBHex() 232 rgbconvert = RGBHex()
229 233
230 for i in xrange(0,len(self.changes)): 234 for i in xrange(0,len(self.changes)):
231 self.settings.set_setting(self.changes[i][0], self.changes[i][1]) 235 self.settings.set_setting(self.changes[i][0], self.changes[i][1])
232 top_frame = open_rpg.get_component('frame') 236 top_frame = component.get('frame')
233 237
234 if self.changes[i][0] == 'defaultfontsize' or self.changes[i][0] == 'defaultfont': 238 if self.changes[i][0] == 'defaultfontsize' or self.changes[i][0] == 'defaultfont':
235 self.chat.chatwnd.SetDefaultFontAndSize(self.settings.get_setting('defaultfont'), 239 self.chat.chatwnd.SetDefaultFontAndSize(self.settings.get_setting('defaultfont'),
236 self.settings.get_setting('defaultfontsize')) 240 self.settings.get_setting('defaultfontsize'))
237 self.chat.InfoPost("Font is now " + 241 self.chat.InfoPost("Font is now " +
383 (w,h) = self.GetClientSizeTuple() 387 (w,h) = self.GetClientSizeTuple()
384 cols = self.GetNumberCols() 388 cols = self.GetNumberCols()
385 col_w = w/(cols) 389 col_w = w/(cols)
386 for i in range(0,cols): self.SetColSize(i,col_w) 390 for i in range(0,cols): self.SetColSize(i,col_w)
387 self.Refresh() 391 self.Refresh()
392
393 settings = orpgSettings()
394 component.add('settings', settings)