Пример #1
0
def showImgWithLegend(width=None, height=None):
    """ This function shows the image and legend from current IDV window while in GUI mode. Optional arguments are width and height in pixels, they currently default to 600 and 400"""
    from java.util import Base64  ##only in java8
    from javax.imageio import ImageIO
    from java.io import ByteArrayOutputStream
    from ucar.unidata.ui.ImageUtils import resize, toBufferedImage
    import java
    import java.awt.Robot as Robot
    import java.awt.Rectangle as Rectangle
    import java.awt.Toolkit as Toolkit
    from ucar.unidata.util import Misc
    VM = idv.getViewManager()
    VMC = VM.getContents()
    VMCC = VMC.getComponent(
        1
    )  # the view and legend ; 0 is left most part of view window with controls for perspective views
    siz = VMCC.getSize()
    loc = VMCC.getLocationOnScreen()
    gc = VMCC.getGraphicsConfiguration()
    loc.x -= gc.getBounds().x
    loc.y -= gc.getBounds().y
    robotx = Robot(gc.getDevice())
    VM.toFront()
    Misc.sleep(250)
    img = robotx.createScreenCapture(
        Rectangle(loc.x, loc.y, siz.width, siz.height))
    if width != None and height != None:
        img = toBufferedImage(resize(img, width, height))
    bos = ByteArrayOutputStream()
    ImageIO.write(img, "png",
                  Base64.getEncoder().wrap(bos))
    data = bos.toString("UTF-8")
    return {"display": "image", "data": data}
Пример #2
0
def showImgWithFullWindow(width=None, height=None):
    """ This function shows the image from current IDV window while in GUI mode. optional arguments are width and height in pixels, they
    currently default to 600 and 400"""
    from java.util import Base64  ##only in java8
    from javax.imageio import ImageIO
    from java.io import ByteArrayOutputStream
    from ucar.unidata.ui.ImageUtils import resize, toBufferedImage
    import java
    import java.awt.Robot as Robot
    import java.awt.Rectangle as Rectangle
    import java.awt.Toolkit as Toolkit
    from ucar.unidata.util import Misc
    VM = idv.getViewManager()
    myframe = VM.getDisplayWindow().getComponent()
    robotx = Robot(myframe.getGraphicsConfiguration().getDevice())
    VM.toFront()
    #robotx.delay(250)
    Misc.sleep(350)
    pause()
    img = robotx.createScreenCapture(
        Rectangle(myframe.getX(), myframe.getY(), myframe.getWidth(),
                  myframe.getHeight()))
    if width != None and height != None:
        img = toBufferedImage(resize(img, width, height))
    bos = ByteArrayOutputStream()
    ImageIO.write(img, "png",
                  Base64.getEncoder().wrap(bos))
    data = bos.toString("UTF-8")
    return {"display": "image", "data": data}
Пример #3
0
def pixelColor(posX,posY):   
    pixel = Robot().getPixelColor(posX,posY)
    r = pixel.getRed()
    g = pixel.getGreen() 
    b = pixel.getBlue() 
    color = '{:02x}{:02x}{:02x}'.format(r,g,b)
    return color
Пример #4
0
    def GetDotBoard(self, clock):
        #logging.debug("GetDotBoard")
        if exists("lost_message.png", 0.001):
            return -1
        dotLoc = []
        dotColor = []
        dotLoc.append(self.clock.getCenter().offset(221, 475))
        stepX = 96
        stepY = 97
        for i in range(1, 7):
            dotLoc.append(Location(dotLoc[i - 1].x + stepX, dotLoc[i - 1].y))
        for i in range(0, 7):
            dotLoc.append(Location(dotLoc[i].x, dotLoc[i].y + stepY))

        r = Robot()
        question_mark_count = 0
        for i in range(0, 14):
            c = r.getPixelColor(dotLoc[i].x,
                                dotLoc[i].y)  # get the color object
            color = self._check_color(c)  # 檢查該點的顏色
            if color == "?":
                color = self._check_around(r, dotLoc[i].x, dotLoc[i].y)
            if color == "?":
                question_mark_count += 1
                if question_mark_count > 3:  #魂盤有太多沒辨識出來, 則跳過這次魂盤
                    return 0

            dotColor.append(color)
            #crgb = ( c.getRed(), c.getGreen(), c.getBlue() ) # decode to RGB values
            #print dotColor[i]
        self.SetBoard(dotLoc, dotColor)
        return 1
