Class: LCDProc::Widgets::Icon

Inherits:
Object
  • Object
show all
Includes:
LCDProc::Widget
Defined in:
lib/lcdproc/widgets/icon.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 = "IconWidget_#{@@widget_count}", icon_name = "", col = 1, row = 1) ⇒ Icon

Creates a new Icon widget which can then be displayed anywhere on the screen.

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

  • :icon_name - The name of the icon that you wish to display on the screen. Default to “”.

  • :col - The column in which you wish to display the text on screen. Defaults to 1.

  • :row - The row in which you wish to display the text on screen. Defaults to 1.

Example:

w = Icon.new

or

w = Icon.new( 'Test', 'This is a icon', 1, 5 )


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/lcdproc/widgets/icon.rb', line 54

def initialize( id = "IconWidget_#{@@widget_count}", icon_name = "", col = 1, row = 1 )
  if id.nil?
    id = "IconWidget_#{@@widget_count}"
  end
  
  @id = id
  @type = :icon
  @screen = nil
  @visible = false
  
  @name = icon_name
  @x = col
  @y = row
  
  @@widget_count += 1
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#updateObject

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/lcdproc/widgets/icon.rb', line 73

def update
  if @screen
    response = @screen.client.send_command( Command.new( "widget_set #{@screen.id} #{self.id} #{@x} #{@y} \"#{@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