Class: LCDProc::Widgets::Title

Inherits:
Object
  • Object
show all
Includes:
LCDProc::Widget
Defined in:
lib/lcdproc/widgets/title.rb

Constant Summary collapse

@@widget_count =
0

Instance Attribute Summary collapse

Attributes included from LCDProc::Widget

#id, #screen, #type, #visible

Instance Method Summary collapse

Methods included from LCDProc::Widget

add_support, #attach_to, #detach, #hide, new, #show, supported_types

Constructor Details

#initialize(id = "TitleWidget_#{@@widget_count}", text = "Title") ⇒ Title

Creates a new Title widget which gets displayed at the top of the screen

  • :id - A unique string which identifies this widget. Defaults to “TitleWidget_” + a sequence number.

  • :text - The text that you wish to display as the title. Default to “Title”.

Example:

w = Title.new

or

w = Title.new( 'Test', 'My Wonderful Title' )


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lcdproc/widgets/title.rb', line 52

def initialize( id = "TitleWidget_#{@@widget_count}", text = "Title" )
  if id.nil?
    id = "TitleWidget_#{@@widget_count}"
  end
  
  @id = id
  @type = :title
  @screen = nil
  @visible = false
  
  @title_text = text
  
  @@widget_count += 1
end

Instance Attribute Details

#title_textObject

Returns the value of attribute title_text.



35
36
37
# File 'lib/lcdproc/widgets/title.rb', line 35

def title_text
  @title_text
end

Instance Method Details

#updateObject

Sends to command to the LCDd server to update the widget on screen



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/lcdproc/widgets/title.rb', line 69

def update
  if @screen
    response = @screen.client.send_command( Command.new( "widget_set #{@screen.id} #{self.id} \"#{@title_text}\"" ) )
    
    if response.successful?
      @screen.client.add_message( "Widget '#{@id}' was successfully updated" )
      return true
    else
      @screen.client.add_message( "Error: Widget '#{@id}' was NOT successfully updated (#{response.message})" )
      return true
    end
  else
    @screen.client.add_message( "Error: Cannot update Widget '#{@id}' until it is attached to a screen" )
    return false
  end
end