Commit e3944495 authored by Ivan Yossi's avatar Ivan Yossi 👌

Add reload script button to Python scripter

We now return a tuple for every action, this allows to place the action
in different contexts. We only use multiple contexts for reload action
for now.

Differential revision: https://phabricator.kde.org/D10839
parent eeda1122
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
height="512px"
width="512px"
xml:space="preserve"
style="enable-background:new 0 0 41.999 41.999;"
viewBox="0 0 41.999 41.999"
y="0px"
x="0px"
id="Capa_1"
version="1.1"><metadata
id="metadata39"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs37" /><g
id="g4" /><g
id="g6" /><g
id="g8" /><g
id="g10" /><g
id="g12" /><g
id="g14" /><g
id="g16" /><g
id="g18" /><g
id="g20" /><g
id="g22" /><g
id="g24" /><g
id="g26" /><g
id="g28" /><g
id="g30" /><g
id="g32" /><g
style="stroke:none;fill:#ffffff;fill-opacity:1"
id="layer1"
transform="matrix(2.6249375,0,0,2.6249375,-7.8748125,-2712.5112)"><path
style="fill:#ffffff;fill-opacity:1;stroke:none"
d="m 4,3 v 16 h 1 8 1 c 1.374765,-1.357993 2.779209,-2.768314 4,-4 V 13.59375 3 H 17 5 Z m 0.625,0.6250039 h 12.75 V 14 15.000004 H 14 v 1.1875 2.1875 H 13 4.625 Z"
transform="translate(0,1030.3622)"
id="rect4139" /></g><g
style="fill:#ffffff;fill-opacity:1;stroke:none"
id="layer1-7"
transform="matrix(1.5380493,0,0,1.5380493,4.0809577,-1580.6669)"><path
style="fill:#ffffff;fill-opacity:1;stroke:none"
d="m 11,1049.3622 c -4.431966,0 -8,-3.568 -8,-8 0,-1.4417 0.382871,-2.7893 1.044922,-3.9551 l 0.738281,0.7383 C 4.285829,1039.1083 4,1040.1997 4,1041.3622 c 0,3.878 3.12203,7 7,7 1.162509,0 2.25389,-0.2858 3.216797,-0.7832 l 0.738281,0.7383 c -1.165789,0.662 -2.513364,1.0449 -3.955078,1.0449 z m 6.955078,-4.0449 -0.738281,-0.7383 C 17.714172,1043.6161 18,1042.5247 18,1041.3622 c 0,-3.878 -3.12203,-7 -7,-7 -1.16251,0 -2.25389,0.2858 -3.216797,0.7832 l -0.738281,-0.7383 c 1.165789,-0.662 2.513364,-1.0449 3.955078,-1.0449 4.431966,0 8,3.568 8,8 0,1.4417 -0.382871,2.7893 -1.044922,3.9551 z"
id="rect4085" /><rect
style="color:#000000;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="rect4336"
width="1"
height="4"
x="-726.45117"
y="737.3905"
transform="rotate(-45)" /><rect
style="color:#000000;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="rect4336-5"
width="1"
height="4"
x="-731.69507"
y="746.88037"
transform="rotate(-45)" /></g><g
transform="translate(-1.5159899,11.623502)"
id="g1153"><g
id="g1100" /><g
id="g1102" /><g
id="g1104" /><g
id="g1106" /><g
id="g1108" /><g
id="g1110" /><g
id="g1112" /><g
id="g1114" /><g
id="g1116" /><g
id="g1118" /><g
id="g1120" /><g
id="g1122" /><g
id="g1124" /><g
id="g1126" /><g
id="g1128" /></g></svg>
\ No newline at end of file
This diff is collapsed.
......@@ -3,6 +3,7 @@
<file alias="debug.svg">icons/debug.svg</file>
<file alias="debug_arrow.svg">icons/debug_arrow.svg</file>
<file alias="run.svg">icons/run.svg</file>
<file alias="reload_script.svg">icons/reload_script.svg</file>
<file alias="step.svg">icons/step.svg</file>
<file alias="stop.svg">icons/stop.svg</file>
</qresource>
......
......@@ -35,7 +35,7 @@ class CloseAction(QAction):
@property
def parent(self):
return 'File'
return 'File',
def close(self):
msgBox = QMessageBox(self.scripter.uicontroller.mainWidget)
......
......@@ -37,7 +37,7 @@ class DebugAction(QAction):
@property
def parent(self):
return 'toolBar'
return 'toolBar',
def debug(self):
if self.scripter.uicontroller.invokeAction('save'):
......
......@@ -35,7 +35,7 @@ class NewAction(QAction):
@property
def parent(self):
return 'File'
return 'File',
def new(self):
msgBox = QMessageBox(self.scripter.uicontroller.mainWidget)
......
......@@ -37,7 +37,7 @@ class OpenAction(QAction):
@property
def parent(self):
return 'File'
return 'File',
def open(self):
dialog = QFileDialog(self.scripter.uicontroller.mainWidget)
......
......@@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
from PyQt5.QtWidgets import QAction, QMessageBox
from PyQt5.QtGui import QKeySequence
from PyQt5.QtGui import QIcon, QKeySequence
from PyQt5.QtCore import Qt
import krita
......@@ -34,9 +34,12 @@ class ReloadAction(QAction):
self.setObjectName('reloadfile')
self.setShortcut(QKeySequence(Qt.ALT + Qt.Key_R))
self.setToolTip(i18n('Reload File Alt+R'))
self.setIcon(QIcon(':/icons/reload_script.svg'))
@property
def parent(self):
return 'File'
return 'File', 'toolBar'
def reloadFile(self):
# get the currently open document's path
......
......@@ -54,7 +54,7 @@ class RunAction(QAction):
@property
def parent(self):
return 'toolBar'
return 'toolBar',
def run(self):
""" This method execute python code from an activeDocument (file) or direct
......
......@@ -36,7 +36,7 @@ class SaveAction(QAction):
@property
def parent(self):
return 'File'
return 'File',
def save(self):
text = self.editor.toPlainText()
......
......@@ -36,7 +36,7 @@ class SaveAsAction(QAction):
@property
def parent(self):
return 'File'
return 'File',
def save(self):
text = self.editor.toPlainText()
......
......@@ -37,7 +37,7 @@ class SettingsAction(QAction):
@property
def parent(self):
return 'File'
return 'File',
def openSettings(self):
self.settingsDialog.show()
......
......@@ -132,8 +132,10 @@ class UIController(object):
m = importlib.import_module(module['module'])
action_class = getattr(m, module['klass'])
obj = action_class(self.scripter)
parent = self.mainWidget.findChild(QObject, i18n(obj.parent))
self.actions.append(dict(action=obj, parent=parent))
obj_parent = obj.parent
for name in obj_parent:
parent = self.mainWidget.findChild(QObject, i18n(name))
self.actions.append(dict(action=obj, parent=parent))
for action in self.actions:
action['parent'].addAction(action['action'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment