@@ -77,7 +77,7 @@ class gameScoreBoardManager():
7777
7878 # is_visible = False
7979 # 5、错误的表达式,一旦算出报错,永远不再算,显示error
80- def __init__ (self , r_path , score_board_path , game_setting_path , pix_size , parent ):
80+ def __init__ (self , r_path , score_board_setting , game_setting , pix_size , parent ):
8181 # 从文件中读取指标并设置
8282 # self.ms_board = None
8383 self .pix_size = pix_size
@@ -88,42 +88,42 @@ def __init__(self, r_path, score_board_path, game_setting_path, pix_size, parent
8888 self .delta_time = 0.0
8989
9090 self .initialized = False
91- self .game_setting_path = game_setting_path
92- self .score_board_path = score_board_path
93- config_score_board = configparser .ConfigParser ()
94- if config_score_board .read (self .score_board_path ):
95- # 计时器配置list[tuple(str, str)]
96- _score_board_items = config_score_board .items ('DEFAULT' )
97- else :
98- config_score_board ["DEFAULT" ] = {
99- "游戏模式" : "mode" ,
100- "RTime" : "f'{time:.3f}'" ,
101- "Est RTime" : "f'{etime:.3f}'" ,
102- "3BV" : "f'{bbbv_solved}/{bbbv}'" ,
103- "3BV/s" : "f'{bbbv_s:.3f}'" ,
104- "Ops" : "op" ,
105- "Isls" : "isl" ,
106- "Left" : "f'{left}@{left_s:.3f}'" ,
107- "Right" : "f'{right}@{right_s:.3f}'" ,
108- "Double" : "f'{double}@{double_s:.3f}'" ,
109- "STNB" : "f'{stnb:.3f}'" ,
110- "IOE" : "f'{ioe:.3f}'" ,
111- "Thrp" : "f'{thrp:.3f}'" ,
112- "Corr" : "f'{corr:.3f}'" ,
113- "Path" : "f'{path:.1f}'" ,
114- }
115- _score_board_items = list (config_score_board .items ('DEFAULT' ))
116- with open (self .score_board_path , 'w' ) as configfile :
117- config_score_board .write (configfile ) # 将对象写入文件
118- self .score_board_items = [[i [0 ], mm .trans_expression (i [1 ])] for \
119- i in _score_board_items ]
91+ self .game_setting = game_setting
92+ self .score_board_setting = score_board_setting
93+ # self.score_board_setting.beginGroup('DEFAULT')
94+ # _score_board_items = self.score_board_setting.allKeys()
95+ # config_score_board = configparser.ConfigParser()
96+ # if not _score_board_items:
97+ default_config = [
98+ ("游戏模式" , "mode" ),
99+ ("RTime" , "f'{time:.3f}'" ),
100+ ("Est RTime" , "f'{etime:.3f}'" ),
101+ ("3BV" , "f'{bbbv_solved}/{bbbv}'" ),
102+ ("3BV/s" , "f'{bbbv_s:.3f}'" ),
103+ ("Ops" , "op" ),
104+ ("Isls" , "isl" ),
105+ ("Left" , "f'{left}@{left_s:.3f}'" ),
106+ ("Right" , "f'{right}@{right_s:.3f}'" ),
107+ ("Double" , "f'{double}@{double_s:.3f}'" ),
108+ ("STNB" , "f'{stnb:.3f}'" ),
109+ ("IOE" , "f'{ioe:.3f}'" ),
110+ ("Thrp" , "f'{thrp:.3f}'" ),
111+ ("Corr" , "f'{corr:.3f}'" ),
112+ ("Path" , "f'{path:.1f}'" ),
113+ ("Pluck" , "f'{pluck:.3f}'" ),
114+ ]
115+ self .score_board_items = self .score_board_setting .get_or_set_section ("DEFAULT" , default_config )
116+
117+ self .score_board_setting .sync ()
118+
120119 self .update_score_board_items_type ()
121120 self .index_num = len (self .score_board_items_type )
122121 self .ui = ui_Form (r_path , pix_size , parent )
123122 self .ui .tableWidget .doubleClicked .connect (self .__table_change )
124123 self .ui .tableWidget .clicked .connect (self .__table_ok )
125- self .ui .tableWidget .cellChanged .connect (self .__cell_changed )
124+ # self.ui.tableWidget.cellChanged.connect(self.__cell_changed)
126125 self .ui .pushButton_add .clicked .connect (self .__add_blank_line )
126+ self .ui .QWidget .closeEvent_ .connect (self .close )
127127 QShortcut (QtGui .QKeySequence (QtCore .Qt .Key_Return ), self .ui .QWidget ).\
128128 activated .connect (self .__table_ok )
129129 self .editing_row = - 1 # -1不在编辑状态,-2不能编辑(正在游戏)
@@ -213,7 +213,7 @@ def update_namespace(self, ms_board, index_type):
213213 "flag" : ms_board .flag ,
214214 "flag_s" : ms_board .flag_s ,
215215 })
216- if index_type = = 2 :
216+ if index_type > = 2 :
217217 self .namespace .update ({
218218 "rtime" : ms_board .rtime ,
219219 "etime" : ms_board .etime ,
@@ -228,6 +228,9 @@ def update_namespace(self, ms_board, index_type):
228228 "corr" : ms_board .corr ,
229229 "ce" : ms_board .ce ,
230230 "ce_s" : ms_board .ce_s ,
231+ })
232+ if index_type >= 3 :
233+ self .namespace .update ({
231234 "pluck" : ms_board .pluck ,
232235 })
233236
@@ -300,28 +303,31 @@ def __table_ok(self, e = None):
300303 if e == None or (self .editing_row >= 0 and self .editing_column >= 0 and (self .editing_row != e .row () or \
301304 self .editing_column != e .column ())):
302305 # 编辑完成后修改指标值
303- self .ui .tableWidget .setDisabled (True )
304- self .ui .tableWidget .setDisabled (False )
306+ # self.ui.tableWidget.setDisabled(True)
307+ # self.ui.tableWidget.setDisabled(False)
305308 new_formula = self .ui .tableWidget .item (self .editing_row , self .editing_column ).text ()
306309 if self .editing_column == 0 :
307310 if not new_formula :
311+ # 删除键名后并完成编辑后,删除此指标
308312 self .score_board_items .pop (self .editing_row )
309313 self .score_board_items_type .pop (self .editing_row )
310314 else :
311- self .score_board_items [self .editing_row ][0 ] = new_formula
315+ # 正常修改键名
316+ self .score_board_items [self .editing_row ] = (new_formula , self .score_board_items [self .editing_row ][1 ])
312317 else :
313- self .score_board_items [self .editing_row ][1 ] = new_formula
318+ # 正常修改公式
319+ self .score_board_items [self .editing_row ] = (self .score_board_items [self .editing_row ][0 ], new_formula )
314320 self .update_score_board_items_type ()
315321 self .reshow (self .ms_board )
316322 self .editing_row = - 1
317323 self .editing_column = - 1
318324
319- def __cell_changed (self , x , y ):
320- # 把计数器里的公式改成新设置的公式
321- if y == 0 :
322- t = self .ui .tableWidget .item (x , y ).text ()
323- if self .score_board_items [x ][0 ] != t :
324- self .score_board_items [x ][0 ] = self .ui .tableWidget .item (x , 0 ).text ()
325+ # def __cell_changed(self, x, y):
326+ # # 把计数器里的公式改成新设置的公式
327+ # if y == 0:
328+ # t = self.ui.tableWidget.item(x, y).text()
329+ # if self.score_board_items[x][0] != t:
330+ # self.score_board_items[x][0] = self.ui.tableWidget.item(x, 0).text()
325331
326332 def __add_blank_line (self ):
327333 # 添加一个空开的行,并刷新显示
@@ -330,15 +336,17 @@ def __add_blank_line(self):
330336 self .reshow (self .ms_board )
331337
332338 def close (self ):
333- config = configparser .ConfigParser ()
334- config ["DEFAULT" ] = dict (filter (lambda x : x [0 ], self .score_board_items ))
335- config .write (open (self .score_board_path , "w" ))
336- conf = configparser .ConfigParser ()
337- conf .read (self .game_setting_path , encoding = 'utf-8' )
338- conf .set ("DEFAULT" , "scoreBoardTop" , str (self .ui .QWidget .x ()))
339- conf .set ("DEFAULT" , "scoreBoardLeft" , str (self .ui .QWidget .y ()))
340- conf .write (open (self .game_setting_path , "w" , encoding = 'utf-8' ))
341- self .ui .QWidget .close ()
339+ self .score_board_setting .set_section ("DEFAULT" , self .score_board_items )
340+ self .score_board_setting .sync ()
341+ # config = configparser.ConfigParser()
342+ # config["DEFAULT"] = dict(filter(lambda x: x[0], self.score_board_items))
343+ # config.write(open(self.score_board_path, "w"))
344+ # conf = configparser.ConfigParser()
345+ # conf.read(self.game_setting_path, encoding='utf-8')
346+ # conf.set("DEFAULT", "scoreBoardTop", str(self.ui.QWidget.x()))
347+ # conf.set("DEFAULT", "scoreBoardLeft", str(self.ui.QWidget.y()))
348+ # conf.write(open(self.game_setting_path, "w", encoding='utf-8'))
349+ # self.ui.QWidget.close()
342350
343351
344352
0 commit comments