Class: LCDProc::Widgets::Scroller

Inherits:
Object
  • Object
show all
Includes:
LCDProc::Widget
Defined in:
lib/lcdproc/widgets/scroller.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, #detach, #hide, new, #show, supported_types

Constructor Details

#initialize(id = "ScrollerWidget_#{@@widget_count}", left = 1, top = 1, right = 10, bottom = 2, direction = "h", speed = 1, text = "Hello, here is some really long text.") ⇒ Scroller

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

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

  • :left - The column in which to begin the scrolling text. Defaults to 1.

  • :top - The row in which to begin the scrolling text. Defaults to 1.

  • :right - The column in which to end the scrolling text. Defaults to 10 until attached to a screen, then defaults to the width of the screen.

  • :bottom - The row in which to end the scrolling text. Defaults to 2 until attached to a screen, then defaults to the height of the screen.

  • :direction - The direction that the text should scroll. One of “h” for horizontal, “v” for vertical, or “m” for marquee.

  • :speed - The number of movements per rendering stroke (8 times per second).

  • :text - The text that you wish to display on the screen. Default to “Hello, here is some really long text.”. Note that if this string is shorter than the allotted width or height, no scrolling occurs.

Example:

w = Scroller.new

or

w = Scroller.new( 'TestScroller', 1, 1, 20, 4, "h", 1, "Some Scrolling Text")


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/lcdproc/widgets/scroller.rb', line 58

def initialize( id = "ScrollerWidget_#{@@widget_count}", left = 1, top = 1, right = 10, bottom = 2, direction = "h", speed = 1, text = "Hello, here is some really long text." )
  if id.nil?
    id = "ScrollerWidget_#{@@widget_count}"
  end
  
  @id = id
  @type = :scroller
  @screen = nil
  @visible = false
  
  @left = left
  @top = top
  @right = right
  @bottom = bottom
  @direction = direction
  @speed = speed
  @text = text
  
  @@widget_count += 1
end

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



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

def bottom
  @bottom
end

#directionObject

Returns the value of attribute direction.



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

def direction
  @direction
end

#leftObject

Returns the value of attribute left.



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

def left
  @left
end

#rightObject

Returns the value of attribute right.



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

def right
  @right
end

#speedObject

Returns the value of attribute speed.



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

def speed
  @speed
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

#topObject

Returns the value of attribute top.



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

def top
  @top
end

Instance Method Details

#attach_to(screen) ⇒ Object

Allows a widget to be attached to a screen.



81
82
83
84
85
86
# File 'lib/lcdproc/widgets/scroller.rb', line 81

def attach_to( screen )
  @right = screen.client.width
  @bottom = screen.client.height
  
  return super(screen )
end

#updateObject

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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/lcdproc/widgets/scroller.rb', line 89

def update
  if @screen
    response = @screen.client.send_command( Command.new( "widget_set #{@screen.id} #{self.id} #{@left} #{@top} #{@right} #{@bottom} #{@direction} #{@speed} \"#{@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