Example #1
0
    def addConfigOption(
        cls,
        attrname,
        type_=None,
        section=None,
        key=None,
        environment=None,
        default=None,
        notify=False,
    ):
        """Adds a configuration option.

        This function should be called during module initialization, before
        the config file is actually read. By default, only options registered
        beforehand will be loaded.

        If you want to add configuration options after initialization,
        use the `readSettingSectionFromFile` method to force reading later on.

        Args:
            attrname (str): The attribute of this class for accessing the option.
            type_ (Optional[type]): The type of the attribute. Unnecessary if a
                `default` value is specified.
            section (Optional[str]): The section of the config file under which
                this option is saved. This section must have been added with
                addConfigSection(). Not necessary if `key` is not given.
            key (Optional[str]): The key under which this option is to be saved.
                By default the option will not be saved.
            notify (Optional[bool]): Whether this attribute should emit
                signals when modified. By default signals are not emitted.
        """
        if section and section not in cls.options:
            raise ConfigError("You must add the section `%s` first" % section)
        if key and not section:
            raise ConfigError("You must specify a section for key `%s`" % key)
        if section and key in cls.options[section]:
            raise ConfigError("Key `%s` is already in use" % key)
        if hasattr(cls, attrname):
            raise ConfigError("Attribute `%s` is already in use" % attrname)
        if environment and environment in cls.environment:
            raise ConfigError("Env var `%s` is already in use" % environment)
        if not type_ and default is None:
            raise ConfigError("Attribute `%s` must have a type or a default" %
                              attrname)
        if not type_:
            type_ = type(default)
        if notify:
            notification = Notification(attrname)
            setattr(cls, attrname, notification)
            setattr(cls, "_" + attrname, default)
            if notification.signame not in GObject.signal_list_names(cls):
                GObject.signal_new(notification.signame, cls,
                                   GObject.SignalFlags.RUN_LAST, None, ())
        else:
            setattr(cls, attrname, default)
        if section and key:
            cls.options[section][attrname] = type_, key, environment
        cls.environment.add(environment)
        cls.defaults[attrname] = default
Example #2
0
def _connect_events(obj, cls):
    for signal_name in GObject.signal_list_names(cls):
        signal_name = signal_name.replace('-', '_')
        event = Event(obj.__class__.__name__ + '.' + signal_name)
        setattr(obj, signal_name, event)

        def send_event(event, *args):
            event.send(args)

        obj.connect(signal_name, partial(send_event, event))
Example #3
0
    def _connect_battery(self):
        """Connect to battery signals so we are told of changes."""

        if 'changed' not in GObject.signal_list_names(UPowerGlib.Device):
            # For UPower 0.99.4 and later
            self._battery.connect('notify::percentage', self.__notify_cb)
            self._battery.connect('notify::state', self.__notify_cb)
            self._battery.connect('notify::is-present', self.__notify_cb)
            self._battery.connect('notify::time-to-empty', self.__notify_cb)
            self._battery.connect('notify::time-to-full', self.__notify_cb)
        else:
            # For UPower 0.19.9
            self._battery.connect('changed', self.__notify_cb, None)
Example #4
0
    def _connect_battery(self):
        """Connect to battery signals so we are told of changes."""

        if 'changed' not in GObject.signal_list_names(UPowerGlib.Device):
            # For UPower 0.99.4 and later
            self._battery.connect('notify::percentage', self.__notify_cb)
            self._battery.connect('notify::state', self.__notify_cb)
            self._battery.connect('notify::is-present', self.__notify_cb)
            self._battery.connect('notify::time-to-empty', self.__notify_cb)
            self._battery.connect('notify::time-to-full', self.__notify_cb)
        else:
            # For UPower 0.19.9
            self._battery.connect('changed', self.__notify_cb, None)
Example #5
0
def list_signal_names(type_):
    """List of supported signal names for a GType, instance or class"""

    type_ = getattr(type_, "__gtype__", type_)

    names = []
    if not type_.is_instantiatable() and not type_.is_interface():
        return names
    names.extend(GObject.signal_list_names(type_))
    if type_.parent:
        names.extend(list_signal_names(type_.parent))
    for iface in type_.interfaces:
        names.extend(list_signal_names(iface))
    return names
Example #6
0
def list_signal_names(type_):
    """List of supported signal names for a GType, instance or class"""

    type_ = getattr(type_, "__gtype__", type_)

    names = []
    if not type_.is_instantiatable() and not type_.is_interface():
        return names
    names.extend(GObject.signal_list_names(type_))
    if type_.parent:
        names.extend(list_signal_names(type_.parent))
    for iface in type_.interfaces:
        names.extend(list_signal_names(iface))
    return names
