eric7/Plugins/WizardPlugins/PyRegExpWizard/PyRegExpWizardDialog.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 8881
54e42bc2437a
child 9153
506e35e424d5
equal deleted inserted replaced
9151:8c5296fe3056 9152:8a68afaf1ba2
6 """ 6 """
7 Module implementing the Python re wizard dialog. 7 Module implementing the Python re wizard dialog.
8 """ 8 """
9 9
10 import os 10 import os
11 import pathlib
11 import re 12 import re
12 13
13 from PyQt6.QtCore import QFileInfo, pyqtSlot 14 from PyQt6.QtCore import pyqtSlot
14 from PyQt6.QtGui import QClipboard, QTextCursor 15 from PyQt6.QtGui import QClipboard, QTextCursor
15 from PyQt6.QtWidgets import ( 16 from PyQt6.QtWidgets import (
16 QWidget, QDialog, QInputDialog, QApplication, QDialogButtonBox, 17 QWidget, QDialog, QInputDialog, QApplication, QDialogButtonBox,
17 QVBoxLayout, QTableWidgetItem 18 QVBoxLayout, QTableWidgetItem
18 ) 19 )
325 "", 326 "",
326 self.tr("RegExp Files (*.rx);;All Files (*)"), 327 self.tr("RegExp Files (*.rx);;All Files (*)"),
327 None, 328 None,
328 EricFileDialog.DontConfirmOverwrite) 329 EricFileDialog.DontConfirmOverwrite)
329 if fname: 330 if fname:
330 ext = QFileInfo(fname).suffix() 331 fpath = pathlib.Path(fname)
331 if not ext: 332 if not fpath.suffix:
332 ex = selectedFilter.split("(*")[1].split(")")[0] 333 ex = selectedFilter.split("(*")[1].split(")")[0]
333 if ex: 334 if ex:
334 fname += ex 335 fpath = fpath.with_suffix(ex)
335 if QFileInfo(fname).exists(): 336 if fpath.exists():
336 res = EricMessageBox.yesNo( 337 res = EricMessageBox.yesNo(
337 self, 338 self,
338 self.tr("Save regular expression"), 339 self.tr("Save regular expression"),
339 self.tr("<p>The file <b>{0}</b> already exists." 340 self.tr("<p>The file <b>{0}</b> already exists."
340 " Overwrite it?</p>").format(fname), 341 " Overwrite it?</p>").format(str(fpath)),
341 icon=EricMessageBox.Warning) 342 icon=EricMessageBox.Warning)
342 if not res: 343 if not res:
343 return 344 return
344 345
345 fname = Utilities.toNativeSeparators(fname)
346 try: 346 try:
347 with open(fname, "w", encoding="utf-8") as f: 347 with fpath.open("w", encoding="utf-8") as f:
348 f.write(self.regexpTextEdit.toPlainText()) 348 f.write(self.regexpTextEdit.toPlainText())
349 except OSError as err: 349 except OSError as err:
350 EricMessageBox.information( 350 EricMessageBox.information(
351 self, 351 self,
352 self.tr("Save regular expression"), 352 self.tr("Save regular expression"),

eric ide

mercurial