Пример #5
0
def showImgWithLegend(width=None,height=None):
    """ This function shows the image and legend from current IDV window while in GUI mode. Optional arguments are width and height in pixels, they currently default to 600 and 400"""
    from java.util import Base64 ##only in java8
    from javax.imageio import ImageIO
    from java.io import ByteArrayOutputStream
    from ucar.unidata.ui.ImageUtils import resize,toBufferedImage
    import java
    import java.awt.Robot as Robot
    import java.awt.Rectangle as Rectangle
    import java.awt.Toolkit as Toolkit
    from ucar.unidata.util import Misc
    VM=idv.getViewManager()
    VMC=VM.getContents()
    VMCC=VMC.getComponent(1) # the view and legend ; 0 is left most part of view window with controls for perspective views
    siz=VMCC.getSize()
    loc= VMCC.getLocationOnScreen()
    gc= VMCC.getGraphicsConfiguration()
    loc.x -= gc.getBounds().x
    loc.y -= gc.getBounds().y
    robotx=Robot(gc.getDevice())
    VM.toFront()
    Misc.sleep(250)
    img = robotx.createScreenCapture(Rectangle(loc.x, loc.y,siz.width, siz.height))
    if width != None and height != None:
        img=toBufferedImage(resize(img,width,height));
    bos=ByteArrayOutputStream();
    ImageIO.write(img, "png", Base64.getEncoder().wrap(bos));
    data = bos.toString("UTF-8");
    return {"display":"image","data":data}
Пример #6
0
def showImgWithFullWindow(width=None,height=None):
    """ This function shows the image from current IDV window while in GUI mode. optional arguments are width and height in pixels, they
    currently default to 600 and 400"""
    from java.util import Base64 ##only in java8
    from javax.imageio import ImageIO
    from java.io import ByteArrayOutputStream
    from ucar.unidata.ui.ImageUtils import resize,toBufferedImage
    import java
    import java.awt.Robot as Robot
    import java.awt.Rectangle as Rectangle
    import java.awt.Toolkit as Toolkit
    from ucar.unidata.util import Misc
    VM=idv.getViewManager()
    myframe=VM.getDisplayWindow().getComponent()
    robotx = Robot(myframe.getGraphicsConfiguration().getDevice())
    VM.toFront();
    #robotx.delay(250)
    Misc.sleep(350)
    pause()
    img=robotx.createScreenCapture(Rectangle( myframe.getX(),myframe.getY(),myframe.getWidth(),myframe.getHeight()))
    if width != None and height != None:
        img=toBufferedImage(resize(img,width,height));
    bos=ByteArrayOutputStream();
    ImageIO.write(img, "png", Base64.getEncoder().wrap(bos));
    data = bos.toString("UTF-8");
    return {"display":"image","data":data}
Пример #7
0
 def find_monsters(self):  # returns array of map_index position
     self.monsters = []
     for cell in self.map_cells:
         point = self.map_pos_to_screen_point(cell)
         point_color = Robot().getPixelColor(point.getX(), point.getY())
         if 30 < point_color.getRed() < 65:
             self.monsters.append(cell)
             point.highlight()
     return self.monsters
