Class: TE3270::Emulators::Extra

Inherits:
Object
  • Object
show all
Defined in:
lib/te3270/emulators/extra.rb

Overview

This class has the code necessary to communicate with the terminal emulator called EXTRA! X-treme. You can use this emulator by providing the :extra parameter to the constructor of your screen object or by passing the same value to the emulator_for method on the TE3270 module.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_wait_time=(value) ⇒ Object

Sets the attribute max_wait_time

Parameters:

  • value

    the value to set the attribute max_wait_time to.



21
22
23
# File 'lib/te3270/emulators/extra.rb', line 21

def max_wait_time=(value)
  @max_wait_time = value
end

#session_file=(value) ⇒ Object (writeonly)

Sets the attribute session_file

Parameters:

  • value

    the value to set the attribute session_file to.



21
22
23
# File 'lib/te3270/emulators/extra.rb', line 21

def session_file=(value)
  @session_file = value
end

#visible=(value) ⇒ Object

Sets the attribute visible

Parameters:

  • value

    the value to set the attribute visible to.



21
22
23
# File 'lib/te3270/emulators/extra.rb', line 21

def visible=(value)
  @visible = value
end

#window_state=(value) ⇒ Object

Sets the attribute window_state

Parameters:

  • value

    the value to set the attribute window_state to.



21
22
23
# File 'lib/te3270/emulators/extra.rb', line 21

def window_state=(value)
  @window_state = value
end

Instance Method Details

#connect {|_self| ... } ⇒ Object

Creates a method to connect to Extra System. This method expects a block in which certain platform specific values can be set. Extra can take the following parameters.

  • session_file - this value is required and should be the filename of the session.

  • visible - determines if the emulator is visible or not. If not set it will default to true.

  • window_state - determines the state of the session window. Valid values are :minimized, :normal, and :maximized. If not set it will default to :normal.

Examples:

Example calling screen object constructor with a block

screen_object = MyScreenObject.new(:extra)
screen_object.connect do |emulator|
  emulator.session_file = 'path_to_session_file'
  emulator.visible = true
  emulator.window_state = :maximized
end

Yields:

  • (_self)

Yield Parameters:



41
42
43
44
45
46
47
48
49
# File 'lib/te3270/emulators/extra.rb', line 41

def connect
  start_extra_system

  yield self if block_given?
  raise 'The session file must be set in a block when calling connect with the Extra emulator.' if @session_file.nil?
  open_session
  @screen = session.Screen
  @area = screen.SelectAll
end

#disconnectObject

Disconnects the Extra System connection



54
55
56
# File 'lib/te3270/emulators/extra.rb', line 54

def disconnect
  system.Quit
end

#get_string(row, column, length) ⇒ String

Extracts text of specified length from a start point.

Parameters:

  • row (Fixnum)

    the x coordinate of location on the screen.

  • column (Fixnum)

    the y coordinate of location on the screen.

  • length (Fixnum)

    the length of string to extract

Returns:

  • (String)


66
67
68
# File 'lib/te3270/emulators/extra.rb', line 66

def get_string(row, column, length)
  screen.GetString(row, column, length)
end

#put_string(str, row, column) ⇒ Object

Puts string at the coordinates specified.

Parameters:

  • str (String)

    the string to set

  • row (Fixnum)

    the x coordinate of the location on the screen.

  • column (Fixnum)

    the y coordinate of the location on the screen.



77
78
79
80
# File 'lib/te3270/emulators/extra.rb', line 77

def put_string(str, row, column)
  screen.PutString(str, row, column)
  quiet_period
end

#screenshot(filename) ⇒ Object

Creates a method to take screenshot of the active screen. If you have set the :visible property to false it will be made visible prior to taking the screenshot and then changed to invisible after.

Parameters:

  • filename (String)

    the path and name of the screenshot file to be saved



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/te3270/emulators/extra.rb', line 135

def screenshot(filename)
  File.delete(filename) if File.exists?(filename)
  session.Visible = true unless visible

  toolkit = Toolkit::getDefaultToolkit()
  screen_size = toolkit.getScreenSize()
  rect = Rectangle.new(screen_size)
  robot = Robot.new
  image = robot.createScreenCapture(rect)
  f = java::io::File.new(filename)
  ImageIO::write(image, "png", f)

  session.Visible = false unless visible
end

#send_keys(keys) ⇒ Object

Sends keystrokes to the host, including function keys.

Parameters:

  • keys (String)

    keystokes up to 255 in length



87
88
89
90
# File 'lib/te3270/emulators/extra.rb', line 87

def send_keys(keys)
  screen.SendKeys(keys)
  quiet_period
end

#textString

Returns the text of the active screen

Returns:

  • (String)


155
156
157
# File 'lib/te3270/emulators/extra.rb', line 155

def text
  area.Value
end

#wait_for_host(seconds) ⇒ Object

Waits for the host to not send data for a specified number of seconds

Parameters:

  • seconds (Fixnum)

    the maximum number of seconds to wait



110
111
112
113
114
# File 'lib/te3270/emulators/extra.rb', line 110

def wait_for_host(seconds)
  wait_for(seconds) do
    screen.WaitHostQuiet
  end
end

#wait_for_string(str, row, column) ⇒ Object

Wait for the string to appear at the specified location

Parameters:

  • str (String)

    the string to wait for

  • row (Fixnum)

    the x coordinate of location

  • column (Fixnum)

    the y coordinate of location



99
100
101
102
103
# File 'lib/te3270/emulators/extra.rb', line 99

def wait_for_string(str, row, column)
  wait_for do
    screen.WaitForString(str, row, column)
  end
end

#wait_until_cursor_at(row, column) ⇒ Object

Waits until the cursor is at the specified location.

Parameters:

  • row (Fixnum)

    the x coordinate of the location

  • column (Fixnum)

    the y coordinate of the location



122
123
124
125
126
# File 'lib/te3270/emulators/extra.rb', line 122

def wait_until_cursor_at(row, column)
  wait_for do
    screen.WaitForCursor(row, column)
  end
end