Sublets » History » Version 13
« Previous -
Version 13/66
(diff) -
Next » -
Current version
Anonymous, 08/10/2009 07:53 AM
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\012self.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\012self.data = icon("/usr/share/icons/subtle.xbm") + "subtle"
\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\012class 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\012class 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\012{{tocnavi(Subtler,Quickstart,Grabs)}}¶
self.data = color("#ff0000") + "su" + color("#00ff00") + "bt" + color("#0000ff") + "le"
self.data = icon("/usr/share/icons/subtle.xbm") + "subtle"
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
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