Пример #8
0
def run(title):
    gd = ij.gui.GenericDialog('Record Desktop')
    gd.addNumericField('Max. frames:', 50, 0)
    gd.addNumericField('Milisecond interval:', 300, 0)
    gd.addSlider('Start in (seconds):', 0, 20, 5)
    gd.showDialog()
    if gd.wasCanceled():
        return
    n_frames = int(gd.getNextNumber())
    interval = gd.getNextNumber() / 1000.0  # in seconds
    delay = int(gd.getNextNumber())

    snaps = []

    try:
        while delay > 0:
            ij.IJ.showStatus('Starting in ' + str(delay) + 's.')
            time.sleep(1)  # one second
            delay -= 1
        ij.IJ.showStatus('')
        ij.IJ.showStatus("Starting...")
        out.println("Starting...")
        # start capturing
        robot = Robot()
        box = Rectangle(ij.IJ.getScreenSize())
        start = currentTimeMillis() / 1000.0  # in seconds
        last = start
        intervals = []
        real_interval = 0
        # Initial shot
        snaps.append(robot.createScreenCapture(box))
        while len(snaps) < n_frames and last - start < n_frames * interval:
            now = currentTimeMillis() / 1000.0  # in seconds
            real_interval = now - last
            if real_interval >= interval:
                last = now
                snaps.append(robot.createScreenCapture(box))
                intervals.append(real_interval)
            else:
                time.sleep(interval / 5)  # time in seconds
        # Create stack
        out.println("End")
        awt = snaps[0]
        stack = ij.ImageStack(awt.getWidth(None), awt.getHeight(None), None)
        t = 0
        for snap, real_interval in zip(snaps, intervals):
            stack.addSlice(str(ij.IJ.d2s(t, 3)),
                           ij.ImagePlus('', snap).getProcessor())
            snap.flush()
            t += real_interval

        ImagePlus("Desktop recording", stack).show()
    except Exception, e:
        print "Some error ocurred:"
        print e
        for snap in snaps:
            snap.flush()
Пример #9
0
 def find_characters(self):  # returns array of map_index position
     self.characters = []
     for cell in self.map_cells:
         point = self.map_pos_to_screen_point(cell)
         point_color = Robot().getPixelColor(point.getX(), point.getY())
         if 100 < point_color.getRed() < 260:
             if point_color.getBlue() < 80:
                 self.characters.append(cell)
                 point.highlight()
     return self.characters
Пример #10
0
def run(title):
	gd = ij.gui.GenericDialog('Record Desktop')
	gd.addNumericField('Max. frames:', 50, 0)
	gd.addNumericField('Milisecond interval:', 300, 0)
	gd.addSlider('Start in (seconds):', 0, 20, 5)
	gd.showDialog()
	if gd.wasCanceled():
		return
	n_frames = int(gd.getNextNumber())
	interval = gd.getNextNumber() / 1000.0 # in seconds
	delay = int(gd.getNextNumber())
	
	snaps = []

	try:
		while delay > 0:
			ij.IJ.showStatus('Starting in ' + str(delay) + 's.')
			time.sleep(1) # one second
			delay -= 1
		ij.IJ.showStatus('')
		ij.IJ.showStatus("Starting...")
		out.println("Starting...")
		# start capturing
		robot = Robot()
		box = Rectangle(ij.IJ.getScreenSize())
		start = currentTimeMillis() / 1000.0 # in seconds
		last = start
		intervals = []
		real_interval = 0
		# Initial shot
		snaps.append(robot.createScreenCapture(box))
		while len(snaps) < n_frames and last - start < n_frames * interval:
			now = currentTimeMillis() / 1000.0 # in seconds
			real_interval = now - last
			if real_interval >= interval:
				last = now
				snaps.append(robot.createScreenCapture(box))
				intervals.append(real_interval)
			else:
				time.sleep(interval / 5) # time in seconds
		# Create stack
		out.println("End")
		awt = snaps[0]
		stack = ij.ImageStack(awt.getWidth(None), awt.getHeight(None), None)
		t = 0
		for snap,real_interval in zip(snaps,intervals):
			stack.addSlice(str(ij.IJ.d2s(t, 3)), ij.ImagePlus('', snap).getProcessor())
			snap.flush()
			t += real_interval

		ImagePlus("Desktop recording", stack).show()
	except Exception, e:
		print "Some error ocurred:"
		print e
		for snap in snaps: snap.flush()
