summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens@jens-laptop.(none)>2010-02-12 18:03:04 +0100
committerJens Bache-Wiig <jens@jens-laptop.(none)>2010-02-12 18:03:04 +0100
commit3b5bfffcbec6076fbe1d908d75703a5a59f45076 (patch)
tree37673d0069fd0afcbea04be734d0e347cb61ae2d
First revision of qmlexporter
-rw-r--r--INSTALL.txt15
-rw-r--r--example.xcfbin0 -> 304843 bytes
-rw-r--r--exampleoutput/MyElement.qml108
-rw-r--r--exampleoutput/MyElement_images/background.pngbin0 -> 53805 bytes
-rw-r--r--exampleoutput/MyElement_images/background_text.pngbin0 -> 3118 bytes
-rw-r--r--exampleoutput/MyElement_images/drop_shadow.pngbin0 -> 1862 bytes
-rw-r--r--exampleoutput/MyElement_images/drop_shadow__1.pngbin0 -> 3318 bytes
-rw-r--r--exampleoutput/MyElement_images/drop_shadow__2.pngbin0 -> 6043 bytes
-rw-r--r--exampleoutput/MyElement_images/drop_shadow__3.pngbin0 -> 2062 bytes
-rw-r--r--exampleoutput/MyElement_images/mybutton.pngbin0 -> 1191 bytes
-rw-r--r--exampleoutput/MyElement_images/new_layer.pngbin0 -> 6998 bytes
-rw-r--r--exampleoutput/MyElement_images/new_layer__1.pngbin0 -> 691 bytes
-rw-r--r--exampleoutput/MyElement_images/new_layer_copy.pngbin0 -> 4928 bytes
-rw-r--r--exampleoutput/MyElement_images/new_layer_copy__1.pngbin0 -> 4977 bytes
-rw-r--r--exampleoutput/MyElement_images/new_layer_copy__2.pngbin0 -> 8016 bytes
-rw-r--r--exampleoutput/MyElement_images/push_me.pngbin0 -> 1081 bytes
-rw-r--r--exampleoutput/MyElement_images/qml.pngbin0 -> 941 bytes
-rwxr-xr-xqmlexporter.py78
18 files changed, 201 insertions, 0 deletions
diff --git a/INSTALL.txt b/INSTALL.txt
new file mode 100644
index 0000000..435c5ef
--- /dev/null
+++ b/INSTALL.txt
@@ -0,0 +1,15 @@
+INSTALLATION
+To use this plugin, make sure you have a recent version of GIMP 2 installed.
+
+- Copy the file qmlexporter.py to ~/.gimp/plug-ins
+- Run chmod u+rx on the file to make sure it is executable
+- Run or restart gimp
+
+The exporter should now show up at the bottom of the File menu.
+When you run it, it will ask for the element name and the directory
+to dump the output consisting of a .qml file and a series of .png files.
+
+Note that names are preserved from your layer names, but # and space are
+replaced by underscores to make them usable id tags. Offset, size, ordering
+and opacity are currently preserved.
+
diff --git a/example.xcf b/example.xcf
new file mode 100644
index 0000000..5167ee5
--- /dev/null
+++ b/example.xcf
Binary files differ
diff --git a/exampleoutput/MyElement.qml b/exampleoutput/MyElement.qml
new file mode 100644
index 0000000..0b07fba
--- /dev/null
+++ b/exampleoutput/MyElement.qml
@@ -0,0 +1,108 @@
+import Qt 4.6
+Rectangle {
+ Image {
+ id:background
+ source:"MyElement_images/background.png"
+ x:-2 ; y:0
+ width:400
+ height:255
+ }
+ Image {
+ id:new_layer__1
+ opacity: 0.2
+ source:"MyElement_images/new_layer__1.png"
+ x:1 ; y:0
+ width:399
+ height:255
+ }
+ Image {
+ id:new_layer
+ source:"MyElement_images/new_layer.png"
+ x:62 ; y:160
+ width:144
+ height:61
+ }
+ Image {
+ id:new_layer_copy
+ source:"MyElement_images/new_layer_copy.png"
+ x:135 ; y:11
+ width:139
+ height:46
+ }
+ Image {
+ id:push_me
+ source:"MyElement_images/push_me.png"
+ x:137 ; y:20
+ width:132
+ height:32
+ }
+ Image {
+ id:drop_shadow__2
+ opacity: 0.38431372549
+ source:"MyElement_images/drop_shadow__2.png"
+ x:22 ; y:75
+ width:263
+ height:39
+ }
+ Image {
+ id:background_text
+ source:"MyElement_images/background_text.png"
+ x:21 ; y:71
+ width:256
+ height:37
+ }
+ Image {
+ id:drop_shadow__1
+ opacity: 0.8
+ source:"MyElement_images/drop_shadow__1.png"
+ x:294 ; y:156
+ width:106
+ height:99
+ }
+ Image {
+ id:mybutton
+ source:"MyElement_images/mybutton.png"
+ x:309 ; y:168
+ width:82
+ height:82
+ }
+ Image {
+ id:new_layer_copy__1
+ opacity: 0.643137254902
+ source:"MyElement_images/new_layer_copy__1.png"
+ x:115 ; y:144
+ width:144
+ height:61
+ }
+ Image {
+ id:drop_shadow
+ opacity: 0.8
+ source:"MyElement_images/drop_shadow.png"
+ x:137 ; y:110
+ width:172
+ height:89
+ }
+ Image {
+ id:new_layer_copy__2
+ opacity: 0.643137254902
+ source:"MyElement_images/new_layer_copy__2.png"
+ x:158 ; y:120
+ width:144
+ height:61
+ }
+ Image {
+ id:drop_shadow__3
+ opacity: 0.574712643678
+ source:"MyElement_images/drop_shadow__3.png"
+ x:315 ; y:194
+ width:76
+ height:36
+ }
+ Image {
+ id:qml
+ source:"MyElement_images/qml.png"
+ x:316 ; y:190
+ width:69
+ height:37
+ }
+}
diff --git a/exampleoutput/MyElement_images/background.png b/exampleoutput/MyElement_images/background.png
new file mode 100644
index 0000000..59c02bd
--- /dev/null
+++ b/exampleoutput/MyElement_images/background.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/background_text.png b/exampleoutput/MyElement_images/background_text.png
new file mode 100644
index 0000000..b1b1d21
--- /dev/null
+++ b/exampleoutput/MyElement_images/background_text.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/drop_shadow.png b/exampleoutput/MyElement_images/drop_shadow.png
new file mode 100644
index 0000000..a6d41ea
--- /dev/null
+++ b/exampleoutput/MyElement_images/drop_shadow.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/drop_shadow__1.png b/exampleoutput/MyElement_images/drop_shadow__1.png
new file mode 100644
index 0000000..3b9128b
--- /dev/null
+++ b/exampleoutput/MyElement_images/drop_shadow__1.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/drop_shadow__2.png b/exampleoutput/MyElement_images/drop_shadow__2.png
new file mode 100644
index 0000000..34e7e2d
--- /dev/null
+++ b/exampleoutput/MyElement_images/drop_shadow__2.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/drop_shadow__3.png b/exampleoutput/MyElement_images/drop_shadow__3.png
new file mode 100644
index 0000000..c89ab3d
--- /dev/null
+++ b/exampleoutput/MyElement_images/drop_shadow__3.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/mybutton.png b/exampleoutput/MyElement_images/mybutton.png
new file mode 100644
index 0000000..40dcded
--- /dev/null
+++ b/exampleoutput/MyElement_images/mybutton.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/new_layer.png b/exampleoutput/MyElement_images/new_layer.png
new file mode 100644
index 0000000..ed572b3
--- /dev/null
+++ b/exampleoutput/MyElement_images/new_layer.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/new_layer__1.png b/exampleoutput/MyElement_images/new_layer__1.png
new file mode 100644
index 0000000..b7311cb
--- /dev/null
+++ b/exampleoutput/MyElement_images/new_layer__1.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/new_layer_copy.png b/exampleoutput/MyElement_images/new_layer_copy.png
new file mode 100644
index 0000000..a8e90e7
--- /dev/null
+++ b/exampleoutput/MyElement_images/new_layer_copy.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/new_layer_copy__1.png b/exampleoutput/MyElement_images/new_layer_copy__1.png
new file mode 100644
index 0000000..339a69d
--- /dev/null
+++ b/exampleoutput/MyElement_images/new_layer_copy__1.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/new_layer_copy__2.png b/exampleoutput/MyElement_images/new_layer_copy__2.png
new file mode 100644
index 0000000..cb688b4
--- /dev/null
+++ b/exampleoutput/MyElement_images/new_layer_copy__2.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/push_me.png b/exampleoutput/MyElement_images/push_me.png
new file mode 100644
index 0000000..db17b61
--- /dev/null
+++ b/exampleoutput/MyElement_images/push_me.png
Binary files differ
diff --git a/exampleoutput/MyElement_images/qml.png b/exampleoutput/MyElement_images/qml.png
new file mode 100644
index 0000000..d53640a
--- /dev/null
+++ b/exampleoutput/MyElement_images/qml.png
Binary files differ
diff --git a/qmlexporter.py b/qmlexporter.py
new file mode 100755
index 0000000..fbfc1b5
--- /dev/null
+++ b/qmlexporter.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+# Author: Jens Bache/Wiig
+# Copyright 2010 Jens Bache-Wiig
+# License: GPL v3
+# Version 0.1
+# GIMP plugin to export layers as QML
+
+from gimpfu import *
+import os
+
+gettext.install("gimp20-python", gimp.locale_directory, unicode = True)
+
+def export_qml(image, qmlname, path):
+ qmlfilename = os.path.join(path, qmlname + '.qml')
+ imagedirectory = qmlname + "_images"
+
+ # Create a subfolder for the image content
+ imagepath = os.path.join(path, imagedirectory);
+ if not os.path.isdir(imagepath):
+ os.mkdir(imagepath)
+
+ f = open(qmlfilename, 'w')
+ f.write('import Qt 4.6\n')
+ f.write('Rectangle {\n')
+ copy = image.duplicate()
+
+ i = len(copy.layers) - 1
+ while i >= 0 :
+ layer = copy.layers[i]
+ layer.visible = 1
+ layername = layer.name.lower()
+ layername = layername.replace(' ', '_')
+ layername = layername.replace('#', '__')
+
+ name = imagepath + "/" + layername + ".png"
+ fullpath = os.path.join(path, name);
+ opacity = layer.opacity / 100.0
+
+ # Write out the element
+ f.write(' Image {\n')
+ f.write(' id:' + layername +'\n')
+
+ if opacity < 1.0: # Only dump opacity if it is required
+ f.write(' opacity: %s' % opacity +'\n')
+
+ f.write(' source:\"' + imagedirectory + "/" + layername + '.png\"\n')
+ f.write(' x:%s ; y:%s' % layer.offsets + '\n')
+ f.write(' width:%s ' % layer.width + '\n')
+ f.write(' height:%s ' % layer.height + '\n')
+
+ # Store the layer as a .png
+ pdb.file_png_save(copy, layer, fullpath, name, 0, 9, 1, 1, 1, 1, 1)
+ f.write(' }\n')
+ i = i - 1
+ f.write('}\n')
+ f.close()
+
+register(
+ proc_name = ("python-fu-export-qml"),
+ blurb = ("Export layers to a QML document"),
+ help = ("Export layers as a QML document."),
+ author = ("Jens Bache-Wiig"),
+ copyright = ("Jens Bache-Wiig"),
+ date = ("2010"),
+ label = ("Export to _QML"),
+ imagetypes=("*"),
+ params=[
+ (PF_IMAGE, "image", "Image", None),
+ (PF_STRING, "qmlname", "QML Element", "MyElement"),
+ (PF_DIRNAME, "path", "Save QML to this directory", os.getcwd()),],
+ results=[],
+ function=(export_qml),
+ menu=("<Image>/File"),
+ domain=("gimp20-python",
+ gimp.locale_directory)
+)
+
+main()