From c23a1388fc5240377815c64a16a7803a385c5e9f Mon Sep 17 00:00:00 2001 From: steffen123 Date: Sat, 17 Jul 2010 00:23:48 +0200 Subject: [PATCH] GUI: HUD configurator fully working, dont even need to restart fpdb --- pyfpdb/Configuration.py | 51 +++++++++++++++++++++++++++++++++++++++++ pyfpdb/fpdb.pyw | 25 ++++++++++++-------- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 7af32d03..faeb5e23 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -655,6 +655,14 @@ class Config: if site_node.getAttribute("site_name") == site: return site_node + def getGameNode(self,gameName): + """returns DOM game node for a given game""" + for gameNode in self.doc.getElementsByTagName("game"): + #print "getGameNode gameNode:",gameNode + if gameNode.getAttribute("game_name") == gameName: + return gameNode + #end def getGameNode + def get_aux_node(self, aux): for aux_node in self.doc.getElementsByTagName("aw"): if aux_node.getAttribute("name") == aux: @@ -734,6 +742,49 @@ class Config: location_node.setAttribute("y", str( locations[i-1][1] )) self.supported_sites[site_name].layout[max].location[i] = ( locations[i-1][0], locations[i-1][1] ) + def editStats(self, gameName, statArray): + """replaces stat selection for the given gameName with the given statArray""" + gameNode = self.getGameNode(gameName) + statNodes = gameNode.getElementsByTagName("stat") + + for node in statNodes: + gameNode.removeChild(node) + + gameNode.setAttribute("rows", str(len(statArray))) + gameNode.setAttribute("cols", str(len(statArray[0]))) + + for rowNumber in range(len(statArray)): + for columnNumber in range(len(statArray[rowNumber])): + newStat=self.doc.createElement("stat") + + newAttrStatName=self.doc.createAttribute("stat_name") + newStat.setAttributeNode(newAttrStatName) + newStat.setAttribute("stat_name", statArray[rowNumber][columnNumber]) + + newAttrStatName=self.doc.createAttribute("row") + newStat.setAttributeNode(newAttrStatName) + newStat.setAttribute("row", str(rowNumber)) + + newAttrStatName=self.doc.createAttribute("col") + newStat.setAttributeNode(newAttrStatName) + newStat.setAttribute("col", str(columnNumber)) + + newAttrStatName=self.doc.createAttribute("click") + newStat.setAttributeNode(newAttrStatName) + newStat.setAttribute("click", "tog_decorate") + + newAttrStatName=self.doc.createAttribute("popup") + newStat.setAttributeNode(newAttrStatName) + newStat.setAttribute("popup", "default") + + newAttrStatName=self.doc.createAttribute("tip") + newStat.setAttributeNode(newAttrStatName) + newStat.setAttribute("tip", "tip1") + + gameNode.appendChild(newStat) + statNodes = gameNode.getElementsByTagName("stat") + #end def editStats + def edit_aux_layout(self, aux_name, max, width = None, height = None, locations = None): aux_node = self.get_aux_node(aux_name) layout_node = self.get_layout_node(aux_node, max) diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index 69e64924..d2f06f35 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -339,6 +339,7 @@ class fpdb: #end def dia_database_stats def diaHudConfigurator(self, widget, data=None): + """Opens dialog to set parameters (game category, row count, column count for HUD stat configurator""" self.hudConfiguratorRows=None self.hudConfiguratorColumns=None self.hudConfiguratorGame=None @@ -353,8 +354,6 @@ class fpdb: diaSelections.vbox.add(label) label.show() - #combo=gtk.ComboBox() - comboGame = gtk.combo_box_new_text() comboGame.connect("changed", self.hudConfiguratorComboSelection) diaSelections.vbox.add(comboGame) @@ -384,11 +383,12 @@ class fpdb: diaSelections.destroy() if response == gtk.RESPONSE_ACCEPT and self.hudConfiguratorRows!=None and self.hudConfiguratorColumns!=None and self.hudConfiguratorGame!=None: - print "clicked ok and selected:", self.hudConfiguratorGame,"with", str(self.hudConfiguratorRows), "rows and", str(self.hudConfiguratorColumns), "columns" + #print "clicked ok and selected:", self.hudConfiguratorGame,"with", str(self.hudConfiguratorRows), "rows and", str(self.hudConfiguratorColumns), "columns" self.diaHudConfiguratorTable() #end def diaHudConfigurator def hudConfiguratorComboSelection(self, widget): + #TODO: remove this and handle it directly in diaHudConfigurator result=widget.get_active_text() if result.endswith(" rows"): self.hudConfiguratorRows=int(result[0]) @@ -399,6 +399,8 @@ class fpdb: #end def hudConfiguratorComboSelection def diaHudConfiguratorTable(self): + """shows dialogue with Table of ComboBoxes to allow choosing of HUD stats""" + #TODO: add notices to hud configurator: no duplicates, no empties, display options #TODO: show explanation of what each stat means diaHudTable = gtk.Dialog("HUD Configurator - please choose your stats", self.window, @@ -421,11 +423,9 @@ class fpdb: "player", "c", "db_connection", "do_stat", "do_tip", "stat_dict", "h", "re", "re_Percent", "re_Places", ): continue statDict[attr]=eval("Stats.%s.__doc__" % (attr)) - #print "statDict:",statDict for rowNumber in range(self.hudConfiguratorRows+1): newRow=[] - for columnNumber in range(self.hudConfiguratorColumns+1): if rowNumber==0: if columnNumber==0: @@ -449,7 +449,8 @@ class fpdb: table.attach(child=comboBox, left_attach=columnNumber, right_attach=columnNumber+1, top_attach=rowNumber, bottom_attach=rowNumber+1) comboBox.show() - self.hudConfiguratorTableContents.append(newRow) + if rowNumber!=0: + self.hudConfiguratorTableContents.append(newRow) diaHudTable.vbox.add(table) table.show() @@ -461,12 +462,18 @@ class fpdb: #end def diaHudConfiguratorTable def storeNewHudStatConfig(self): - print "start of storeNewHudStatConfig" + """stores selections made in diaHudConfiguratorTable""" self.obtain_global_lock("diaHudConfiguratorTable") + statTable=[] for row in self.hudConfiguratorTableContents: + newRow=[] for column in row: - print column.get_active_text() - + newField = column.get_active_text() + newRow.append(newField) + statTable.append(newRow) + + self.config.editStats(self.hudConfiguratorGame,statTable) + self.config.save() #TODO: make it not store in horrible formatting self.release_global_lock() #end def storeNewHudStatConfig