Ejemplo n.º 1
0
    def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)

        from automagica.utilities import all_activities

        self.activities = all_activities()

        self.nodes_label = tk.Label(
            self,
            text=_("Activities"),
            anchor="w",
            justify="left",
            font=font.Font(family=config.FONT, size=12),
            fg=config.COLOR_0,
            bg=config.COLOR_4,
        )
        self.nodes_label.pack()

        self.query = tk.StringVar()
        self.search_entry = InputField(
            self,
            textvariable=self.query,
            placeholder=_("Search activities..."),
        )
        self.query.trace("w", self.search_activities)
        self.search_entry.focus()
        self.search_entry.bind("<Return>", self.search_activities)
        self.search_entry.pack(fill="x")

        self.canvas = tk.Canvas(
            self,
            bg="white",
            scrollregion=(0, 0, 300, 35 * len(self.activities)),
        )

        self.render_activity_blocks(
            [val for key, val in self.activities.items()]
        )

        self.vertical_scrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)
        self.vertical_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
        self.vertical_scrollbar.config(command=self.canvas.yview)

        self.canvas.config(yscrollcommand=self.vertical_scrollbar.set)
        self.canvas.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)

        self.bind("<Enter>", self._bound_to_mousewheel)
        self.bind("<Leave>", self._unbound_to_mousewheel)
Ejemplo n.º 2
0
def test_all_activities_flow(flow_designer_window, tmp_path):
    """Create a simple flow using all Automagica activities"""
    # Add all Automagica activities to the flow
    for key in all_activities().keys():
        flow_designer_window.add_activity(key)
        flow_designer_window.update()

    # Save the flow
    d = tmp_path / "flows"
    d.mkdir()
    flow_designer_window.flow.save(d / "simple_flow.json")

    assert len(list(tmp_path.iterdir())) == 1

    # Open properties window for every block
    for node in flow_designer_window.flow.nodes:
        window = node.graph.double_clicked(None)
        window.update()
        window.destroy()

    assert True
Ejemplo n.º 3
0
import os
from gettext import gettext, translation
import logging

import sys
import pyglet
import json

from automagica.utilities import all_activities
from PIL import ImageTk, Image

ACTIVITIES = all_activities()


class IconGraph:
    def __init__(self, icon_size=20, color="#2196f3"):
        icons_path = os.path.join(
            os.path.dirname(
                os.path.dirname(
                    os.path.abspath(__file__).replace(
                        os.path.basename(os.path.realpath(__file__)), ""))),
            "automagica",
            "gui",
            "icons",
        )

        self.icon_names = os.listdir(icons_path)

        self.icon_paths = [
            os.path.join(icons_path, fn) for fn in self.icon_names
        ]
Ejemplo n.º 4
0
def test_activity_requirements():
    """
    Test whether all Automagica activities are defined correctly
    """
    import inspect
    import ast
    import textwrap

    from automagica.utilities import AUTOMAGICA_ACTIVITIES, all_activities

    # Test whether each function listed in AUTOMAGICA_ACTIVITIES

    assert len(all_activities()) == len(AUTOMAGICA_ACTIVITIES)

    for key, activity in all_activities().items():

        # Test that the activity has:

        # - a name?
        assert activity.get("name")

        # - a description?
        assert activity.get("description")

        # - an icon?
        assert activity.get("icon")

        # - icon that begins with 'la' (line awesome)
        assert activity["icon"].startswith("la")

        # - keywords?
        assert activity.get("keywords")

        # - docstring parameters matching the function signature?
        f = activity.get("function")

        signature = inspect.signature(f)
        params = signature.parameters

        function_signature_params = list(params.keys())

        if "self" in function_signature_params:
            function_signature_params.remove("self")

        docstring_lines = [
            line.strip() for line in f.__doc__.split("\n") if line.strip()
        ]

        docstring_params = []

        for line in docstring_lines:
            if line.startswith(":parameter"):
                name = line.split(":")[1].replace("parameter ", "")
                docstring_params.append(name)

        assert set(function_signature_params) == set(docstring_params)

        # - a return parameter in docstring (if applicable)
        source = textwrap.dedent(inspect.getsource(f))

        returns = [
            isinstance(element, ast.Return)
            for element in ast.walk(ast.parse(source))
        ]

        if any(returns):
            assert ":return:" in f.__doc__