Code

A little more work to Web Slicer (not usable yet)
authorAurelio A. Heckert (a) <auriumgmaildotcom>
Wed, 3 Mar 2010 13:53:15 +0000 (10:53 -0300)
committerAurelio A. Heckert (a) <auriumgmaildotcom>
Wed, 3 Mar 2010 13:53:15 +0000 (10:53 -0300)
share/extensions/webslicer-create-group.inx
share/extensions/webslicer-create-group.py
share/extensions/webslicer-create-rect.inx
share/extensions/webslicer-create-rect.py
share/extensions/webslicer-export.inx

index 683795213daf0fe5b664f60826a794e74db385fe..b5c5b48ed06987dfe0bb513ec7b2d8bd2667f649 100644 (file)
@@ -17,7 +17,7 @@
     <_item value="percent">Percent (relative to parent size)</_item>
     <_item value="undefined">Undefined (relative to non-floating content size)</_item>
   </param>
-  <effect>
+  <effect needs-live-preview="false">
     <object-type>all</object-type>
     <effects-menu>
       <submenu _name="Web">
index 3c44b2cb436d8aa8a3189ee8d2a382c772f4d9cf..8a496c4bac7e4aa80d4924c008daec17a451105e 100755 (executable)
@@ -50,17 +50,23 @@ class WebSlicer_CreateGroup(inkex.Effect):
                                      help="")
 
     def effect(self):
-        if len(self.selected) == 0:
-            inkex.errormsg(_('You must to select some "Slicer rectangles".'))
-            return
         layer = self.document.xpath(
                      '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]',
                      namespaces=inkex.NSS)[0]
-        group = inkex.etree.SubElement(layer, 'g')
+        if len(self.selected) == 0:
+            inkex.errormsg(_('You must to select some "Slicer rectangles" or other "Layout groups".'))
+            exit(1)
+        descendants = get_descendants_in_array(layer)
+        for id,node in self.selected.iteritems():
+            if node not in descendants:
+                inkex.errormsg(_('Opss... The element "%s" is not in the Web Slicer layer') % id)
+                exit(2)
+        g_parent = self.find_node_parent(node)
+        group = inkex.etree.SubElement(g_parent, 'g')
         desc = inkex.etree.SubElement(group, 'desc')
         conf_txt = ''
         if not is_empty(self.options.html_id):
-            conf_txt += 'html-id:'    + self.options.html_class +'\n'
+            conf_txt += 'html-id:'    + self.options.html_id +'\n'
         if not is_empty(self.options.html_class):
             conf_txt += 'html-class:' + self.options.html_class +'\n'
         conf_txt += 'width-unity:' + self.options.width_unity +'\n'
@@ -70,6 +76,18 @@ class WebSlicer_CreateGroup(inkex.Effect):
             group.insert( 1, node )
 
 
+    def find_node_parent(self, node):
+        #TODO: make it real!
+        return self.document.xpath(
+                    '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]',
+                    namespaces=inkex.NSS)[0]
+
+def get_descendants_in_array(el):
+    descendants = el.getchildren()
+    for e in descendants:
+        descendants.extend( get_descendants_in_array(e) )
+    return descendants
+
 if __name__ == '__main__':
     e = WebSlicer_CreateGroup()
     e.affect()
index 2a41ff4d81b4911c693e17589fa713e78e79a33c..7ac681e690f9624ed63835999219845ac0831e2d 100644 (file)
@@ -52,7 +52,7 @@
       </param>
     </page>
   </param>
-  <effect>
+  <effect needs-live-preview="false">
     <object-type>all</object-type>
     <effects-menu>
       <submenu _name="Web">
index 2c495e7afea6d0ec1a7fb77e282136b339009b2c..9761fd3a576b70bf85a9e129b5d09da6cb0c1a6d 100755 (executable)
@@ -83,12 +83,30 @@ class WebSlicer_CreateRect(inkex.Effect):
         # inkscape param workarround
         self.OptionParser.add_option("--tab")
 
+
+    def unique_slice_name(self):
+        name = self.options.name
+        el = self.document.xpath( '//*[@id="'+name+'"]', namespaces=inkex.NSS )
+        if len(el) > 0:
+            if name[-3:] == '-00': name = name[:-3]
+            num = 0
+            num_s = '00'
+            while len(el) > 0:
+                num += 1
+                num_s = str(num)
+                if len(num_s)==1 : num_s = '0'+num_s
+                el = self.document.xpath( '//*[@id="'+name+'-'+num_s+'"]',
+                                          namespaces=inkex.NSS )
+            self.options.name = name+'-'+num_s
+
+
     def effect(self):
         layer = self.get_slicer_layer()
         #TODO: get selected elements to define location and size
         rect = inkex.etree.SubElement(layer, 'rect')
         if is_empty(self.options.name):
-            self.options.name = 'rect0001'
+            self.options.name = 'slice-00'
+        self.unique_slice_name()
         rect.set('id', self.options.name)
         rect.set('fill', 'red')
         rect.set('opacity', '0.5')
index 06863ece548f13be8fd6910266c69b6ffde4b567..9f7aac32338c384bf64b05a7fe6778a14f9dd259 100644 (file)
@@ -7,7 +7,7 @@
   <_param name="about" type="description">All sliced images, and optionaly code, will be generated as you had configured and saved to one directory.</_param>
   <param name="dir" type="string" _gui-text="Directory path to export"></param>
   <param name="with-code" type="boolean" _gui-text="With HTML and CSS">true</param>
-  <effect>
+  <effect needs-live-preview="false">
     <object-type>all</object-type>
     <effects-menu>
       <submenu _name="Web">