Skip to content

Commit

Permalink
Stop importing enum from scc.lib, please fix CI?
Browse files Browse the repository at this point in the history
  • Loading branch information
C0rn3j committed Sep 17, 2024
1 parent fe95d44 commit 7f4598d
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 144 deletions.
121 changes: 60 additions & 61 deletions generate_svg.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/usr/bin/env python3
from scc.tools import _
import os
from enum import IntEnum

from scc.actions import Action, DPadAction, XYAction, MouseAction
from scc.modifiers import ModeModifier, DoubleclickModifier
from scc.special_actions import MenuAction
from scc.parser import TalkingActionParser
from scc.actions import Action, DPadAction, MouseAction, XYAction
from scc.constants import SCButtons
from scc.gui.svg_widget import SVGEditor
from scc.modifiers import DoubleclickModifier, ModeModifier
from scc.parser import TalkingActionParser
from scc.profile import Profile
from scc.tools import nameof
from scc.special_actions import MenuAction
from scc.tools import _, nameof
from scc.uinput import Rels
from scc.gui.svg_widget import SVGEditor
from scc.lib import IntEnum
import os


class Align(IntEnum):
Expand All @@ -30,33 +29,33 @@ def find_image(name):


class Line(object):

def __init__(self, icon, text):
self.icons = [ icon ]
self.text = text


def get_size(self, gen):
# TODO: This
return gen.char_width * len(self.text), gen.line_height


def add_icon(self, icon):
self.icons.append(icon)
return self


def to_string(self):
return "%-10s: %s" % (",".join([ x for x in self.icons if x ]), self.text)


class LineCollection(object):
""" Allows calling add_icon on multiple lines at once """

def __init__(self, *lines):
self.lines = lines


def add_icon(self, icon):
for line in self.lines:
line.add_icon(icon)
Expand All @@ -68,7 +67,7 @@ class Box(object):
SPACING = 2
MIN_WIDTH = 100
MIN_HEIGHT = 50

def __init__(self, anchor_x, anchor_y, align, name,
min_width = MIN_WIDTH, min_height = MIN_HEIGHT):
self.name = name
Expand All @@ -79,15 +78,15 @@ def __init__(self, anchor_x, anchor_y, align, name,
self.x, self.y = 0, 0
self.min_width = min_width
self.min_height = min_height


def to_string(self):
return "--- %s ---\n%s\n" % (
self.name,
"\n".join([ x.to_string() for x in self.lines ])
)


def add(self, icon, context, action):
if not action: return LineCollection()
if isinstance(action, ModeModifier):
Expand All @@ -107,7 +106,7 @@ def add(self, icon, context, action):
lines.append( self.add("HOLD", context, action.holdaction)
.add_icon(icon) )
return LineCollection(*lines)

action = action.strip()
if isinstance(action, MenuAction):
if self.name == "bcs" and action.menu_id == "Default.menu":
Expand All @@ -127,16 +126,16 @@ def add(self, icon, context, action):
# Special case, pad bound to wheel
line = Line(icon, _("Mouse Wheel"))
self.lines.append(line)
return line
return line
return LineCollection(
self.add("AXISX", Action.AC_BUTTON, action.x),
self.add("AXISY", Action.AC_BUTTON, action.y)
)
line = Line(icon, action.describe(context))
self.lines.append(line)
return line


def calculate(self, gen):
self.width, self.height = self.min_width, 2 * self.PADDING
self.icount = 0
Expand All @@ -146,23 +145,23 @@ def calculate(self, gen):
self.icount = max(self.icount, len(line.icons))
self.width += 2 * self.PADDING + self.icount * (gen.line_height + self.SPACING)
self.height = max(self.height, self.min_height)

anchor_x, anchor_y = self.anchor
if (self.align & Align.TOP) != 0:
self.y = anchor_y
elif (self.align & Align.BOTTOM) != 0:
self.y = gen.full_height - self.height - anchor_y
else:
self.y = (gen.full_height - self.height) / 2

if (self.align & Align.LEFT) != 0:
self.x = anchor_x
elif (self.align & Align.RIGHT) != 0:
self.x = gen.full_width - self.width - anchor_x
else:
self.x = (gen.full_width - self.width) / 2


def place(self, gen, root):
e = SVGEditor.add_element(root, "rect",
style = "opacity:1;fill-opacity:0.0;stroke-width:2.0;",
Expand All @@ -172,7 +171,7 @@ def place(self, gen, root):
width = self.width, height = self.height,
x = self.x, y = self.y,
)

y = self.y + self.PADDING
for line in self.lines:
h = gen.line_height
Expand All @@ -191,8 +190,8 @@ def place(self, gen, root):
)
SVGEditor.set_text(txt, line.text)
y += self.SPACING


def place_marker(self, gen, root):
x1, y1 = self.x, self.y
x2, y2 = x1 + self.width, y1 + self.height
Expand All @@ -213,7 +212,7 @@ def place_marker(self, gen, root):
edges = [ [ x2, y1 ], [ x2, y2 ] ]
elif self.align & Align.RIGHT != 0:
edges = [ [ x1, y1 ], [ x2, y2 ] ]

targets = SVGEditor.get_element(root, "markers_%s" % (self.name,))
if targets is None:
return
Expand All @@ -226,7 +225,7 @@ def place_marker(self, gen, root):
except IndexError:
break
edges = [ i for i in edges if len(i) == 4]