Пример #11
0
 def get_start_battle_positions(self):  # incompleto
     start_position = []
     for cell in self.map_cells:
         point = self.map_pos_to_screen_point(cell)
         point_color = Robot().getPixelColor(point.getX(), point.getY())
         color = [point_color.getRed(), point_color.getBlue()]
         if 220 < color[0]:
             start_position.append(cell)
             my_team = "red"
             continue
         if 220 < color[1]:
             start_position.append(cell)
     return start_position
Пример #12
0
def checkTextAndColorFromSpin():
    Region(717,828,95,90).click()
    time.sleep(1)
    textFromSpin = Region(435,754,73,24).text()
    colorRegion = find("1460730720660.png")
    colorPattern = colorRegion.getTopLeft().offset(5,5)
    robot = Robot()
    colorRobot = robot.getPixelColor(colorPattern.x, colorPattern.y)
    color = ( colorRobot.getRed())
    if color == 173:
        colorRed = 'red'
        textFromSpin = textFromSpin + colorRed
        return textFromSpin
    elif color == 31:
        colorBlack = 'black'
        textFromSpin = textFromSpin + colorBlack
        return textFromSpin
    else: 
        return textFromSpin
Пример #13
0
 def get_map_info(self):
     count_index = 0
     count_rows = 0
     while count_rows < 40:
         count_columns = 0
         while count_columns < 14:
             coord_x = self.get_column_position(count_columns, count_rows)
             coord_y = self.get_row_position(count_rows) + 10
             pixel_color = Robot().getPixelColor(
                 coord_x, coord_y)  # get the color object
             color = [
                 pixel_color.getRed(),
                 pixel_color.getGreen(),
                 pixel_color.getBlue()
             ]  #array [R,G,B]
             #print color[0],color[1],color[2]
             # 0 -> cells
             # 1 -> holes
             # 2 -> walls
             if 100 < color[0]:
                 self.map.append(0)
                 self.map_cells.append(count_index)
             elif color[0] <= 30:
                 if color[2] > 50:
                     self.map.append(0)
                     self.map_cells.append(count_index)
                 else:
                     self.map.append(1)
                     self.map_holes.append(count_index)
             elif 65 < color[0] <= 100:
                 self.map.append(2)
                 self.map_walls.append(count_index)
             elif 30 < color[0] <= 65:
                 self.map.append(0)  #monsters
                 self.map_cells.append(count_index)
             count_index += 1
             count_columns += 1
         count_rows += 1
Пример #14
0
    def save_screenshot_to(self, path):
        """Saves a screenshot to the specified file.

        The directory holding the file must exist or an exception is raised.
        """
        path = os.path.abspath(path.replace('/', os.sep))
        if not os.path.exists(os.path.dirname(path)):
            raise RuntimeError(
                "Directory '%s' where to save the screenshot does "
                "not exist" % os.path.dirname(path))
        screensize = Toolkit.getDefaultToolkit().getScreenSize()
        rectangle = Rectangle(0, 0, screensize.width, screensize.height)
        image = Robot().createScreenCapture(rectangle)
        ImageIO.write(image, "jpg", File(path))
        print "Screenshot saved to '%s'" % path
        return path
Пример #15
0
 def checkColor(self, SCREEN):
     print" checkColor !!"
     i = Robot().createScreenCapture(Rectangle(SCREEN.getX(),
                 SCREEN.getY(), self.patternW, self.patternH))
     bColor = Color(200, 4, 4)
     pColor = Color(45, 48, 177)
     print"self.patternW:"+self.patternW+ " self.patternH:"+self.patternH
     for x in range(0, self.patternW):
         for y in range(0, self.patternH):
             print" color"
             print i.getRGB(x, y)
             if bColor == Color(i.getRGB(x, y)):
                 return "B"
             if pColor == Color(i.getRGB(x, y)):
                 return "P"
