def fill_signals(self, full_class_name, class_name, class_type):

        self.app.storeSignals.clear()

        try:
            sigs = gobject.signal_list_names( class_type )
        except:
            sigs = []

        for sig in sigs:
            details = gobject.signal_query( sig, class_type )

            sig_id = details[0]
            sig_ret = self.gtype_to_py( details[4].name )

            sig_params = details[5]
            if len(sig_params) > 0:

                sparams = []
                for sig_param in sig_params:
                    sparams.append( self.gtype_to_py( sig_param.name ) )

                s_sig_params = ", ".join( sparams )
            else:
                s_sig_params = "<None>"

            img = self.get_type_image( 'signal_default' )
            if "-event" in sig:
                img = self.get_type_image( 'signal_event' )

            self.app.storeSignals.append( [img, sig, sig_id, sig_ret, s_sig_params] )
    def get_params_for_handler(self, class_scope, pyfunc):
        """:type pyfunc: rope.base.pyobjectsdef.PyFunction"""
        try:
            cls, signal = self.handlers[class_scope][pyfunc.get_name()]
        except KeyError:
            return {}

        attrs = {}

        idx = 0
        names = pyfunc.get_param_names(False)
        if pyfunc.get_kind() in ("method", "classmethod"):
            names = names[1:]
            idx += 1

        if names:
            attrs[idx] = self.get_type(self.get_pygtk_class_name(cls)).get_object()
            names = names[1:]
            idx += 1

        if names:
            for t in gobject.signal_query(signal, str(cls))[-1]:
                try:
                    tname = self.get_type(self.get_pygtk_class_name(t.name))
                    if tname:
                        attrs[idx] = tname.get_object()
                except ModuleNotFoundError:
                    pass

                idx += 1

        return attrs
Beispiel #3
0
	def __add_signal(self):
		# Add new signal to window.
		from gobject import signal_new, signal_query, SIGNAL_RUN_LAST
		from gobject import TYPE_STRING, TYPE_BOOLEAN, SIGNAL_ACTION
		from gobject import SIGNAL_NO_RECURSE, type_register
		SIGNAL = SIGNAL_ACTION|SIGNAL_RUN_LAST|SIGNAL_NO_RECURSE
		from gtk import Window
		if signal_query("scribes-key-event", Window): return False
		signal_new("scribes-key-event", Window, SIGNAL_ACTION, None, ())
		signal_new("scribes-close-window", Window, SIGNAL, TYPE_BOOLEAN, (TYPE_STRING,))
		signal_new("scribes-close-window-nosave", Window, SIGNAL, TYPE_BOOLEAN, (TYPE_STRING,))
		signal_new("shutdown", Window, SIGNAL, TYPE_BOOLEAN, (TYPE_STRING,))
		signal_new("fullscreen", Window, SIGNAL, TYPE_BOOLEAN, (TYPE_STRING,))
		type_register(type(self.__window))
		return False
Beispiel #4
0
    def evt_signaledited(self, projectpath, widgetname, widgettype, signalname,
                         callbackname):
        projectdir, projectfile = os.path.split(projectpath)
        callbackfile = projectfile.replace('.glade', '_callbacks.py')
        callbackfile = os.path.join(projectdir, callbackfile)
        if not os.path.exists(callbackfile):
            f = open(callbackfile, 'w')
            f.write('# pida generated ui file\n')
            f.write('class CallbacksMixin(object):\n')
            f.close()
        
        f = open(callbackfile, 'r')
        foundline = 0
        lastline = 0
        if callbackname.startswith('<'):
            callbackname = '%s_%s' % (widgetname, signalname.replace('-', '_'))

        for i, line in enumerate(f):
            if line.count(callbackname):
                foundline = i
                break
            lastline = i
        
        f.close()

        gotoline = 0
        if not foundline:
            argtypes = gobject.signal_query(signalname, widgettype)[-1]
            widgetarg = widgettype.__class__.__name__.lower()
            extraargs = [argname_from_gtype(typ) for typ in argtypes]
            cbargs = ['self', widgetarg] + extraargs
            f = open(callbackfile, 'a')
            f.write('\n')
            f.write('%sdef %s(%s):\n%spass\n' % (' ' * 4, callbackname,
                                                 ', '.join(cbargs), ' ' * 8))
            f.close()
            self.do_edit('openfile', callbackfile)
            gotoline = lastline + 4
        else:
            if callbackfile != self.filename:
                self.do_edit('openfile', callbackfile)
            gotoline = foundline + 1

        def go():
            self.do_edit('gotoline', gotoline)
            return False
        gobject.timeout_add(200, go)
