Krita Source Code Documentation
Loading...
Searching...
No Matches
openaction.py
Go to the documentation of this file.
1"""
2SPDX-FileCopyrightText: 2017 Eliakin Costa <eliakim170@gmail.com>
3
4SPDX-License-Identifier: GPL-2.0-or-later
5"""
6try:
7 from PyQt6.QtWidgets import QMessageBox
8 from PyQt6.QtGui import QKeySequence, QAction
9 from PyQt6.QtCore import Qt
10except:
11 from PyQt5.QtWidgets import QAction, QMessageBox
12 from PyQt5.QtGui import QKeySequence
13 from PyQt5.QtCore import Qt
14from krita import FileDialog
15from builtins import i18n
16
17import os.path
18
19
20class OpenAction(QAction):
21
22 def __init__(self, scripter, parent=None):
23 super(OpenAction, self).__init__(parent)
24 self.scripter = scripter
25
26 self.triggered.connect(self.openopen)
27
28 self.setText(i18n("Open"))
29 self.setObjectName('open')
30 self.setShortcut(QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_O))
31
32 @property
33 def parent(self):
34 return 'File',
35
36 def open(self):
37 dialog = FileDialog(self.scripter.uicontroller.mainWidget)
38 dialog.setNameFilter((i18n("Python Files") + " (*.py)"))
39 selectedFile = dialog.filename()
40 if selectedFile:
41 try:
42 _, fileExtension = os.path.splitext(selectedFile)
43
44 if fileExtension == '.py':
45 document = self.scripter.documentcontroller.openDocument(selectedFile)
46 self.scripter.uicontroller.setDocumentEditor(document)
47 self.scripter.uicontroller.setStatusBar(document.filePath)
48 else:
49 raise
50 except Exception:
51 QMessageBox.information(self.scripter.uicontroller.mainWidget,
52 i18n("Invalid File"),
53 i18n("Open files with .py extension"))
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))