Пример #16
0
def run(title):
    gd = GenericDialog('Record Window')
    gd.addMessage(
        "Maximum number of frames to record.\nZero means infinite, interrupt with ESC key."
    )
    gd.addNumericField('Max. frames:', 50, 0)
    gd.addNumericField('Milisecond interval:', 300, 0)
    gd.addSlider('Start in (seconds):', 0, 20, 5)
    frames = []
    titles = []
    for f in Frame.getFrames():
        if f.isEnabled() and f.isVisible():
            frames.append(f)
            titles.append(f.getTitle())
    gd.addChoice('Window:', titles, titles[0])
    gd.addCheckbox("To file", False)
    gd.showDialog()
    if gd.wasCanceled():
        return
    n_frames = int(gd.getNextNumber())
    interval = gd.getNextNumber() / 1000.0  # in seconds
    frame = frames[gd.getNextChoiceIndex()]
    delay = int(gd.getNextNumber())
    tofile = gd.getNextBoolean()

    dir = None
    if tofile:
        dc = DirectoryChooser("Directory to store image frames")
        dir = dc.getDirectory()
        if dir is None:
            return  # dialog canceled

    snaps = []
    borders = None
    executors = Executors.newFixedThreadPool(1)
    try:
        while delay > 0:
            IJ.showStatus('Starting in ' + str(delay) + 's.')
            time.sleep(1)  # one second
            delay -= 1

        IJ.showStatus('Capturing frame borders...')
        bounds = frame.getBounds()
        robot = Robot()
        frame.toFront()
        time.sleep(0.5)  # half a second
        borders = robot.createScreenCapture(bounds)

        IJ.showStatus("Recording " + frame.getTitle())

        # Set box to the inside borders of the frame
        insets = frame.getInsets()
        box = bounds.clone()
        box.x = insets.left
        box.y = insets.top
        box.width -= insets.left + insets.right
        box.height -= insets.top + insets.bottom

        start = System.currentTimeMillis() / 1000.0  # in seconds
        last = start
        intervals = []
        real_interval = 0
        i = 1
        fus = None
        if tofile:
            fus = []

        # 0 n_frames means continuous acquisition
        while 0 == n_frames or (len(snaps) < n_frames
                                and last - start < n_frames * interval):
            now = System.currentTimeMillis() / 1000.0  # in seconds
            real_interval = now - last
            if real_interval >= interval:
                last = now
                img = snapshot(frame, box)
                if tofile:
                    fus.append(
                        executors.submit(
                            Saver(i, dir, bounds, borders, img,
                                  insets)))  # will flush img
                    i += 1
                else:
                    snaps.append(img)
                intervals.append(real_interval)
            else:
                time.sleep(interval / 5)
            # interrupt capturing:
            if IJ.escapePressed():
                IJ.showStatus("Recording user-interrupted")
                break

        # debug:
        #print "insets:", insets
        #print "bounds:", bounds
        #print "box:", box
        #print "snap dimensions:", snaps[0].getWidth(), snaps[0].getHeight()

        # Create stack
        stack = None
        if tofile:
            for fu in snaps:
                fu.get()  # wait on all
            stack = VirtualStack(bounds.width, bounds.height, None, dir)
            files = File(dir).list(TifFilter())
            Arrays.sort(files)
            for f in files:
                stack.addSlice(f)
        else:
            stack = ImageStack(bounds.width, bounds.height, None)
            t = 0
            for snap, real_interval in zip(snaps, intervals):
                bi = BufferedImage(bounds.width, bounds.height,
                                   BufferedImage.TYPE_INT_RGB)
                g = bi.createGraphics()
                g.drawImage(borders, 0, 0, None)
                g.drawImage(snap, insets.left, insets.top, None)
                stack.addSlice(str(IJ.d2s(t, 3)),
                               ImagePlus('', bi).getProcessor())
                t += real_interval
                snap.flush()
                bi.flush()

        borders.flush()

        ImagePlus(frame.getTitle() + " recording", stack).show()
        IJ.showStatus('Done recording ' + frame.getTitle())
    except Exception, e:
        print "Some error ocurred:"
        print e.printStackTrace()
        IJ.showStatus('')
        if borders is not None: borders.flush()
        for snap in snaps:
            snap.flush()