Beispiel #5
0
def exiter_callback():
    global t0
    global gidle_id

    if 't0' in globals():  # globals().has_key('t0')
        t0.join(
            1
        )  # if we don't exit threadMainTest otherwise (here via runthread),
        # timeout as arg to join() here will NOT help to force exit !!

    atexit.register(curses.endwin)  # end curses

    mngr = p.get_current_fig_manager()

    #~ mngr.destroy() # mngr.canvas=canvas -> no attribute 'canvas??!!!
    # mngr.window - http://www.pygtk.org/docs/pygtk/class-gtkwindow.html

    # in callback, these messages spill in curses..
    print p, ax  #, manager1
    #~ print "No input data, exiting...", gobject.signal_name(gidle_id), gobject.signal_query(gidle_id), mngr, "\n", dir(mngr), "\n", dir(p), "\n", dir(canvas), "\n", dir(p.allclose), "\n", dir(mngr.window)

    # note, if time.sleep is 0.3 here, it blocks until mouseover;
    # 	if time.sleep is 0.1, it exits with crash!
    #~ time.sleep(0.2) # give it time so update_loop dies; takes more than the set value
    # ... but not if it if handled with callbacks with a bit of waiting time..
    # ... also, as we're in callback now, we probably don't need to call
    #     update_line() (so as to "refresh" the global 'runthread', and cause exit )

    # same message always : 'size-changed'
    logging.debug('TEST0')
    for i in range(1, 10):
        logging.debug('INLOOP')
        # note, using "% %s" % here, will fail w/ "not enough args for format string"!
        logging.debug("%s" % str(gobject.signal_name(gidle_id)))
        logging.debug("%s" % str(gobject.signal_query(gidle_id)))

    # kill/destroy/close the maplotlib/pyplot window
    #~ mngr.window.close() # no attribute 'close'
    mngr.window.set_destroy_with_parent(True)  #
    mngr.window.destroy()  #
    canvas.destroy()
    # after these cmds are execd, gobject.signal_name(gidle_id) is 'null' !!
    p.close('all')  #~ p.allclose() # p.close()

    print "... exiting done.."
    sys.exit(0)
    return
Beispiel #6
0
    def evt_signaledited(self, projectpath, widgetname, widgettype, signalname,
                         callbackname):
        projectdir, projectfile = os.path.split(projectpath)
        callbackfile = projectfile.replace('.glade', '_callbacks.py')
        callbackfile = os.path.join(projectdir, callbackfile)
        if not os.path.exists(callbackfile):
            f = open(callbackfile, 'w')
            f.write('# pida generated ui file\n')
            f.write('class CallbacksMixin(object):\n')
            f.close()

        f = open(callbackfile, 'r')
        foundline = 0
        if callbackname.startswith('<'):
            callbackname = '%s_%s' % (widgetname, signalname.replace('-', '_'))

        for i, line in enumerate(f):
            if line.count(callbackname):
                foundline = i
                break
        f.close()

        if not foundline:
            argtypes = gobject.signal_query(signalname, widgettype)[-1]
            widgetarg = widgettype.__class__.__name__.lower()
            extraargs = [argname_from_gtype(typ) for typ in argtypes]
            cbargs = ['self', widgetarg] + extraargs
            print cbargs
            f = open(callbackfile, 'a')
            f.write('\n')
            f.write('%sdef %s(%s):\n%spass\n' %
                    (' ' * 4, callbackname, ', '.join(cbargs), ' ' * 8))
            f.close()
            self.do_edit('openfile', callbackfile)
            self.do_edit('gotoline', '%')
        else:
            if callbackfile != self.filename:
                self.do_edit('openfile', callbackfile)
            self.do_edit('gotoline', '%')
