scrap code for combining grids, will fix when design is fleshed out more

main
Howard DaCosta 2021-11-17 20:48:48 -05:00
rodzic dc8d9f86f2
commit 34f70c9aec
2 zmienionych plików z 65 dodań i 16 usunięć

Wyświetl plik

@ -1,41 +1,83 @@
from .base import InkstitchExtension
import json
import os
import sys
from base64 import b64decode
from argparse import ArgumentParser, REMAINDER
import appdirs
import inkex
from inkex import Line, Rectangle, Path
from inkex import Line, Rectangle, Path, Polyline, PathElement
import wx
import wx.adv
from lxml import etree
from ..elements import nodes_to_elements
from ..gui import PresetsPanel, SimulatorPreview, info_dialog
from ..i18n import _
from ..lettering import Font, FontError
from ..svg import get_correction_transform
from ..svg.tags import (INKSCAPE_LABEL, INKSTITCH_LETTERING, SVG_GROUP_TAG,
SVG_PATH_TAG)
from ..utils import DotDict, cache, get_bundled_dir, get_resource_dir
from .commands import CommandsExtension
from .lettering_custom_font_dir import get_custom_font_dir
from .create_grid import BoundingBoxMetadata
class CombineGridsFrame(wx.Frame):
DEFAULT_FONT = "small_font"
def __init__(self, shape1, shape2, svg, *args, **kwargs):
if sys.platform.startswith('win32'):
import locale
locale.setlocale(locale.LC_ALL, "C")
lc = wx.Locale()
lc.Init(wx.LANGUAGE_DEFAULT)
pass
class CombineGrids(InkstitchExtension):
COMMANDS = ["combine_grids"]
def __init__(self, *args, **kwargs):
self.cancelled = False
InkstitchExtension.__init__(self, *args, **kwargs)
for command in self.COMMANDS:
self.arg_parser.add_argument("--%s" % command, type=inkex.Boolean)
self.arg_parser.add_argument("--alignment")
args, _ = self.arg_parser.parse_known_args()
inkex.errormsg("args:{}".format(args.alignment))
self.is_horizontal_connection = True if args.alignment == 1 else False
self.wires = []
self.wire_rectangles = []
def cancel(self):
self.cancelled = True
def connect_horizontally(self):
rect1, rect2 = self.wire_rectangles
if not rect1.is_horizontally_aligned(rect2):
inkex.errormsg("Unable to horizontally connect the two objects.")
return
leftmost_rectangle = None
letmost_wire = None
other_rectangle = None
other_wire = None
if rect1.left < rect2.left:
leftmost_rectangle = rect1
letmost_wire = self.wires[0]
other_rectangle = rect2
other_wire = self.wires[1]
else:
leftmost_rectangle = rect2
letmost_wire = self.wires[1]
other_rectangle = rect1
other_wire = self.wires[0]
def effect(self):
pass
for elem in self.svg.get_selected():
# inkex.errormsg("things selected:{}".format(len(self.svg.get_selected())))
inkex.errormsg("type of elem:{}".format(type(elem)))
# have to separate shapes and wires here!
wire_points = [p for p in elem.path.end_points]
if type(elem) == Polyline:
self.wires.append(wire_points)
self.wire_rectangles.append(elem.bounding_box())
if len(self.wires) != 2:
inkex.errormsg("Please select only two wires to combine!")
return
if self.is_horizontal_connection:
if __name__ == '__main__':

Wyświetl plik

@ -11,6 +11,13 @@
</submenu>
</effects-menu>
</effect>
<param name="description" type="description">
This extension will try to combine wires together.
</param>
<param name="alignment" type="optiongroup" gui-text="Method">
<option value="0">Vertical</option>
<option value="1">Horizontal</option>
</param>
<script>
{{ command_tag | safe }}
</script>