Example #7
0
    def __init__ (self,use_pywebkit=False,use_gncwebkit=True):

        # story so far
        # the python webkit displays blank for the jqplot
        # - normal html is displayed, javascript text display works
        # but jqplot fails to display
        # using the gnucash webkit GObject everything works - jqplot is displayed!!
        # (the show data function writes the html to a temporary file before
        # displaying using webkit show_uri - is this the issue??)
        # cant see immediately what the difference - only difference I can see
        # so far is gnucash sets a default encoding and font  

        self.use_pywebkit = use_pywebkit
        self.use_gncwebkit = use_gncwebkit

        if self.use_pywebkit:
            # create raw widget here - no use of gnucash html stuff at all
            self.widget = Gtk.ScrolledWindow()
            self.widget.set_policy(Gtk.POLICY_AUTOMATIC,Gtk.POLICY_AUTOMATIC)

            # this is pywebkit access - fails - locks up the whole gnucash GUI
            # unless just access the underlying webkit bindings
            self.webview = webkit.WebView()
            self.widget.add(self.webview)

        if self.use_gncwebkit:
            # use gnucash access to webkit via gi wrapper
            self.html = GncHtmlWebkit.HtmlWebkit()
            print(GObject.signal_list_names(GncHtmlWebkit.HtmlWebkit), file=sys.stderr)
            #pdb.set_trace()
            #self.html = PythonHtmlWebkit()
            # so this is annoying - the gir bindings are generating
            # the wrong offset for the priv field (but not for the parent field)
            # probably some inconsistency in the Gtk.Bin gir definition
            # (which GncHtml is a subclass of)
            # yes - Gtk.Bin is a subclass of Gtk.Container which has bit fields
            # at end of instance structure and apparently introspection cant handle
            # bit fields - so all offsets after Gtk.Container are wrong!!
            # added a hack to GObjectField to handle this if know offset
            #prnt = GObjectField.Setup(self.html,"parent_instance")
            # for Gtk 2
            #self.privfld = GObjectField.Setup(self.html,"priv",offset_adjust_hack=-16,check_adjust_hack=144)
            # for Gtk 3
            self.privfld = GObjectField.Setup(self.html,"priv",offset_adjust_hack=-8,check_adjust_hack=56)
            # note this creates the base scrolled window widget internally
            # we get the widget (a scrolled window) via html.get_widget()
            self.widget = self.html.get_widget()
            print("webkit widget",type(self.widget))
            print("webkit widget",self.widget)
            print("webkit widget",self.widget.get_child())
Example #8
0
def test(target, props, methods, signals) ->bool:
    labels = [prop.name for prop in target.props]
    for prop in props:
        if prop not in labels:
            print('Property {0} is not produced.'.format(prop))
            return False
    for method in methods:
        if not hasattr(target, method):
            print('Method {0} is not produced.'.format(method))
            return False
    labels = GObject.signal_list_names(target)
    for signal in signals:
        if signal not in labels:
            print('Signal {0} is not produced.'.format(signal))
            return False
    return True
Example #9
0
 def register_signals(self, widget):
     """Register gobject signals in a way that avoids multiple inheritance"""
     existing = GObject.signal_list_names(widget)
     for signal in self.signals:
         if signal['name'] in existing:
             dbg('Container:: skipping signal %s for %s, already exists' %
                 (signal['name'], widget))
         else:
             dbg('Container:: registering signal for %s on %s' %
                 (signal['name'], widget))
             try:
                 GObject.signal_new(signal['name'], widget, signal['flags'],
                                    signal['return_type'],
                                    signal['param_types'])
             except RuntimeError:
                 err('Container:: registering signal for %s on %s failed' %
                     (signal['name'], widget))
Example #10
0
 def register_signals(self, widget):
     """Register gobject signals in a way that avoids multiple inheritance"""
     existing = GObject.signal_list_names(widget)
     for signal in self.signals:
         if signal['name'] in existing:
             dbg('Container:: skipping signal %s for %s, already exists' % (
                     signal['name'], widget))
         else:
             dbg('Container:: registering signal for %s on %s' % 
                     (signal['name'], widget))
             try:
                 GObject.signal_new(signal['name'],
                                    widget,
                                    signal['flags'],
                                    signal['return_type'],
                                     signal['param_types'])
             except RuntimeError:
                 err('Container:: registering signal for %s on %s failed' %
                         (signal['name'], widget))
