eric7/IconEditor/IconEditorWindow.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 8881
54e42bc2437a
child 9153
506e35e424d5
equal deleted inserted replaced
9151:8c5296fe3056 9152:8a68afaf1ba2
7 Module implementing the icon editor main window. 7 Module implementing the icon editor main window.
8 """ 8 """
9 9
10 import os 10 import os
11 import contextlib 11 import contextlib
12 import pathlib
12 13
13 from PyQt6.QtCore import ( 14 from PyQt6.QtCore import (
14 pyqtSignal, Qt, QSize, QSignalMapper, QFileInfo, QFile, QEvent, QIODevice 15 pyqtSignal, Qt, QSize, QSignalMapper, QFile, QEvent, QIODevice
15 ) 16 )
16 from PyQt6.QtGui import ( 17 from PyQt6.QtGui import (
17 QPalette, QImage, QImageReader, QImageWriter, QKeySequence 18 QPalette, QImage, QImageReader, QImageWriter, QKeySequence
18 ) 19 )
19 from PyQt6.QtWidgets import QScrollArea, QLabel, QDockWidget, QWhatsThis 20 from PyQt6.QtWidgets import QScrollArea, QLabel, QDockWidget, QWhatsThis
1107 self.__defaultFilter, 1108 self.__defaultFilter,
1108 EricFileDialog.DontConfirmOverwrite) 1109 EricFileDialog.DontConfirmOverwrite)
1109 if not fileName: 1110 if not fileName:
1110 return False 1111 return False
1111 1112
1112 ext = QFileInfo(fileName).suffix() 1113 fpath = pathlib.Path(fileName)
1113 if not ext: 1114 if not fpath.suffix:
1114 ex = selectedFilter.split("(*")[1].split(")")[0] 1115 ex = selectedFilter.split("(*")[1].split(")")[0]
1115 if ex: 1116 if ex:
1116 fileName += ex 1117 fpath = fpath.with_suffix(ex)
1117 if QFileInfo(fileName).exists(): 1118 if fpath.exists():
1118 res = EricMessageBox.yesNo( 1119 res = EricMessageBox.yesNo(
1119 self, 1120 self,
1120 self.tr("Save icon file"), 1121 self.tr("Save icon file"),
1121 self.tr("<p>The file <b>{0}</b> already exists." 1122 self.tr("<p>The file <b>{0}</b> already exists."
1122 " Overwrite it?</p>").format(fileName), 1123 " Overwrite it?</p>").format(str(fpath)),
1123 icon=EricMessageBox.Warning) 1124 icon=EricMessageBox.Warning)
1124 if not res: 1125 if not res:
1125 return False 1126 return False
1126 1127
1127 self.__lastSavePath = os.path.dirname(fileName) 1128 self.__lastSavePath = fpath.parent
1128 1129
1129 return self.__saveIconFile(fileName) 1130 return self.__saveIconFile(str(fpath))
1130 1131
1131 def __closeAll(self): 1132 def __closeAll(self):
1132 """ 1133 """
1133 Private slot to close all windows. 1134 Private slot to close all windows.
1134 """ 1135 """
1234 Private method to return the filename part of the given path. 1235 Private method to return the filename part of the given path.
1235 1236
1236 @param fullFileName full pathname of the given file (string) 1237 @param fullFileName full pathname of the given file (string)
1237 @return filename part (string) 1238 @return filename part (string)
1238 """ 1239 """
1239 return QFileInfo(fullFileName).fileName() 1240 return pathlib.Path(fullFileName).name
1240 1241
1241 def __maybeSave(self): 1242 def __maybeSave(self):
1242 """ 1243 """
1243 Private method to ask the user to save the file, if it was modified. 1244 Private method to ask the user to save the file, if it was modified.
1244 1245

eric ide

mercurial