Steve> I wan't to use a GtkSpinButton to display the port of a service
    Steve> but I want to display the text for know services.  e.g. if 79 is
    Steve> displayed and they increment, display 'http' instead of 80.  

This isn't quite what you're looking for, but I was able to create a slider
that displayed a list of strings instead of numbers.  The trick there is to
define a handler for the "format-value" signal.  In your case, instead of
simply displaying a number, you'd look it up in a dict that maps port
numbers to service names and display the service name when found:

    import gtk

    class PortScale(gtk.HScale):
        def __init__(self, min, max):
            adj = gtk.Adjustment(min, min, max, 1.0, 1.0, 0.0)
            gtk.HScale.__init__(self, adj)
            self.protocol_map = {
                21: "ftp",
                23: "telnet",
                25: "smtp",
                80: "http",
                # etc - probably should parse /etc/services
                }
            self.set_digits(1)
            self.connect("format-value", self.get_label)

        def get_label(self, slider, val):
            val = int(val)
            return self.protocol_map.get(val, val)

    w = gtk.Window()
    w.set_title("port slider")
    w.connect("destroy", gtk.mainquit)

    s = PortScale(21, 80)
    s.set_size_request(150, -1)
    w.add(s)

    w.show_all()
    gtk.mainloop()

HTH...

-- 
Skip Montanaro ([EMAIL PROTECTED] - http://www.mojam.com/)
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to