Beispiel #1
0
    def __init__(self, sketch, renderers=None):
        self.sketch = sketch
        if renderers is not None:
            renderers = [self.renderers_mapping[r] for r in renderers]
        if not renderers:
            renderers = [TkRenderer]
        self.renderers = renderers

        self.pp = PyProcessing()
Beispiel #2
0
class Runner:
    renderers_mapping = {
        'TkRenderer': TkRenderer,
    }

    @classmethod
    def from_sketch_path(cls, sketch_path, **kwargs):
        spec = importlib.util.spec_from_file_location(
            "module.name",
            sketch_path,
        )
        sketch = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(sketch)
        return Runner(sketch, **kwargs)

    @classmethod
    def from_sketch_source(cls, sketch_source, **kwargs):
        with tempfile.NamedTemporaryFile('w') as tf:
            tf.write(sketch_source)
            return cls.from_sketch_path(tf.name, **kwargs)

    def __init__(self, sketch, renderers=None, logging_level=40):
        self.sketch = sketch
        if renderers is not None:
            renderers = [self.renderers_mapping[r] for r in renderers]
        if not renderers:
            renderers = [TkRenderer]
        self.renderers = renderers
        self.pp = PyProcessing()
        self.pp.logger.setLevel(logging_level)

        for renderer_class in self.renderers:
            self.pp.attach_renderer(renderer_class)

    def run(self):
        if 'setup' in dir(self.sketch):
            self.sketch.setup()
        self.pp.windows.setup()

        if 'draw' in dir(self.sketch):
            draw = self.sketch.draw
        else:

            def draw():
                return

        callables = {
            func_name: getattr(self.sketch, func_name)
            for func_name in dir(self.sketch)
            if callable(getattr(self.sketch, func_name))
        }

        self.pp.draw_fn = draw
        self.pp.callables.update(callables)
        self.pp.start()
Beispiel #3
0
    def __init__(self, sketch, renderers=None, logging_level=40):
        self.sketch = sketch
        if renderers is not None:
            renderers = [self.renderers_mapping[r] for r in renderers]
        if not renderers:
            renderers = [TkRenderer]
        self.renderers = renderers
        self.pp = PyProcessing()
        self.pp.logger.setLevel(logging_level)

        for renderer_class in self.renderers:
            self.pp.attach_renderer(renderer_class)
Beispiel #4
0
class Runner:
    renderers_mapping = {
        'TkRenderer': TkRenderer,
    }

    @classmethod
    def from_sketch_path(cls, sketch_path, renderers=None):
        spec = importlib.util.spec_from_file_location(
            "module.name", sketch_path,
        )
        sketch = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(sketch)
        return Runner(sketch, renderers=renderers)

    @classmethod
    def from_sketch_source(cls, sketch_source, renderers=None):
        with tempfile.NamedTemporaryFile('w') as tf:
            tf.write(sketch_source)
            return cls.from_sketch_path(tf.name, renderers=renderers)

    def __init__(self, sketch, renderers=None):
        self.sketch = sketch
        if renderers is not None:
            renderers = [self.renderers_mapping[r] for r in renderers]
        if not renderers:
            renderers = [TkRenderer]
        self.renderers = renderers

        self.pp = PyProcessing()

    def run(self):
        if 'setup' in dir(self.sketch):
            self.sketch.setup()

        if 'draw' in dir(self.sketch):
            draw = self.sketch.draw
        else:
            def draw():
                return

        self.pp.draw = draw

        for renderer_class in self.renderers:
            self.pp.attach_renderer(renderer_class)

        self.pp.start()
def thread(thread_name):
    pp = PyProcessing()
    callback = pp.callables[thread_name]
    thread = PyProcessingThread(callback)
    if not hasattr(callback, '__timeout__'):
        timeout = None
    else:
        timeout = callback.__timeout__
    thread.join(timeout)
Beispiel #6
0
def cursor(cursor_type):
    '''
    Change the cursor used on the window.

    :param cursor_type: A cursor type to change to
    :type cursor_type: Union[pyprocessing.environment.CursorType, int]
    '''
    pp = PyProcessing()
    pp.renderers.set_cursor(cursor_type)