Пример #17
0
def healerColor(posX,posY,id):

    pixel = Robot().getPixelColor(posX,posY)
    if   id == "life": return pixel.getRed()
    elif id == "mana": return pixel.getBlue() 
    else: return 0
Пример #18
0
        sc.setAutoWaitTimeout(timeout)
        sc.setROI(region)
        try:
            target = sc.find(image)
            click(target.getCenter())
            return True
        except FindFailed:
            Debug.user("[clickImageInRegion] can't find %s" % message)
            return False

    #def excuteAutomation(automation):
    #    automation.execute()


from java.awt import Robot
ControlLib_robot = Robot()


def getColor(loc):
    return ControlLib_robot.getPixelColor(loc.x, loc.y)


import time


# log text to file with timestamp
def logToFile(strMessage, strFileName=os.path.join(getBundlePath(),
                                                   "log.txt")):
    localtime = time.localtime(time.time())
    timestring = time.strftime('%Y/%m/%d %H:%M:%S')
    inp = open(strFileName, "a")
Пример #19
0
from java.awt import Robot
robot = Robot()

DirectionStr = sys.argv[1]
# up=1 or down=-1
direction = -1
if DirectionStr == 'up':
    direction = 1

Kol = int(sys.argv[2])

keyDown(Key.CTRL)
sleep(0.1)
for x in range(0, Kol):
    robot.mouseWheel(direction)
    sleep(0.1)

keyUp()
Пример #20
0
if System.getProperty("os.name").startswith("Windows"):
    import os
    srcFileDir = os.path.dirname(os.path.abspath(__file__))
    os.chdir(srcFileDir)
    sys.path = [srcFileDir] + sys.path


REMAP_WIDTH = 480
REMAP_HEIGHT = 800
MARGIN = 10

CONNECTION_TIMEOUT = 5000

nextPort = 6789

robot = Robot()
connectedDevices = []
devConnListener = None

class Device:
    serialno = None
    mdevice = None
    socket = None
    cursorRatio = None
    productName = None
    focused = None

    def __init__(self):
        pass

    def __init__(self, serial, mdev, sock, ratio, name):
Пример #21
0
try:
    from java.awt import Robot, Toolkit
    from java.awt.event import InputEvent
    from java.awt.MouseInfo import getPointerInfo
    import time

    r = Robot()
    move_mouse_right = True
    while True:
        loc = getPointerInfo().getLocation()
        x = int(loc.getX())
        y = int(loc.getY())
        print(x, y)
        if move_mouse_right:
            r.mouseMove(x + 1, y)
        else:
            r.mouseMove(x - 1, y)
        if move_mouse_right:
            move_mouse_right = False
        else:
            move_mouse_right = True
        time.sleep(10)

except Exception as e:
    print(e)
Пример #22
0
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

from java.awt import Robot, Toolkit
from java.awt.event import InputEvent
from java.awt.MouseInfo import getPointerInfo
from .base import PyMouseMeta

r = Robot()

class PyMouse(PyMouseMeta):
    def press(self, x, y, button = 1):
        button_list = [None, InputEvent.BUTTON1_MASK, InputEvent.BUTTON3_MASK, InputEvent.BUTTON2_MASK]
        self.move(x, y)
        r.mousePress(button_list[button])

    def release(self, x, y, button = 1):
        button_list = [None, InputEvent.BUTTON1_MASK, InputEvent.BUTTON3_MASK, InputEvent.BUTTON2_MASK]
        self.move(x, y)
        r.mouseRelease(button_list[button])
    
    def move(self, x, y):
        r.mouseMove(x, y)
