How to use the circuits.Component function in circuits

To help you get started, we’ve selected a few circuits examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github circuits / circuits / tests / core / exitcodeapp.py View on Github external
#!/usr/bin/env python
import sys

from circuits import Component


class App(Component):

    def started(self, *args):
        try:
            code = int(sys.argv[1])
        except ValueError:
            code = sys.argv[1]

        raise SystemExit(code)


def main():
    App().run()


if __name__ == "__main__":
    main()
github realXtend / tundra / src / Application / PythonScriptModule / pymodules_old / apitest / webmodule_example.py View on Github external
def __init__(self):
        Component.__init__(self)
        #loader = QUiLoader()
        #uism = r.getUiSceneManager() #self.canvas = r.createCanvas(EXTERNAL)

        group = QGroupBox()
        box = QVBoxLayout(group)

        button1 = QPushButton("Button 1", group)
        box.addWidget(button1)

        button2 = QPushButton("Button 2", group)
        box.addWidget(button2)

        slider = QtGui.QSlider(PythonQt.QtCore.Qt.Horizontal)
        box.addWidget(slider)
        slider.connect('valueChanged(int)', self.changed)
github realXtend / tundra / src / Application / PythonScriptModule / pymodules_old / apitest / pythonqt_gui.py View on Github external
import rexviewer as r
import naali
import PythonQt
from PythonQt import QtGui
from PythonQt.QtGui import QLineEdit, QGroupBox, QVBoxLayout, QPushButton

from circuits import Component

#INTERNAL = 1
#EXTERNAL = 0

#print dir(PythonQt)
#UiWidgetProperties = PythonQt.__dict__['UiServices::UiWidgetProperties']

class TestGui(Component):
    def __init__(self):
        Component.__init__(self)
        #loader = QUiLoader()
        #uism = r.getUiSceneManager() #self.canvas = r.createCanvas(EXTERNAL)

        group = QGroupBox()
        box = QVBoxLayout(group)

        button1 = QPushButton("Button 1", group)
        box.addWidget(button1)

        button2 = QPushButton("Button 2", group)
        box.addWidget(button2)

        slider = QtGui.QSlider(PythonQt.QtCore.Qt.Horizontal)
        box.addWidget(slider)
github realXtend / tundra / src / Application / PythonScriptModule / pymodules_old / objecttools / edit.py View on Github external
except: #first run
    try:
        #import window
        import transform
    except ImportError, e:
        print "couldn't load window and transform:", e
else:
    #window = reload(window)
    transform= reload(transform)

# note: difference from develop: in tundra there is no EC_OpenSimPrim, so we assume
# everything that is placeable is editable
def editable(ent):
    return ent.HasComponent('EC_Placeable')
    
class ObjectEdit(Component):
    EVENTHANDLED = False
 
    UPDATE_INTERVAL = 0.05 #how often the networkUpdate will be sent
    
    MANIPULATE_FREEMOVE = 0
    MANIPULATE_MOVE = 1
    MANIPULATE_SCALE = 2
    MANIPULATE_ROTATE = 3
    
    def __init__(self):
        self.sels = []  
        self.selmasses = {}
        Component.__init__(self)
        self.resetValues()
        self.worldstream = r.getServerConnection()
        self.usingManipulator = False
github circuits / circuits / examples / async_worker_webpage_download.py View on Github external
import requests

from circuits import Component, Debugger, Event, Timer, Worker, task


def download_web_page(url):
    print('Downloading {}'.format(url))
    response = requests.get(url)
    sleep(2)  # This website is really slow.
    # Only returning portion of web page.
    # You would probably process web page for data before sending back
    return response.text[:200]


class App(Component):

    def init(self, *args, **kwargs):
        self.foo_count = 0
        Worker(process=False).register(self)

    def foo(self):
        self.foo_count += 1
        print("Foo!")
        if self.foo_count > 10:
            self.stop()

    def started(self, component):
        # x = yield self.call(task(factorial, 10))
        Timer(1, Event.create("foo"), persist=True).register(self)
        self.fire(task(download_web_page, 'http://www.slickdeals.net'))  # async
        self.fire(task(download_web_page, 'http://www.google.com'))  # async