Example #11
0
def test(target, props, methods, vmethods, signals) ->bool:
    labels = [prop.name for prop in target.props]
    for prop in props:
        if prop not in labels:
            print('Property {0} is not produced.'.format(prop))
            return False
    for method in methods:
        if not hasattr(target, method):
            print('Method {0} is not produced.'.format(method))
            return False
    for vmethod in vmethods:
        if not hasattr(target, method):
            print('Vmethod {0} is not produced.'.format(vmethod))
            return False
    labels = GObject.signal_list_names(target)
    for signal in signals:
        if signal not in labels:
            print('Signal {0} is not produced.'.format(signal))
            return False
    return True
Example #12
0
    def __init__(self, stat=None):
        GObject.GObject.__init__(self)

        self.signals = GObject.signal_list_names(self)

        self.stat = stat or linuxcnc.stat()
        self.error = linuxcnc.error_channel()

        self.report_actual_position = ini_info.get_position_feedback()
        axes = ini_info.get_axis_list()
        self.axis_list = ['xyzabcuvw'.index(axis) for axis in axes]
        self.num_joints = ini_info.get_num_joints()

        self.file = None

        self.registry = []
        self.old = {}

        self.old['joint'] = getattr(self.stat, 'joint')

        # Setup joint dict signals
        self.joint_keys = self.old['joint'][0].keys(
        )  # keys() is slow, but we only use it on init
        for key in self.joint_keys:
            key = 'joint-{}'.format(key)
            GObject.signal_new(key.replace('_', '-'), self,
                               GObject.SignalFlags.RUN_FIRST, None,
                               (int, object))

        self.max_time = 0
        self.counter = 0

        # Connect internally used signal callbacks
        self.on_changed('stat.gcodes', self._update_active_gcodes)
        self.on_changed('stat.mcodes', self._update_active_mcodes)
        self.on_changed('stat.file', self._update_file)

        GLib.timeout_add(50, self._periodic)
Example #13
0
 def testListObject(self):
     self.assertEqual(GObject.signal_list_names(C), ('my-signal',))
Example #14
0
    # GncPlugin.Plugin and GncPlugin.PluginClass??
    # well GncPlugin.Plugin is the GObject object for subclassing
    # GncPlugin.PluginClass is the class structure object

    print(GObject.type_query(GncPlugin.Plugin), file=sys.stderr)
    typptr = GObject.type_query(GncPlugin.Plugin)
    print("gtype",typptr.type_name, file=sys.stderr)
    print("gtype",typptr.type, file=sys.stderr)
    print("gtype",typptr.class_size, file=sys.stderr)
    print("gtype",typptr.instance_size, file=sys.stderr)

    # this lists the properties
    print(GObject.list_properties(GncPlugin.Plugin), file=sys.stderr)

    # this lists the signal names
    print(GObject.signal_list_names(GncPlugin.Plugin), file=sys.stderr)

    BaseGncPlugin = GncPlugin.Plugin
    BaseGncPluginClass = GncPlugin.PluginClass


# for the moment save the plugins
python_plugins = {}


# lets not use subclasses of subclasses yet - NO
# - switching back to subclass of subclass - using multiple inheritance with
# metaclass seems fraught - unless manually merge the various base class attributes
# in __new__ other base class attributes seem to be ignored
# - still dont quite understand why a python subclass of a python subclass
# using __metaclass__ still calls parent metaclass functions if the sub subclass
Example #15
0
 def is_signal(self, name):
     if name in GObject.signal_list_names(self):
         return True
     return False
Example #16
0
 def is_signal(self, name):
     if name in GObject.signal_list_names(self):
         return True
     return False
    # Forma 1 de se coletar a versão do GTK+.
    gtk_versao = '%d.%d.%d' % (Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION,
                               Gtk.MICRO_VERSION)

    # Forma 2 de se coletar a versão do GTK+.
    gtk_versao1 = '%d.%d.%d' % (Gtk.get_major_version(),
                                Gtk.get_minor_version(),
                                Gtk.get_micro_version())

    # Versão do PyGObject.
    pygobject_versao = GObject.pygobject_version

    # Nome do Widget.
    widget_name = widget.get_name()

    # Props do widget.
    widget_props = dir(widget.props)

    # Signals do widget.
    widget_signals = GObject.signal_list_names(widget)

    # Métodos get do widget.
    widget_metodos_get = get_methods_get(widget)

    # Métodos set do widget.
    widget_metodos_set = get_methods_set(widget)

    save_data()

    print('[!] Salvo com sucesso [!]')
Example #18
0
 def test_list_names(self):
     self.assertEqual(GObject.signal_list_names(C), ('my-signal', ))
Example #19
0
 def on_done(signal, inst):
     set_cursor(inst)
     if isinstance(signal, str) and signal.replace(
             "_", "-") in GObject.signal_list_names(inst):
         inst.emit(signal)