Class: LCDProc::Widgets::Graph
- Inherits:
-
Object
- Object
- LCDProc::Widgets::Graph
- Includes:
- LCDProc::Widget
- Defined in:
- lib/lcdproc/widgets/graph.rb
Constant Summary collapse
- @@widget_count =
0
Instance Attribute Summary collapse
-
#bars ⇒ Object
Returns the value of attribute bars.
-
#length ⇒ Object
readonly
Note that the lenght is not changeable after you have added a graph.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes included from LCDProc::Widget
Instance Method Summary collapse
-
#hide ⇒ Object
Actually sends the command to the LCDd server to remove the widget from the screen.
-
#initialize(id = "GraphWidget_" + @@widget_count.to_s, col = 1, row = 1, length = 21 - col) ⇒ Graph
constructor
Creates a new Graph widget which can then be displayed anywhere on the screen.
-
#show ⇒ Object
Actually sends the command to the LCDd server to add the widget to the screen.
-
#update ⇒ Object
Sends to command to the LCDd server to update the widget on screen.
Methods included from LCDProc::Widget
add_support, #attach_to, #detach, new, supported_types
Constructor Details
#initialize(id = "GraphWidget_" + @@widget_count.to_s, col = 1, row = 1, length = 21 - col) ⇒ Graph
Creates a new Graph widget which can then be displayed anywhere on the screen.
-
id
- A unique string which identifies this widget. Defaults to “GraphWidget_” + a sequence number. -
col
- The beginning column in which you wish to display the graph on screen. Defaults to 1. -
row
- The beginning row in which you wish to display the text on screen. Defaults to 1. -
length
- The length of the graph (how many vertical bars to show). Defaults to 21 - x for a 20x4 screen.
Example:
w = Graph.new
or
w = Graph.new( 'Test', 'This is a graph', 1, 5, 10 )
NOTE: The length of the graph is not changeable after it has been created
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/lcdproc/widgets/graph.rb', line 59 def initialize( id = "GraphWidget_" + @@widget_count.to_s, col = 1, row = 1, length = 21 - col) if id.nil? id = "GraphWidget_#{@@widget_count}" end @id = id @type = :graph @screen = nil @visible = false @x = col @y = row @length = length @bars = [] @length.times{ |i| @bars << VBar.new( "#{self.id}_Bar_#{i}", 1, @x + i, @y ) } @@widget_count += 1 end |
Instance Attribute Details
#bars ⇒ Object
Returns the value of attribute bars.
35 36 37 |
# File 'lib/lcdproc/widgets/graph.rb', line 35 def @bars end |
#length ⇒ Object (readonly)
Note that the lenght is not changeable after you have added a graph.
38 39 40 |
# File 'lib/lcdproc/widgets/graph.rb', line 38 def length @length end |
#x ⇒ Object
Returns the value of attribute x.
35 36 37 |
# File 'lib/lcdproc/widgets/graph.rb', line 35 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
35 36 37 |
# File 'lib/lcdproc/widgets/graph.rb', line 35 def y @y end |
Instance Method Details
#hide ⇒ Object
Actually sends the command to the LCDd server to remove the widget from the screen
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/lcdproc/widgets/graph.rb', line 81 def hide # Only if we are visible, attempt to hide ourselves if @visible passed = true @bars.each do || # If at any point we fail, bail out and return false if not .hide or not .detach passed = false break end end if passed @visible = false @screen.client.( "Widget '#{@id}' is now hidden" ) return true else @visible = true @screen.client.( "Error: Widget '#{@id}' could NOT be hidden (#{response.})" ) return false end else return true end end |
#show ⇒ Object
Actually sends the command to the LCDd server to add the widget to the screen
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/lcdproc/widgets/graph.rb', line 114 def show # If we aren't already visible, attempt to make oursevles visible if not @visible commands = [] passed = true @bars.each do || # If at any point we fail, bail out and return false if not .attach_to( @screen ) or not .show( false ) passed = false break end end @bars.each do || commands << "widget_add #{@screen.id} #{.id} #{.type.to_s}" end response = @screen.client.send_command( Command.new( commands ) ) if response.successful? and passed @visible = true @screen.client.( "Widget '#{@id}' is now visible" ) self.update return true else @visible = false @screen.client.( "Error: Widget '#{@id}' could NOT be displayed (#{response.})" ) return false end else return true end end |
#update ⇒ Object
Sends to command to the LCDd server to update the widget on screen
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/lcdproc/widgets/graph.rb', line 157 def update if @screen commands = [] @bars.each do || commands << "widget_set #{@screen.id} #{.id} #{.x} #{.y} #{.height}" end response = @screen.client.send_command( Command.new( commands ) ) if response.successful? @screen.client.( "Widget '#{@id}' was successfully updated" ) return true else @screen.client.( "Error: Widget '#{@id}' was NOT successfully updated (#{response.})" ) return true end else @screen.client.( "Error: Cannot update Widget '#{@id}' until it is attached to a screen" ) return false end end |