Coverage for GuiPrefs.py: 0%

72 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-28 16:41 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3 

4#Copyright 2008-2011 Carl Gherardi 

5#This program is free software: you can redistribute it and/or modify 

6#it under the terms of the GNU Affero General Public License as published by 

7#the Free Software Foundation, version 3 of the License. 

8# 

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. 

13# 

14#You should have received a copy of the GNU Affero General Public License 

15#along with this program. If not, see <http://www.gnu.org/licenses/>. 

16#In the "official" distribution you can find the license in agpl-3.0.txt. 

17 

18 

19 

20#import L10n 

21#_ = L10n.get_translation() 

22 

23import xml.dom.minidom 

24from xml.dom.minidom import Node 

25 

26from PyQt5.QtWidgets import (QDialog, QDialogButtonBox, QVBoxLayout, QTreeWidget, 

27 QTreeWidgetItem) 

28from PyQt5.QtCore import Qt 

29 

30#from pyfpdb import Configuration 

31import Configuration 

32 

33rewrite = { 'general' : ('General'), 'supported_databases' : ('Databases') 

34 , 'import' : ('Import'), 'hud_ui' : ('HUD') 

35 , 'supported_sites' : ('Sites'), 'supported_games' : ('Games') 

36 , 'popup_windows' : ('Popup Windows'), 'pu' : ('Window') 

37 , 'pu_name' : ('Popup Name'), 'pu_stat' : ('Stat') 

38 , 'pu_stat_name' : ('Stat Name') 

39 , 'aux_windows' : ('Auxiliary Windows'), 'aw stud_mucked' : ('Stud mucked') 

40 , 'aw mucked' : ('Mucked'), 'hhcs' : ('Hand History Converters') 

41 , 'gui_cash_stats' : ('Ring Player Stats'), 'field_type' : ('Field Type') 

42 , 'col_title' : ('Column Heading'), 'xalignment' : ('Left/Right Align') 

43 , 'disp_all' : ('Show in Summaries'), 'disp_posn' : ('Show in Position Stats') 

44 , 'col_name' : ('Stat Name'), 'field_format' : ('Format') 

45 , 'gui_tour_stats' : ('Tour Player Stats'), 

46 } 

47 

48class GuiPrefs(QDialog): 

49 

50 def __init__(self, config, parentwin): 

51 QDialog.__init__(self, parentwin) 

52 self.resize(600, 350) 

53 self.config = config 

54 self.setLayout(QVBoxLayout()) 

55 

56 

57 self.doc = self.config.get_doc() 

58 

59 self.configView = QTreeWidget() 

60 self.configView.setColumnCount(2) 

61 self.configView.setHeaderLabels([("Setting"), ("Value (double-click to change)")]) 

62 

63 if self.doc.documentElement.tagName == 'FreePokerToolsConfig': 

64 self.root = QTreeWidgetItem(["fpdb", None]) 

65 self.configView.addTopLevelItem(self.root) 

66 self.root.setExpanded(True) 

67 for elem in self.doc.documentElement.childNodes: 

68 self.addTreeRows(self.root, elem) 

69 self.layout().addWidget(self.configView) 

70 self.configView.resizeColumnToContents(0) 

71 

72 self.configView.itemChanged.connect(self.updateConf) 

73 btns = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Cancel, self) 

74 btns.accepted.connect(self.accept) 

75 btns.rejected.connect(self.reject) 

76 self.layout().addWidget(btns) 

77 

78 def updateConf(self, item, column): 

79 if column != 1: 

80 return 

81 item.data(1, Qt.UserRole).value = item.data(1, Qt.DisplayRole) 

82 

83 def rewriteText(self, s): 

84 upd = False 

85 if s in rewrite: 

86 s = rewrite[s] 

87 upd = True 

88 return( (s,upd) ) 

89 

90 def addTreeRows(self, parent, node): 

91 if (node.nodeType == node.ELEMENT_NODE): 

92 (setting, value) = (node.nodeName, None) 

93 elif (node.nodeType == node.TEXT_NODE): 

94 # text nodes hold the whitespace (or whatever) between the xml elements, not used here 

95 (setting, value) = ("TEXT: ["+node.nodeValue+"|"+node.nodeValue+"]", node.data) 

96 else: 

97 (setting, value) = ("?? "+node.nodeValue, "type="+str(node.nodeType)) 

98 

99 if node.nodeType != node.TEXT_NODE and node.nodeType != node.COMMENT_NODE: 

100 name = "" 

101 item = QTreeWidgetItem(parent, [setting, value]) 

102 if node.hasAttributes(): 

103 for i in range(node.attributes.length): 

104 localName,updated = self.rewriteText( node.attributes.item(i).localName ) 

105 attritem = QTreeWidgetItem(item, [localName, node.attributes.item(i).value]) 

106 attritem.setData(1, Qt.UserRole, node.attributes.item(i)) 

107 attritem.setFlags(attritem.flags() | Qt.ItemIsEditable) 

108 

109 if node.attributes.item(i).localName in ('site_name', 'game_name', 'stat_name', 'name', 'db_server', 'site', 'col_name'): 

110 name = " " + node.attributes.item(i).value 

111 

112 label,updated = self.rewriteText(setting+name) 

113 if name != "" or updated: 

114 item.setData(0, 0, label) 

115 

116 if node.hasChildNodes(): 

117 for elem in node.childNodes: 

118 self.addTreeRows(item, elem) 

119 

120if __name__=="__main__": 

121 Configuration.set_logfile("fpdb-log.txt") 

122 

123 config = Configuration.Config() 

124 

125 from PyQt5.QtWidgets import QApplication, QMainWindow 

126 app = QApplication([]) 

127 main_window = QMainWindow() 

128 main_window.show() 

129 prefs = GuiPrefs(config, main_window) 

130 prefs.exec_() 

131 app.exec_()