Beispiel #7
0
def rect(x, y, width, height, *args):
    pp = PyProcessing()
    if len(args) == 0:
        pp.windows.set_rectangle(x, y, width, height)
    elif len(args) == 1:
        pp.windows.set_rounded_rectangle(x, y, width, height, args[0], args[0],
                                         args[0], args[0])
    elif len(args) == 4:
        pp.windows.set_rounded_rectangle(x, y, width, height, args[0], args[1],
                                         args[2], args[3])
    else:
        raise ValueError(
            f'rect() takes 4, 5 or 8 parameters. ({len(args) + 4} given)')
Beispiel #8
0
def stroke_cap(cap):
    pp = PyProcessing()
    if cap == 1:
        pp.namespace['stroke_cap_attribute'] = 'butt'
    elif cap == 2:
        pp.namespace['stroke_cap_attribute'] = 'round'
    elif cap == 4:
        pp.namespace['stroke_cap_attribute'] = 'projecting'
    else:
        pp.namespace['stroke_cap_attribute'] = 'butt'
Beispiel #9
0
def stroke_join(join):
    pp = PyProcessing()
    if join == 2:
        pp.namespace['stroke_join_attribute'] = 'round'
    elif join == 8:
        pp.namespace['stroke_join_attribute'] = 'miter'
    elif join == 32:
        pp.namespace['stroke_join_attribute'] = 'bevel'
    else:
        pp.namespace['stroke_join_attribute'] = 'bevel'
Beispiel #10
0
def size(w, h):
    pp = PyProcessing()
    global width
    global height
    pp.namespace['width'] = w
    pp.namespace['height'] = h
    width = w
    height = h
    pp.width = w
    pp.height = h
Beispiel #11
0
def stroke_weight(weight):
    pp = PyProcessing()
    pp.namespace['stroke_thickness_attribute'] = weight
Beispiel #12
0
def no_cursor():
    '''
    Hides the cursor from view.
    '''
    pp = PyProcessing()
    pp.renderers.disable_cursor()
Beispiel #13
0
def quad(x1, y1, x2, y2, x3, y3, x4, y4):
    pp = PyProcessing()
    corners = [x1, y1, x2, y2, x3, y3, x4, y4]
    pp.windows.set_polygon(corners)
Beispiel #14
0
def fill(color=255):
    pp = PyProcessing()
    color = Color(color)
    pp.namespace['fill'] = color
 def __init__(self):
     self.pp = PyProcessing()
Beispiel #16
0
def point(x, y):
    pp = PyProcessing()
    pp.windows.set_point(x, y)
Beispiel #17
0
def line(x1, y1, x2, y2):
    pp = PyProcessing()
    pp.windows.set_line(x1, y1, x2, y2)
Beispiel #18
0
def square(x, y, extent):
    pp = PyProcessing()
    pp.windows.set_rectangle(x, y, extent, extent)
Beispiel #19
0
def circle(x, y, size):
    pp = PyProcessing()
    pp.windows.set_ellipse(x, y, size, size)
Beispiel #20
0
def arc(x, y, width, height, start, stop, mode='PIE'):
    pp = PyProcessing()
    pp.windows.set_arc(x, y, width, height, start, stop, mode)
Beispiel #21
0
def ellipse(x, y, width, height):
    pp = PyProcessing()
    pp.windows.set_ellipse(x, y, width, height)
Beispiel #22
0
def stroke(color=0):
    pp = PyProcessing()
    color = Color(color)
    pp.namespace['stroke'] = color
Beispiel #23
0
def frame_rate(fr=60):
    pp = PyProcessing()
    pp.namespace['framerate'] = fr
Beispiel #24
0
def background(color):
    pp = PyProcessing()
    color = Color(color)

    pp.windows.set_background(color)
Beispiel #25
0
def triangle(x1, y1, x2, y2, x3, y3):
    pp = PyProcessing()
    corners = [x1, y1, x2, y2, x3, y3]
    pp.windows.set_polygon(corners)