示例#1
0
 def test_default(self):
     tree_str = ''
     for w in walk(self.window):
         tree_str += w.get_name() + ' '
     self.assertEqual(tree_str,
         'GtkWindow GtkBox GtkPaned GtkButton ' +
         'GtkMenuBar GtkMenuItem GtkAccelLabel GtkMenu ')
示例#2
0
 def test_no_submenu(self):
     tree_str = ''
     for w in walk(self.window, False):
         tree_str += w.get_name() + ' '
     self.assertEqual(tree_str,
         'GtkWindow GtkBox GtkPaned GtkButton ' +
         'GtkMenuBar GtkMenuItem GtkAccelLabel ')
示例#3
0
    def __init__(self, window_agents):
        Thread.__init__(self)
        # Make sure this thread is a daemon not to prevent program exit.
        self.daemon = True
        realm = manhole_ssh.TerminalRealm()
        namespace = {
            'Gtk': Gtk,
            'walk': walk,
            'widgets': lambda: walk(iter(window_agents).next()),
            'window_agents': window_agents,
            'window': lambda: iter(window_agents).next()
        }
        realm.chainedProtocolFactory.protocolFactory = \
            lambda _: manhole.Manhole(namespace)
        p = portal.Portal(realm)
        p.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(nemo='nemo'))
        reactor.listenTCP(2222, manhole_ssh.ConchFactory(p))

        # Starting the thread is not enough because the Python interpreter
        # is no running all the time and therefore the thread will not run
        # too. Workaround this by using a timer to run the interpreter
        # periodically.
        def timer():
            time.sleep(0.001)  # Yield to other threads.
            return True

        GObject.timeout_add(10, timer)
示例#4
0
 def test_no_submenu(self):
     tree_str = ''
     for w in walk(self.window, False):
         tree_str += w.get_name() + ' '
     self.assertEqual(
         tree_str, 'GtkWindow GtkBox GtkPaned GtkButton ' +
         'GtkMenuBar GtkMenuItem GtkAccelLabel ')
示例#5
0
 def __init__(self, window_agents):
     Thread.__init__(self)
     # Make sure this thread is a daemon not to prevent program exit.
     self.daemon = True
     realm = manhole_ssh.TerminalRealm()
     namespace = {
       'Gtk': Gtk,
       'walk': walk,
       'widgets': lambda: walk(iter(window_agents).next()),
       'window_agents': window_agents,
       'window': lambda: iter(window_agents).next()
     }
     realm.chainedProtocolFactory.protocolFactory = \
         lambda _: manhole.Manhole(namespace)
     p = portal.Portal(realm)
     p.registerChecker(
         checkers.InMemoryUsernamePasswordDatabaseDontUse(nemo='nemo'))
     reactor.listenTCP(2222, manhole_ssh.ConchFactory(p))
     # Starting the thread is not enough because the Python interpreter
     # is no running all the time and therefore the thread will not run
     # too. Workaround this by using a timer to run the interpreter
     # periodically.
     def timer():
         time.sleep(0.001) # Yield to other threads.
         return True
     GObject.timeout_add(10, timer)
示例#6
0
 def test_default(self):
     tree_str = ''
     for w in walk(self.window):
         tree_str += w.get_name() + ' '
     self.assertEqual(
         tree_str, 'GtkWindow GtkBox GtkPaned GtkButton ' +
         'GtkMenuBar GtkMenuItem GtkAccelLabel GtkMenu ')
示例#7
0
 def test_depth(self):
     tree_str = ''
     walker = walk(self.window)
     for w in walker:
         tree_str += '%s %d ' % (w.get_name(), walker.depth())
     self.assertEqual(tree_str,
         'GtkWindow 0 GtkBox 1 GtkPaned 2 GtkButton 3 ' +
         'GtkMenuBar 2 GtkMenuItem 3 GtkAccelLabel 4 GtkMenu 4 ')
示例#8
0
 def test_depth(self):
     tree_str = ''
     walker = walk(self.window)
     for w in walker:
         tree_str += '%s %d ' % (w.get_name(), walker.depth())
     self.assertEqual(
         tree_str, 'GtkWindow 0 GtkBox 1 GtkPaned 2 GtkButton 3 ' +
         'GtkMenuBar 2 GtkMenuItem 3 GtkAccelLabel 4 GtkMenu 4 ')
示例#9
0
 def test_skip_children(self):
     tree_str = ''
     walker = walk(self.window)
     for w in walker:
         tree_str += w.get_name() + ' '
         if w.get_name() == 'GtkPaned': walker.skip_children()
     self.assertEqual(tree_str,
         'GtkWindow GtkBox GtkPaned ' +
         'GtkMenuBar GtkMenuItem GtkAccelLabel GtkMenu ')
示例#10
0
 def test_skip_children(self):
     tree_str = ''
     walker = walk(self.window)
     for w in walker:
         tree_str += w.get_name() + ' '
         if w.get_name() == 'GtkPaned': walker.skip_children()
     self.assertEqual(
         tree_str, 'GtkWindow GtkBox GtkPaned ' +
         'GtkMenuBar GtkMenuItem GtkAccelLabel GtkMenu ')