Пример #23
0
def run(title):
    gd = GenericDialog("Record Window")
    gd.addMessage("Maximum number of frames to record.\nZero means infinite, interrupt with ESC key.")
    gd.addNumericField("Max. frames:", 50, 0)
    gd.addNumericField("Milisecond interval:", 300, 0)
    gd.addSlider("Start in (seconds):", 0, 20, 5)
    frames = []
    titles = []
    for f in Frame.getFrames():
        if f.isEnabled() and f.isVisible():
            frames.append(f)
            titles.append(f.getTitle())
    gd.addChoice("Window:", titles, titles[0])
    gd.addCheckbox("To file", False)
    gd.showDialog()
    if gd.wasCanceled():
        return
    n_frames = int(gd.getNextNumber())
    interval = gd.getNextNumber() / 1000.0  # in seconds
    frame = frames[gd.getNextChoiceIndex()]
    delay = int(gd.getNextNumber())
    tofile = gd.getNextBoolean()

    dir = None
    if tofile:
        dc = DirectoryChooser("Directory to store image frames")
        dir = dc.getDirectory()
        if dir is None:
            return  # dialog canceled

    snaps = []
    borders = None
    executors = Executors.newFixedThreadPool(1)
    try:
        while delay > 0:
            IJ.showStatus("Starting in " + str(delay) + "s.")
            time.sleep(1)  # one second
            delay -= 1

        IJ.showStatus("Capturing frame borders...")
        bounds = frame.getBounds()
        robot = Robot()
        frame.toFront()
        time.sleep(0.5)  # half a second
        borders = robot.createScreenCapture(bounds)

        IJ.showStatus("Recording " + frame.getTitle())

        # Set box to the inside borders of the frame
        insets = frame.getInsets()
        box = bounds.clone()
        box.x = insets.left
        box.y = insets.top
        box.width -= insets.left + insets.right
        box.height -= insets.top + insets.bottom

        start = System.currentTimeMillis() / 1000.0  # in seconds
        last = start
        intervals = []
        real_interval = 0
        i = 1
        fus = None
        if tofile:
            fus = []

            # 0 n_frames means continuous acquisition
        while 0 == n_frames or (len(snaps) < n_frames and last - start < n_frames * interval):
            now = System.currentTimeMillis() / 1000.0  # in seconds
            real_interval = now - last
            if real_interval >= interval:
                last = now
                img = snapshot(frame, box)
                if tofile:
                    fus.append(executors.submit(Saver(i, dir, bounds, borders, img, insets)))  # will flush img
                    i += 1
                else:
                    snaps.append(img)
                intervals.append(real_interval)
            else:
                time.sleep(interval / 5)
                # interrupt capturing:
            if IJ.escapePressed():
                IJ.showStatus("Recording user-interrupted")
                break

                # debug:
                # print "insets:", insets
                # print "bounds:", bounds
                # print "box:", box
                # print "snap dimensions:", snaps[0].getWidth(), snaps[0].getHeight()

                # Create stack
        stack = None
        if tofile:
            for fu in snaps:
                fu.get()  # wait on all
            stack = VirtualStack(bounds.width, bounds.height, None, dir)
            files = File(dir).list(TifFilter())
            Arrays.sort(files)
            for f in files:
                stack.addSlice(f)
        else:
            stack = ImageStack(bounds.width, bounds.height, None)
            t = 0
            for snap, real_interval in zip(snaps, intervals):
                bi = BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB)
                g = bi.createGraphics()
                g.drawImage(borders, 0, 0, None)
                g.drawImage(snap, insets.left, insets.top, None)
                stack.addSlice(str(IJ.d2s(t, 3)), ImagePlus("", bi).getProcessor())
                t += real_interval
                snap.flush()
                bi.flush()

        borders.flush()

        ImagePlus(frame.getTitle() + " recording", stack).show()
        IJ.showStatus("Done recording " + frame.getTitle())
    except Exception, e:
        print "Some error ocurred:"
        print e.printStackTrace()
        IJ.showStatus("")
        if borders is not None:
            borders.flush()
        for snap in snaps:
            snap.flush()