for x1, y1, x2, y2 in edges:
e = SVGEditor.add_element(root, "line",
style = "opacity:1;stroke:#06a400;stroke-width:0.5;",
Expand All @@ -238,7 +237,7 @@ def place_marker(self, gen, root):

class Generator(object):
PADDING = 10

def __init__(self):
svg = SVGEditor(file("images/binding-display.svg").read())
background = SVGEditor.get_element(svg, "background")
Expand All @@ -247,18 +246,18 @@ def __init__(self):
self.char_width = int(float(self.label_template.attrib.get("width") or 8))
self.full_width = int(float(background.attrib.get("width") or 800))
self.full_height = int(float(background.attrib.get("height") or 800))

profile = Profile(TalkingActionParser()).load("test.sccprofile")
boxes = []


box_bcs = Box(0, self.PADDING, Align.TOP, "bcs")
box_bcs.add("BACK", Action.AC_BUTTON, profile.buttons.get(SCButtons.BACK))
box_bcs.add("C", Action.AC_BUTTON, profile.buttons.get(SCButtons.C))
box_bcs.add("START", Action.AC_BUTTON, profile.buttons.get(SCButtons.START))
boxes.append(box_bcs)


box_left = Box(self.PADDING, self.PADDING, Align.LEFT | Align.TOP, "left",
min_height = self.full_height * 0.5,
min_width = self.full_width * 0.2)
Expand All @@ -267,8 +266,8 @@ def __init__(self):
box_left.add("LGRIP", Action.AC_BUTTON, profile.buttons.get(SCButtons.LGRIP))
box_left.add("LPAD", Action.AC_PAD, profile.pads.get(profile.LEFT))
boxes.append(box_left)


box_right = Box(self.PADDING, self.PADDING, Align.RIGHT | Align.TOP, "right",
min_height = self.full_height * 0.5,
min_width = self.full_width * 0.2)
Expand All @@ -277,47 +276,47 @@ def __init__(self):
box_right.add("RGRIP", Action.AC_BUTTON, profile.buttons.get(SCButtons.RGRIP))
box_right.add("RPAD", Action.AC_PAD, profile.pads.get(profile.RIGHT))
boxes.append(box_right)


box_abxy = Box(4 * self.PADDING, self.PADDING, Align.RIGHT | Align.BOTTOM, "abxy")
box_abxy.add("A", Action.AC_BUTTON, profile.buttons.get(SCButtons.A))
box_abxy.add("B", Action.AC_BUTTON, profile.buttons.get(SCButtons.B))
box_abxy.add("X", Action.AC_BUTTON, profile.buttons.get(SCButtons.X))
box_abxy.add("Y", Action.AC_BUTTON, profile.buttons.get(SCButtons.Y))
boxes.append(box_abxy)


box_stick = Box(4 * self.PADDING, self.PADDING, Align.LEFT | Align.BOTTOM, "stick")
box_stick.add("STICK", Action.AC_STICK, profile.stick)
boxes.append(box_stick)


w = int(float(background.attrib.get("width") or 800))
h = int(float(background.attrib.get("height") or 800))

root = SVGEditor.get_element(svg, "root")
for b in boxes:
b.calculate(self)

# Set ABXY and Stick size & position
box_abxy.height = box_stick.height = self.full_height * 0.25
box_abxy.width = box_stick.width = self.full_width * 0.3
box_abxy.y = self.full_height - self.PADDING - box_abxy.height
box_stick.y = self.full_height - self.PADDING - box_stick.height
box_abxy.x = self.full_width - self.PADDING - box_abxy.width

self.equal_width(box_left, box_right)
self.equal_height(box_left, box_right)

for b in boxes:
b.place_marker(self, root)
for b in boxes:
b.place(self, root)

file("out.svg", "w").write(svg.to_string())



def equal_width(self, *boxes):
""" Sets width of all passed boxes to width of widest box """
width = 0
Expand All @@ -326,8 +325,8 @@ def equal_width(self, *boxes):
b.width = width
if b.align & Align.RIGHT:
b.x = self.full_width - b.width - self.PADDING


def equal_height(self, *boxes):
""" Sets height of all passed boxes to height of tallest box """
height = 0
Expand Down
2 changes: 1 addition & 1 deletion scc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from scc.lib import IntEnum
from enum import IntEnum

"""
If SC-Controller is updated while daemon is running, DAEMON_VERSION send by
Expand Down
2 changes: 1 addition & 1 deletion scc/drivers/ds5drv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import time
import zlib
from enum import IntEnum

from scc.constants import (
OUTPUT_360_STICK_MAX,
Expand Down Expand Up @@ -45,7 +46,6 @@
hiddrv_test,
)
from scc.drivers.usb import register_hotplug_device
from scc.lib import IntEnum
from scc.lib.hidraw import HIDRaw
from scc.sccdaemon import SCCDaemon
from scc.tools import init_logging, set_logging_level
Expand Down
2 changes: 1 addition & 1 deletion scc/drivers/hiddrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import sys
from enum import IntEnum

from scc.constants import STICK_PAD_MAX, STICK_PAD_MIN, ControllerFlags, SCButtons
from scc.controller import Controller
Expand All @@ -16,7 +17,6 @@
register_hotplug_device,
unregister_hotplug_device,
)
from scc.lib import IntEnum
from scc.lib.hidparse import (
AXES,
GenericDesktopPage,
Expand Down
Loading

0 comments on commit 7f4598d

Please sign in to comment.