Class: TE3270::Emulators::Quick3270

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

Overview

This class has the code necessary to communicate with the terminal emulator called Quick3270. You can use this emulator by providing the :quick 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

Constructor Details

#initializeQuick3270

Returns a new instance of Quick3270.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/te3270/emulators/quick3270.rb', line 14

def initialize
  if RUBY_PLATFORM == "java"
    require 'jruby-win32ole'
    require 'java'

    include_class 'java.awt.Dimension'
    include_class 'java.awt.Rectangle'
    include_class 'java.awt.Robot'
    include_class 'java.awt.Toolkit'
    include_class 'java.awt.event.InputEvent'
    include_class 'java.awt.image.BufferedImage'
    include_class 'javax.imageio.ImageIO'
  else
    require 'win32ole'
    require 'win32/screenshot'
  end


end

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.



12
13
14
# File 'lib/te3270/emulators/quick3270.rb', line 12

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.



12
13
14
# File 'lib/te3270/emulators/quick3270.rb', line 12

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.



12
13
14
# File 'lib/te3270/emulators/quick3270.rb', line 12

def visible=(value)
  @visible = value
end

Instance Method Details

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

Creates a method to connect to Quick System. This method expects a block in which certain platform specific values can be set. Quick 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.

Examples:

Example calling screen object constructor with a block

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

Yields:

  • (_self)

Yield Parameters:



48
49
50
51
52
53
# File 'lib/te3270/emulators/quick3270.rb', line 48

def connect
  start_quick_system
  yield self if block_given?
  raise "The session file must be set in a block when calling connect with the Quick3270 emulator." if @session_file.nil?
  establish_session
end

#disconnectObject

Disconnects the Quick System connection



58
59
60
61
# File 'lib/te3270/emulators/quick3270.rb', line 58

def disconnect
  session.Disconnect
  system.Application.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)


71
72
73
# File 'lib/te3270/emulators/quick3270.rb', line 71

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.



82
83
84
85
86
# File 'lib/te3270/emulators/quick3270.rb', line 82

def put_string(str, row, column)
  screen.MoveTo(row, column)
  screen.PutString(str)
  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
149
150
151
152
# File 'lib/te3270/emulators/quick3270.rb', line 135

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

  if RUBY_PLATFORM == "java"
    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)
    system.Visible = false unless visible
  else
    hwnd = session.WindowHandle
    Win32::Screenshot::Take.of(:window, hwnd: hwnd).write(filename)
  end
end

#send_keys(keys) ⇒ Object

Sends keystrokes to the host, including function keys.

Parameters:

  • keys (String)

    keystokes up to 255 in length



93
94
95
96
# File 'lib/te3270/emulators/quick3270.rb', line 93

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

#textString

Returns the text of the active screen

Returns:

  • (String)


159
160
161
162
163
164
165
# File 'lib/te3270/emulators/quick3270.rb', line 159

def text
  rows = screen.Rows
  columns = screen.Cols
  result = ''
  rows.times { |row| result += "#{screen.GetString(row+1, 1, columns)}\\n" }
  result
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



114
115
116
# File 'lib/te3270/emulators/quick3270.rb', line 114

def wait_for_host(seconds)
  screen.WaitHostQuiet(seconds * 1000)
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



105
106
107
# File 'lib/te3270/emulators/quick3270.rb', line 105

def wait_for_string(str, row, column)
  screen.WaitForString(str, row, column)
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



124
125
126
# File 'lib/te3270/emulators/quick3270.rb', line 124

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