Giter Club home page Giter Club logo

Comments (2)

 avatar commented on August 24, 2024

In the above list is missing, I think a class somekind of ModelManager from Django that can retrieve objects from the backend/application and which notifies the frontend/UI.


In sudo python I started framework based on desktop experience that I think can be useful, it takes inspiration from Nerfed. It has:

  • A messaging class for loose coupling of views/widgets
  • A state-machine called Machinima
  • Animator class that can handle animation "fire and forget" and "repeat & stoppable" mode
class Messaging:
    """Class for sending message which allows for loose coupling of
component in the app.

Example usage:

.. code-block:: python

messaging = Messaging()
messaging.subscribe(something, 'boot:done')
messaging.publish(boot, 'boot:done')
"""

    def __init__(self):
        self.omni = list()
        self.channels = dict()

    def publish(self, sender, channel, param=None):
        print 'publish', sender, channel, param
        for receiver in self.omni:
            receiver(sender, channel, param)
        channel = self.channels.get(channel, None)
        if channel:
            channel = self.channels.get(channel)
            for receiver in channel:
                receiver(sender, channel, param)

    def subscribe(self, receiver, channel=None):
        print 'subscribe', channel
        if not channel:
            self.omni.append(receiver)
        else:
            receivers = self.channels.get(channel)
            if receivers:
                receivers.append(receiver)
            else:
                receivers = list()
                receivers.append(receiver)
                self.channels.set(channel, receivers)


class Node:
    """Node in a state machine"""

    def __init__(self, app):
        self.app = app
        self.transitions = dict()

    def transition(self, message, end):
        """Change state on ``message`` to ``end``"""
        self.transitions.set(message, end)

    def on_leave(self, next, sender, message, param=None):
        print 'on_leave empty', next, sender, message, param

    def on_enter(self, before, sender, message, param=None):
        print 'on_enter empty', before, sender, message, param


class Machinima:
    """State machine"""

    def __init__(self, name):
        self.name = name
        self.node = None

    def handle(self, sender, message, param=None):
        print 'handle', sender, message, param
        end = self.node.transitions.get(message)
        if end:
            self.node.on_leave(next, sender, message, param)
            end.on_enter(self.node, sender, message, param)
            self.node = end

    def start(self):
        self.node.on_enter(None, None, None, None)


class Animator:

    def __init__(self, func, delay, loop):
        self.func = func
        self.delay = delay
        self.loop = loop

    def run(self):
        var(delay, func)
        delay = self.delay
        func = self.func
        if self.loop:
            self.id = JS('setInterval(adapt_arguments(func), delay)')
        else:
            JS('setTimeout(adapt_arguments(func), delay)')

    def stop(self):
        var(id)
        id = self.id
        JS('clearInterval(id)')


class Application:

    def __init__(self):
        self.messaging = Messaging()
        self.machinima = Machinima('main')
        self.messaging.subscribe(self.machinima.handle)

from pythonjs.

 avatar commented on August 24, 2024

this is done in weblib https://github.com/PythonScript-/weblib.py

from pythonjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.