kcg.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. from PyQt4 import QtGui, QtCore
  2. import os
  3. import logging
  4. # --------[ Backend ]---------
  5. import backendinterface as bif
  6. # --------[ Essentials ]---------
  7. import storage
  8. from settings import Settings
  9. # --------[ Necessary Widgets ]------
  10. import kcgwidget as kcgw
  11. from controlwidget import ControlWidget
  12. from multiWidget import MultiWidget
  13. from groupedelements import MenuItems, Elements
  14. from backend.board import available_boards
  15. from backend import board
  16. from multipage import MultiPage
  17. from globals import glob as global_objects
  18. import bitsTable as bt
  19. import log
  20. from ..widgets import initialconfig
  21. # ---------[ Widgets IMPORTANT!!! ]------------------
  22. # this enables widgets. If this is not imported (even though it is not directly used) no widgets will be available
  23. from ..widgets import *
  24. # from widgets import * # copy in case the above line gets removed by ide
  25. # ---------[ IMPORTANT ]---------------------
  26. tr = kcgw.tr
  27. from .. import config
  28. import time
  29. import getpass
  30. def readconfig(parent):
  31. """
  32. Reads the config and evalues certain variables
  33. Also: Validates config to check if all necessary values are there
  34. :param parent: parent for popup windows
  35. :return: -
  36. """
  37. nec_conf = ['acquireSettingsIcon', 'bunches_per_turn', 'default_log_entries', 'default_save_location', 'default_subdirectory_name',
  38. 'epics_base_path', 'epics_log_entry_pvs', 'epics_test_pv', 'force_ask', 'guiIcon', 'language', 'logCommentIcon',
  39. 'logIcon', 'newPlotDataIcon', 'newPlotLiveIcon', 'save_header', 'show_advanced_control', 'singleReadIcon', 'startIcon',
  40. 'stopIcon', 'style', 'tRev', 'timingIcon']
  41. missing_conf = []
  42. for c in nec_conf:
  43. if c not in dir(config):
  44. missing_conf.append(c)
  45. if missing_conf:
  46. class ConfigError(Exception):
  47. pass
  48. raise ConfigError('The Following variables are missing in config.py: "' + '", "'.join(missing_conf)+'"')
  49. if config.language != "en_GB":
  50. kcgw.translator.load(config.install_path+'lang/'+ config.language)
  51. else:
  52. global tr
  53. kcgw.tr = lambda _, x: x
  54. tr = lambda _, x: x
  55. dateG = "{d}.{m}.{y}"
  56. dateGd = "{d}_{m}_{y}"
  57. dateA = "{m}-{d}-{y}"
  58. times = "{H}_{M}"
  59. timel = "{H}_{M}_{S}"
  60. session = ""
  61. if "{ask}" in config.default_subdirectory_name:
  62. status = False
  63. while not status:
  64. text, status = QtGui.QInputDialog.getText(parent, tr("Heading", "Subdirectory"),
  65. tr("Dialog", "Enter a name for the Subdirectory\n"
  66. "in which data will be saved:\n"
  67. "NOTE: You are being asked because it "
  68. "was set this way in the config file."))
  69. if not status and not config.force_ask:
  70. config.default_subdirectory_name = "{user}_{dateGd}-{timel}"
  71. break
  72. else:
  73. config.subdirectory_name = text.replace(" ", "_")
  74. return
  75. if "{sessionname}" in config.default_subdirectory_name:
  76. status = False
  77. while not status:
  78. text, status = QtGui.QInputDialog.getText(parent, tr("Heading", "Sessionname"),
  79. tr("Dialog", "Enter Sessionname\n"
  80. "NOTE: You are being asked because it "
  81. "was set this way in the config file.:"))
  82. if not status and not config.force_ask:
  83. config.default_subdirectory_name = "{user}_{dateGd}-{timel}"
  84. break
  85. else:
  86. session = text.replace(" ", "_")
  87. config.default_subdirectory_name = config.default_subdirectory_name.format(
  88. dateG=dateG, dateGd=dateGd, dateA=dateA, times=times, timel=timel,
  89. d=time.strftime("%d"), m=time.strftime("%m"), y=time.strftime("%y"),
  90. H=time.strftime("%H"), M=time.strftime("%M"), S=time.strftime("%S"),
  91. timestamp=time.localtime(), user=getpass.getuser(), sessionname=session
  92. )
  93. config.subdirectory_name = config.default_subdirectory_name.format(
  94. d=time.strftime("%d"), m=time.strftime("%m"), y=time.strftime("%y"),
  95. H=time.strftime("%H"), M=time.strftime("%M"), S=time.strftime("%S"),
  96. timestamp=time.localtime(), user=getpass.getuser()
  97. )
  98. if config.default_save_location == "pwd":
  99. import os
  100. config.save_location = os.getcwd()
  101. else:
  102. config.save_location = config.default_save_location
  103. storage.storage.offset_correction = config.fifty_ohm_timescan_datafile
  104. _MultiView_Name_ = "MultiView"
  105. class CentralWidget(kcgw.KCGWidgets):
  106. """
  107. Central Widget for the KCG gui main window
  108. """
  109. def __init__(self, parent=None):
  110. super(CentralWidget, self).__init__(parent=parent)
  111. # -------[ Create empty Groups to avoid warnings ]---------
  112. MenuItems.createEmptyGroup('Setup/Control')
  113. MenuItems.createEmptyGroup('Bits Table')
  114. # -------[ END ]---------------
  115. self.layout = QtGui.QHBoxLayout()
  116. self.setLayout(self.layout)
  117. self.pagesWidget = MultiPage(self)
  118. self.layout.addWidget(self.pagesWidget)
  119. self.mainControlWidget = ControlWidget()
  120. self.pagesWidget.addPage(self.mainControlWidget, "Setup/Control")
  121. self.mainMultiWidget = MultiWidget()
  122. self.pagesWidget.addPage(self.mainMultiWidget, "MultiView")
  123. # self.tableWidget = bt.AdvancedBoardInterface(parent=self)
  124. self.tableWidget = bt.AdvanceControlView()
  125. self.tableWidget.hide()
  126. class Gui(QtGui.QMainWindow):
  127. """
  128. Main Window of the KCG gui
  129. """
  130. def __init__(self):
  131. super(Gui, self).__init__()
  132. self.createEmptyGroups()
  133. # -------[ Check for boards and create corresponding objects ]------
  134. for board_id in available_boards:
  135. board.create_new_board_config(board_id)
  136. # board.get_board_config(board_id).observe(None, lambda x: bif.update_header(board_id), 'header') # Set update_header as function to call when header config is changed
  137. for board_id in available_boards:
  138. bif.initStatus(board.get_board_status(board_id)) # fill status storage with correct variables
  139. readconfig(self)
  140. # ----------[ Set Variables and create objects ]-----------------
  141. # self.storage = storage.Storage()
  142. self.storage = storage.storage
  143. # storage.storage = self.storage
  144. self.settings = None # (this holds the settings window) Only create Window when used
  145. self.statusbar = self.statusBar()
  146. # kcgw.statusbar = self.statusbar # set status bar to kcgw to easily access from other sources
  147. global_objects.set_global('statusbar', self.statusbar)
  148. self.pageIndicator = QtGui.QLabel()
  149. self.statusbar.addPermanentWidget(self.pageIndicator)
  150. self.cw = CentralWidget(self)
  151. self.doMenu()
  152. self.setCentralWidget(self.cw)
  153. self.initUI()
  154. self.finalizeInit()
  155. self.after_start_status_handler()
  156. self.setContentsMargins(0, -10, 0, 0)
  157. def initUI(self):
  158. """
  159. Initialize ui
  160. :return: -
  161. """
  162. self.setWindowTitle("KCG - Kapture Control Gui")
  163. self.setWindowIcon(QtGui.QIcon(config.install_path + config.guiIcon))
  164. # QtGui.QApplication.setStyle("Oxygen") # Make it look less blown up in Gnome for example
  165. def createEmptyGroups(self):
  166. """
  167. This creates empty groups with the GroupedObjects class in groupedelements module.
  168. This has to be done to avoid warnings when groups are enabled or disabled before creation.
  169. :return: -
  170. """
  171. for board_id in available_boards:
  172. Elements.createEmptyGroup("acquire_{}".format(board_id))
  173. Elements.createEmptyGroup("timing_{}".format(board_id))
  174. Elements.createEmptyGroup("no_board_{}".format(board_id))
  175. Elements.createEmptyGroup("continuous_read_{}".format(board_id))
  176. def finalizeInit(self):
  177. """
  178. Final things done at initialisation
  179. :return: -
  180. """
  181. self.populate_storage()
  182. with open(config.install_path+"style/style.css") as f:
  183. styleSheet = f.read()
  184. if config.style == 'blue':
  185. with open(config.install_path+'style/blue.css') as f:
  186. styleSheet += f.read()
  187. self.setStyleSheet(styleSheet)
  188. # evaluate config file regarding advanced_control
  189. self.showAdvancedControl(config.show_advanced_control)
  190. self.storage.advanced_control = config.show_advanced_control
  191. if not os.path.isdir(storage.storage.save_location + '/' + storage.storage.subdirname):
  192. os.makedirs(storage.storage.save_location + '/' + storage.storage.subdirname)
  193. self.measurementLogger = log.MeasurementLogger()
  194. log.logger = self.measurementLogger
  195. logStrings = []
  196. functionAndParameter = []
  197. for par in self.measurementLogger.predefined_parameters: # get strings and functions in seperate lists
  198. logStrings.append(par[0])
  199. functionAndParameter.append(par[1])
  200. for e in config.default_log_entries: # for every entry:
  201. if e in logStrings:
  202. self.measurementLogger.register_parameter(e, functionAndParameter[logStrings.index(e)][0], functionAndParameter[logStrings.index(e)][1])
  203. if log.no_epics and log.epics_reachable:
  204. logging.error("Epics installation not found. Logfiles will not contain information that is to be "
  205. "obtained via epics.")
  206. if not log.epics_reachable:
  207. logging.error("Epics PVs could not be accessed. Check Internet connection and Epics PV provider. Logfiles will not contain"
  208. "information that is to be obtained via epics.")
  209. def doMenu(self):
  210. """
  211. Create and show the menu and it's entries
  212. :return: -
  213. """
  214. self.menu = self.menuBar()
  215. self.fileMenu = self.menu.addMenu("&"+tr("Button", "File"))
  216. self.saveConfigAction = self.fileMenu.addAction(tr("Button", "Save Board Configuration"), self.saveConfig)
  217. self.saveConfigAction = self.fileMenu.addAction(tr("Button", "Load Board Configuration"), self.loadConfig)
  218. self.settingsAction = self.fileMenu.addAction(tr("Button", "Settings"), self.showSettings, "Ctrl+P")
  219. self.configAction = self.fileMenu.addAction(tr("Button", "Rerun Configuration Wizard"), self.rerunConfig)
  220. self.quitAction = self.fileMenu.addAction(QtGui.QIcon(config.install_path + "icons/exit.png"), tr("Button", "Quit"), self.close, "Ctrl+Q")
  221. self.menu.setCornerWidget(self.cw.pagesWidget.leftright)
  222. # ----------[ Page specific Menu Entries ]-------------
  223. self.multiMenu = self.menu.addMenu("&"+tr("Button", "Windows"))
  224. MenuItems.addMenuItem(_MultiView_Name_, self.multiMenu)
  225. self.plotAction = self.multiMenu.addAction(QtGui.QIcon(config.install_path + config.newPlotLiveIcon), tr("Button", "New Plot"), self.cw.mainMultiWidget.leftBar.add_plot)
  226. self.addWindowMenuEntries()
  227. if not available_boards.multi_board:
  228. self.acquireMenu = self.menu.addMenu("&"+tr("Button", "Acquire"))
  229. MenuItems.addMenuItem(_MultiView_Name_, self.acquireMenu)
  230. self.startAcquisitionAction = self.acquireMenu.addAction(QtGui.QIcon(config.install_path + config.startIcon),
  231. tr("Button", "Start Acquisition"), lambda: bif.bk_acquire(available_boards[0]))
  232. self.startAcquisitionAction.setObjectName("start_acquisition_action")
  233. MenuItems.addMenuItem("continuous_read_{}".format(available_boards[0]), self.startAcquisitionAction)
  234. MenuItems.addMenuItem("acquireTrigger_{}".format(available_boards[0]), self.startAcquisitionAction)
  235. # -----[ disable Menu Items for MultiView as it is not the startup page ]-------------
  236. # this could be avoided if menu is created before the multipage widget
  237. MenuItems.setEnabled(_MultiView_Name_, False)
  238. self.help = self.menu.addMenu("&"+tr("Button", "Help"))
  239. import webbrowser
  240. self.help.addAction(tr("Button", "Open Manual"), lambda: webbrowser.open(config.install_path + "Documentation/build/html/index.html"))
  241. self.help.addAction(tr("Button", "About"), self.showAbout)
  242. def _show_board_chooser(self):
  243. selected_boards = []
  244. if len(available_boards.board_ids) == 1:
  245. return [available_boards.board_ids[0]]
  246. chooser = QtGui.QDialog(self)
  247. chooser.setWindowTitle("KCG - Choose Boards")
  248. chooser_layout = QtGui.QVBoxLayout()
  249. chooser.setLayout(chooser_layout)
  250. chooser_layout.addWidget(QtGui.QLabel("Choose Boards"))
  251. boards = {}
  252. for bid in available_boards.board_ids:
  253. boards[bid] = QtGui.QCheckBox(str(bid), chooser)
  254. chooser_layout.addWidget(boards[bid])
  255. button = QtGui.QPushButton("OK", chooser)
  256. def ok():
  257. for bi, box in boards.items():
  258. if box.isChecked():
  259. selected_boards.append(bi)
  260. chooser.close()
  261. button.clicked.connect(ok)
  262. chooser_layout.addWidget(button)
  263. chooser.exec_()
  264. return selected_boards
  265. def saveConfig(self, board_id=None):
  266. """
  267. Save the current configuration to a configuration file
  268. :param board_id: the board to save the configuration for
  269. """
  270. filenameDialog = QtGui.QFileDialog(self, tr("Heading", "Save Configuration"), '', 'KAPTURE Configuration File (*.kcf)')
  271. filenameDialog.setDefaultSuffix("kcf")
  272. filenameDialog.setAcceptMode(filenameDialog.AcceptSave)
  273. filenameDialog.exec_()
  274. filename = filenameDialog.selectedFiles()
  275. if not filename:
  276. return
  277. if board_id is None:
  278. board_id = self._show_board_chooser()
  279. elif not isinstance(board_id, list):
  280. board_id = [board_id]
  281. fname = filename[0].split(".")
  282. for bid in board_id:
  283. if len(board_id) == 1:
  284. fname_board = filename[0]
  285. else:
  286. fname_board = ".".join(map(str, fname[:-1]))+"_"+str(bid)+"."+fname[-1]
  287. if not board.get_board_config(bid).save_config(fname_board):
  288. QtGui.QMessageBox.critical(self, tr("Heading", "Error Saving Config"), tr("Dialog", "There was an error saving to a config file."))
  289. def loadConfig(self, board_id=None):
  290. """
  291. Load the configuration for the given board from a file
  292. :param board_id: the board to read the configuration for
  293. """
  294. filename = QtGui.QFileDialog.getOpenFileName(self, 'Open Configuration', '', 'KAPTURE Configuration File (*.kcf)')
  295. if not filename:
  296. return
  297. if board_id is None:
  298. board_id = self._show_board_chooser()
  299. elif not isinstance(board_id, list):
  300. board_id = [board_id]
  301. for bid in board_id:
  302. if board.get_board_config(bid).load_config(filename):
  303. bif.bk_write_values(bid, defaults=False)
  304. else:
  305. 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."))
  306. def rerunConfig(self):
  307. """
  308. Rerun the initial configuration wizard
  309. """
  310. self.setupConfig = initialconfig.ConfigSetup(restart=True)
  311. self.setupConfig.setWindowModality(QtCore.Qt.ApplicationModal)
  312. def restart():
  313. import subprocess
  314. import sys
  315. import os
  316. try:
  317. subprocess.Popen(['kcg'])
  318. except OSError as exception:
  319. try:
  320. path = config.install_path[:-4]+'kcg'
  321. subprocess.Popen([sys.executable, path])
  322. except:
  323. print('ERROR: could not restart aplication:')
  324. print(' %s' % str(exception))
  325. else:
  326. QtGui.qApp.quit()
  327. else:
  328. QtGui.qApp.quit()
  329. self.setupConfig.success_signal.connect(restart)
  330. self.setupConfig.show()
  331. def showAbout(self):
  332. """
  333. Show the about window.
  334. :return: -
  335. """
  336. version = open(config.install_path+"VERSION").read()
  337. about = QtGui.QDialog(self)
  338. about.setWindowTitle("KCG - About")
  339. about_label = QtGui.QLabel(tr("About", "KAPTURE Control Gui\n"
  340. "KCG is a graphical control interface to the KAPTURE board\n\n"
  341. "Author: Patrick Schreiber\n\n"
  342. "Version:\n")+version)
  343. about_label.setAlignment(QtCore.Qt.AlignCenter)
  344. header_label = QtGui.QLabel(tr("About", "KCG"))
  345. header_label.setStyleSheet("font-size: 25pt; text-align: center;")
  346. header_label.setAlignment(QtCore.Qt.AlignCenter)
  347. footer_label = QtGui.QLabel(tr("About", "\nKAPTURE - Karlsruhe Pulse-Taking and Ultrafast Readout Electronics"))
  348. footer_label.setStyleSheet("font-size: 7pt;")
  349. footer_label.setAlignment(QtCore.Qt.AlignRight)
  350. about_layout = QtGui.QHBoxLayout()
  351. about_text_layout = QtGui.QVBoxLayout()
  352. about.setLayout(about_layout)
  353. # pxm = QtGui.QPixmap(config.guiIcon)
  354. # icon_layout = QtGui.QVBoxLayout()
  355. # icon_label = QtGui.QLabel("")
  356. # icon_label.setPixmap(pxm.scaled(QtCore.QSize(128, 128), QtCore.Qt.KeepAspectRatio))
  357. # icon_label.setFixedSize(130, 130)
  358. # icon_layout.addWidget(icon_label)
  359. # icon_layout.addStretch(1)
  360. # about_layout.addLayout(icon_layout)
  361. about_layout.addLayout(about_text_layout)
  362. about_text_layout.addWidget(header_label)
  363. about_text_layout.addWidget(about_label)
  364. about_text_layout.addWidget(footer_label)
  365. about.setFixedSize(400, 230)
  366. about.setStyleSheet("background-color: darkgrey;")
  367. about.exec_()
  368. def addWindowMenuEntries(self):
  369. """
  370. Adds Window Menu entries for custom widgets
  371. :return: -
  372. """
  373. for f in kcgw.get_registered_widgets():
  374. self.multiMenu.addAction(*f[:3]) # TODO: icon - ???
  375. def showSettings(self):
  376. """
  377. Create and show settings window
  378. :return: -
  379. """
  380. if self.settings: # use preopened window
  381. self.settings.show()
  382. self.settings.raise_()
  383. self.settings.activateWindow()
  384. else:
  385. self.settings = Settings(self.storage)
  386. self.settings.changed.connect(self.updateSettings)
  387. def updateSettings(self, changedsettings):
  388. """
  389. Update settings in storage if settings were changed in the settings window.
  390. :param changedsettings: list of settings that have been changed
  391. :return: -
  392. """
  393. for setting in changedsettings:
  394. if setting == 'language':
  395. lang = getattr(self.storage, setting)
  396. self.update_configuration_file({'language':'"'+str(lang)+'"'})
  397. QtGui.QMessageBox.information(self, "Change Language", "Language change takes effect after Gui restart", 1)
  398. if setting == 'advanced_control':
  399. self.showAdvancedControl(getattr(self.storage, setting))
  400. # if setting == 'offset_correction':
  401. # config.fifty_ohm_timescan_datafile = getattr(self.storage, setting)
  402. for bid in available_boards.board_ids:
  403. try:
  404. if bif.bk_get_config(bid, setting) != None:
  405. bif.bk_update_config(bid, setting, getattr(self.storage, setting))
  406. except board.NoSuchKeyError:
  407. pass
  408. def showAdvancedControl(self, value):
  409. """
  410. Enable or disable advanced table control view (Tables for registers)
  411. :param value: (bool) True to show and False to hide advanced view
  412. :return: -
  413. """
  414. if value:
  415. if self.cw.tableWidget.isHidden():
  416. self.cw.pagesWidget.addPage(self.cw.tableWidget, 'Bits Table', set_to_first=False)
  417. self.cw.tableWidget.show()
  418. else:
  419. if not self.cw.tableWidget.isHidden():
  420. self.cw.pagesWidget.removePage(self.cw.tableWidget)
  421. self.cw.tableWidget.hide()
  422. def after_start_status_handler(self):
  423. """
  424. Method to check for boards and perform a status_readout after the gui is fully started
  425. :return:
  426. """
  427. for bid in available_boards.board_ids: # there is always at least a dummy board
  428. bif.bk_check_for_board(bid)
  429. bif.bk_status_readout()
  430. def populate_storage(self):
  431. """
  432. Initially fills storage with predefined settings and configuration values
  433. :return: -
  434. """
  435. self.storage.header = config.save_header
  436. self.storage.subdirname = config.subdirectory_name
  437. self.storage.save_location = config.save_location
  438. self.storage.language = config.language
  439. self.storage.advanced_control = False
  440. def update_header(val):
  441. '''Update header'''
  442. self.storage.header = val
  443. if self.settings:
  444. self.settings.headerTick.setChecked(val)
  445. board.get_board_config(available_boards[0]).observe(self.storage.header, update_header, 'header') # TODO: header at one place for all boards? (here it uses the first board)
  446. def update_configuration_file(self, new_conf):
  447. """
  448. Update variablevalues in config file
  449. NOTE: this doesn't use standard ConfigParser as that would delete comments
  450. :param new_conf: Dictionary with variable, value pair
  451. :return:
  452. """
  453. import re
  454. # filename = "config.py"
  455. filename = os.path.expanduser("~")+"/.kcg/config.cfg"
  456. RE = '(('+'|'.join(new_conf.keys())+')\s*=)[^\r\n]*?(\r?\n|\r)'
  457. pat = re.compile(RE)
  458. def jojo(mat,dic = new_conf ):
  459. return dic[mat.group(2)].join(mat.group(1,3))
  460. with open(filename,'rb') as f:
  461. content = f.read()
  462. with open(filename,'wb') as f:
  463. f.write(pat.sub(jojo,content))
  464. def closeEvent(self, ev):
  465. """
  466. Handles closing of the GUI - this function is called by pyqt upon a close event.
  467. Asks if user really wants to close the gui
  468. :param ev: event
  469. :return: -
  470. """
  471. extra = ""
  472. for b in available_boards:
  473. if board.get_board_status(b).wait_on_trigger:
  474. extra += '\n'+tr('Dialog', 'Waiting on external trigger is still enabled.')
  475. if board.get_board_status(b).continuous_read:
  476. extra += '\n'+tr('Dialog', 'Continuous read is still enabled.')
  477. if extra:
  478. break
  479. cl = None
  480. if extra:
  481. cl = QtGui.QMessageBox.critical(self, tr("Heading", "Close KCG"),
  482. tr("Dialog", "Close KCG?")+extra,
  483. QtGui.QMessageBox.No | QtGui.QMessageBox.Yes,
  484. QtGui.QMessageBox.No)
  485. if not cl or cl == QtGui.QMessageBox.Yes:
  486. cl = QtGui.QMessageBox.question(self, tr("Heading", "Close KCG"),
  487. tr("Dialog", "Close KCG?\nYou will loose the state of open plots etc."),
  488. QtGui.QMessageBox.No | QtGui.QMessageBox.Yes,
  489. QtGui.QMessageBox.No)
  490. if cl == QtGui.QMessageBox.Yes:
  491. if self.settings:
  492. self.settings.close()
  493. ev.accept()
  494. else:
  495. ev.ignore()