Эх сурвалжийг харах

Fix Save/Load Config

Now asks for board to save for if multiple boards are connected
Patrick Schreiber 7 жил өмнө
parent
commit
dd9a11916c

+ 4 - 1
KCG/base/backend/board/boards_connected.py

@@ -67,7 +67,10 @@ class BoardsConnected(object):
             self._device_files = {int(i.replace(searchstring, '')): i for i in device_list}
 
         elif config.board_detection_method == 'dummy':
-            num = 5
+            if config.num_dummy_boards:
+                num = int(config.num_dummy_boards)
+            else:
+                num = 5
             self._board_ids = {i: get(config.device_names, 'test'+str(i)) for i in range(num)}
             self._device_files = {i: '/dev/fpga0' for i in self.board_ids}
 

+ 58 - 10
KCG/base/kcg.py

@@ -276,23 +276,63 @@ class Gui(QtGui.QMainWindow):
         self.help.addAction(tr("Button", "Open Manual"), lambda: webbrowser.open(config.install_path + "Documentation/build/html/index.html"))
         self.help.addAction(tr("Button", "About"), self.showAbout)
 
-    def saveConfig(self, board_id):
+    def _show_board_chooser(self):
+        selected_boards = []
+        if len(available_boards.board_ids) == 1:
+            return [available_boards.board_ids[0]]
+        chooser = QtGui.QDialog(self)
+        chooser.setWindowTitle("KCG - Choose Boards")
+
+        
+        chooser_layout = QtGui.QVBoxLayout()
+        chooser.setLayout(chooser_layout)
+        chooser_layout.addWidget(QtGui.QLabel("Choose Boards"))
+        boards = {}
+        for bid in available_boards.board_ids:
+            boards[bid] = QtGui.QCheckBox(str(bid), chooser)
+            chooser_layout.addWidget(boards[bid])
+        button = QtGui.QPushButton("OK", chooser)
+        def ok():
+            for bi, box in boards.items():
+                if box.isChecked():
+                    selected_boards.append(bi)
+            chooser.close()
+        button.clicked.connect(ok)
+        chooser_layout.addWidget(button)
+        chooser.exec_()
+        return selected_boards
+
+
+    def saveConfig(self, board_id=None):
         """
         Save the current configuration to a configuration file
         :param board_id: the board to save the configuration for
         """
+
         filenameDialog = QtGui.QFileDialog(self, tr("Heading", "Save Configuration"), '', 'KAPTURE Configuration File (*.kcf)')
         filenameDialog.setDefaultSuffix("kcf")
         filenameDialog.setAcceptMode(filenameDialog.AcceptSave)
         filenameDialog.exec_()
         filename = filenameDialog.selectedFiles()
-        if filename[0]:
-            if not board.get_board_config(board_id).save_config(filename[0]):
+        if not filename[0]:
+            return
+
+        if board_id is None:
+            board_id = self._show_board_chooser()
+        elif not isinstance(board_id, list):
+            board_id = [board_id]
+
+
+        fname = filename[0].split(".")
+        for bid in board_id:
+            if len(board_id) == 1:
+                fname_board = filename[0]
+            else:
+                fname_board = ".".join(map(str, fname[:-1]))+"_"+str(bid)+"."+fname[-1]
+            if not board.get_board_config(bid).save_config(fname_board):
                 QtGui.QMessageBox.critical(self, tr("Heading", "Error Saving Config"), tr("Dialog", "There was an error saving to a config file."))
-        else:
-            QtGui.QMessageBox.critical(self, tr("Heading", "Error Saving Config"), tr("Dialog", "There was an error saving to a config file."))
 
-    def loadConfig(self, board_id):
+    def loadConfig(self, board_id=None):
         """
         Load the configuration for the given board from a file
         :param board_id: the board to read the configuration for
@@ -300,10 +340,18 @@ class Gui(QtGui.QMainWindow):
         filename = QtGui.QFileDialog.getOpenFileName(self, 'Open Configuration', '', 'KAPTURE Configuration File (*.kcf)')
         if not filename:
             return
-        if board.get_board_config(board_id).load_config(filename):
-            bif.bk_write_values(board_id, defaults=False)
-        else:
-            QtGui.QMessageBox.critical(self, tr("Heading", "Error Loading Config"), tr("Dialog", "There was an error loading the config file, make sure it is valid and try again."))
+
+
+        if board_id is None:
+            board_id = self._show_board_chooser()
+        elif not isinstance(board_id, list):
+            board_id = [board_id]
+
+        for bid in board_id:
+            if board.get_board_config(bid).load_config(filename):
+                bif.bk_write_values(bid, defaults=False)
+            else:
+                QtGui.QMessageBox.critical(self, tr("Heading", "Error Loading Config"), tr("Dialog", "There was an error loading the config file, make sure it is valid and try again."))
 
     def rerunConfig(self):
         """

+ 2 - 0
KCG/config.cfg

@@ -119,3 +119,5 @@ device_list = []
 # format is: device_names = {'device id': 'device name', ...}
 # if this is an empty dict it won't be used
 device_names = {'test0': 'ich_bin_toll', 'test1': 'ne'}
+# num_dummy_boards is the number of dummy boards to create
+num_dummy_boards = 5

+ 2 - 1
KCG/config.py

@@ -138,7 +138,8 @@ class Configuration(object):
         Logging_conf = ["epics_test_pv", "epics_base_path", "epics_log_entry_pvs", "default_log_entries"]
         Misc_conf = ['newPlotLiveIcon', 'newPlotDataIcon', 'timingIcon', 'singleReadIcon',
                      'acquireSettingsIcon', 'startIcon', 'stopIcon', 'logIcon', 'logCommentIcon', 'guiIcon', 'style',
-                     'board_detection_method', 'device_list', 'device_names']
+                     'board_detection_method', 'device_list', 'device_names',
+                     'num_dummy_boards']
 
         try:
             machine_c = ConfSection('Machine', Machine_conf, config, log_level=self._log_level)