Python gi.repository.GObject.signal_new() Examples

The following are 2 code examples of gi.repository.GObject.signal_new(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.GObject , or try the search function .
Example #1
Source File: status.py    From hazzy with GNU General Public License v2.0 6 votes vote down vote up
def _connect_stat_callback(self, attribute, callback):

        if hasattr(self.stat, attribute) \
                or attribute.replace('_', '-') in self.signals:

            if attribute.replace('_', '-') not in self.signals \
                    and attribute not in self.registry:
                GObject.signal_new(attribute, self, GObject.SignalFlags.RUN_FIRST, None, (object,))
                self.registry.append(attribute)

            self.connect(attribute, callback)

            # Cause update
            if attribute in SIGNALS.keys():
                self.old[SIGNALS[attribute]] = None
            else:
                self.old[attribute] = None

        else:
            log.error('linuxcnc.stat object has no attribute "{}"'.format(attribute)) 
Example #2
Source File: status.py    From hazzy with GNU General Public License v2.0 5 votes vote down vote up
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)

    # This allows monitoring any of the linuxcnc.stat attributes
    # and connecting a callback to be called on attribute value change