Project

General

Profile

unexist.dev

subtle

Assorted tidbits and projects

Sublets » History » Version 16

« Previous - Version 16/66 (diff) - Next » - Current version
Anonymous, 08/12/2009 12:46 PM


Sublets\015\012\015\012Sublets are small Ruby scripts that provide the data for the statusbar. They are run in an embedded Ruby interpreter and are well included in the main loop of subtle.\015\012\015\012Unit tests for sublets are also included. Read more about unit tests\015\012\015\012h2. Types\015\012\015\012Currently there are two types of 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 sublet data can be either of type String, everything else will be ignored.\015\012\015\012h2. Customization\015\012\015\012The color of the ouput of a Sublets can be changed in this way:\015\012\015\012
self.data = color("#ff0000") + "su" + color("#00ff00") + "bt" + color("#0000ff") + "le"
\015\012\015\012There is also a way to add a x bitmap to a sublet:\015\012\015\012
self.data = icon("/usr/share/icons/subtle.xbm") + "subtle"
\015\012\015\012A nice collection of this pixmap can be found here. 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 sublets. Can have three arguments: button, x, y\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 sublets that displays the time. It should be really straight forward:\015\012\015\012
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
\015\012\015\012Another example for the inotify sublet which is also included within subtle:\015\012\015\012
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
\015\012\015\012And finally an example with a click callback:\015\012\015\012
class Click < Subtle::Sublet\015\012  def initialize\015\012    self.interval = 999 #< Do nothing\015\012  end\015\012\015\012  def click(button, x, y)\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
\015\012{{tocnavi(Subtler,Quickstart,Grabs)}}