Comments (2)
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.
this is done in weblib https://github.com/PythonScript-/weblib.py
from pythonjs.
Related Issues (20)
- Can't subclass from Exception HOT 1
- reload() doesn't work... HOT 3
- C++ backend for Qt prototyping HOT 7
- Support "from module import name1, name2" ?
- print [[0]][0][0]
- f()[0][0]
- Rust Backend
- Safari can't parse 'data.function'
- Int8Array... do not exist in Safari
- ArrayBuffer does not exists in Safari
- HTMLDocument undefined
- Same syntax for all backends , possible? HOT 2
- PythonJS changing to WebPython or WPython?
- How to use python script with web2py project
- Help getting started with --lua HOT 1
- Array append broken
- name 'require' is not defined
- This is a great project, but why it is not update for 2 years?
- AttributeError: 'NoneType' object has no attribute 'endswith'
- H
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pythonjs.