개정판 f5f79e97
issue #622: add save alert
Change-Id: I0a77f0377fb8f14c23e4b8174aea8a7d436f3f5d
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
130 | 130 |
# set title |
131 | 131 |
self.setWindowTitle(self.title) |
132 | 132 |
|
133 |
# save timer |
|
134 |
self.save_timer = None |
|
135 |
|
|
133 | 136 |
self.lineComboBox = QComboBox(self.toolBar) |
134 | 137 |
for condition in LineTypeConditions.items(): |
135 | 138 |
self.lineComboBox.addItem(condition.name) |
... | ... | |
755 | 758 |
|
756 | 759 |
app_doc_data = AppDocData.instance() |
757 | 760 |
if app_doc_data.activeDrawing and app_doc_data.activeDrawing.modified: |
758 |
if QMessageBox.Yes == QMessageBox.question(self, self.tr("Question"), |
|
759 |
self.tr("Do you want to save drawing?"), |
|
760 |
QMessageBox.Yes | QMessageBox.No): |
|
761 |
# self.actionSaveCliked() |
|
762 |
return True |
|
761 |
#if QMessageBox.Yes == QMessageBox.question(self, self.tr("Question"), |
|
762 |
# self.tr("Do you want to save drawing?"), |
|
763 |
# QMessageBox.Yes | QMessageBox.No): |
|
764 |
# self.actionSaveCliked() |
|
765 |
# return True |
|
766 |
if QMessageBox.Yes == QMessageBox.question(self, self.tr('Continue?'), |
|
767 |
self.tr('Changes may not have been saved.'), |
|
768 |
QMessageBox.Yes | QMessageBox.Cancel): |
|
769 |
return False |
|
763 | 770 |
|
764 | 771 |
''' |
765 | 772 |
@brief action save click event |
... | ... | |
780 | 787 |
if not self.actionSave.isEnabled(): |
781 | 788 |
return |
782 | 789 |
self.actionSave.setEnabled(False) |
790 |
|
|
791 |
# save alarm |
|
792 |
self.save_alarm_enable(False) |
|
793 |
|
|
783 | 794 |
app_doc_data = AppDocData.instance() |
784 | 795 |
if app_doc_data.imgName is None: |
785 | 796 |
self.showImageSelectionMessageBox() |
... | ... | |
838 | 849 |
self.setWindowTitle(title[:-1] if title[-1] == '*' else title) |
839 | 850 |
|
840 | 851 |
self.actionSave.setEnabled(True) |
852 |
|
|
853 |
# save alarm |
|
854 |
self.save_alarm_enable(True) |
|
841 | 855 |
|
842 | 856 |
''' |
843 | 857 |
@brief refresh resultPropertyTableWidget |
... | ... | |
1372 | 1386 |
from Drawing import Drawing |
1373 | 1387 |
|
1374 | 1388 |
try: |
1389 |
app_doc_data = AppDocData.instance() |
|
1390 |
|
|
1375 | 1391 |
if not self.actionSave.isEnabled(): |
1376 | 1392 |
return |
1377 | 1393 |
|
1378 | 1394 |
if self.save_drawing_if_necessary(): |
1379 | 1395 |
return |
1380 | 1396 |
|
1397 |
if not app_doc_data.set_occupying_drawing(drawing.UID): |
|
1398 |
QMessageBox.about(self.graphicsView, self.tr("Notice"), |
|
1399 |
self.tr("The drawing is locked for editing by another user")) |
|
1400 |
return |
|
1401 |
|
|
1402 |
# save alarm |
|
1403 |
self.save_alarm_enable(False) |
|
1404 |
|
|
1381 | 1405 |
if hasattr(self, '_save_work_cmd'): |
1382 | 1406 |
self._save_work_cmd.wait() |
1383 | 1407 |
|
1384 |
app_doc_data = AppDocData.instance() |
|
1385 | 1408 |
project = app_doc_data.getCurrentProject() |
1386 | 1409 |
|
1387 | 1410 |
self.path = self.graphicsView.loadImageFromFile(drawing) |
... | ... | |
1391 | 1414 |
|
1392 | 1415 |
app_doc_data.setImgFilePath(self.path) |
1393 | 1416 |
app_doc_data.activeDrawing = drawing |
1394 |
if not app_doc_data.set_occupying_drawing(app_doc_data.activeDrawing.UID): |
|
1395 |
QMessageBox.about(self.graphicsView, self.tr("Notice"), |
|
1396 |
self.tr("The drawing is locked for editing by another user")) |
|
1397 |
return |
|
1417 |
|
|
1398 | 1418 |
app_doc_data.activeDrawing.set_pid_source(Image.open(self.path)) |
1399 | 1419 |
self.itemTreeWidget.setCurrentPID(app_doc_data.activeDrawing.name) |
1400 | 1420 |
|
... | ... | |
1433 | 1453 |
|
1434 | 1454 |
self.changeViewCheckedState(True) |
1435 | 1455 |
self.setWindowTitle(self.title) |
1456 |
|
|
1457 |
# save alarm |
|
1458 |
self.save_alarm_enable(True) |
|
1436 | 1459 |
except Exception as ex: |
1437 | 1460 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1438 | 1461 |
sys.exc_info()[-1].tb_lineno) |
... | ... | |
1440 | 1463 |
|
1441 | 1464 |
return self.path |
1442 | 1465 |
|
1466 |
def save_alarm_enable(self, enable): |
|
1467 |
app_doc_data = AppDocData.instance() |
|
1468 |
configs = app_doc_data.getConfigs('Data Save', 'Time') |
|
1469 |
time_min = int(configs[0].value) if 1 == len(configs) else 0 |
|
1470 |
|
|
1471 |
if enable and time_min > 0: |
|
1472 |
if not self.save_timer: |
|
1473 |
self.save_timer = QTimer() |
|
1474 |
self.save_timer.timeout.connect(self.save_alarm) |
|
1475 |
self.save_timer.setInterval(60000 * time_min) |
|
1476 |
|
|
1477 |
if 60000 * time_min != self.save_timer.interval(): |
|
1478 |
self.save_timer.setInterval(60000 * time_min) |
|
1479 |
|
|
1480 |
self.save_timer.start() |
|
1481 |
else: |
|
1482 |
if self.save_timer: |
|
1483 |
self.save_timer.stop() |
|
1484 |
|
|
1485 |
def save_alarm(self): |
|
1486 |
self.save_timer.stop() |
|
1487 |
if self.graphicsView.hasFocus(): |
|
1488 |
QMessageBox.information(self, self.tr('Information'), self.tr('Please save Drawing')) |
|
1489 |
self.save_timer.start() |
|
1490 |
|
|
1443 | 1491 |
def export_as_svg(self): |
1444 | 1492 |
"""export scene to svg file""" |
1445 | 1493 |
from ExportCommand import ExportCommand |
... | ... | |
2056 | 2104 |
self.showImageSelectionMessageBox() |
2057 | 2105 |
return |
2058 | 2106 |
|
2107 |
# save alarm |
|
2108 |
self.save_alarm_enable(False) |
|
2109 |
|
|
2059 | 2110 |
try: |
2060 | 2111 |
appDocData = AppDocData.instance() |
2061 | 2112 |
|
... | ... | |
2092 | 2143 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
2093 | 2144 |
sys.exc_info()[-1].tb_lineno) |
2094 | 2145 |
self.addMessage.emit(MessageType.Error, message) |
2146 |
finally: |
|
2147 |
# save alarm |
|
2148 |
self.save_alarm_enable(True) |
|
2095 | 2149 |
|
2096 | 2150 |
''' |
2097 | 2151 |
@brief remove item from tree widget and then remove from scene |
... | ... | |
2200 | 2254 |
self.showImageSelectionMessageBox() |
2201 | 2255 |
return |
2202 | 2256 |
|
2257 |
# save alarm |
|
2258 |
self.save_alarm_enable(False) |
|
2259 |
|
|
2203 | 2260 |
try: |
2204 | 2261 |
dlg = QConnectAttrDialog(self, self.graphicsView.scene()) |
2205 | 2262 |
dlg.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) |
... | ... | |
2225 | 2282 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
2226 | 2283 |
sys.exc_info()[-1].tb_lineno) |
2227 | 2284 |
self.addMessage.emit(MessageType.Error, message) |
2285 |
finally: |
|
2286 |
# save alarm |
|
2287 |
self.save_alarm_enable(True) |
|
2228 | 2288 |
|
2229 | 2289 |
''' |
2230 | 2290 |
@history 2018.05.25 Jeongwoo Moved from MainWindow |
내보내기 Unified diff