From 7bef5075e7c39cf318847f8ba9282c25c3ceded2 Mon Sep 17 00:00:00 2001 From: ben Date: Sun, 31 May 2009 12:57:02 +0000 Subject: =?UTF-8?q?Tool=20um=20kommandos=20=C3=BCber=20trayicon=20auszuf?= =?UTF-8?q?=C3=BChren=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.neo-layout.org@1883 b9310e46-f624-0410-8ea1-cfbb3a30dc96 --- linux/traycommand/layoutswitch.yaml | 7 ++ linux/traycommand/traycommand | 141 ++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 linux/traycommand/layoutswitch.yaml create mode 100755 linux/traycommand/traycommand (limited to 'linux/traycommand') diff --git a/linux/traycommand/layoutswitch.yaml b/linux/traycommand/layoutswitch.yaml new file mode 100644 index 0000000..5b8d369 --- /dev/null +++ b/linux/traycommand/layoutswitch.yaml @@ -0,0 +1,7 @@ +--- +- command: "~/bin/asdf; xmodmap ~/thinkpad.xmodmap" + icon: "~/neo/windows/neo-vars/src/neo_enabled.ico" + menutext: "Neo" +- command: "~/bin/uiae; xmodmap ~/thinkpad.xmodmap" + icon: "~/neo/windows/neo-vars/src/neo_disabled.ico" + menutext: "qwertz" diff --git a/linux/traycommand/traycommand b/linux/traycommand/traycommand new file mode 100755 index 0000000..6a4e9fe --- /dev/null +++ b/linux/traycommand/traycommand @@ -0,0 +1,141 @@ +#!/usr/bin/env ruby + +begin + require 'gtk2' +rescue LoadError + $stderr << "########################################################\n" + $stderr << "# In order to run this programm you need ruby-gnome2! #\n" + $stderr << "########################################################\n" + raise +end + +require 'yaml' +require 'pp' +require 'optparse' +require 'ostruct' +require 'gconf2' + +TRAYCOMMANDVERSION = [0,1] + +Gtk.init +$options = OpenStruct.new + +optpars = OptionParser.new { |opts| + + opts.banner = "Usage: #{File.basename($0)} [options]" + + opts.separator "Options:" + + opts.on("--configfile=file", "Path to the configfile.") {|string| + $options.configfile = string + } + + opts.on_tail("--version", "Show version and exit") { + puts "traycommand #{TRAYCOMMANDVERSION.join('.')}" + puts "written by Benjamin Kellermann " + exit + } +} + +begin + optpars.parse! +rescue => e + puts e + puts optpars + exit +end + +############################################################################ +# init the things from the configfile +############################################################################ +unless File.exist?($options.configfile) and $config = YAML::load_file($options.configfile) + $config = [] + 2.times{ + $config << {"command" => "/path/to/command.sh", + "icon" => "/path/to/icon.{png|ico|jpg|...}", + "menutext" => "Some Useful text"} + } + File.open($options.configfile, 'w') do |out| + out << $config.to_yaml + end + puts "Created configfile template, exiting now" + exit +end + +############################################################################ +# init the tray and GTK stuff +############################################################################ +currentconfig = 0 +$sicon = Gtk::StatusIcon.new +$sicon.pixbuf = Gdk::Pixbuf.new(File.expand_path($config[currentconfig]["icon"])) + +# Add a menu +menu = Gtk::Menu.new + +$config.each_with_index{|citem,i| + item = Gtk::MenuItem.new(citem["menutext"]) + item.signal_connect("activate"){ + `#{citem["command"]}` + $sicon.pixbuf = Gdk::Pixbuf.new(File.expand_path(citem["icon"])) + currentconfig = i + } + menu.append(item.show) +} +$sicon.signal_connect("activate"){ + nextconf = (currentconfig+1) % $config.size + `#{$config[nextconf]["command"]}` + $sicon.pixbuf = Gdk::Pixbuf.new(File.expand_path($config[nextconf]["icon"])) + currentconfig = nextconf +} + + + + +############################################################################ +# set the about dialog +############################################################################ +aboutitem = Gtk::ImageMenuItem.new(Gtk::Stock::ABOUT) +aboutitem.signal_connect("activate") { + Gtk::AboutDialog.set_email_hook {|about, link| + `xdg-open mailto:#{link}` + } + Gtk::AboutDialog.set_url_hook {|about, link| + `xdg-open #{link}` + } + + a = Gtk::AboutDialog.new + a.authors = ["Benjamin Kellermann "] + a.comments = "This is an applet to execute commands fastly." + a.copyright = "Copyright (C) 2009 Benjamin Kellermann" + a.license = "This program is licenced under CC-by-sa" + a.logo_icon_name = "gtk-about" + a.name = "keyspeedapplet" + a.version = TRAYCOMMANDVERSION.join(".") + a.website = "http://www.eigenheimstrasse.de/~ben/traycommand/" + a.website_label = "Download Website" + a.signal_connect('response') { a.destroy } + a.show +} +menu.append(aboutitem.show) + +# add an exit button +quit = Gtk::ImageMenuItem.new(Gtk::Stock::QUIT) +quit.signal_connect("activate") { Gtk.main_quit } +menu.append(Gtk::SeparatorMenuItem.new.show) +menu.append(quit.show) + +$sicon.signal_connect('popup-menu') do |w,e,time| + menu.popup(nil, nil, e, time) +end + +pid = fork { + Signal.trap("USR1") { + $sicon.activate + } + Gtk.main +} +File.open("/tmp/traycommand-#{$options.configfile}.pid","w"){|f| + f << pid +} + +Process.waitpid(pid) -- cgit v1.2.3