Beispiel #7
0
class SimpleTextView(WidgetDecorator):

    WINDOWS = {
        'widget': gtk.TEXT_WINDOW_WIDGET,
        'text': gtk.TEXT_WINDOW_TEXT,
        'left': gtk.TEXT_WINDOW_LEFT,
        'right': gtk.TEXT_WINDOW_RIGHT,
        'top': gtk.TEXT_WINDOW_TOP,
        'bottom': gtk.TEXT_WINDOW_BOTTOM
    }

    __gsignals__ = {
        'changed': gobject.signal_query('changed', gtk.TextBuffer)[3:]
    }

    def __init__(self, widget):
        super(SimpleTextView, self).__init__(widget)
        self._tab_width = 4
        self.set_tab_width(self._tab_width, force=True)
        self.buffer.connect('changed', self._on_buffer_changed)

    @property
    def buffer(self):
        return self.widget.get_buffer()

    def _on_buffer_changed(self, buf):
        self.emit('changed')

    def create_tag(self, name=None, **props):
        return self.buffer.create_tag(name, **props)

    def apply_tag(self, tag, start, end):
        # convert offsets to iter
        if not isinstance(start, gtk.TextIter):
            start = self.buffer.get_iter_at_offset(start)
        if not isinstance(end, gtk.TextIter):
            end = self.buffer.get_iter_at_offset(end)
        if isinstance(tag, gtk.TextTag):
            self.buffer.apply_tag(tag, start, end)
        else:
            self.buffer.apply_tag_by_name(str(tag), start, end)

    def remove_all_tags(self, start=None, end=None):
        if not start:
            start = self.buffer.get_start_iter()
        if not end:
            end = self.buffer.get_end_iter()
        self.buffer.remove_all_tags(start, end)

    def set_text(self, text):
        return self.widget.get_buffer().set_text(text)

    def get_text(self):
        buf = self.widget.get_buffer()
        start, end = buf.get_bounds()
        return buf.get_text(start, end)

    def set_font(self, spec):
        set_font(self.widget, spec)
        self.set_tab_width(self._tab_width, force=True)

    def set_tab_width(self, width, force=False):
        if width < 1:
            return
        if not force and width == self._tab_width:
            return
        tab_size = self._calculate_tab_size(width, ' ')
        if not tab_size:
            return
        tab_array = pango.TabArray(1, True)
        tab_array.set_tab(0, pango.TAB_LEFT, tab_size)
        self.widget.set_tabs(tab_array)
        self._tab_width = width

    def get_tab_width(self):
        return self._tab_width

    def set_background_color(self, spec):
        set_background_color(self.widget, spec)
        self._update_background(spec)

    def set_text_color(self, spec):
        set_text_color(self.widget, spec)

    def set_cursor_color(self, primary, secondary=None):
        set_cursor_color(self.widget, primary, secondary)

    def set_padding(self, padding):
        for win in ('left', 'right', 'top', 'bottom'):
            self.widget.set_border_window_size(self.WINDOWS[win], padding)
        self._update_background()

    def _update_background(self, color=None):
        if not color:
            style = self.widget.get_style()
            color = style.bg[gtk.STATE_NORMAL]
        for win in ('left', 'right', 'top', 'bottom'):
            win = self.widget.get_window(self.WINDOWS[win])
            if win:
                set_background_color(win, color)

    def _calculate_tab_size(self, tab_width, tab_char):
        tab_str = tab_char * tab_width
        layout = self.widget.create_pango_layout(tab_str)
        if not layout:
            return
        width, height = layout.get_pixel_size()
        return width
    def read_signals(self, obj):
        self.ide.storeSignals.clear()
        sobj = get_object_name( obj )

        try:
            sigs = gobject.signal_list_names( type(obj) )

            # gets signals from all implemented interfaces too.
            # for example, gtk.Entry implements gtk.Editable, which has
            # the "changed" signal, but that is not listed on
            # gtk.Entry's signals.
            # 
            interfaces = gobject.type_interfaces( type(obj) )
            for interface in interfaces:
                sigs += gobject.signal_list_names( interface )

        except:
            sigs = []


        parents = self.get_parent_list( obj )
        for parent in parents:
            try:
                sigs += gobject.signal_list_names( parent )
            except:
                pass


        for sig in sigs:
            details = gobject.signal_query( sig, type(obj) )

            if details[4].name == 'void':
                sig_ret = "return"
            else:
                sig_ret = "return " + details[4].name

            sig_params = details[5]
            if len(sig_params) > 0:

                sparams = ["self", "widget"]
                for sig_param in sig_params:
                    sp = sig_param.name

                    if sp[:3] == 'Gtk' or sp[:3] == 'Gdk':
                        sp = sp[3:]

                    sp = sp[0].lower() + sp[1:]
                    sparams.append( sp )

                s_sig_params = ", ".join( sparams )
            else:
                s_sig_params = "self, widget"

            s_sig_params = "(" + s_sig_params + ")"

            img = get_image_by_name( 'signal_default' )

            if details[2].pytype != type(obj):
                img = get_image_by_name( 'signal_parent' )

            if "-event" in sig:
                img = get_image_by_name( 'signal_event' )


            sig_implemented, sig_line = self.ide.analyser.check_obj_signal( \
                sobj, sig )

            sig_markup = sig

            if sig_implemented:
                sig_markup = "<b>" + sig + "</b> <span foreground='gray'><i>" + \
                    "(source line %d)</i></span>" % sig_line

            self.ide.storeSignals.append( [img, sig, s_sig_params, sig_ret, \
                sig_line, sig_markup] )