Class: SodaScreenShot
- Inherits:
-
Object
- Object
- SodaScreenShot
- Defined in:
- lib/SodaScreenShot.rb
Overview
SodaScreenShot – Class This class is for taking desktop screen shots of the current running os.
Currently only Winows & Linux are supported. Really any unix platform
running X11 is supported, they just have to be added to the case.
Input: dir: This is the directory to store the snapshots in.
Constant Summary collapse
- LINUX_XWD_BIN =
"xwd"
- LINUX_CONVERT_BIN =
"convert"
- OUTPUT_FILE =
"screenshot-"
Instance Method Summary collapse
-
#GetOutputFile ⇒ Object
GetOutputFile – Method This is a getter for getting the newly created snapshot file.
-
#initialize(dir) ⇒ SodaScreenShot
constructor
A new instance of SodaScreenShot.
Constructor Details
#initialize(dir) ⇒ SodaScreenShot
Returns a new instance of SodaScreenShot.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/SodaScreenShot.rb', line 46 def initialize(dir) os = nil err = nil time = Time.now() time = time.to_i() hostname = "#{ENV['HOSTNAME']}" @outputfile = nil if (!File.exist?(dir)) raise "Failed to find needed diectory: '#{dir}!'\n" end if ( (hostname.empty?) || (hostname.length < 5) ) hostname = `hostname` hostname = hostname.chomp() end os = SodaUtils.GetOsType() case (os) when /linux/i xwd = FindLinuxXwd() if (xwd == nil) raise "Failed to find needed program: 'xwd'!\n" end @outputfile = "#{dir}/#{OUTPUT_FILE}#{time}-#{hostname}.xwd" cmd = "#{xwd} -root -out #{@outputfile}" err = Kernel.system(cmd) if (!err) raise "Failed trying to take screenshot!\n" end convert = FindLinuxConvert() if (convert != nil) old_outfile = @outputfile ext = File.extname(old_outfile) @outputfile = @outputfile.gsub(/#{ext}$/, "") @outputfile << ".png" cmd = "#{convert} #{old_outfile} #{@outputfile}" err = Kernel.system(cmd) if (!err) @outputfile = old_outfile else File.unlink(old_outfile) end end when /windows/i require 'win32/screenshot' @outputfile = "#{dir}/#{OUTPUT_FILE}#{time}-#{hostname}.bmp" begin img = Win32::Screenshot::Take.of(:desktop) img.write(@outputfile) rescue Exception => e end end end |
Instance Method Details
#GetOutputFile ⇒ Object
GetOutputFile – Method This is a getter for getting the newly created snapshot file.
Input: None.
Output: retutns a string with the full path and filename to the new file.
114 115 116 |
# File 'lib/SodaScreenShot.rb', line 114 def GetOutputFile() return @outputfile end |