Пример #24
0
# Click save button, enter the new file name and save the file
try:
  saveButton = windowRegion.wait("SaveButton.png", 10)
except FindFailed:
  print "[ERROR] Save button in config file saver dialog cannot be found in original window boundaries!"
  captureScreenAndExit()

click(saveButton)
wait(5)
type("TEST_ConfigFileSaverDialogTest_Result")
type(Key.ENTER)
wait(5)

# Check if errors occurred
import java.awt.Robot as JRobot
colorPickerRobot = JRobot()

try:
  statusIcon = windowRegion.find("GreenStatusIcon.png")
except FindFailed:
  print "[ERROR] Cannot find green StatusIcon!"
  captureScreenAndExit()

statusIconCenter = statusIcon.getCenter()
color = colorPickerRobot.getPixelColor(statusIconCenter.x, statusIconCenter.y)

if color.getGreen() < color.getRed() or color.getGreen() < color.getBlue():
  print "[ERROR] StatusIcon is not green (", color, ")"
  captureScreenAndExit()
  
closeApp(appTitle) # close the window - stop the process
Пример #25
0
from java.awt import Robot
cp = find(capture())
r = Robot()
c = r.getPixelColor(cp.getX(), cp.getY())  # get the color object
crgb = (c.getRed(), c.getGreen(), c.getBlue())  # decode to RGB values
print crgb

#def get_top_line(a):
# central_top = []
# central_position = float(a)
# print central_position/14
# while central_position/14/2 != 0 and central_position > 14:
#    if (central_position//14) % 2 == 0:
#        central_position -=  15
#    else:
#        central_position -=  14
#   central_top.append(central_position)
# return central_top

#print(get_top_line(85))
Пример #26
0
 def _java_screenshot(self, path):
     size = Toolkit.getDefaultToolkit().getScreenSize()
     rectangle = Rectangle(0, 0, size.width, size.height)
     image = Robot().createScreenCapture(rectangle)
     ImageIO.write(image, 'jpg', File(path))
Пример #27
0
def is_last():
    p = find("previous.png").getCenter()
    c = JRobot().getPixelColor(p.x, p.y)
    crgb = (c.getRed(), c.getGreen(), c.getBlue())
    gris = (183, 123, 35)
    return crgb == gris
    print "[ERROR] Application cannot be found on any screen after ", maxNumberOfTries, "tries!"
    captureScreenAndExit()


#------------------------------------------------------------------------------
# Main program

exe = getCommandFromArguments("D:/devel/PlusBuild-bin")

appTitle = "SegmentationParameterDialogTest"

testApp = App.open(exe)

import java.awt.Robot as JRobot
colorPickerRobot = JRobot()

connectButton = findApplicationOnAllMonitors("ConnectButton.png")

App.focus(appTitle)

# Get the region of the segmentation parameter dialog window
applicationTopLeft = connectButton.getTopLeft()
applicationTopLeft = applicationTopLeft.left(205).above(295)
windowRegion = Region(applicationTopLeft.x, applicationTopLeft.y, 495, 355)
messageBoxRegion = Region(applicationTopLeft.x - 15,
                          applicationTopLeft.y - 195, 510, 550)

# Look for green status icon
try:
    statusIcon = windowRegion.find("GreenStatusIcon.png")
Пример #29
0
def getListColor(SCREEN):  #pass a Region and get pixel (r,g,b)
    i = Robot().createScreenCapture(
        Rectangle(SCREEN.getX(), SCREEN.getY(), SCREEN.getW(), SCREEN.getH()))

    c = Color(i.getRGB(0, 0))
    return c.getRed(), c.getGreen(), c.getBlue()