{"id":337,"date":"2006-05-04T09:00:37","date_gmt":"2006-05-04T14:00:37","guid":{"rendered":"http:\/\/ywwg.com\/wordpress\/?p=337"},"modified":"2006-05-07T09:31:02","modified_gmt":"2006-05-07T14:31:02","slug":"fun-with-python-1-totem-applet","status":"publish","type":"post","link":"https:\/\/ywwg.com\/wordpress\/archives\/337","title":{"rendered":"Fun With Python 1: totem applet"},"content":{"rendered":"<p>I listen to a lot of podcasts, and I use totem to do it.  However I would like to be able to pause the player without having it take up all that screen real estate.  What we need is an applet!  Thankfully python is super compact and the gnome bindings are great, so this barely takes 75 lines.<\/p>\n<p><!--more--><br \/>\nPut this file in \/usr\/local\/bin and make it executable (sudo chmod +x \/usr\/local\/bin\/totem-applet.py)<\/p>\n<h2>totem-applet.py<\/h2>\n<pre>#!\/usr\/bin\/env python\r\nimport pygtk\r\nimport sys\r\npygtk.require('2.0')\r\n\r\nimport gtk\r\nimport gnomeapplet\r\n\r\nimport subprocess\r\n\r\ndef sample_factory(applet, iid):\r\n\thbox = gtk.HBox()\r\n\tlabel = gtk.Label(\"Totem:\")\r\n\thbox.add(label)\r\n\t\r\n\tbutton = gtk.Button(\"\")\r\n\timage = gtk.Image()\r\n\timage.set_from_stock(\"gtk-media-previous\",gtk.ICON_SIZE_BUTTON)\r\n\tbutton.set_image(image)\r\n\tbutton.connect(\"clicked\",previous_clicked)\r\n\thbox.add(button)\r\n\t\r\n\tbutton = gtk.Button(\"\")\r\n\timage = gtk.Image()\r\n\timage.set_from_stock(\"gtk-media-play\",gtk.ICON_SIZE_BUTTON)\r\n\tbutton.set_image(image)\r\n\tbutton.connect(\"clicked\",play_clicked)\r\n\thbox.add(button)\r\n\t\r\n\tbutton = gtk.Button(\"\")\r\n\timage = gtk.Image()\r\n\timage.set_from_stock(\"gtk-media-pause\",gtk.ICON_SIZE_BUTTON)\r\n\tbutton.set_image(image)\r\n\tbutton.connect(\"clicked\",pause_clicked)\r\n\thbox.add(button)\r\n\t\r\n\tbutton = gtk.Button(\"\")\r\n\timage = gtk.Image()\r\n\timage.set_from_stock(\"gtk-media-next\",gtk.ICON_SIZE_BUTTON)\r\n\tbutton.set_image(image)\r\n\tbutton.connect(\"clicked\",next_clicked)\r\n\thbox.add(button)\r\n\t\r\n\tapplet.add(hbox)\r\n\tapplet.show_all()\r\n\treturn True\r\n\r\ndef previous_clicked(event):\r\n\tsubprocess.Popen((\"totem\",\"--previous\"))\r\n\t\r\ndef play_clicked(event):\r\n\tsubprocess.Popen((\"totem\",\"--play\"))\r\n\t\r\ndef pause_clicked(event):\r\n\tsubprocess.Popen((\"totem\",\"--pause\"))\r\n\t\r\ndef next_clicked(event):\r\n\tsubprocess.Popen((\"totem\",\"--next\"))\r\n\t\r\nif len(sys.argv) == 2:\r\n\tif sys.argv[1] == \"run-in-window\":   \r\n\t\tmain_window = gtk.Window(gtk.WINDOW_TOPLEVEL)\r\n\t\tmain_window.set_title(\"Python Applet\")\r\n\t\tmain_window.connect(\"destroy\", gtk.main_quit) \r\n\t\tapp = gnomeapplet.Applet()\r\n\t\tsample_factory(app, None)\r\n\t\tapp.reparent(main_window)\r\n\t\tmain_window.show_all()\r\n\t\tgtk.main()\r\n\t\tsys.exit()\r\n        \r\ngnomeapplet.bonobo_factory(\"OAFIID:GNOME_TotemApplet_Factory\", \r\n                                     gnomeapplet.Applet.__gtype__, \r\n                                     \"simple remote control\", \"1.0\", sample_factory)\r\n<\/pre>\n<p>You&#8217;ll also need <a href=\"http:\/\/ywwg.com\/misc\/totem-applet.server\">totem-applet.server<\/a>, which should be copied to \/usr\/lib\/bonobo\/servers\/. Then you can right click on a panel and add the Totem Applet like any other applet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I listen to a lot of podcasts, and I use totem to do it. However I would like to be able to pause the player without having it take up all that screen real estate. What we need is an applet! Thankfully python is super compact and the gnome bindings are great, so this barely &hellip; <a href=\"https:\/\/ywwg.com\/wordpress\/archives\/337\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fun With Python 1: totem applet&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"_links":{"self":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/posts\/337"}],"collection":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":0,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/posts\/337\/revisions"}],"wp:attachment":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/media?parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/categories?post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/tags?post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}