Coverage for GuiPrefs.py: 0%

70 statements  

« prev     ^ index     » next       coverage.py v7.6.3, created at 2024-10-15 19:33 +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# import L10n 

20# _ = L10n.get_translation() 

21 

22 

23from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QTreeWidget, QTreeWidgetItem 

24from PyQt5.QtCore import Qt 

25 

26# from pyfpdb import Configuration 

27import Configuration 

28 

29rewrite = { 

30 "general": ("General"), 

31 "supported_databases": ("Databases"), 

32 "import": ("Import"), 

33 "hud_ui": ("HUD"), 

34 "supported_sites": ("Sites"), 

35 "supported_games": ("Games"), 

36 "popup_windows": ("Popup Windows"), 

37 "pu": ("Window"), 

38 "pu_name": ("Popup Name"), 

39 "pu_stat": ("Stat"), 

40 "pu_stat_name": ("Stat Name"), 

41 "aux_windows": ("Auxiliary Windows"), 

42 "aw stud_mucked": ("Stud mucked"), 

43 "aw mucked": ("Mucked"), 

44 "hhcs": ("Hand History Converters"), 

45 "gui_cash_stats": ("Ring Player Stats"), 

46 "field_type": ("Field Type"), 

47 "col_title": ("Column Heading"), 

48 "xalignment": ("Left/Right Align"), 

49 "disp_all": ("Show in Summaries"), 

50 "disp_posn": ("Show in Position Stats"), 

51 "col_name": ("Stat Name"), 

52 "field_format": ("Format"), 

53 "gui_tour_stats": ("Tour Player Stats"), 

54} 

55 

56 

57class GuiPrefs(QDialog): 

58 def __init__(self, config, parentwin): 

59 QDialog.__init__(self, parentwin) 

60 self.resize(600, 350) 

61 self.config = config 

62 self.setLayout(QVBoxLayout()) 

63 

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

65 

66 self.configView = QTreeWidget() 

67 self.configView.setColumnCount(2) 

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

69 

70 if self.doc.documentElement.tagName == "FreePokerToolsConfig": 

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

72 self.configView.addTopLevelItem(self.root) 

73 self.root.setExpanded(True) 

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

75 self.addTreeRows(self.root, elem) 

76 self.layout().addWidget(self.configView) 

77 self.configView.resizeColumnToContents(0) 

78 

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

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

81 btns.accepted.connect(self.accept) 

82 btns.rejected.connect(self.reject) 

83 self.layout().addWidget(btns) 

84 

85 def updateConf(self, item, column): 

86 if column != 1: 

87 return 

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

89 

90 def rewriteText(self, s): 

91 upd = False 

92 if s in rewrite: 

93 s = rewrite[s] 

94 upd = True 

95 return (s, upd) 

96 

97 def addTreeRows(self, parent, node): 

98 if node.nodeType == node.ELEMENT_NODE: 

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

100 elif node.nodeType == node.TEXT_NODE: 

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

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

103 else: 

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

105 

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

107 name = "" 

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

109 if node.hasAttributes(): 

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

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

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

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

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

115 

116 if node.attributes.item(i).localName in ( 

117 "site_name", 

118 "game_name", 

119 "stat_name", 

120 "name", 

121 "db_server", 

122 "site", 

123 "col_name", 

124 ): 

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

126 

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

128 if name != "" or updated: 

129 item.setData(0, 0, label) 

130 

131 if node.hasChildNodes(): 

132 for elem in node.childNodes: 

133 self.addTreeRows(item, elem) 

134 

135 

136if __name__ == "__main__": 

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

138 

139 config = Configuration.Config() 

140 

141 from PyQt5.QtWidgets import QApplication, QMainWindow 

142 

143 app = QApplication([]) 

144 main_window = QMainWindow() 

145 main_window.show() 

146 prefs = GuiPrefs(config, main_window) 

147 prefs.exec_() 

148 app.exec_()