added generate palette, inklin, simple frame
This commit is contained in:
parent
31724fc36e
commit
b4cd212908
12
extensions/fablabchemnitz/generate_palette/.editorconfig
Normal file
12
extensions/fablabchemnitz/generate_palette/.editorconfig
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
|
<name>Generate Palette</name>
|
||||||
|
<id>fablabchemnitz.de.generate_palette</id>
|
||||||
|
<label>Select a set of objects and create a custom color palette.</label>
|
||||||
|
<label appearance="header">Palette Properties</label>
|
||||||
|
<label>Palette Name</label>
|
||||||
|
<param name="name" type="string" gui-text=" " />
|
||||||
|
<vbox>
|
||||||
|
<param name="property" type="optiongroup" appearance="combo" gui-text="Color Property">
|
||||||
|
<option value="fill">Fill Color</option>
|
||||||
|
<option value="stroke">Stroke Color</option>
|
||||||
|
<option value="both">Both</option>
|
||||||
|
</param>
|
||||||
|
</vbox>
|
||||||
|
<label appearance="header">Options</label>
|
||||||
|
<param name="default" type="bool" gui-text="Include default grays">false</param>
|
||||||
|
<param name="replace" type="bool" gui-text="Replace existing palette">false</param>
|
||||||
|
<param name="sort" type="optiongroup" appearance="combo" gui-text="Sort colors">
|
||||||
|
<option value="selection">Selection / Z-index</option>
|
||||||
|
<option value="hsl">By HSL values</option>
|
||||||
|
<option value="rgb">By RGB values</option>
|
||||||
|
<option value="x_location">X Location</option>
|
||||||
|
<option value="y_location">Y Location</option>
|
||||||
|
</param>
|
||||||
|
<spacer />
|
||||||
|
<hbox>
|
||||||
|
<image>info.svg</image>
|
||||||
|
<label>Don't forget to restart Inkscape</label>
|
||||||
|
</hbox>
|
||||||
|
<effect needs-live-preview="false">
|
||||||
|
<object-type>all</object-type>
|
||||||
|
<effects-menu>
|
||||||
|
<submenu name="Palette" />
|
||||||
|
</effects-menu>
|
||||||
|
</effect>
|
||||||
|
<script>
|
||||||
|
<command location="inx" interpreter="python">generate_palette.py</command>
|
||||||
|
</script>
|
||||||
|
</inkscape-extension>
|
180
extensions/fablabchemnitz/generate_palette/generate_palette.py
Normal file
180
extensions/fablabchemnitz/generate_palette/generate_palette.py
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import inkex
|
||||||
|
|
||||||
|
def log(text):
|
||||||
|
inkex.utils.debug(text)
|
||||||
|
|
||||||
|
|
||||||
|
def abort(text):
|
||||||
|
inkex.errormsg(_(text))
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
|
class GeneratePalette(inkex.EffectExtension):
|
||||||
|
|
||||||
|
|
||||||
|
def add_arguments(self, pars):
|
||||||
|
pars.add_argument('--name', help='Palette name')
|
||||||
|
pars.add_argument('--property', help='Color property')
|
||||||
|
pars.add_argument('--default', type=inkex.Boolean, help='Default grays')
|
||||||
|
pars.add_argument('--sort', help='Sort type')
|
||||||
|
pars.add_argument('--replace', type=inkex.Boolean, dest='replace', help='Replace existing')
|
||||||
|
|
||||||
|
|
||||||
|
def get_palettes_path(self):
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
path = os.path.join(os.environ['APPDATA'], 'inkscape', 'palettes')
|
||||||
|
else:
|
||||||
|
path = os.environ.get('XDG_CONFIG_HOME', '~/.config')
|
||||||
|
path = os.path.join(path, 'inkscape', 'palettes')
|
||||||
|
|
||||||
|
return os.path.expanduser(path)
|
||||||
|
|
||||||
|
|
||||||
|
def get_file_path(self):
|
||||||
|
name = str(self.options.name).replace(' ', '-')
|
||||||
|
return "%s/%s.gpl" % (self.palettes_path, name)
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_colors(self):
|
||||||
|
colors = [
|
||||||
|
" 0 0 0 Black",
|
||||||
|
" 26 26 26 90% Gray",
|
||||||
|
" 51 51 51 80% Gray",
|
||||||
|
" 77 77 77 70% Gray",
|
||||||
|
"102 102 102 60% Gray",
|
||||||
|
"128 128 128 50% Gray",
|
||||||
|
"153 153 153 40% Gray",
|
||||||
|
"179 179 179 30% Gray",
|
||||||
|
"204 204 204 20% Gray",
|
||||||
|
"230 230 230 10% Gray",
|
||||||
|
"236 236 236 7.5% Gray",
|
||||||
|
"242 242 242 5% Gray",
|
||||||
|
"249 249 249 2.5% Gray",
|
||||||
|
"255 255 255 White"
|
||||||
|
]
|
||||||
|
|
||||||
|
return colors if self.options.default else []
|
||||||
|
|
||||||
|
|
||||||
|
def get_node_prop(self, node, property):
|
||||||
|
attr = node.attrib.get('style')
|
||||||
|
style = dict(inkex.Style.parse_str(attr))
|
||||||
|
|
||||||
|
return style.get(property, 'none')
|
||||||
|
|
||||||
|
|
||||||
|
def get_node_index(self, item):
|
||||||
|
node = item[1]
|
||||||
|
id = node.attrib.get('id')
|
||||||
|
|
||||||
|
return self.options.ids.index(id)
|
||||||
|
|
||||||
|
|
||||||
|
def get_node_x(self, item):
|
||||||
|
node = item[1]
|
||||||
|
return node.bounding_box().center_x
|
||||||
|
|
||||||
|
|
||||||
|
def get_node_y(self, item):
|
||||||
|
node = item[1]
|
||||||
|
return node.bounding_box().center_y
|
||||||
|
|
||||||
|
|
||||||
|
def get_formatted_color(self, color):
|
||||||
|
rgb = inkex.Color(color).to_rgb()
|
||||||
|
|
||||||
|
if self.options.sort == 'hsl':
|
||||||
|
key = inkex.Color(color).to_hsl()
|
||||||
|
key = "{:03d}{:03d}{:03d}".format(*key)
|
||||||
|
else:
|
||||||
|
key = "{:03d}{:03d}{:03d}".format(*rgb)
|
||||||
|
|
||||||
|
rgb = "{:3d} {:3d} {:3d}".format(*rgb)
|
||||||
|
color = str(color).upper()
|
||||||
|
name = str(inkex.Color(color).to_named()).upper()
|
||||||
|
|
||||||
|
if name != color:
|
||||||
|
name = "%s (%s)" % (name.capitalize(), color)
|
||||||
|
|
||||||
|
return "%s %s %s" % (key, rgb, name)
|
||||||
|
|
||||||
|
|
||||||
|
def get_selected_colors(self):
|
||||||
|
colors = []
|
||||||
|
selected = list(self.svg.selected.items())
|
||||||
|
|
||||||
|
if self.options.sort == 'y_location':
|
||||||
|
selected.sort(key=self.get_node_x)
|
||||||
|
selected.sort(key=self.get_node_y)
|
||||||
|
elif self.options.sort == 'x_location':
|
||||||
|
selected.sort(key=self.get_node_y)
|
||||||
|
selected.sort(key=self.get_node_x)
|
||||||
|
else:
|
||||||
|
selected.sort(key=self.get_node_index)
|
||||||
|
|
||||||
|
for id, node in selected:
|
||||||
|
if self.options.property in ['fill', 'both']:
|
||||||
|
fill = self.get_node_prop(node, 'fill')
|
||||||
|
|
||||||
|
if inkex.colors.is_color(fill):
|
||||||
|
if fill != 'none' and fill not in colors:
|
||||||
|
colors.append(fill)
|
||||||
|
|
||||||
|
if self.options.property in ['stroke', 'both']:
|
||||||
|
stroke = self.get_node_prop(node, 'stroke')
|
||||||
|
|
||||||
|
if inkex.colors.is_color(stroke):
|
||||||
|
if stroke != 'none' and stroke not in colors:
|
||||||
|
colors.append(stroke)
|
||||||
|
|
||||||
|
colors = list(map(self.get_formatted_color, colors))
|
||||||
|
|
||||||
|
if self.options.sort == 'hsl' or self.options.sort == 'rgb':
|
||||||
|
colors.sort()
|
||||||
|
|
||||||
|
return list(map(lambda x : x[11:], colors))
|
||||||
|
|
||||||
|
|
||||||
|
def write_palette(self):
|
||||||
|
file = open(self.file_path, 'w')
|
||||||
|
try:
|
||||||
|
file.write("GIMP Palette\n")
|
||||||
|
file.write("Name: %s\n" % self.options.name)
|
||||||
|
file.write("#\n# Generated with Inkscape Generate Palette\n#\n")
|
||||||
|
|
||||||
|
for color in self.default_colors:
|
||||||
|
file.write("%s\n" % color)
|
||||||
|
|
||||||
|
for color in self.selected_colors:
|
||||||
|
if color[:11] not in list(map(lambda x : x[:11], self.default_colors)):
|
||||||
|
file.write("%s\n" % color)
|
||||||
|
finally:
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
def effect(self):
|
||||||
|
self.palettes_path = self.get_palettes_path()
|
||||||
|
self.file_path = self.get_file_path()
|
||||||
|
self.default_colors = self.get_default_colors()
|
||||||
|
self.selected_colors = self.get_selected_colors()
|
||||||
|
|
||||||
|
if not self.options.replace and os.path.exists(self.file_path):
|
||||||
|
abort('Palette already exists!')
|
||||||
|
|
||||||
|
if not self.options.name:
|
||||||
|
abort('Please enter a palette name.')
|
||||||
|
|
||||||
|
if len(self.options.ids) < 2:
|
||||||
|
abort('Please select at least 2 objects.')
|
||||||
|
|
||||||
|
if not len(self.selected_colors):
|
||||||
|
abort('No colors found in selected objects!')
|
||||||
|
|
||||||
|
self.write_palette()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
GeneratePalette().run()
|
1
extensions/fablabchemnitz/generate_palette/info.svg
Normal file
1
extensions/fablabchemnitz/generate_palette/info.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg height="12" viewBox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg"><path d="m6 1c2.757 0 5 2.243 5 5s-2.243 5-5 5-5-2.243-5-5 2.243-5 5-5zm0-1c-3.3135 0-6 2.6865-6 6s2.6865 6 6 6 6-2.6865 6-6-2.6865-6-6-6zm-.0005 2.875c.345 0 .6255.28.6255.625s-.2805.625-.6255.625-.6245-.28-.6245-.625.2795-.625.6245-.625zm1.0005 6.125h-2v-.5c.242-.0895.5-.1005.5-.3675v-2.2335c0-.267-.258-.309-.5-.3985v-.5h1.5v3.1325c0 .2675.2585.279.5.3675z"/></svg>
|
After Width: | Height: | Size: 452 B |
421
extensions/fablabchemnitz/inklin/inklin.glade
Normal file
421
extensions/fablabchemnitz/inklin/inklin.glade
Normal file
@ -0,0 +1,421 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.22.2 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.0"/>
|
||||||
|
<object class="GtkAdjustment" id="0_to_200">
|
||||||
|
<property name="upper">200</property>
|
||||||
|
<property name="value">100</property>
|
||||||
|
<property name="step_increment">1</property>
|
||||||
|
<property name="page_increment">10</property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkAdjustment" id="1_to_50">
|
||||||
|
<property name="lower">3</property>
|
||||||
|
<property name="upper">50</property>
|
||||||
|
<property name="value">3</property>
|
||||||
|
<property name="step_increment">1</property>
|
||||||
|
<property name="page_increment">1</property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkTextBuffer" id="AboutText">
|
||||||
|
<property name="text" translatable="yes">Inklin - a collection of things I 'ave an inkling might be useful to someone.
|
||||||
|
|
||||||
|
https://inkscape.org/~inklinea/
|
||||||
|
|
||||||
|
https://inkscape.org/~bipper/</property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkAdjustment" id="arc_radius1_adjustment">
|
||||||
|
<property name="upper">500</property>
|
||||||
|
<property name="value">20</property>
|
||||||
|
<property name="step_increment">0.10000000000000001</property>
|
||||||
|
<property name="page_increment">0.10000000000000001</property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkAdjustment" id="arc_radius2_adjustment">
|
||||||
|
<property name="upper">500</property>
|
||||||
|
<property name="value">20</property>
|
||||||
|
<property name="step_increment">0.10000000000000001</property>
|
||||||
|
<property name="page_increment">0.10000000000000001</property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkAdjustment" id="deg_rotate">
|
||||||
|
<property name="upper">359</property>
|
||||||
|
<property name="step_increment">0.050000000000000003</property>
|
||||||
|
<property name="page_increment">0.10000000000000001</property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkWindow" id="main_window">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="resizable">False</property>
|
||||||
|
<property name="default_width">600</property>
|
||||||
|
<property name="default_height">600</property>
|
||||||
|
<property name="destroy_with_parent">True</property>
|
||||||
|
<child type="titlebar">
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkNotebook">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<signal name="destroy" handler="onDestroy" swapped="no"/>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCheckButton" id="arc_radius1_gtk_checkbutton">
|
||||||
|
<property name="label" translatable="yes">Arc Radius 1</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<signal name="activate" handler="arcRadiusCheckbuttonChange" swapped="no"/>
|
||||||
|
<signal name="clicked" handler="arcRadiusCheckbuttonChange" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScale" id="arc_radius2_gtk_scale">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="adjustment">arc_radius2_adjustment</property>
|
||||||
|
<property name="round_digits">1</property>
|
||||||
|
<signal name="value-changed" handler="onScaleChangeArcRadius" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">3</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScale" id="arc_radius1_gtk_scale">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="adjustment">arc_radius1_adjustment</property>
|
||||||
|
<property name="round_digits">1</property>
|
||||||
|
<signal name="value-changed" handler="onScaleChangeArcRadius" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCheckButton" id="arc_radius2_gtk_checkbutton">
|
||||||
|
<property name="label" translatable="yes">Arc Radius 2</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<signal name="activate" handler="arcRadiusCheckbuttonChange" swapped="no"/>
|
||||||
|
<signal name="clicked" handler="arcRadiusCheckbuttonChange" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScale" id="radius_gtk_scale">
|
||||||
|
<property name="name">Test Slider</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="adjustment">0_to_200</property>
|
||||||
|
<property name="round_digits">1</property>
|
||||||
|
<signal name="value-changed" handler="onScaleChangeRadius" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Radius</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Sectors</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScale" id="sectors_gtk_scale">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="adjustment">1_to_50</property>
|
||||||
|
<property name="round_digits">1</property>
|
||||||
|
<signal name="value-changed" handler="onScaleChangeSides" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCheckButton" id="arc_sweep_flag_gtk_checkbutton">
|
||||||
|
<property name="label" translatable="yes">Sweep Flag</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="tooltip_text" translatable="yes">Arc sweep flag</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<signal name="activate" handler="arcSweepFlagCheckbuttonChange" swapped="no"/>
|
||||||
|
<signal name="clicked" handler="arcSweepFlagCheckbuttonChange" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCheckButton" id="arc_large_flag_gtk_checkbutton">
|
||||||
|
<property name="label" translatable="yes">Large Flag</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="tooltip_text" translatable="yes">Arc large flag</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<signal name="activate" handler="arcLargeFlagCheckbuttonChange" swapped="no"/>
|
||||||
|
<signal name="clicked" handler="arcLargeFlagCheckbuttonChange" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCheckButton" id="point_circles_gtk_checkbutton">
|
||||||
|
<property name="label" translatable="yes">Point Circles</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="tooltip_text" translatable="yes">Draw a small circle at each vertex point</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<signal name="activate" handler="pointCirclesCheckbuttonChange" swapped="no"/>
|
||||||
|
<signal name="clicked" handler="pointCirclesCheckbuttonChange" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">4</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCheckButton" id="outer_circle_gtk_checkbutton">
|
||||||
|
<property name="label" translatable="yes">Outer Circle</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="tooltip_text" translatable="yes">Show the outer circle the vertices lie on</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<signal name="activate" handler="outerCircleCheckbuttonChange" swapped="no"/>
|
||||||
|
<signal name="clicked" handler="outerCircleCheckbuttonChange" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">3</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSeparator">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCheckButton" id="numbering_gtk_checkbutton">
|
||||||
|
<property name="label" translatable="yes">Numbering</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="tooltip_text" translatable="yes">Numbering of vertices</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<signal name="activate" handler="numberingCheckbuttonChange" swapped="no"/>
|
||||||
|
<signal name="clicked" handler="numberingCheckbuttonChange" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">5</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">2</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImage" id="preview_image">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="stock">gtk-ok</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">2</property>
|
||||||
|
<property name="width">3</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScale" id="arc_x_rotate_gtk_scale">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="adjustment">deg_rotate</property>
|
||||||
|
<property name="round_digits">1</property>
|
||||||
|
<signal name="value-changed" handler="onScaleChangeXRotate" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCheckButton" id="arc_x_rotate_gtk_checkbutton">
|
||||||
|
<property name="label" translatable="yes">x rotate</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<signal name="activate" handler="arcXRotateCheckbuttonChange" swapped="no"/>
|
||||||
|
<signal name="clicked" handler="arcXRotateCheckbuttonChange" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
<property name="width">4</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child type="tab">
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">PolyArcs</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="tab_fill">False</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkTextView" id="AboutTextView">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="margin_left">10</property>
|
||||||
|
<property name="margin_right">10</property>
|
||||||
|
<property name="margin_top">10</property>
|
||||||
|
<property name="margin_bottom">10</property>
|
||||||
|
<property name="pixels_above_lines">2</property>
|
||||||
|
<property name="pixels_below_lines">3</property>
|
||||||
|
<property name="left_margin">15</property>
|
||||||
|
<property name="right_margin">15</property>
|
||||||
|
<property name="top_margin">15</property>
|
||||||
|
<property name="bottom_margin">15</property>
|
||||||
|
<property name="buffer">AboutText</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child type="tab">
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">About</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="position">1</property>
|
||||||
|
<property name="tab_fill">False</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</interface>
|
16
extensions/fablabchemnitz/inklin/inklin.inx
Executable file
16
extensions/fablabchemnitz/inklin/inklin.inx
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
|
<name>Inklin</name>
|
||||||
|
<id>fablabchemnitz.de.inklin</id>
|
||||||
|
<effect implements-custom-gui="true">
|
||||||
|
<object-type>path</object-type>
|
||||||
|
<effects-menu>
|
||||||
|
<submenu name="FabLab Chemnitz">
|
||||||
|
<submenu name="Shape/Pattern from Generator"/>
|
||||||
|
</submenu>
|
||||||
|
</effects-menu>
|
||||||
|
</effect>
|
||||||
|
<script>
|
||||||
|
<command location="inx" interpreter="python">inklin.py</command>
|
||||||
|
</script>
|
||||||
|
</inkscape-extension>
|
251
extensions/fablabchemnitz/inklin/inklin.py
Normal file
251
extensions/fablabchemnitz/inklin/inklin.py
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# Copyright (C) [2021] [Matt Cottam], [mpcottam@raincloud.co.uk]
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Inklin - a collection of things I 'ave an inkling might be useful to someone.
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
import inkex
|
||||||
|
from inkex import Group
|
||||||
|
import random
|
||||||
|
from lxml import etree
|
||||||
|
import math
|
||||||
|
import gi
|
||||||
|
import io
|
||||||
|
|
||||||
|
gi.require_version("Gtk", "3.0")
|
||||||
|
from gi.repository import Gtk
|
||||||
|
from gi.repository import Gtk, GdkPixbuf, Gdk
|
||||||
|
from gi.repository.GdkPixbuf import Pixbuf, InterpType
|
||||||
|
|
||||||
|
|
||||||
|
def group_wrapper(self, my_objects):
|
||||||
|
group_id = 'g' + str(random.randrange(100000, 1000000))
|
||||||
|
|
||||||
|
new_group = self.svg.add(Group.new('#' + group_id))
|
||||||
|
# inkex set, takes account of NS attribs etc
|
||||||
|
new_group.set('inkscape:groupmode', 'layer')
|
||||||
|
new_group.set('inkscape:label', 'My_Layer_' + group_id)
|
||||||
|
|
||||||
|
for my_object in my_objects:
|
||||||
|
new_group.append(my_object)
|
||||||
|
|
||||||
|
new_group.attrib['id'] = group_id
|
||||||
|
|
||||||
|
|
||||||
|
def svg_arcs(cx, cy, radius, sectors, arc_radius1, arc_radius2, arc_x_rotate, arc_large_flag, arc_sweep_flag,
|
||||||
|
outer_circle_checkbutton_bool, point_circles_checkbutton_bool, numbering_checkbutton_bool):
|
||||||
|
|
||||||
|
x_start = cx
|
||||||
|
y_start = cy - radius
|
||||||
|
|
||||||
|
point_circles = ''
|
||||||
|
point_labels = ''
|
||||||
|
|
||||||
|
angle = 0
|
||||||
|
|
||||||
|
y_start = cy / 2 + (radius * (math.sin(angle)))
|
||||||
|
x_start = cx / 2 + (radius * (math.cos(angle)))
|
||||||
|
|
||||||
|
arcs = f'M {x_start} {y_start}'
|
||||||
|
|
||||||
|
for sector in range(1, sectors + 1):
|
||||||
|
angle = (sector * math.pi) / (sectors / 2)
|
||||||
|
|
||||||
|
y = cy / 2 + (radius * (math.sin(angle)))
|
||||||
|
x = cx / 2 + (radius * (math.cos(angle)))
|
||||||
|
|
||||||
|
x_start = x
|
||||||
|
y_start = y
|
||||||
|
|
||||||
|
|
||||||
|
# A rx ry x-axis-rotation large-arc-flag sweep-flag x y
|
||||||
|
|
||||||
|
arcs = arcs + f'A {arc_radius1} {arc_radius2} {arc_x_rotate} {arc_large_flag} {arc_sweep_flag} {x} {y} '
|
||||||
|
|
||||||
|
if not point_circles_checkbutton_bool:
|
||||||
|
point_circles = ''
|
||||||
|
else:
|
||||||
|
point_circles = point_circles + f'<circle fill="none" stroke="orange" stroke-width="1" r="{2}" cx="{x}" cy="{y}"/>'
|
||||||
|
|
||||||
|
if not numbering_checkbutton_bool:
|
||||||
|
None
|
||||||
|
else:
|
||||||
|
point_labels = point_labels + f'<text x="{x}" y="{y}">{sector}</text>'
|
||||||
|
|
||||||
|
if not outer_circle_checkbutton_bool:
|
||||||
|
outline_circle = ''
|
||||||
|
else:
|
||||||
|
outline_circle = f'<circle fill="none" stroke="green" stroke-width="1" r="{radius}" cx="{cx / 2}" cy="{cy / 2}"/>'
|
||||||
|
|
||||||
|
# svg = f'<svg width="{cx}" height="{cy}" viewBox="0 0 {cx} {cy}" ' \
|
||||||
|
svg = f'<svg width="{500}" height="{500}" viewBox="0 0 {500} {500}" ' \
|
||||||
|
f'xmlns="http://www.w3.org/2000/svg" ' \
|
||||||
|
f'xmlns:svg="http://www.w3.org/2000/svg" ' \
|
||||||
|
f'>' \
|
||||||
|
f'{outline_circle}' \
|
||||||
|
f'{point_circles}' \
|
||||||
|
f'{point_labels}' \
|
||||||
|
f'<path fill="none" stroke="black" d="{arcs} "/>' \
|
||||||
|
f'</svg>'
|
||||||
|
|
||||||
|
LoadSvg.master_svg = svg
|
||||||
|
|
||||||
|
gtk3_add_svg_image(svg)
|
||||||
|
|
||||||
|
|
||||||
|
def gtk3_add_svg_image(svg):
|
||||||
|
loader = GdkPixbuf.PixbufLoader()
|
||||||
|
loader.write(svg.encode())
|
||||||
|
loader.close()
|
||||||
|
pixbuf = loader.get_pixbuf()
|
||||||
|
|
||||||
|
# pixbuf = pixbuf.scale_simple(500, 500, InterpType.BILINEAR)
|
||||||
|
|
||||||
|
LoadSvg.preview_image.set_from_pixbuf(pixbuf)
|
||||||
|
|
||||||
|
LoadSvg.preview_image.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def init_arc():
|
||||||
|
radius = LoadSvg.builder.get_object('radius_gtk_scale').get_value()
|
||||||
|
arc_radius1 = LoadSvg.builder.get_object('arc_radius1_gtk_scale').get_value()
|
||||||
|
arc_radius2 = LoadSvg.builder.get_object('arc_radius2_gtk_scale').get_value()
|
||||||
|
arc_x_rotate_checkbutton1_bool = LoadSvg.builder.get_object('arc_x_rotate_gtk_checkbutton').get_active()
|
||||||
|
arc_radius_checkbutton1_bool = LoadSvg.builder.get_object('arc_radius1_gtk_checkbutton').get_active()
|
||||||
|
arc_radius_checkbutton2_bool = LoadSvg.builder.get_object('arc_radius2_gtk_checkbutton').get_active()
|
||||||
|
sectors = int(LoadSvg.builder.get_object('sectors_gtk_scale').get_value())
|
||||||
|
arc_large_flag = LoadSvg.builder.get_object('arc_large_flag_gtk_checkbutton').get_active()
|
||||||
|
arc_sweep_flag = LoadSvg.builder.get_object('arc_sweep_flag_gtk_checkbutton').get_active()
|
||||||
|
|
||||||
|
outer_circle_checkbutton_bool = LoadSvg.builder.get_object('outer_circle_gtk_checkbutton').get_active()
|
||||||
|
point_circles_checkbutton_bool = LoadSvg.builder.get_object('point_circles_gtk_checkbutton').get_active()
|
||||||
|
numbering_checkbutton_bool = LoadSvg.builder.get_object('numbering_gtk_checkbutton').get_active()
|
||||||
|
|
||||||
|
if not arc_radius_checkbutton1_bool:
|
||||||
|
arc_radius1 = radius
|
||||||
|
LoadSvg.builder.get_object('arc_radius1_gtk_scale').set_value(radius)
|
||||||
|
|
||||||
|
if not arc_radius_checkbutton2_bool:
|
||||||
|
arc_radius2 = radius
|
||||||
|
LoadSvg.builder.get_object('arc_radius2_gtk_scale').set_value(radius)
|
||||||
|
|
||||||
|
if not arc_x_rotate_checkbutton1_bool:
|
||||||
|
arc_x_rotate = 0
|
||||||
|
else:
|
||||||
|
arc_x_rotate = LoadSvg.builder.get_object('arc_x_rotate_gtk_scale').get_value()
|
||||||
|
|
||||||
|
if not arc_sweep_flag:
|
||||||
|
arc_sweep_flag = 0
|
||||||
|
else:
|
||||||
|
arc_sweep_flag = 1
|
||||||
|
|
||||||
|
if not arc_large_flag:
|
||||||
|
arc_large_flag = 0
|
||||||
|
else:
|
||||||
|
arc_large_flag = 1
|
||||||
|
|
||||||
|
|
||||||
|
svg_arcs(500, 500, radius, sectors, arc_radius1, arc_radius2, arc_x_rotate, arc_large_flag, arc_sweep_flag, outer_circle_checkbutton_bool, point_circles_checkbutton_bool, numbering_checkbutton_bool)
|
||||||
|
|
||||||
|
# inkex.errormsg(f'arc1 {arc_radius_checkbutton1_bool} arc2 {arc_radius_checkbutton2_bool}')
|
||||||
|
|
||||||
|
|
||||||
|
########################################################
|
||||||
|
# Gtk Section #
|
||||||
|
########################################################
|
||||||
|
|
||||||
|
class Handler:
|
||||||
|
def onDestroy(self, *args):
|
||||||
|
Gtk.main_quit()
|
||||||
|
|
||||||
|
def onButtonPressed(self, button):
|
||||||
|
print("Hello World!")
|
||||||
|
|
||||||
|
# def arcButtonPressed(self, button):
|
||||||
|
# svg_arcs(500, 500, 50, 8)
|
||||||
|
# test_print()
|
||||||
|
|
||||||
|
def onScaleChangeRadius(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def onScaleChangeSides(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def onScaleChangeArcRadius(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def arcRadiusCheckbuttonChange(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def onScaleChangeXRotate(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def arcXRotateCheckbuttonChange(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def arcSweepFlagCheckbuttonChange(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def arcLargeFlagCheckbuttonChange(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def outerCircleCheckbuttonChange(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def pointCirclesCheckbuttonChange(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
def numberingCheckbuttonChange(self, scale):
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
|
||||||
|
def run_gtk():
|
||||||
|
LoadSvg.builder = Gtk.Builder()
|
||||||
|
LoadSvg.builder.add_from_file("inklin.glade")
|
||||||
|
LoadSvg.builder.connect_signals(Handler())
|
||||||
|
|
||||||
|
LoadSvg.window = LoadSvg.builder.get_object("main_window")
|
||||||
|
LoadSvg.window.show_all()
|
||||||
|
LoadSvg.window.set_title('Inklin')
|
||||||
|
|
||||||
|
LoadSvg.preview_image = LoadSvg.builder.get_object('preview_image')
|
||||||
|
|
||||||
|
init_arc()
|
||||||
|
|
||||||
|
Gtk.main()
|
||||||
|
|
||||||
|
|
||||||
|
########################################################
|
||||||
|
# Inkex effect section #
|
||||||
|
########################################################
|
||||||
|
|
||||||
|
class LoadSvg(inkex.EffectExtension):
|
||||||
|
|
||||||
|
def effect(self):
|
||||||
|
run_gtk()
|
||||||
|
|
||||||
|
svg_etree = etree.fromstring(LoadSvg.master_svg)
|
||||||
|
|
||||||
|
group_wrapper(self, svg_etree)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
LoadSvg().run()
|
23
extensions/fablabchemnitz/simple_frame/simple_frame.inx
Normal file
23
extensions/fablabchemnitz/simple_frame/simple_frame.inx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
|
<name>Simple Frame</name>
|
||||||
|
<id>fablabchemnitz.de.simple_frame</id>
|
||||||
|
<param name="unit" gui-text="Unit:" type="optiongroup" appearance="combo">
|
||||||
|
<option value="mm">mm</option>
|
||||||
|
</param>
|
||||||
|
<param name="width" type="float" min="0.1" max="300.0" gui-text="Inner width:">100.0</param>
|
||||||
|
<param name="height" type="float" min="0.1" max="300.0" gui-text="Inner height:">150.0</param>
|
||||||
|
<param name="depth" type="float" min="0.1" max="300.0" gui-text="Depth">10.0</param>
|
||||||
|
<param name="border" type="float" min="0.1" max="300.0" gui-text="Frame border width">20.0</param>
|
||||||
|
<effect>
|
||||||
|
<object-type>all</object-type>
|
||||||
|
<effects-menu>
|
||||||
|
<submenu name="FabLab Chemnitz">
|
||||||
|
<submenu name="Paper/Cardboard Boxes"/>
|
||||||
|
</submenu>
|
||||||
|
</effects-menu>
|
||||||
|
</effect>
|
||||||
|
<script>
|
||||||
|
<command location="inx" interpreter="python">simple_frame.py</command>
|
||||||
|
</script>
|
||||||
|
</inkscape-extension>
|
272
extensions/fablabchemnitz/simple_frame/simple_frame.py
Normal file
272
extensions/fablabchemnitz/simple_frame/simple_frame.py
Normal file
@ -0,0 +1,272 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
|
#
|
||||||
|
# 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 3 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
__version__ = "0.1"
|
||||||
|
|
||||||
|
import inkex
|
||||||
|
import math
|
||||||
|
|
||||||
|
class GenerateFrame(inkex.EffectExtension):
|
||||||
|
|
||||||
|
def add_arguments(self, pars):
|
||||||
|
pars.add_argument("--width", type=float, default=100.0, help="Inner width")
|
||||||
|
pars.add_argument("--height", type=float, default=150.0, help="Inner height")
|
||||||
|
pars.add_argument("--depth", type=float, default=10.0, help="Frame depth")
|
||||||
|
pars.add_argument("--border", type=float, default=20.0, help="Frame border width")
|
||||||
|
pars.add_argument("--unit", default="mm", help="Unit of measure")
|
||||||
|
|
||||||
|
def effect(self):
|
||||||
|
center_x = self.svg.unittouu(self.document.getroot().get('width'))/2
|
||||||
|
center_y = self.svg.unittouu(self.document.getroot().get('height'))/2
|
||||||
|
|
||||||
|
_width = self.svg.unittouu(str(self.options.width) + self.options.unit)
|
||||||
|
_height = self.svg.unittouu(str(self.options.height) + self.options.unit)
|
||||||
|
_depth = self.svg.unittouu(str(self.options.depth) + self.options.unit)
|
||||||
|
|
||||||
|
_border = self.svg.unittouu(str(self.options.border) + self.options.unit)
|
||||||
|
_border_hyp = math.sqrt(2 * _border * _border)
|
||||||
|
|
||||||
|
id_frame = self.svg.get_unique_id('papercraft-frame')
|
||||||
|
group = self.svg.get_current_layer().add(inkex.Group(id=id_frame))
|
||||||
|
id_score = self.svg.get_unique_id('papercraft-scores')
|
||||||
|
score_group = group.add(inkex.Group(id=id_score))
|
||||||
|
cut_line = {'stroke': '#FF0000', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px'))}
|
||||||
|
safe_line = {'stroke': '#0000FF', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px'))}
|
||||||
|
valley_score_line = {'stroke': '#00FF00', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px')), 'stroke-dasharray': '1.05999995,0.52999997,0.26499999,0.52999997'}
|
||||||
|
mountain_score_line = {'stroke': '#00FF00', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px')), 'stroke-dasharray': '5,5'}
|
||||||
|
|
||||||
|
# line.path --> M = absolute coordinates
|
||||||
|
# line.path --> l = draws a line from the current point to the specified relative coordinates
|
||||||
|
# line.path --> c = draws a beizer curve from the current point to the specified coordinates
|
||||||
|
# line.path --> q = draw an arc from the current point to the specified coordinates using a point as reference
|
||||||
|
# line.path --> Z = close path
|
||||||
|
|
||||||
|
# outer profile (cut)
|
||||||
|
line = group.add(inkex.PathElement(id=id_frame + '-outer-profile'))
|
||||||
|
line.path = [
|
||||||
|
# top-left
|
||||||
|
['M', [0, 2 * (_border+_depth)]],
|
||||||
|
['l', [_border+_depth+_border,0]],
|
||||||
|
['l', [0,-_depth]],
|
||||||
|
['l', [_depth,0]],
|
||||||
|
['l', [_border,-_border]],
|
||||||
|
['l', [0,-_depth]],
|
||||||
|
['l', [-_border,-_border]],
|
||||||
|
['l', [_width+2*_border,0]],
|
||||||
|
|
||||||
|
# top-right
|
||||||
|
['l', [-_border,_border]],
|
||||||
|
['l', [0,_depth]],
|
||||||
|
['l', [_border,_border]],
|
||||||
|
['l', [_depth,0]],
|
||||||
|
['l', [0,_depth]],
|
||||||
|
['l', [_border+_depth+_border,0]],
|
||||||
|
['l', [0,_height+2*_border]],
|
||||||
|
|
||||||
|
# bottom-right
|
||||||
|
['l', [-(_border+_depth+_border),0]],
|
||||||
|
['l', [0,_depth]],
|
||||||
|
['l', [-_depth,0]],
|
||||||
|
['l', [-_border,_border]],
|
||||||
|
['l', [0,_depth]],
|
||||||
|
['l', [_border,_border]],
|
||||||
|
['l', [-(_width+2*_border),0]],
|
||||||
|
|
||||||
|
# bottom-left
|
||||||
|
['l', [_border,-_border]],
|
||||||
|
['l', [0,-_depth]],
|
||||||
|
['l', [-_border,-_border]],
|
||||||
|
['l', [-_depth,0]],
|
||||||
|
['l', [0,-_depth]],
|
||||||
|
['l', [-(_border+_depth+_border),0]],
|
||||||
|
|
||||||
|
['Z', []]
|
||||||
|
]
|
||||||
|
line.style = cut_line
|
||||||
|
|
||||||
|
line = group.add(inkex.PathElement(id=id_frame + '-inner-profile'))
|
||||||
|
line.path = [
|
||||||
|
['M', [2*_depth+3*_border, 2*_depth+3*_border]],
|
||||||
|
['l', [_width,0]],
|
||||||
|
['l', [0,_height]],
|
||||||
|
['l', [-_width,0]],
|
||||||
|
['Z', []]
|
||||||
|
]
|
||||||
|
line.style = safe_line
|
||||||
|
|
||||||
|
# score lines -- vertical
|
||||||
|
_top_edge = 2 *_border+2*_depth
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-1'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_border, _top_edge]],
|
||||||
|
['l', [0, _height+2*_border]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-2'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_border+_depth, _top_edge]],
|
||||||
|
['l', [0, _height+2*_border]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-3'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_border+_depth+_border, _top_edge]],
|
||||||
|
['l', [0, _height+2*_border]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-4'))
|
||||||
|
line.path = [
|
||||||
|
['M', [2*(_border+_depth), _top_edge-_depth]],
|
||||||
|
['l', [0, _height+2*_border+2*_depth]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
_right_side = _width+4*_border+2*_depth
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-5'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_right_side, _top_edge-_depth]],
|
||||||
|
['l', [0, _height+2*_border+2*_depth]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-6'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_right_side+_depth, _top_edge]],
|
||||||
|
['l', [0, _height+2*_border]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-7'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_right_side+_border+_depth, _top_edge]],
|
||||||
|
['l', [0, _height+2*_border]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-8'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_right_side+_border+_depth+_depth, _top_edge]],
|
||||||
|
['l', [0, _height+2*_border]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
# corners
|
||||||
|
_o1_x = 2*_border + _depth
|
||||||
|
_o1_y = _o1_x + _depth
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-22'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_o1_x+_depth, _o1_y]],
|
||||||
|
['l', [-_depth,-_depth]],
|
||||||
|
]
|
||||||
|
line.style = mountain_score_line
|
||||||
|
|
||||||
|
_o2_x = _o1_x + _width + 2*_border + 2*_depth
|
||||||
|
_o2_y = _o1_y
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-24'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_o2_x-_depth, _o2_y]],
|
||||||
|
['l', [_depth,-_depth]],
|
||||||
|
]
|
||||||
|
line.style = mountain_score_line
|
||||||
|
|
||||||
|
_o3_x = _o1_x
|
||||||
|
_o3_y = _o1_y + _height + 2*_border
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-26'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_o3_x + _depth, _o3_y]],
|
||||||
|
['l', [-_depth,_depth]],
|
||||||
|
]
|
||||||
|
line.style = mountain_score_line
|
||||||
|
|
||||||
|
_o4_x = _o2_x
|
||||||
|
_o4_y = _o3_y
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-28'))
|
||||||
|
line.path = [
|
||||||
|
['M', [_o4_x - _depth, _o4_y]],
|
||||||
|
['l', [_depth,_depth]],
|
||||||
|
]
|
||||||
|
line.style = mountain_score_line
|
||||||
|
|
||||||
|
# horizontals
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-31'))
|
||||||
|
line.path = [
|
||||||
|
['M', [2*_border+_depth, 2*_border+2*_depth]],
|
||||||
|
['l', [_width+2*_border+2*_depth,0]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-32'))
|
||||||
|
line.path = [
|
||||||
|
['M', [2*_border+2*_depth, 2*_border+_depth]],
|
||||||
|
['l', [_width+2*_border,0]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-33'))
|
||||||
|
line.path = [
|
||||||
|
['M', [3*_border+2*_depth, _border+_depth]],
|
||||||
|
['l', [_width,0]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-34'))
|
||||||
|
line.path = [
|
||||||
|
['M', [3*_border+2*_depth, _border]],
|
||||||
|
['l', [_width,0]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
_bottom = _height + 4*_border+2*_depth
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-35'))
|
||||||
|
line.path = [
|
||||||
|
['M', [2*_border+_depth, _bottom]],
|
||||||
|
['l', [_width+2*_border+2*_depth,0]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-36'))
|
||||||
|
line.path = [
|
||||||
|
['M', [2*_border+2*_depth, _bottom+_depth]],
|
||||||
|
['l', [_width+2*_border,0]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-37'))
|
||||||
|
line.path = [
|
||||||
|
['M', [3*_border+2*_depth, _bottom+_border+_depth]],
|
||||||
|
['l', [_width,0]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
line = score_group.add(inkex.PathElement(id=id_score + '-score-38'))
|
||||||
|
line.path = [
|
||||||
|
['M', [3*_border+2*_depth, _bottom+_border+2*_depth]],
|
||||||
|
['l', [_width,0]],
|
||||||
|
]
|
||||||
|
line.style = valley_score_line
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
GenerateFrame().run()
|
@ -3,7 +3,7 @@
|
|||||||
<name>Selected columns width</name>
|
<name>Selected columns width</name>
|
||||||
<id>fablabchemnitz.de.table_edit_columns</id>
|
<id>fablabchemnitz.de.table_edit_columns</id>
|
||||||
<param name="width" type="string" gui-text="Input the new width:">10mm</param>
|
<param name="width" type="string" gui-text="Input the new width:">10mm</param>
|
||||||
<!--param name="keep" type="boolean" gui-text="Keep the table original height">false</param-->
|
<!--param name="keep" type="bool" gui-text="Keep the table original height">false</param-->
|
||||||
<effect>
|
<effect>
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<name>Selected rows height</name>
|
<name>Selected rows height</name>
|
||||||
<id>fablabchemnitz.de.table_edit_rows</id>
|
<id>fablabchemnitz.de.table_edit_rows</id>
|
||||||
<param name="height" type="string" gui-text="Input the new height:">10mm</param>
|
<param name="height" type="string" gui-text="Input the new height:">10mm</param>
|
||||||
<!--param name="keep" type="boolean" gui-text="Keep the table original height">false</param-->
|
<!--param name="keep" type="bool" gui-text="Keep the table original height">false</param-->
|
||||||
<effect>
|
<effect>
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
<name>Selected table width and height</name>
|
<name>Selected table width and height</name>
|
||||||
<id>fablabchemnitz.de.table_edit_table</id>
|
<id>fablabchemnitz.de.table_edit_table</id>
|
||||||
<dependency type="executable" location="extensions">table_edit_table.py</dependency>
|
|
||||||
<param name="width" type="string" gui-text="Input the new width of the table:">150mm</param>
|
<param name="width" type="string" gui-text="Input the new width of the table:">150mm</param>
|
||||||
<param name="height" type="string" gui-text="Input the new height of the table:">60mm</param>
|
<param name="height" type="string" gui-text="Input the new height of the table:">60mm</param>
|
||||||
<!--param name="keep" type="boolean" gui-text="Keep the table original height">false</param-->
|
<!--param name="keep" type="bool" gui-text="Keep the table original height">false</param-->
|
||||||
<effect>
|
<effect>
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
|
Reference in New Issue
Block a user