Skip to content

Commit e27b837

Browse files
committed
设置属性修改
1 parent 8eee3ce commit e27b837

File tree

3 files changed

+165
-159
lines changed

3 files changed

+165
-159
lines changed

src/gameSettingShortcuts.py

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# 减少ui文件生成的原始的.py的改动
88

99
class myGameSettingShortcuts(Ui_Form):
10-
def __init__(self, game_setting_path, ico_path, r_path, parent):
11-
self.game_setting_path = game_setting_path
10+
def __init__(self, game_setting, ico_path, r_path, parent):
11+
self.game_setting = game_setting
1212
self.r_path = r_path
1313
self.Dialog = RoundQDialog(parent)
1414
self.setupUi(self.Dialog)
@@ -19,35 +19,32 @@ def __init__(self, game_setting_path, ico_path, r_path, parent):
1919
self.alter = False
2020

2121
def setParameter(self):
22-
config = configparser.ConfigParser()
23-
config.read(self.game_setting_path, encoding='utf-8')
24-
2522
# modTable = [0,1,4,2,3,5,6,7]
2623
modTable = [0,0,0,0,1,4,2,3,5,6,7]
27-
self.comboBox_gamemode4.setCurrentIndex(modTable[config.getint('CUSTOM_PRESET_4','gameMode')])
28-
self.spinBox_height4.setProperty("value", config.getint('CUSTOM_PRESET_4','row'))
29-
self.spinBox_width4.setProperty("value", config.getint('CUSTOM_PRESET_4','column'))
30-
self.spinBox_pixsize4.setProperty("value", config.getint('CUSTOM_PRESET_4','pixSize'))
31-
self.spinBox_attempt_times_limit4.setProperty("value", config.getint('CUSTOM_PRESET_4','attempt_times_limit'))
32-
self.spinBox_minenum4.setProperty("value", config.getint('CUSTOM_PRESET_4','mineNum'))
33-
self.lineEdit_constraint4.setProperty("value", config["CUSTOM_PRESET_4"]["board_constraint"])
34-
35-
self.comboBox_gamemode5.setCurrentIndex(modTable[config.getint('CUSTOM_PRESET_5','gameMode')])
36-
self.spinBox_height5.setProperty("value", config.getint('CUSTOM_PRESET_5','row'))
37-
self.spinBox_width5.setProperty("value", config.getint('CUSTOM_PRESET_5','column'))
38-
self.spinBox_pixsize5.setProperty("value", config.getint('CUSTOM_PRESET_5','pixSize'))
39-
self.spinBox_attempt_times_limit5.setProperty("value", config.getint('CUSTOM_PRESET_5','attempt_times_limit'))
40-
self.spinBox_minenum5.setProperty("value", config.getint('CUSTOM_PRESET_5','mineNum'))
41-
self.lineEdit_constraint5.setProperty("value", config["CUSTOM_PRESET_5"]["board_constraint"])
42-
43-
self.comboBox_gamemode6.setCurrentIndex(modTable[config.getint('CUSTOM_PRESET_6','gameMode')])
44-
self.spinBox_height6.setProperty("value", config.getint('CUSTOM_PRESET_6','row'))
45-
self.spinBox_width6.setProperty("value", config.getint('CUSTOM_PRESET_6','column'))
46-
self.spinBox_pixsize6.setProperty("value", config.getint('CUSTOM_PRESET_6','pixSize'))
47-
self.spinBox_attempt_times_limit6.setProperty("value", config.getint('CUSTOM_PRESET_6','attempt_times_limit'))
48-
self.spinBox_minenum6.setProperty("value", config.getint('CUSTOM_PRESET_6','mineNum'))
49-
self.lineEdit_constraint6.setProperty("value", config["CUSTOM_PRESET_6"]["board_constraint"])
50-
24+
self.comboBox_gamemode4.setCurrentIndex(modTable[self.game_setting.value("CUSTOM_PRESET_4/gamemode", None, int)])
25+
self.spinBox_height4.setProperty("value", self.game_setting.value("CUSTOM_PRESET_4/row", None, int))
26+
self.spinBox_width4.setProperty("value", self.game_setting.value("CUSTOM_PRESET_4/column", None, int))
27+
self.spinBox_pixsize4.setProperty("value", self.game_setting.value("CUSTOM_PRESET_4/pixsize", None, int))
28+
self.spinBox_attempt_times_limit4.setProperty("value", self.game_setting.value("CUSTOM_PRESET_4/attempt_times_limit", None, int))
29+
self.spinBox_minenum4.setProperty("value", self.game_setting.value("CUSTOM_PRESET_4/mine_num", None, int))
30+
self.lineEdit_constraint4.setProperty("value", self.game_setting.value("CUSTOM_PRESET_4/board_constraint", None, str))
31+
32+
self.comboBox_gamemode5.setCurrentIndex(modTable[self.game_setting.value("CUSTOM_PRESET_5/gamemode", None, int)])
33+
self.spinBox_height5.setProperty("value", self.game_setting.value("CUSTOM_PRESET_5/row", None, int))
34+
self.spinBox_width5.setProperty("value", self.game_setting.value("CUSTOM_PRESET_5/column", None, int))
35+
self.spinBox_pixsize5.setProperty("value", self.game_setting.value("CUSTOM_PRESET_5/pixsize", None, int))
36+
self.spinBox_attempt_times_limit5.setProperty("value", self.game_setting.value("CUSTOM_PRESET_5/attempt_times_limit", None, int))
37+
self.spinBox_minenum5.setProperty("value", self.game_setting.value("CUSTOM_PRESET_5/mine_num", None, int))
38+
self.lineEdit_constraint5.setProperty("value", self.game_setting.value("CUSTOM_PRESET_5/board_constraint", None, str))
39+
40+
self.comboBox_gamemode6.setCurrentIndex(modTable[self.game_setting.value("CUSTOM_PRESET_6/gamemode", None, int)])
41+
self.spinBox_height6.setProperty("value", self.game_setting.value("CUSTOM_PRESET_6/row", None, int))
42+
self.spinBox_width6.setProperty("value", self.game_setting.value("CUSTOM_PRESET_6/column", None, int))
43+
self.spinBox_pixsize6.setProperty("value", self.game_setting.value("CUSTOM_PRESET_6/pixsize", None, int))
44+
self.spinBox_attempt_times_limit6.setProperty("value", self.game_setting.value("CUSTOM_PRESET_6/attempt_times_limit", None, int))
45+
self.spinBox_minenum6.setProperty("value", self.game_setting.value("CUSTOM_PRESET_6/mine_num", None, int))
46+
self.lineEdit_constraint6.setProperty("value", self.game_setting.value("CUSTOM_PRESET_6/board_constraint", None, str))
47+
5148
self.pushButton.setStyleSheet("border-image: url(" + str(self.r_path.with_name('media').joinpath('button.png')).replace("\\", "/") + ");\n"
5249
"font: 16pt \"黑体\";\n"
5350
"color:white;font: bold;")
@@ -61,32 +58,29 @@ def processParameter(self):
6158

