Commit 3c4517c5 authored by Gemy Cédric's avatar Gemy Cédric

interactive mockup (ex webgoto) with test file and correction on set_att and transmit

parent d67f37fc
......@@ -189,4 +189,16 @@ InkWeb.moveElTo = function (startConf) {
}
}
InkWeb.moveViewbox = function (conf) {
if ( typeof(conf.from) == "string" )
conf.from = document.getElementById( conf.from );
if ( ! conf.to )
conf.to = conf.to ;
if ( typeof(toEl) == "string" )
toEl = document.getElementById( toEl );
toEl = document.getElementById( conf.to );
document.getElementsByTagName("svg")[0].viewBox.baseVal.x = toEl.getAttribute("x");
document.getElementsByTagName("svg")[0].viewBox.baseVal.y = toEl.getAttribute("y");
}
InkWeb.log = function () { /* if you need that, use the inkweb-debug.js too */ }
This diff is collapsed.
......@@ -115,30 +115,6 @@ InkWeb.transmitAtt = function (conf) {
}
}
InkWeb.goto = function (conf) {
if ( typeof(conf.from) == "string" )
conf.from = document.getElementById( conf.from );
if ( ! conf.to )
conf.to = conf.to ;
if ( typeof(toEl) == "string" )
toEl = document.getElementById( toEl );
toEl = document.getElementById( conf.to );
document.getElementsByTagName("svg")[0].viewBox.baseVal.x = toEl.getAttribute("x");
document.getElementsByTagName("svg")[0].viewBox.baseVal.y = toEl.getAttribute("y");
}
InkWeb.goto = function (conf) {
if ( typeof(conf.from) == "string" )
conf.from = document.getElementById( conf.from );
if ( ! conf.to )
conf.to = conf.to ;
if ( typeof(toEl) == "string" )
toEl = document.getElementById( toEl );
toEl = document.getElementById( conf.to );
document.getElementsByTagName("svg")[0].viewBox.baseVal.x = toEl.getAttribute("x");
document.getElementsByTagName("svg")[0].viewBox.baseVal.y = toEl.getAttribute("y");
}
InkWeb.setAtt = function (conf) {
if ( ! conf.el.join )
conf.to = [ conf.el ];
......@@ -216,6 +192,18 @@ InkWeb.moveElTo = function (startConf) {
}
}
InkWeb.moveViewbox = function (conf) {
if ( typeof(conf.from) == "string" )
conf.from = document.getElementById( conf.from );
if ( ! conf.to )
conf.to = conf.to ;
if ( typeof(toEl) == "string" )
toEl = document.getElementById( toEl );
toEl = document.getElementById( conf.to );
document.getElementsByTagName("svg")[0].viewBox.baseVal.x = toEl.getAttribute("x");
document.getElementsByTagName("svg")[0].viewBox.baseVal.y = toEl.getAttribute("y");
}
InkWeb.log = function () { /* if you need that, use the inkweb-debug.js too */ }
]]></script><defs id="defs33">
<marker inkscape:stockid="Arrow2Lstart" orient="auto" refY="0.0" refX="0.0" id="Arrow2Lstart" style="overflow:visible" inkscape:isstock="true">
......
......@@ -115,20 +115,6 @@ InkWeb.transmitAtt = function (conf) {
}
}
InkWeb.goto = function (conf) {
if ( typeof(conf.from) == "string" )
conf.from = document.getElementById( conf.from );
if ( ! conf.to )
conf.to = conf.to ;
if ( typeof(toEl) == "string" )
toEl = document.getElementById( toEl );
toEl = document.getElementById( conf.to );
console.log(toEl);
console.log(toEl.getAttribute("height"));
document.getElementsByTagName("svg")[0].viewBox.baseVal.x = toEl.getAttribute("x");
document.getElementsByTagName("svg")[0].viewBox.baseVal.y = toEl.getAttribute("y");
}
InkWeb.setAtt = function (conf) {
if ( ! conf.el.join )
conf.to = [ conf.el ];
......@@ -206,6 +192,18 @@ InkWeb.moveElTo = function (startConf) {
}
}
InkWeb.moveViewbox = function (conf) {
if ( typeof(conf.from) == "string" )
conf.from = document.getElementById( conf.from );
if ( ! conf.to )
conf.to = conf.to ;
if ( typeof(toEl) == "string" )
toEl = document.getElementById( toEl );
toEl = document.getElementById( conf.to );
document.getElementsByTagName("svg")[0].viewBox.baseVal.x = toEl.getAttribute("x");
document.getElementsByTagName("svg")[0].viewBox.baseVal.y = toEl.getAttribute("y");
}
InkWeb.log = function () { /* if you need that, use the inkweb-debug.js too */ }
]]></script><defs id="defs33">
<marker inkscape:stockid="Arrow2Lstart" orient="auto" refY="0.0" refX="0.0" id="Arrow2Lstart" style="overflow:visible" inkscape:isstock="true">
......
# coding=utf-8
from web_interactive_mockup import InkWebIMockup
from inkex.tester import ComparisonMixin, InkscapeExtensionTestMixin, TestCase
class TestInkWebInteractiveMockupBasic(ComparisonMixin, InkscapeExtensionTestMixin, TestCase):
effect_class = InkWebIMockup
comparisons = [('--id=p1', '--id=r3')]
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Interactive Mockup</_name>
<id>org.inkscape.webdesign.interactive_mockup</id>
<dependency type="executable" location="extensions">web_interactive_mockup.py</dependency>
<param name="tab" type="notebook">
<page name="Options" _gui-text="Options">
<param name="when" type="enum" _gui-text="When to transmit:">
<_item value="onclick">on click</_item>
<_item value="onfocusin">on focus</_item>
<_item value="onfocusout">on blur</_item>
<_item value="onactivate">on activate</_item>
<_item value="onmousedown">on mouse down</_item>
<_item value="onmouseup">on mouse up</_item>
<_item value="onmouseover">on mouse over</_item>
<_item value="onmousemove">on mouse move</_item>
<_item value="onmouseout">on mouse out</_item>
<_item value="onload">on element loaded</_item>
</param>
</page>
<page name="Help" _gui-text="Help">
<_param name="intro" type="description">This effect adds interaction in a viewer like a web browser.</_param>
<_param name="desc1" type="description">It creates a link effect by changing to viewbox from one position to another.</_param>
<_param name="desc2" type="description">When selecting object the last one is the one we jump to.</_param>
</page>
</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="Web design">
</submenu>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">web_interactive_mockup.py</command>
</script>
</inkscape-extension>
#!/usr/bin/env python
# Copyright (C) 2019 Gemy Cedric Activdesign.eu
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# local library
import inkwebeffect
import inkex
class InkWebIMockup(inkwebeffect.InkWebEffect):
def __init__(self):
super(InkWebIMockup, self).__init__()
self.arg_parser.add_argument("--when", type=str, dest="when", default="onclick",
help="Event that will trigger the action")
self.arg_parser.add_argument("--tab", type=str, dest="tab",
help="The selected UI-tab when OK was pressed")
def effect(self):
self.ensureInkWebSupport()
if len(self.options.ids) < 2:
raise inkex.AbortExtension("You must select at least two elements. The last one is the object you want to go to")
elFrom = []
for selId in self.options.ids[:-1]:
elFrom.append( self.svg.selected[selId] )
evCode = "InkWeb.moveViewbox({from:this, " + \
"to:'"+ self.options.ids[-1] +"'})" #+ \
elEvCode = ""
for el in elFrom:
prevEvCode = el.get( self.options.when )
if prevEvCode == None: prevEvCode = ""
elEvCode = evCode +";"+ prevEvCode
el.set( self.options.when, elEvCode )
if __name__ == '__main__':
e = InkWebIMockup().run()
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