66from safe_eval import safe_eval
77from PyQt5 .QtWidgets import QTableWidgetItem
88from PyQt5 import QtCore , QtGui
9- from PyQt5 .QtWidgets import QShortcut
10- from PyQt5 .QtCore import Qt
9+ from PyQt5 .QtWidgets import QShortcut , QHeaderView
1110
1211class ui_Form (Ui_Form ):
1312 # barSetMineNum = QtCore.pyqtSignal(int)
1413 # barSetMineNumCalPoss = QtCore.pyqtSignal(int)
1514 # doubleClick = QtCore.pyqtSignal (int, int)
1615 # leftClick = QtCore.pyqtSignal (int, int)
17- def __init__ (self , r_path , pix_size ):
16+ def __init__ (self , r_path , pix_size , parent ):
1817 self .pix_size = pix_size
19- self .QWidget = RoundQWidget ()
18+ self .QWidget = RoundQWidget (parent )
2019 self .setupUi (self .QWidget )
2120
2221 self .tableWidget .setColumnWidth (0 , 80 )
23- self .tableWidget .setColumnWidth (1 , 120 )
24- self .tableWidget .verticalHeader ().setDefaultSectionSize (24 )
22+ self .tableWidget .setColumnWidth (1 , 150 )
23+ self .tableWidget .verticalHeader ().setDefaultSectionSize (25 )
24+ self .tableWidget .verticalHeader ().setSectionResizeMode (QHeaderView .Fixed )
2525
2626 self .QWidget .setWindowIcon (QtGui .QIcon (str (r_path .with_name ('media' ).joinpath ('cat.ico' ))))
2727
@@ -37,13 +37,11 @@ def reshow(self, index_name_list: list[str], index_value_list: list[str]):
3737 # 更新数值、指标。指标数量可能变
3838 table_height = len (index_name_list )* 24
3939 self .tableWidget .setRowCount (len (index_name_list ))
40- self .tableWidget .setMinimumWidth (202 )
41- self .tableWidget .setMaximumWidth (202 )
40+ # self.tableWidget.setMinimumWidth(232 )
41+ # self.tableWidget.setMaximumWidth(232 )
4242 self .tableWidget .setMaximumHeight (table_height + len (index_name_list ) + 2 )
4343 self .tableWidget .setMinimumHeight (table_height + len (index_name_list ) + 2 )
4444
45- # self.QWidget.setMinimumSize(QtCore.QSize(224+2, table_height + 88))
46- # self.QWidget.setMaximumSize(QtCore.QSize(224+2, table_height + 88))
4745 for idx , i in enumerate (index_name_list ):
4846 self .tableWidget .setItem (idx , 0 , QTableWidgetItem (i ))
4947 self .show (index_value_list )
@@ -79,7 +77,7 @@ class gameScoreBoardManager():
7977
8078 # is_visible = False
8179 # 5、错误的表达式,一旦算出报错,永远不再算,显示error
82- def __init__ (self , r_path , score_board_path , game_setting_path , pix_size ):
80+ def __init__ (self , r_path , score_board_path , game_setting_path , pix_size , parent ):
8381 # 从文件中读取指标并设置
8482 # self.ms_board = None
8583 self .pix_size = pix_size
@@ -121,7 +119,7 @@ def __init__(self, r_path, score_board_path, game_setting_path, pix_size):
121119 i in _score_board_items ]
122120 self .update_score_board_items_type ()
123121 self .index_num = len (self .score_board_items_type )
124- self .ui = ui_Form (r_path , pix_size )
122+ self .ui = ui_Form (r_path , pix_size , parent )
125123 self .ui .tableWidget .doubleClicked .connect (self .__table_change )
126124 self .ui .tableWidget .clicked .connect (self .__table_ok )
127125 self .ui .tableWidget .cellChanged .connect (self .__cell_changed )
@@ -131,12 +129,6 @@ def __init__(self, r_path, score_board_path, game_setting_path, pix_size):
131129 self .editing_row = - 1 # -1不在编辑状态,-2不能编辑(正在游戏)
132130 self .editing_column = - 1
133131
134- # self.ui.QWidget.closeEvent_.connect(self.close)
135-
136- # def keyPressEvent(self, event):
137- # print(666)
138- # if event.key() == Qt.Key_Return:
139- # self.__table_ok()
140132
141133 def update_score_board_items_type (self ):
142134 self .score_board_items_type = []
@@ -154,6 +146,9 @@ def with_namespace(self, namespace: dict):
154146 # 埋雷结束后调用,固化参数
155147 # self.pix_size = pix_size
156148 # self.board = board
149+ if "mode" in namespace :
150+ self ._game_mode_code : int = namespace ["mode" ]
151+ namespace ["mode" ] = mm .trans_game_mode (namespace ["mode" ])
157152 self .namespace .update (namespace )
158153 # race_designator, mode .etc
159154 # self.ms_board = ms.BaseVideo(board, pix_size)
@@ -251,7 +246,16 @@ def show(self, ms_board, index_type):
251246 # if self.ui.QWidget.isVisible():
252247 # self.visible()
253248
254- def reshow (self , ms_board , index_type ):
249+ def reshow (self , ms_board , index_type = 0 ):
250+ if not index_type :
251+ if self .ms_board .game_board_state == 1 \
252+ or self .ms_board .game_board_state == 2 \
253+ or self .ms_board .game_board_state == 5 :
254+ index_type = 1
255+ else :
256+ # 3、4为win和loss
257+ index_type = 2
258+
255259 # 指标数量有变。增删指标用。游戏开始前。index_type是2
256260 self .ms_board = ms_board
257261 index_value_list = self .cal_index_value (ms_board , index_type )
@@ -265,7 +269,16 @@ def time_step(self):
265269
266270
267271 self .show ()
268-
272+
273+ # 重写窗口的翻译方法。主要是模式的翻译问题
274+ def retranslateUi (self , Form ):
275+ self .ui .retranslateUi (Form )
276+ if hasattr (self , "ms_board" ):
277+ self .with_namespace ({
278+ "mode" : self ._game_mode_code ,
279+ })
280+ self .show (self .ms_board , index_type = 1 )
281+
269282 def __table_change (self , e ):
270283 # 编辑开始时,把数值换成公式
271284 if e .column () == 1 and self .editing_row == - 1 :
@@ -298,13 +311,7 @@ def __table_ok(self, e = None):
298311 else :
299312 self .score_board_items [self .editing_row ][1 ] = new_formula
300313 self .update_score_board_items_type ()
301- if self .ms_board .game_board_state == 1 \
302- or self .ms_board .game_board_state == 2 \
303- or self .ms_board .game_board_state == 5 :
304- self .reshow (self .ms_board , 1 )
305- else :
306- # 3、4为win和loss
307- self .reshow (self .ms_board , 2 )
314+ self .reshow (self .ms_board )
308315 self .editing_row = - 1
309316 self .editing_column = - 1
310317
@@ -319,7 +326,7 @@ def __add_blank_line(self):
319326 # 添加一个空开的行,并刷新显示
320327 self .score_board_items .append (["" , "" ])
321328 self .score_board_items_type .append (1 )
322- self .reshow (self .ms_board , 1 )
329+ self .reshow (self .ms_board )
323330
324331 def close (self ):
325332 config = configparser .ConfigParser ()
0 commit comments