6259
# modTable = [0,1,3,4,2,5,6,7]
6360
modTable = [0,4,6,7,5,8,9,10]
64-
conf = configparser.ConfigParser()
65-
conf.read(self.game_setting_path, encoding='utf-8')
66-
conf.set("CUSTOM_PRESET_4", "gameMode", str(modTable[self.comboBox_gamemode4.currentIndex()]))
67-
conf.set("CUSTOM_PRESET_4", "row", str(self.spinBox_height4.value()))
68-
conf.set("CUSTOM_PRESET_4", "column", str(self.spinBox_width4.value()))
69-
conf.set("CUSTOM_PRESET_4", "pixSize", str(self.spinBox_pixsize4.value()))
70-
conf.set("CUSTOM_PRESET_4", "attempt_times_limit", str(self.spinBox_attempt_times_limit4.value()))
71-
conf.set("CUSTOM_PRESET_4", "mineNum", str(self.spinBox_minenum4.value()))
72-
conf.set("CUSTOM_PRESET_4", "board_constraint", self.lineEdit_constraint4.text())
73-
74-
conf.set("CUSTOM_PRESET_5", "gameMode", str(modTable[self.comboBox_gamemode5.currentIndex()]))
75-
conf.set("CUSTOM_PRESET_5", "row", str(self.spinBox_height5.value()))
76-
conf.set("CUSTOM_PRESET_5", "column", str(self.spinBox_width5.value()))
77-
conf.set("CUSTOM_PRESET_5", "pixSize", str(self.spinBox_pixsize5.value()))
78-
conf.set("CUSTOM_PRESET_5", "attempt_times_limit", str(self.spinBox_attempt_times_limit5.value()))
79-
conf.set("CUSTOM_PRESET_5", "mineNum", str(self.spinBox_minenum5.value()))
80-
conf.set("CUSTOM_PRESET_5", "board_constraint", self.lineEdit_constraint5.text())
81-
82-
conf.set("CUSTOM_PRESET_6", "gameMode", str(modTable[self.comboBox_gamemode6.currentIndex()]))
83-
conf.set("CUSTOM_PRESET_6", "row", str(self.spinBox_height6.value()))
84-
conf.set("CUSTOM_PRESET_6", "column", str(self.spinBox_width6.value()))
85-
conf.set("CUSTOM_PRESET_6", "pixSize", str(self.spinBox_pixsize6.value()))
86-
conf.set("CUSTOM_PRESET_6", "attempt_times_limit", str(self.spinBox_attempt_times_limit6.value()))
87-
conf.set("CUSTOM_PRESET_6", "mineNum", str(self.spinBox_minenum6.value()))
88-
conf.set("CUSTOM_PRESET_6", "board_constraint", self.lineEdit_constraint6.text())
89-
conf.write(open(self.game_setting_path, "w", encoding='utf-8'))
61+
self.game_setting.set_value("CUSTOM_PRESET_4/gamemode", modTable[self.comboBox_gamemode4.currentIndex()])
62+
self.game_setting.set_value("CUSTOM_PRESET_4/board_constraint", self.lineEdit_constraint4.text())
63+
self.game_setting.set_value("CUSTOM_PRESET_4/attempt_times_limit", self.spinBox_attempt_times_limit4.value())
64+
self.game_setting.set_value("CUSTOM_PRESET_4/pixsize", self.spinBox_pixsize4.value())
65+
self.game_setting.set_value("CUSTOM_PRESET_4/row", self.spinBox_height4.value())
66+
self.game_setting.set_value("CUSTOM_PRESET_4/column", self.spinBox_width4.value())
67+
self.game_setting.set_value("CUSTOM_PRESET_4/mine_num", self.spinBox_minenum4.value())
68+
69+
self.game_setting.set_value("CUSTOM_PRESET_5/gamemode", modTable[self.comboBox_gamemode5.currentIndex()])
70+
self.game_setting.set_value("CUSTOM_PRESET_5/board_constraint", self.lineEdit_constraint5.text())
71+
self.game_setting.set_value("CUSTOM_PRESET_5/attempt_times_limit", self.spinBox_attempt_times_limit5.value())
72+
self.game_setting.set_value("CUSTOM_PRESET_5/pixsize", self.spinBox_pixsize5.value())
73+
self.game_setting.set_value("CUSTOM_PRESET_5/row", self.spinBox_height5.value())
74+
self.game_setting.set_value("CUSTOM_PRESET_5/column", self.spinBox_width5.value())
75+
self.game_setting.set_value("CUSTOM_PRESET_5/mine_num", self.spinBox_minenum5.value())
76+
77+
self.game_setting.set_value("CUSTOM_PRESET_6/gamemode", modTable[self.comboBox_gamemode6.currentIndex()])
78+
self.game_setting.set_value("CUSTOM_PRESET_6/board_constraint", self.lineEdit_constraint6.text())
79+
self.game_setting.set_value("CUSTOM_PRESET_6/attempt_times_limit", self.spinBox_attempt_times_limit6.value())
80+
self.game_setting.set_value("CUSTOM_PRESET_6/pixsize", self.spinBox_pixsize6.value())
81+
self.game_setting.set_value("CUSTOM_PRESET_6/row", self.spinBox_height6.value())
82+
self.game_setting.set_value("CUSTOM_PRESET_6/column", self.spinBox_width6.value())
83+
self.game_setting.set_value("CUSTOM_PRESET_6/mine_num", self.spinBox_minenum6.value())
9084

9185
self.Dialog.close ()
9286

0 commit comments

Comments
 (0)