comparison orpg/tools/orpg_settings.py @ 90:d1aff41c031b alpha

Traipse Alpha 'OpenRPG' {090919-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: 00: Adds menu changes to draw attention to important updates, errors, or other events. (image info coming soon) Traipse URL is not included in the repos tab and is set as default. 01: Fixes Copy for Windows and Linux (finally!!) users. Fixes incomplete update to Grid and List nodes. Fixes incomplete update to Chat Commands. 02: Fixes problems with Remote Image Upload. Fixes Drop and Drag of Minis to Map. CherryPy can now use any image in the webfiles/ folder and sub-folders. CherryPy can now Drop and Drag Minis to the Map. 03: Minor changes to Update Manager's GUI. Expert recommendation warning added to Revision Update. Step down compatibility with open_rpg & component added to orpgCore. 19-00: Better backwards compatibility in orpgCore. Using majority of 'Grumpy' network folder to correct server lag.
author sirebral
date Sat, 19 Sep 2009 06:45:21 -0500
parents c54768cffbd4
children 37d26a98883f
comparison
equal deleted inserted replaced
89:b84e0799fed2 90:d1aff41c031b
31 from orpg.dirpath import dir_struct 31 from orpg.dirpath import dir_struct
32 from rgbhex import * 32 from rgbhex import *
33 import sys 33 import sys
34 import os 34 import os
35 from orpg.orpg_xml import xml 35 from orpg.orpg_xml import xml
36 from orpg.tools.orpg_log import logger
37 from orpg.tools.validate import validate
38 from orpg.orpg_xml import xml
36 39
37 class orpgSettings: 40 class orpgSettings:
38 def __init__(self): 41 def __init__(self):
39 self.validate = component.get("validate")
40 component.add('xml', xml)
41 self.xml = component.get("xml") 42 self.xml = component.get("xml")
42 self.orpgLog = component.get("log")
43 self.changes = [] 43 self.changes = []
44 self.validate.config_file("settings.xml","default_settings.xml") 44 validate.config_file("settings.xml","default_settings.xml")
45 self.filename = dir_struct["user"] + "settings.xml" 45 self.filename = dir_struct["user"] + "settings.xml"
46 temp_file = open(self.filename) 46 temp_file = open(self.filename)
47 txt = temp_file.read() 47 txt = temp_file.read()
48 temp_file.close() 48 temp_file.close()
49 49
50 self.xml_dom = self.xml.parseXml(txt) 50 self.xml_dom = xml.parseXml(txt)
51 51
52 if self.xml_dom is None: self.rebuildSettings() 52 if self.xml_dom is None: self.rebuildSettings()
53 self.xml_dom = self.xml_dom._get_documentElement() 53 self.xml_dom = self.xml_dom._get_documentElement()
54 54
55 def rebuildSettings(self): 55 def rebuildSettings(self):
56 self.orpgLog.log("Settings file has be corrupted, rebuilding settings.", ORPG_INFO, True) 56 logger.info("Settings file has be corrupted, rebuilding settings.", True)
57 try: os.remove(self.filename) 57 try: os.remove(self.filename)
58 except: pass 58 except: pass
59 59
60 self.validate.config_file("settings.xml","default_settings.xml") 60 validate.config_file("settings.xml","default_settings.xml")
61 temp_file = open(self.filename) 61 temp_file = open(self.filename)
62 txt = temp_file.read() 62 txt = temp_file.read()
63 temp_file.close() 63 temp_file.close()
64 self.xml_dom = self.xml.parseXml(txt) 64 self.xml_dom = xml.parseXml(txt)
65 65
66 def get_setting(self, name): 66 def get_setting(self, name): ##Depricated
67 return self.get(name)
68
69 def get(self, name):
67 try: return self.xml_dom.getElementsByTagName(name)[0].getAttribute("value") 70 try: return self.xml_dom.getElementsByTagName(name)[0].getAttribute("value")
68 except: return 0 71 except: return 0
69 72
70 def get_setting_keys(self): 73 def get_setting_keys(self): ##Depricated
74 return self.get_keys()
75
76 def get_keys(self):
71 keys = [] 77 keys = []
72 tabs = self.xml_dom.getElementsByTagName("tab") 78 tabs = self.xml_dom.getElementsByTagName("tab")
73 for i in xrange(0, len(tabs)): 79 for i in xrange(0, len(tabs)):
74 if tabs[i].getAttribute("type") == 'grid': 80 if tabs[i].getAttribute("type") == 'grid':
75 children = tabs[i]._get_childNodes() 81 children = tabs[i]._get_childNodes()
76 for c in children: keys.append(c._get_tagName()) 82 for c in children: keys.append(c._get_tagName())
77 return keys 83 return keys
78 84
79 def set_setting(self, name, value): 85 def set_setting(self, name, value): ##Depricated
86 self.change(name, value)
87
88 def change(self, name, value):
80 self.xml_dom.getElementsByTagName(name)[0].setAttribute("value", value) 89 self.xml_dom.getElementsByTagName(name)[0].setAttribute("value", value)
81 90
82 def add_setting(self, tab, setting, value, options, help): 91 def add_setting(self, tab, setting, value, options, help): ##Depricated
92 return self.add(tab, setting, value, options, help)
93
94 def add(self, tab, setting, value, options, help):
83 if len(self.xml_dom.getElementsByTagName(setting)) > 0: return False 95 if len(self.xml_dom.getElementsByTagName(setting)) > 0: return False
84 tabs = self.xml_dom.getElementsByTagName("tab") 96 tabs = self.xml_dom.getElementsByTagName("tab")
85 newsetting = self.xml.parseXml('<' + setting + ' value="' + value + '" options="' + 97 newsetting = xml.parseXml('<' + setting + ' value="' + value + '" options="' +
86 options + '" help="' + help + '" />')._get_documentElement() 98 options + '" help="' + help + '" />')._get_documentElement()
87 for i in xrange(0, len(tabs)): 99 for i in xrange(0, len(tabs)):
88 if tabs[i].getAttribute("name") == tab and tabs[i].getAttribute("type") == 'grid': 100 if tabs[i].getAttribute("name") == tab and tabs[i].getAttribute("type") == 'grid':
89 tabs[i].appendChild(newsetting) 101 tabs[i].appendChild(newsetting)
90 return True 102 return True
92 104
93 def add_tab(self, parent, tabname, tabtype): 105 def add_tab(self, parent, tabname, tabtype):
94 tab_xml = '<tab ' 106 tab_xml = '<tab '
95 if tabtype == 'text': tab_xml += 'name="' + tabname + '" type="text" />' 107 if tabtype == 'text': tab_xml += 'name="' + tabname + '" type="text" />'
96 else: tab_xml += 'name="' + tabname + '" type="' + tabtype + '"></tab>' 108 else: tab_xml += 'name="' + tabname + '" type="' + tabtype + '"></tab>'
97 newtab = self.xml.parseXml(tab_xml)._get_documentElement() 109 newtab = xml.parseXml(tab_xml)._get_documentElement()
98 if parent != None: 110 if parent != None:
99 tabs = self.xml_dom.getElementsByTagName("tab") 111 tabs = self.xml_dom.getElementsByTagName("tab")
100 for i in xrange(0, len(tabs)): 112 for i in xrange(0, len(tabs)):
101 if tabs[i].getAttribute("name") == parent and tabs[i].getAttribute("type") == 'tab': 113 if tabs[i].getAttribute("name") == parent and tabs[i].getAttribute("type") == 'tab':
102 children = tabs[i]._get_childNodes() 114 children = tabs[i]._get_childNodes()
115 def updateIni(self): 127 def updateIni(self):
116 defaultFile = orpg.dirpath.dir_struct['template'] + 'default_settings.xml' 128 defaultFile = orpg.dirpath.dir_struct['template'] + 'default_settings.xml'
117 temp_file = open(defaultFile) 129 temp_file = open(defaultFile)
118 txt = temp_file.read() 130 txt = temp_file.read()
119 temp_file.close() 131 temp_file.close()
120 default_dom = self.xml.parseXml(txt)._get_documentElement() 132 default_dom = xml.parseXml(txt)._get_documentElement()
121 for child in default_dom.getChildren(): 133 for child in default_dom.getChildren():
122 if child._get_tagName() == 'tab' and child.hasChildNodes(): self.proccessChildren(child) 134 if child._get_tagName() == 'tab' and child.hasChildNodes(): self.proccessChildren(child)
123 default_dom.unlink() 135 default_dom.unlink()
124 136
125 def proccessChildren(self, dom, parent=None): 137 def proccessChildren(self, dom, parent=None):
134 child.getAttribute("value"), child.getAttribute("options"), 146 child.getAttribute("value"), child.getAttribute("options"),
135 child.getAttribute("help")) 147 child.getAttribute("help"))
136 148
137 def save(self): 149 def save(self):
138 temp_file = open(self.filename, "w") 150 temp_file = open(self.filename, "w")
139 temp_file.write(self.xml.toxml(self.xml_dom,1)) 151 temp_file.write(xml.toxml(self.xml_dom,1))
140 temp_file.close() 152 temp_file.close()
141 153
142 class orpgSettingsWnd(wx.Dialog): 154 class orpgSettingsWnd(wx.Dialog):
143 def __init__(self, parent): 155 def __init__(self, parent):
144 wx.Dialog.__init__(self,parent,-1,"OpenRPG Preferences", 156 wx.Dialog.__init__(self,parent,-1,"OpenRPG Preferences",
145 wx.DefaultPosition,size = wx.Size(-1,-1), 157 wx.DefaultPosition,size = wx.Size(-1,-1),
146 style=wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION) 158 style=wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION)
147 self.Freeze() 159 self.Freeze()
148 self.validate = component.get("validate")
149 self.settings = component.get("settings") 160 self.settings = component.get("settings")
150 self.chat = component.get("chat") 161 self.chat = component.get("chat")
151 self.changes = [] 162 self.changes = []
152 self.SetMinSize((545,500)) 163 self.SetMinSize((545,500))
153 self.tabber = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON) 164 self.tabber = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON)
170 def on_size(self,evt): 181 def on_size(self,evt):
171 (w,h) = self.GetClientSizeTuple() 182 (w,h) = self.GetClientSizeTuple()
172 self.winsizer.SetDimension(0,0,w,h-25) 183 self.winsizer.SetDimension(0,0,w,h-25)
173 184
174 def build_gui(self): 185 def build_gui(self):
175 self.validate.config_file("settings.xml","default_settings.xml") 186 validate.config_file("settings.xml","default_settings.xml")
176 filename = dir_struct["user"] + "settings.xml" 187 filename = dir_struct["user"] + "settings.xml"
177 temp_file = open(filename) 188 temp_file = open(filename)
178 temp_file.close() 189 temp_file.close()
179 children = self.settings.xml_dom._get_childNodes() 190 children = self.settings.xml_dom._get_childNodes()
180 for c in children: self.build_window(c,self.tabber) 191 for c in children: self.build_window(c,self.tabber)