コード例 #1
0
ファイル: launch.py プロジェクト: jatib/DiyBashScripts
 def on_pulse_toggled(self, button):
     if button.get_active():
         self.entry.set_progress_pulse_step(0.2)
         # Call self.do_pulse every 100 ms
         self.timeout_id = GLib.timeout_add(100, self.do_pulse, None)
     else:
         # Don't call self.do_pulse anymore
         GLib.source_remove(self.timeout_id)
         self.timeout_id = None
         self.entry.set_progress_pulse_step(0)
コード例 #2
0
    def __setitem__(self, key, value):
        # set_value() aborts the program on an unknown key
        if key not in self:
            raise KeyError('unknown key: %r' % (key,))

        # determine type string of this key
        range = self.get_range(key)
        type_ = range.get_child_value(0).get_string()
        v = range.get_child_value(1)
        if type_ == 'type':
            # v is boxed empty array, type of its elements is the allowed value type
            type_str = v.get_child_value(0).get_type_string()
            assert type_str.startswith('a')
            type_str = type_str[1:]
        elif type_ == 'enum':
            # v is an array with the allowed values
            assert v.get_child_value(0).get_type_string().startswith('a')
            type_str = v.get_child_value(0).get_child_value(0).get_type_string()
            allowed = v.unpack()
            if value not in allowed:
                raise ValueError('value %s is not an allowed enum (%s)' % (value, allowed))
        else:
            raise NotImplementedError('Cannot handle allowed type range class ' + str(type_))

        self.set_value(key, GLib.Variant(type_str, value))
コード例 #3
0
    def __call__(self, *args, **kwargs):
        # the first positional argument is the signature, unless we are calling
        # a method without arguments; then signature is implied to be '()'.
        if args:
            signature = args[0]
            args = args[1:]
            if not isinstance(signature, str):
                raise TypeError('first argument must be the method signature string: %r' % signature)
        else:
            signature = '()'

        arg_variant = GLib.Variant(signature, tuple(args))

        if 'result_handler' in kwargs:
            # asynchronous call
            user_data = (kwargs['result_handler'],
                         kwargs.get('error_handler'),
                         kwargs.get('user_data'))
            self.dbus_proxy.call(self.method_name, arg_variant,
                                 kwargs.get('flags', 0), kwargs.get('timeout', -1), None,
                                 self.__async_result_handler, user_data)
        else:
            # synchronous call
            result = self.dbus_proxy.call_sync(self.method_name, arg_variant,
                                               kwargs.get('flags', 0),
                                               kwargs.get('timeout', -1),
                                               None)
            return self._unpack_result(result)
コード例 #4
0
ファイル: server.py プロジェクト: MartorSkull/weaklight
    def start_server(self):
        loop = GLib.MainLoop()

        dbus_segments = []
        dbus_strips = []

        for strip in self.strips:
            if strip.segmented:
                for segment in strip.getSegments():
                    dbus_segments.append(classes.Segment(
                        segment, self.address))
            dbus_strips.append(classes.Strip(strip, self.address))

        publish = self.bus.publish(self.address, *dbus_strips, *dbus_segments)

        loop.run()
コード例 #5
0
 def set_attribute(self, attributes):
     for (name, format_string, value) in attributes:
         self.set_attribute_value(name, GLib.Variant(format_string, value))
コード例 #6
0
ファイル: env.py プロジェクト: ishine/neuralLOGIC
    @dbus.service.method(dbus_interface=dbus_iface)
    def render(self):
        mode = 'human'
        close = False
        return self.__env.render(mode, close)
    
    @dbus.service.method(dbus_interface=dbus_iface, in_signature='d', out_signature='addb')
    def step(self, action):
        ob, reward, done, _ = self.__env.step(np.array([action]))
        return ob, reward, done
    
    @dbus.service.method(dbus_interface=dbus_iface, out_signature='ad')
    def reset(self):
        return self.__env.reset()        

if __name__ == '__main__':
    service = DbusEnv.dbus_iface + '.service'
    path = '/' + DbusEnv.dbus_iface.replace('.', '/')
    print service
    print path

    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    session_bus = dbus.SessionBus()
    name = dbus.service.BusName(service, session_bus)
    object = DbusEnv(session_bus, path)

    mainloop = GLib.MainLoop()
    print "Running example service."
    mainloop.run()