示例#11
0
    def on_widget_selection_changed(self, selection):
        self.property_store.clear()
        self.doc_buffer.set_text('')
        model, iterator = selection.get_selected()
        if iterator == None:
            return
        widget = model[iterator][1]
        doc = widget.__getattribute__('__doc__')
        gdoc = widget.__getattribute__('__gdoc__')
        if gdoc != doc and doc != None:
            gdoc += '\n' + '-' * 80 + '\n' + doc
        self.doc_buffer.set_text(gdoc)
        members = set(dir(widget))
        gtype = widget.__class__.__gtype__

        def get_value(name):
            try:
                w = widget
                return str(eval('w.' + name))
            except:
                return '<error>'

        while gtype.depth != 0:
            name = gtype.name
            type_members = WidgetInspector.get_members(gtype.pytype)
            gtype = gtype.parent
            if len(type_members) == 0:
                continue
            parent_iter = self.property_store.prepend(None)
            self.property_store.set_value(parent_iter, 0, name)
            if type_members == None:
                continue
            for m in type_members:
                members.discard(m)
                if m == '__doc__' or m == '__gdoc__':
                    value = '<string>'
                else:
                    value = get_value(m)
                self.property_store.append(parent_iter, [m, value])
        for m in members:
            self.property_store.append(None, [m, get_value(m)])
        self.unhighlight()
        walker = walk(widget)
        for w in walker:
            if w == self:
                walker.skip_children()
                continue
            w.get_style_context().add_provider(
                self.highlight_style_provider,
                Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
            self.highlighted_widgets.append(w)
示例#12
0
 def on_refresh(self, menuitem):
     self.unhighlight()
     self.widget_tree_store.clear()
     parent_iters = [None]
     walker = walk(self.window)
     for w in walker:
         depth = walker.depth()
         name = w.get_name()
         it = self.widget_tree_store.append(parent_iters[depth], [name, w])
         if len(parent_iters) <= depth + 1:
             parent_iters.append(it)
         else:
             parent_iters[depth + 1] = it
     self.widget_tree.expand_to_path(Gtk.TreePath('0:0:0:0'))
示例#13
0
 def on_refresh(self, menuitem):
     self.unhighlight()
     self.widget_tree_store.clear()
     parent_iters = [None]
     walker = walk(self.window)
     for w in walker:
         depth = walker.depth()
         name = w.get_name()
         it = self.widget_tree_store.append(parent_iters[depth], [name, w])
         if len(parent_iters) <= depth + 1:
             parent_iters.append(it)
         else:
             parent_iters[depth + 1] = it
     self.widget_tree.expand_to_path(Gtk.TreePath('0:0:0:0'))
示例#14
0
 def on_widget_selection_changed(self, selection):
     self.property_store.clear()
     self.doc_buffer.set_text('')
     model, iterator = selection.get_selected()
     if iterator == None:
         return
     widget = model[iterator][1]
     doc = widget.__getattribute__('__doc__')
     gdoc = widget.__getattribute__('__gdoc__')
     if gdoc != doc and doc != None:
         gdoc += '\n' + '-' * 80 + '\n' + doc
     self.doc_buffer.set_text(gdoc)
     members = set(dir(widget))
     gtype = widget.__class__.__gtype__
     def get_value(name):
         try:
             w = widget
             return str(eval('w.' + name))
         except:
             return '<error>'
     while gtype.depth != 0:
         name = gtype.name
         type_members = WidgetInspector.get_members(gtype.pytype)
         gtype = gtype.parent
         if len(type_members) == 0:
             continue
         parent_iter = self.property_store.prepend(None)
         self.property_store.set_value(parent_iter, 0, name)
         if type_members == None:
             continue
         for m in type_members:
             members.discard(m)
             if m == '__doc__' or m == '__gdoc__':
                 value = '<string>'
             else:
                 value = get_value(m)
             self.property_store.append(parent_iter, [m, value])
     for m in members:
         self.property_store.append(None, [m, get_value(m)])
     self.unhighlight()
     walker = walk(widget)
     for w in walker:
         if w == self:
             walker.skip_children()
             continue
         w.get_style_context().add_provider(
             self.highlight_style_provider,
             Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
         self.highlighted_widgets.append(w)
示例#15
0
 def test_break(self):
     tree_str = ''
     for w in walk(self.window):
         tree_str += w.get_name() + ' '
         if w.get_name() == 'GtkButton': break
     self.assertEqual(tree_str, 'GtkWindow GtkBox GtkPaned GtkButton ')
示例#16
0
 def test_break(self):
     tree_str = ''
     for w in walk(self.window):
         tree_str += w.get_name() + ' '
         if w.get_name() == 'GtkButton': break
     self.assertEqual(tree_str, 'GtkWindow GtkBox GtkPaned GtkButton ')