Esempio n. 1
0
    def gui(self):
        table = gtk.Table(rows=2, columns=2)
        gtklogger.setWidgetName(table, 'Right')
        # The length of the base comes from a gtk.Entry
        table.attach(gtk.Label('base'), 0,1, 0,1,
                     xoptions=gtk.FILL, xpadding=2)
        self.baseentry = gtk.Entry()
        self.baseentry.set_text('1.0')
        gtklogger.setWidgetName(self.baseentry, 'base')
        gtklogger.connect_passive(self.baseentry, 'changed')
        table.attach(self.baseentry, 1,2, 0,1,
                     xoptions=gtk.EXPAND|gtk.FILL, xpadding=2)

        # One of the acute angles comes from a gtk.HScale
        table.attach(gtk.Label('angle'), 0,1, 1,2,
                     xoptions=gtk.FILL, xpadding=2)
        self.adjustment = gtk.Adjustment(value=45.0, lower=0.0, upper=90.0,
                                         step_incr=0.01, page_incr=0.01)
        self.angleslider = gtk.HScale(self.adjustment)
        gtklogger.setWidgetName(self.angleslider, 'angle')
        ## The Adjustment is the object that emits a signal, but it's
        ## not a Widget, so it has to be "adopted" before it can be
        ## logged.  Otherwise it can't be located by name within the
        ## Widget tree.
        gtklogger.adoptGObject(self.adjustment, self.angleslider,
                               access_method=self.angleslider.get_adjustment)
        gtklogger.connect_passive(self.adjustment, 'value-changed')
        table.attach(self.angleslider, 1,2, 1,2,
                     xoptions=gtk.EXPAND|gtk.FILL, xpadding=2)
        return table
Esempio n. 2
0
    def gui(self):
        table = gtk.Table(rows=2, columns=2)
        gtklogger.setWidgetName(table, 'Right')
        # The length of the base comes from a gtk.Entry
        table.attach(gtk.Label('base'),
                     0,
                     1,
                     0,
                     1,
                     xoptions=gtk.FILL,
                     xpadding=2)
        self.baseentry = gtk.Entry()
        self.baseentry.set_text('1.0')
        gtklogger.setWidgetName(self.baseentry, 'base')
        gtklogger.connect_passive(self.baseentry, 'changed')
        table.attach(self.baseentry,
                     1,
                     2,
                     0,
                     1,
                     xoptions=gtk.EXPAND | gtk.FILL,
                     xpadding=2)

        # One of the acute angles comes from a gtk.HScale
        table.attach(gtk.Label('angle'),
                     0,
                     1,
                     1,
                     2,
                     xoptions=gtk.FILL,
                     xpadding=2)
        self.adjustment = gtk.Adjustment(value=45.0,
                                         lower=0.0,
                                         upper=90.0,
                                         step_incr=0.01,
                                         page_incr=0.01)
        self.angleslider = gtk.HScale(self.adjustment)
        gtklogger.setWidgetName(self.angleslider, 'angle')
        ## The Adjustment is the object that emits a signal, but it's
        ## not a Widget, so it has to be "adopted" before it can be
        ## logged.  Otherwise it can't be located by name within the
        ## Widget tree.
        gtklogger.adoptGObject(self.adjustment,
                               self.angleslider,
                               access_method=self.angleslider.get_adjustment)
        gtklogger.connect_passive(self.adjustment, 'value-changed')
        table.attach(self.angleslider,
                     1,
                     2,
                     1,
                     2,
                     xoptions=gtk.EXPAND | gtk.FILL,
                     xpadding=2)
        return table
