Project

General

Profile

unexist.dev

/

subtle

Assorted tidbits and projects

Sublets » History » Version 15

Anonymous, 08/10/2009 09:16 AM

1 15
h1. Sublets\015\012\015\012[[Sublets]] are small "Ruby":http://www.ruby-lang.org scripts that provide the data for the statusbar. They are run in an embedded "Ruby":http://www.ruby-lang.org interpreter and are well included in the main loop of [[subtle]].\015\012\015\012Unit tests for [[Subtlets|sublets]] are also included. [[Development|Read more about unit tests]]\015\012\015\012h2. Types\015\012\015\012Currently there are two types of [[Sublets|sublets]]:\015\012* [[sublets]] that are updated by given interval in seconds (default 60s)\015\012* [[sublets]] that are updated when a file is modified (Via "inotify":http://en.wikipedia.org/wiki/Inotify)\015\012\015\012The [[sublet]] data can be either of type "String":http://www.ruby-doc.org/core/classes/String.html, everything else will be ignored.\015\012\015\012h2. Customization\015\012\015\012The color of the ouput of a [[sublet|Sublets]] can be changed in this way:\015\012\015\012<pre><code class="ruby">self.data = color("#ff0000") + "su" + color("#00ff00") + "bt" + color("#0000ff") + "le"</code></pre>\015\012\015\012There is also a way to add a "x bitmap":http://en.wikipedia.org/wiki/XBM to a [[Sublets|sublet]]:\015\012\015\012<pre><code class="ruby">self.data = icon("/usr/share/icons/subtle.xbm") + "subtle"</code></pre>\015\012\015\012A nice collection of this pixmap can be found "here":http://dzen.geekmode.org/dwiki/doku.php?id=dzen:icon-packs.\015\012\015\012h2. Callbacks\015\012\015\012There are two methods that will be called from [[subtle]] on certain conditions:\015\012\015\012* *click()*: whenever a mouse button is pressed on a [[sublet|sublets]]\015\012* *run()*: whenever either the interval time is expired or the watched file is modified\015\012\015\012h2. Examples\015\012\015\012Below is the code of a shipped [[sublet|sublets]] that displays the time. It should be really straight forward:\015\012\015\012<pre><code class="ruby">class Clock < Subtle::Sublet\015\012  def initialize\015\012    self.interval = 60 #< Set interval time\015\012  end\015\012\015\012  def run\015\012    self.data = Time.now.strftime("%d%m%y%H%M") #< Set data\015\012  end\015\012end\015\012</code></pre>\015\012\015\012Another example for the "inotify":http://en.wikipedia.org/wiki/Inotify [[sublets|sublet]] which is also included within [[subtle]]:\015\012\015\012<pre><code class="ruby">class Notify < Subtle::Sublet\015\012  def initialize\015\012    self.path = "/tmp/watch"\015\012  end\015\012\015\012  def run\015\012    begin\015\012      self.data = IO.readlines(self.path).first.chop #< Read data and strip\015\012    rescue => err #< Catch error\015\012      puts err\015\012      self.data = "subtle"\015\012    end\015\012  end\015\012end\015\012</code></pre>\015\012\015\012And finally an example with a click callback:\015\012\015\012<pre><code class="ruby">class Click < Subtle::Sublet\015\012  def initialize\015\012    self.interval = 999 #< Do nothing\015\012  end\015\012\015\012  def click\015\012    find_client("xterm").raise\015\012  end\015\012\015\012  def run\015\012    # Do more nothing\015\012  end\015\012end\015\012</code></pre>\015\012{{tocnavi(Subtler,Quickstart,Grabs)}}