From 4da077afd60d5591b24a32b1082139516fd9f2c2 Mon Sep 17 00:00:00 2001 From: Sebastien Estienne Date: Thu, 8 Sep 2005 18:56:24 +0000 Subject: * take the size of the panel * Fitt's law compliance * try getting the transparency working (not working yet) git-svn-id: file:///home/lennart/svn/public/service-discovery-applet/trunk@12 3be567f1-68ff-0310-b24a-ad7cc433fd2f --- src/service-discovery-applet.in | 71 ++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/src/service-discovery-applet.in b/src/service-discovery-applet.in index 05f8a8e..54cb45e 100755 --- a/src/service-discovery-applet.in +++ b/src/service-discovery-applet.in @@ -65,6 +65,8 @@ zc_pretty_name = {'_ssh._tcp' : 'SSH Servers', '_workstation._tcp': 'Workstations' } +menuZC = gtk.ImageMenuItem() +menubar = gtk.MenuBar() def siocgifname(interface): @@ -205,13 +207,48 @@ def del_service_type(interface, protocol, type, domain): del zc_types[type] + # Callback: panel background changed +def on_change_background(panelapplet, backgroundtype, color, pixmap): + global menubar, menuZC + + panelapplet.modify_bg(gtk.STATE_NORMAL, color) + menuZC.modify_bg(gtk.STATE_NORMAL, color) + menubar.modify_bg(gtk.STATE_NORMAL, color) + + if backgroundtype == gnomeapplet.PIXMAP_BACKGROUND: + print "PIXMAP_BACKGROUND" + s1 = panelapplet.get_style() +# s2 = menuZC.get_style() +# s3 = menubar.get_style() + s1.bg_pixmap[gtk.STATE_NORMAL] = pixmap +# s2.bg_pixmap[gtk.STATE_NORMAL] = pixmap +# s3.bg_pixmap[gtk.STATE_NORMAL] = pixmap + + if backgroundtype == gnomeapplet.COLOR_BACKGROUND: + print "COLOR_BACKGROUP" + + if backgroundtype == gnomeapplet.NO_BACKGROUND: + print "NO_BACKGROUND" + + + def on_menubar_click(widget, event): # allow Middle- and Right-Mouse-Button to go through to the applet window if event.button != 1: widget.emit_stop_by_name("button-press-event") - return False +# This little hack is required to get Fitt's Law compliance - +# i.e. to get the Menubar to be the full height of the panel. +def on_menubar_size_allocate(menubar, rect): + if (rect.x <= 0) or (rect.y <= 0): + return False + rect.x -= 1 + rect.y -= 1 + rect.width += 2 + rect.height += 2 + gtk.Widget.size_allocate(menubar, rect) + return False def on_about(component, verb, applet): icon = gtk.Image() @@ -288,7 +325,7 @@ def gc_options_cb (client, cnxn_id, gc_entry, data): show_local_services = client.get_bool(gc_entry.key) def ServiceDiscoveryApplet_factory(applet, iid): - global menuZC, session_bus, notif, show_notifications, gc_client, server, system_bus, domain + global session_bus, notif, show_notifications, gc_client, server, system_bus, domain, menubar, menuZC # Gconf gc_client = gconf.client_get_default () @@ -304,21 +341,34 @@ def ServiceDiscoveryApplet_factory(applet, iid): gc_client.add_dir (gc_services, gconf.CLIENT_PRELOAD_NONE) gc_client.notify_add (gc_services, gc_services_cb,None) - print "Creating new applet instance" - menubar = gtk.MenuBar() - menubar.connect("button-press-event", on_menubar_click) - + # Applet MenuItem menuZC = gtk.ImageMenuItem() menuZC.add(gtk.Label('ZeroConf')) - img = gtk.Image() - img.set_from_file("@iconsdir@/24x24/service-discovery-applet.png") - menuZC.set_image(img) + image = gtk.Image() + image.set_from_file("@iconsdir@/24x24/service-discovery-applet.png") + menuZC.set_image(image) menuZC.set_right_justified(True) - menubar.add(menuZC) menuZC.set_submenu(service_menu); menuZC.show_all() + # Applet MenuBar + gtk.rc_parse_string(''' + style "service-discovery-applet-menubar-style" + { + GtkMenuBar::shadow-type = none + GtkMenuBar::internal-padding = 0 + } + widget "*.service-discovery-applet" style "service-discovery-applet-menubar-style"''') + menubar = gtk.MenuBar() + menubar.set_name("service-discovery-applet") + menubar.connect("button-press-event", on_menubar_click) + menubar.connect("size-allocate", on_menubar_size_allocate) + menubar.add(menuZC) + + #expand the applet with the panel +# applet.connect("change_background", on_change_background) + applet.set_applet_flags(gnomeapplet.EXPAND_MINOR) applet.add(menubar) applet.show_all() @@ -339,7 +389,6 @@ def ServiceDiscoveryApplet_factory(applet, iid): ("SDA Stop", stop_service_discovery) ], applet) popup = applet.get_popup_component() -# popup.set_prop ("/button3/Service Discovery Applet Start Item", "_label", "prout") #Start Service Discovery domain = "" -- cgit