Esempio n. 3
0
    def __init__(self):
        # This program's goal in life is to manage and display this
        # list of Shape objects.
        self.shapelist = gtk.ListStore(gobject.TYPE_PYOBJECT)

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        ## New top-level widgets (mostly windows) must be given a name
        ## by calling newTopLevelWidget.  No two top-level widgets can
        ## have the same name.
        gtklogger.newTopLevelWidget(self.window, 'ShapeDemo')
        ## All gtk.connect calls must be replaced with
        ## gtklogger.connect calls, if the action that triggers the
        ## callback needs to be logged.
        gtklogger.connect(self.window, 'delete-event', self.deleteEvent)
        ## Use connect_passive for actions that need to be logged, but
        ## don't have callbacks.  This line logs window resize events:
        gtklogger.connect_passive(self.window, 'configure-event')

        ## Widgets that don't do anything don't need to be named, even
        ## if they contain other widgets that do have to be logged.
        bigbox = gtk.VBox()
        self.window.add(bigbox)

        ## MenuItems and MenuBars must have names assigned with
        ## gtklogger.setWidgetName if any of the items they contain
        ## are to be logged.
        menubar = gtk.MenuBar()
        gtklogger.setWidgetName(menubar, 'menubar')
        bigbox.pack_start(menubar, expand=0, fill=0)
        filemenuitem = gtk.MenuItem('File')
        gtklogger.setWidgetName(filemenuitem, 'File')
        menubar.append(filemenuitem)
        filemenu = gtk.Menu()
        ## submenus must be assigned with gtklogger.set_submenu
        ## instead of gtk.MenuItem.set_submenu.
        gtklogger.set_submenu(filemenuitem, filemenu)

        quititem = gtk.MenuItem("Quit")
        filemenu.append(quititem)
        gtklogger.setWidgetName(quititem, 'Quit')
        gtklogger.connect(quititem, 'activate', self.quit)

        ## Keyboard accelerators don't need any special treatment for
        ## logging:
        accelgrp = gtk.AccelGroup()
        self.window.add_accel_group(accelgrp)
        quititem.add_accelerator('activate', accelgrp, ord('Q'),
                                 gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

        ## The main part of the window is a Frame containing a VPaned.
        ## The Frame doesn't need a gtklogger name, since it doesn't
        ## have any signals associated with it.
        frame = gtk.Frame()
        frame.set_shadow_type(gtk.SHADOW_OUT)
        frame.set_border_width(2)
        bigbox.pack_start(frame, expand=1, fill=1)

        pane = gtk.VPaned()
        frame.add(pane)
        ## Panes need names if motion of the divider is to be logged.
        gtklogger.setWidgetName(pane, "pane")
        gtklogger.connect_passive(pane, 'notify::position')

        ## The bottom half of the VPaned contains a button box.  We're
        ## doing the bottom half first because it's simpler.
        buttonframe = gtk.Frame()
        buttonframe.set_shadow_type(gtk.SHADOW_IN)
        pane.pack2(buttonframe, resize=False, shrink=False)

        buttonbox = gtk.HButtonBox()
        buttonframe.add(buttonbox)

        ## Widgets that actually do something need to be connected
        ## with gtklogger.connect.  They also must have names assigned
        ## with gtklogger.setWidgetName.
        addbutton = gtk.Button("Add")
        buttonbox.pack_start(addbutton, expand=1, fill=1)
        gtklogger.setWidgetName(addbutton, "AddButton")
        gtklogger.connect(addbutton, 'clicked', self.addButton)

        self.deletebutton = gtk.Button("Delete")
        buttonbox.pack_start(self.deletebutton, expand=1, fill=1)
        gtklogger.setWidgetName(self.deletebutton, "DeleteButton")
        gtklogger.connect(self.deletebutton, 'clicked', self.deleteButton)

        ## The top pane contains a scrollable list of shapes inside a
        ## decorative Frame.

        listframe = gtk.Frame("Shapes")
        listframe.set_shadow_type(gtk.SHADOW_IN)
        pane.pack1(listframe, resize=True, shrink=True)

        scroll = gtk.ScrolledWindow()
        scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        listframe.add(scroll)
        ## gtklogger contains a utility function, logScrollBars, which
        ## can be used to log the scroll bars on a ScrolledWindow.  We
        ## don't use it here so that we can have an explicit example
        ## of using adoptGObject.
        ##
        ## We want to log scroll events that emit the 'value-changed'
        ## signal from the scrollbar's gtk.Adjustment object.  This
        ## object isn't a gtk.Widget, so it can't be located by
        ## traversing names in the Widget tree rooted at the main
        ## window.  Therefore the Adjustment has to be 'adopted' by a
        ## Widget, in this case the ScrolledWindow itself.  First, the
        ## ScrolledWindow needs a name:
        gtklogger.setWidgetName(scroll, 'scrollwindow')
        ## Then the adjustment is adopted.  The third Argument tells
        ## the logger how to find the Adjustment once it has located
        ## the parent.
        gtklogger.adoptGObject(scroll.get_vadjustment(),
                               scroll,
                               access_method=scroll.get_vadjustment)
        ## connect_passive is used to log the signal, without
        ## connecting it to an explicit callback function.
        gtklogger.connect_passive(scroll.get_vadjustment(), 'value-changed')

        self.treeview = gtk.TreeView(self.shapelist)
        scroll.add(self.treeview)
        self.treeview.set_property("headers-visible", 0)
        self.tvcol = gtk.TreeViewColumn("")
        self.treeview.append_column(self.tvcol)
        cell = gtk.CellRendererText()
        self.tvcol.pack_start(cell, True)
        self.tvcol.set_cell_data_func(cell, self.cell_layout_data_func)

        ## We want to log selection events in the TreeView, but those
        ## events actually take place in the TreeView's TreeSelection,
        ## which isn't a Widget.  Therefore we have to use
        ## adoptGObject again.
        selection = self.treeview.get_selection()
        gtklogger.setWidgetName(self.treeview, 'ShapeList')
        gtklogger.adoptGObject(selection,
                               self.treeview,
                               access_method=self.treeview.get_selection)
        self.selectsignal = gtklogger.connect(selection, 'changed',
                                              self.selectionChanged)

        ## Pop up a menu when the right mouse button is pressed in the
        ## TreeView.
        gtklogger.connect(self.treeview, 'button-press-event', self.tvbuttonCB)
        self.buildPopup()

        self.sensitize()
Esempio n. 4
0
    def __init__(self):
        # This program's goal in life is to manage and display this
        # list of Shape objects.
        self.shapelist = gtk.ListStore(gobject.TYPE_PYOBJECT)
        
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        ## New top-level widgets (mostly windows) must be given a name
        ## by calling newTopLevelWidget.  No two top-level widgets can
        ## have the same name.
        gtklogger.newTopLevelWidget(self.window, 'ShapeDemo')
        ## All gtk.connect calls must be replaced with
        ## gtklogger.connect calls, if the action that triggers the
        ## callback needs to be logged.
        gtklogger.connect(self.window, 'delete-event', self.deleteEvent)
        ## Use connect_passive for actions that need to be logged, but
        ## don't have callbacks.  This line logs window resize events:
        gtklogger.connect_passive(self.window, 'configure-event')


        ## Widgets that don't do anything don't need to be named, even
        ## if they contain other widgets that do have to be logged.
        bigbox = gtk.VBox()
        self.window.add(bigbox)

        ## MenuItems and MenuBars must have names assigned with
        ## gtklogger.setWidgetName if any of the items they contain
        ## are to be logged.
        menubar = gtk.MenuBar()
        gtklogger.setWidgetName(menubar, 'menubar')
        bigbox.pack_start(menubar, expand=0, fill=0)
        filemenuitem = gtk.MenuItem('File')
        gtklogger.setWidgetName(filemenuitem, 'File')
        menubar.append(filemenuitem)
        filemenu = gtk.Menu()
        ## submenus must be assigned with gtklogger.set_submenu
        ## instead of gtk.MenuItem.set_submenu.
        gtklogger.set_submenu(filemenuitem, filemenu)

        quititem = gtk.MenuItem("Quit")
        filemenu.append(quititem)
        gtklogger.setWidgetName(quititem, 'Quit')
        gtklogger.connect(quititem, 'activate', self.quit)

        ## Keyboard accelerators don't need any special treatment for
        ## logging:
        accelgrp = gtk.AccelGroup()
        self.window.add_accel_group(accelgrp)
        quititem.add_accelerator('activate', accelgrp, ord('Q'),
                                 gtk.gdk.CONTROL_MASK,
                                 gtk.ACCEL_VISIBLE)

        ## The main part of the window is a Frame containing a VPaned.
        ## The Frame doesn't need a gtklogger name, since it doesn't
        ## have any signals associated with it.
        frame = gtk.Frame()
        frame.set_shadow_type(gtk.SHADOW_OUT)
        frame.set_border_width(2)
        bigbox.pack_start(frame, expand=1, fill=1)

        pane = gtk.VPaned()
        frame.add(pane)
        ## Panes need names if motion of the divider is to be logged.
        gtklogger.setWidgetName(pane, "pane")
        gtklogger.connect_passive(pane, 'notify::position')

        ## The bottom half of the VPaned contains a button box.  We're
        ## doing the bottom half first because it's simpler.
        buttonframe = gtk.Frame()
        buttonframe.set_shadow_type(gtk.SHADOW_IN)
        pane.pack2(buttonframe, resize=False, shrink=False)

        buttonbox = gtk.HButtonBox()
        buttonframe.add(buttonbox)

        ## Widgets that actually do something need to be connected
        ## with gtklogger.connect.  They also must have names assigned
        ## with gtklogger.setWidgetName.
        addbutton = gtk.Button("Add")
        buttonbox.pack_start(addbutton, expand=1, fill=1)
        gtklogger.setWidgetName(addbutton, "AddButton")
        gtklogger.connect(addbutton, 'clicked', self.addButton)

        self.deletebutton = gtk.Button("Delete")
        buttonbox.pack_start(self.deletebutton, expand=1, fill=1)
        gtklogger.setWidgetName(self.deletebutton, "DeleteButton")
        gtklogger.connect(self.deletebutton, 'clicked', self.deleteButton)

        ## The top pane contains a scrollable list of shapes inside a
        ## decorative Frame.
        
        listframe = gtk.Frame("Shapes")
        listframe.set_shadow_type(gtk.SHADOW_IN)
        pane.pack1(listframe, resize=True, shrink=True)
        
        scroll = gtk.ScrolledWindow()
        scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        listframe.add(scroll)
        ## gtklogger contains a utility function, logScrollBars, which
        ## can be used to log the scroll bars on a ScrolledWindow.  We
        ## don't use it here so that we can have an explicit example
        ## of using adoptGObject.
        ##
        ## We want to log scroll events that emit the 'value-changed'
        ## signal from the scrollbar's gtk.Adjustment object.  This
        ## object isn't a gtk.Widget, so it can't be located by
        ## traversing names in the Widget tree rooted at the main
        ## window.  Therefore the Adjustment has to be 'adopted' by a
        ## Widget, in this case the ScrolledWindow itself.  First, the
        ## ScrolledWindow needs a name:
        gtklogger.setWidgetName(scroll, 'scrollwindow')
        ## Then the adjustment is adopted.  The third Argument tells
        ## the logger how to find the Adjustment once it has located
        ## the parent.
        gtklogger.adoptGObject(scroll.get_vadjustment(), scroll,
                               access_method=scroll.get_vadjustment)
        ## connect_passive is used to log the signal, without
        ## connecting it to an explicit callback function.
        gtklogger.connect_passive(scroll.get_vadjustment(), 'value-changed')

        self.treeview = gtk.TreeView(self.shapelist)
        scroll.add(self.treeview)
        self.treeview.set_property("headers-visible", 0)
        self.tvcol = gtk.TreeViewColumn("")
        self.treeview.append_column(self.tvcol)
        cell = gtk.CellRendererText()
        self.tvcol.pack_start(cell, True)
        self.tvcol.set_cell_data_func(cell, self.cell_layout_data_func)

        ## We want to log selection events in the TreeView, but those
        ## events actually take place in the TreeView's TreeSelection,
        ## which isn't a Widget.  Therefore we have to use
        ## adoptGObject again.
        selection = self.treeview.get_selection()
        gtklogger.setWidgetName(self.treeview, 'ShapeList')
        gtklogger.adoptGObject(selection, self.treeview,
                               access_method=self.treeview.get_selection)
        self.selectsignal = gtklogger.connect(selection, 'changed',
                                              self.selectionChanged)


        ## Pop up a menu when the right mouse button is pressed in the
        ## TreeView.
        gtklogger.connect(self.treeview, 'button-press-event', self.tvbuttonCB)
        self.buildPopup()
        
        self.sensitize()