github circuits / circuits / circuits / web / main.py View on Github external
action="store_true", default=False, dest="debug",
        help="Enable debug mode"
    )

    parser.add_option(
        "", "--validate",
        action="store_true", default=False, dest="validate",
        help="Enable WSGI validation mode"
    )

    opts, args = parser.parse_args()

    return opts, args


class Authentication(Component):

    channel = "web"

    realm = "Secure Area"
    users = {"admin": md5("admin").hexdigest()}

    def __init__(self, channel=channel, realm=None, passwd=None):
        super(Authentication, self).__init__(self, channel=channel)

        if realm is not None:
            self.realm = realm

        if passwd is not None:
            with open(passwd, "r") as f:
                lines = (line.strip() for line in f)
                self.users = dict((line.split(":", 1) for line in lines))
github circuits / circuits / circuits / web / dispatchers.py View on Github external
url = os.path.join("/", path, cur_dir, item)
                        location = os.path.abspath(
                                os.path.join(self.docroot, path, item))
                        if os.path.isdir(location):
                            li = '<li><a href="%s/">%s/</a></li>' % (url, item)
                        else:
                            li = '<li><a href="%s">%s</a></li>' % (url, item)
                        listing.append(li)

                ctx = {}
                ctx["directory"] = cur_dir or os.path.join("/", cur_dir, path)
                ctx["url_up"] = url_up
                ctx["listing"] = "\n".join(listing)
                return _dirlisting_template.safe_substitute(ctx)

class Dispatcher(Component):

    channel = "web"

    def __init__(self, **kwargs):
        super(Dispatcher, self).__init__(**kwargs)

        self.paths = set(["/"])

    def _parseBody(self, request, response, params):
        body = request.body
        headers = request.headers

        if "Content-Type" not in headers:
            headers["Content-Type"] = ""

        try:
github realXtend / tundra / src / Application / PythonScriptModule / pymodules_old / circuits / tools / bench.py View on Github external
###
### Events
###

class Stop(Event): pass
class Term(Event): pass
class Hello(Event): pass
class Received(Event): pass
class Foo(Event): pass

###
### Components
###

class Base(Component):

    def __init__(self, opts, *args, **kwargs):
        super(Base, self).__init__(*args, **kwargs)

        self.opts = opts

class Sender(Base):

    concurrency = 1

    def received(self, message=""):
        self.push(Hello("hello"))

class Receiver(Base):

    def helo(self, address, port):
github realXtend / tundra / src / Application / PythonScriptModule / pymodules_old / voiceindicator.py View on Github external
class PresenceMonitor:
    def __init__(self, ent, handler):
        self._entity = ent
        self._changeHandler = handler
        presence = ent.GetComponentRaw("EC_OpenSimPresence")
        if presence is None:
            return
        presence.connect("AttributeChanged(IAttribute*, AttributeChange::Type)", self._onOpenSimPresenceChanged)

    def _onOpenSimPresenceChanged(self):
        self._changeHandler(self._entity)


class VoiceIndicatorManager(Component):
    def __init__(self):
        Component.__init__(self)
        self._commService = naali.communicationsservice
        self._voiceSession = None
        self._indicators = {}
        self._commService.connect("InWorldVoiceAvailable()", self.onNewVoiceSession)

    def onNewVoiceSession(self):
        naali.getDefaultScene().connect("ComponentAdded(Scene::Entity*, IComponent*, AttributeChange::Type)", self._onComponentAdded)    
        self._indicators = {} # map uuid to VoiceIndicator objects
        self._presenceMonitors = []
        self._voiceSession = self._commService.InWorldVoiceSession() 
        if self._voiceSession is not None:
            print self._voiceSession
            print type(self._voiceSession)
            self._voiceSession.connect("ParticipantJoined(Communications::InWorldVoice::ParticipantInterface*)", self.onParticipantJoined)