src/eric7/IconEditor/IconEditorWindow.py

branch
eric7
changeset 10428
a071d4065202
parent 10372
1444b4bee64b
child 10439
21c28b0f9e41
equal deleted inserted replaced
10427:3733e2b23cf7 10428:a071d4065202
45 project=None, 45 project=None,
46 ): 46 ):
47 """ 47 """
48 Constructor 48 Constructor
49 49
50 @param fileName name of a file to load on startup (string) 50 @param fileName name of a file to load on startup
51 @param parent parent widget of this window (QWidget) 51 @type str
52 @param parent parent widget of this window
53 @type QWidget
52 @param fromEric flag indicating whether it was called from within 54 @param fromEric flag indicating whether it was called from within
53 eric (boolean) 55 eric
56 @type bool
54 @param initShortcutsOnly flag indicating to just initialize the 57 @param initShortcutsOnly flag indicating to just initialize the
55 keyboard shortcuts (boolean) 58 keyboard shortcuts
56 @param project reference to the project object (Project) 59 @type bool
60 @param project reference to the project object
61 @type Project
57 """ 62 """
58 super().__init__(parent) 63 super().__init__(parent)
59 self.setObjectName("eric7_icon_editor") 64 self.setObjectName("eric7_icon_editor")
60 65
61 self.fromEric = fromEric 66 self.fromEric = fromEric
1124 1129
1125 def closeEvent(self, evt): 1130 def closeEvent(self, evt):
1126 """ 1131 """
1127 Protected event handler for the close event. 1132 Protected event handler for the close event.
1128 1133
1129 @param evt the close event (QCloseEvent) 1134 @param evt the close event
1130 <br />This event is simply accepted after the history has been 1135 @type QCloseEvent
1131 saved and all window references have been deleted. 1136 <br />This event is simply accepted after the history has been
1137 saved and all window references have been deleted.
1132 """ 1138 """
1133 if self.__maybeSave(): 1139 if self.__maybeSave():
1134 self.__editor.shutdown() 1140 self.__editor.shutdown()
1135 1141
1136 state = self.saveState() 1142 state = self.saveState()
1196 1202
1197 def __saveIcon(self): 1203 def __saveIcon(self):
1198 """ 1204 """
1199 Private slot to save the icon. 1205 Private slot to save the icon.
1200 1206
1201 @return flag indicating success (boolean) 1207 @return flag indicating success
1208 @rtype bool
1202 """ 1209 """
1203 if not self.__fileName: 1210 if not self.__fileName:
1204 return self.__saveIconAs() 1211 return self.__saveIconAs()
1205 else: 1212 else:
1206 return self.__saveIconFile(self.__fileName) 1213 return self.__saveIconFile(self.__fileName)
1207 1214
1208 def __saveIconAs(self): 1215 def __saveIconAs(self):
1209 """ 1216 """
1210 Private slot to save the icon with a new name. 1217 Private slot to save the icon with a new name.
1211 1218
1212 @return flag indicating success (boolean) 1219 @return flag indicating success
1220 @rtype bool
1213 """ 1221 """
1214 if ( 1222 if (
1215 not self.__lastSavePath 1223 not self.__lastSavePath
1216 and self.__project is not None 1224 and self.__project is not None
1217 and self.__project.isOpen() 1225 and self.__project.isOpen()
1269 1277
1270 def __loadIconFile(self, fileName): 1278 def __loadIconFile(self, fileName):
1271 """ 1279 """
1272 Private method to load an icon file. 1280 Private method to load an icon file.
1273 1281
1274 @param fileName name of the icon file to load (string). 1282 @param fileName name of the icon file to load
1283 @type str
1275 """ 1284 """
1276 img = QImage(fileName) 1285 img = QImage(fileName)
1277 if img.isNull(): 1286 if img.isNull():
1278 EricMessageBox.warning( 1287 EricMessageBox.warning(
1279 self, 1288 self,
1286 1295
1287 def __saveIconFile(self, fileName): 1296 def __saveIconFile(self, fileName):
1288 """ 1297 """
1289 Private method to save to the given file. 1298 Private method to save to the given file.
1290 1299
1291 @param fileName name of the file to save to (string) 1300 @param fileName name of the file to save to
1292 @return flag indicating success (boolean) 1301 @type str
1302 @return flag indicating success
1303 @rtype bool
1293 """ 1304 """
1294 img = self.__editor.iconImage() 1305 img = self.__editor.iconImage()
1295 res = img.save(fileName) 1306 res = img.save(fileName)
1296 1307
1297 if not res: 1308 if not res:
1316 1327
1317 def __setCurrentFile(self, fileName): 1328 def __setCurrentFile(self, fileName):
1318 """ 1329 """
1319 Private method to register the file name of the current file. 1330 Private method to register the file name of the current file.
1320 1331
1321 @param fileName name of the file to register (string) 1332 @param fileName name of the file to register
1333 @type str
1322 """ 1334 """
1323 self.__fileName = fileName 1335 self.__fileName = fileName
1324 1336
1325 shownName = ( 1337 shownName = (
1326 self.__strippedName(self.__fileName) 1338 self.__strippedName(self.__fileName)
1336 1348
1337 def __strippedName(self, fullFileName): 1349 def __strippedName(self, fullFileName):
1338 """ 1350 """
1339 Private method to return the filename part of the given path. 1351 Private method to return the filename part of the given path.
1340 1352
1341 @param fullFileName full pathname of the given file (string) 1353 @param fullFileName full pathname of the given file
1342 @return filename part (string) 1354 @type str
1355 @return filename part
1356 @rtype str
1343 """ 1357 """
1344 return pathlib.Path(fullFileName).name 1358 return pathlib.Path(fullFileName).name
1345 1359
1346 def __maybeSave(self): 1360 def __maybeSave(self):
1347 """ 1361 """
1348 Private method to ask the user to save the file, if it was modified. 1362 Private method to ask the user to save the file, if it was modified.
1349 1363
1350 @return flag indicating, if it is ok to continue (boolean) 1364 @return flag indicating, if it is ok to continue
1365 @rtype bool
1351 """ 1366 """
1352 if self.__editor.isDirty(): 1367 if self.__editor.isDirty():
1353 ret = EricMessageBox.okToClearData( 1368 ret = EricMessageBox.okToClearData(
1354 self, 1369 self,
1355 self.tr("eric Icon Editor"), 1370 self.tr("eric Icon Editor"),
1362 1377
1363 def setRecentPaths(self, openPath, savePath): 1378 def setRecentPaths(self, openPath, savePath):
1364 """ 1379 """
1365 Public method to set the last open and save paths. 1380 Public method to set the last open and save paths.
1366 1381
1367 @param openPath least recently used open path (string) 1382 @param openPath least recently used open path
1368 @param savePath least recently used save path (string) 1383 @type str
1384 @param savePath least recently used save path
1385 @type str
1369 """ 1386 """
1370 if openPath: 1387 if openPath:
1371 self.__lastOpenPath = openPath 1388 self.__lastOpenPath = openPath
1372 if savePath: 1389 if savePath:
1373 self.__lastSavePath = savePath 1390 self.__lastSavePath = savePath
1381 def __modificationChanged(self, m): 1398 def __modificationChanged(self, m):
1382 """ 1399 """
1383 Private slot to handle the modificationChanged signal. 1400 Private slot to handle the modificationChanged signal.
1384 1401
1385 @param m modification status 1402 @param m modification status
1403 @type bool
1386 """ 1404 """
1387 self.setWindowModified(m) 1405 self.setWindowModified(m)
1388 self.__checkActions() 1406 self.__checkActions()
1389 1407
1390 def __updatePosition(self, x, y): 1408 def __updatePosition(self, x, y):
1391 """ 1409 """
1392 Private slot to show the current cursor position. 1410 Private slot to show the current cursor position.
1393 1411
1394 @param x x-coordinate (integer) 1412 @param x x-coordinate
1395 @param y y-coordinate (integer) 1413 @type int
1414 @param y y-coordinate
1415 @type int
1396 """ 1416 """
1397 self.__sbPos.setText("X: {0:d} Y: {1:d}".format(x + 1, y + 1)) 1417 self.__sbPos.setText("X: {0:d} Y: {1:d}".format(x + 1, y + 1))
1398 1418
1399 def __updateSize(self, w, h): 1419 def __updateSize(self, w, h):
1400 """ 1420 """
1401 Private slot to show the current icon size. 1421 Private slot to show the current icon size.
1402 1422
1403 @param w width of the icon (integer) 1423 @param w width of the icon
1404 @param h height of the icon (integer) 1424 @type int
1425 @param h height of the icon
1426 @type int
1405 """ 1427 """
1406 self.__sbSize.setText("Size: {0:d} x {1:d}".format(w, h)) 1428 self.__sbSize.setText("Size: {0:d} x {1:d}".format(w, h))
1407 1429
1408 def __updateZoom(self): 1430 def __updateZoom(self):
1409 """ 1431 """
1468 1490
1469 def wheelEvent(self, evt): 1491 def wheelEvent(self, evt):
1470 """ 1492 """
1471 Protected method to handle wheel events. 1493 Protected method to handle wheel events.
1472 1494
1473 @param evt reference to the wheel event (QWheelEvent) 1495 @param evt reference to the wheel event
1496 @type QWheelEvent
1474 """ 1497 """
1475 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: 1498 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier:
1476 delta = evt.angleDelta().y() 1499 delta = evt.angleDelta().y()
1477 if delta < 0: 1500 if delta < 0:
1478 self.__zoomOut() 1501 self.__zoomOut()
1485 1508
1486 def event(self, evt): 1509 def event(self, evt):
1487 """ 1510 """
1488 Public method handling events. 1511 Public method handling events.
1489 1512
1490 @param evt reference to the event (QEvent) 1513 @param evt reference to the event
1491 @return flag indicating, if the event was handled (boolean) 1514 @type QEvent
1515 @return flag indicating, if the event was handled
1516 @rtype bool
1492 """ 1517 """
1493 if evt.type() == QEvent.Type.Gesture: 1518 if evt.type() == QEvent.Type.Gesture:
1494 self.gestureEvent(evt) 1519 self.gestureEvent(evt)
1495 return True 1520 return True
1496 1521

eric ide

mercurial