コード例 #1
0
def run_osra(osra):
	sdf = " "    
	filedes, filename = tempfile.mkstemp(suffix='.png')

	if os.name=="posix":
		import pygtk
		pygtk.require('2.0')
		import gtk, gobject
		clipboard = gtk.clipboard_get()
		image=clipboard.wait_for_image()
		if not image:
			return sdf
		try:
			image.save(filename,"png")
		except:
			return sdf
	else:
		import ImageGrab
		image = ImageGrab.grabclipboard()
		if not image:
			return sdf
		try:
			image.save(filename)
		except:
			return sdf

	try:
		stdout, stdin, stderr = popen2.popen3('"%s" -f sdf %s' % (osra, filename))
	except:
		os.remove(filename)
		return sdf

	sdf = stdout.read()
	#os.remove(filename)
	return sdf
コード例 #2
0
def upload_clipboard_image():
    im = ImageGrab.grabclipboard()

    if not isinstance(im, Image.Image):
        raise NoUpload

    print 'Uploading clipboard image'

    f = StringIO.StringIO()
    im.save(f, image_file_type)
    data = f.getvalue()

    # Generate remote path

    remote_name = str(uuid.uuid1()) + '.' + image_file_type
    remote_abs_path = remote_root_path + remote_name

    # Upload file with paramiko sftp
    transport = paramiko.Transport((host, port))
    transport.connect(username=username, password=password)
    sftp = paramiko.SFTPClient.from_transport(transport)
    fr = sftp.file(remote_abs_path, 'wb')
    fr.set_pipelined(True)
    fr.write(data)
    fr.close()
    sftp.close()
    transport.close()

    return [remote_name]
コード例 #3
0
def upload_clipboard_image():
  im = ImageGrab.grabclipboard()

  if not isinstance(im, Image.Image):
    raise NoUpload

  print 'Uploading clipboard image'

  f = StringIO.StringIO()
  im.save(f, image_file_type)
  data = f.getvalue()

  # Generate remote path
  
  remote_name = str(uuid.uuid1()) + '.' + image_file_type
  remote_abs_path = remote_root_path + remote_name

  # Upload file with paramiko sftp
  transport = paramiko.Transport((host, port))
  transport.connect(username=username, password=password)
  sftp = paramiko.SFTPClient.from_transport(transport)
  fr = sftp.file(remote_abs_path, 'wb')
  fr.set_pipelined(True)
  fr.write(data)
  fr.close()  
  sftp.close()
  transport.close()

  return [remote_name]
コード例 #4
0
ファイル: my_module.py プロジェクト: sulei1324/CODES-IN-LAB
def getClipBoardImage():
    im = ImageGrab.grabclipboard()
    if isinstance(im, Image.Image):
        print im.format, im.size, im.mode
        width, height = im.size
        pix = im.load()
        im_array = np.array(im)
    else:
        pass
    return im
コード例 #5
0
ファイル: main.py プロジェクト: downpoured/pyxels
	def menu_pasteImage(self):
		import sys
		if sys.platform!='win32':
			print 'Only supported on Windows...'
			return
		import ImageGrab
		im = ImageGrab.grabclipboard()
		if not isinstance(im, Image.Image):
			print 'Could not paste image.'
			return
		if im.mode != 'RGB':
			print 'Error: For now, only RGB mode images are supported.'
			return
		self.imgInput = im
		self.updateInput()
コード例 #6
0
ファイル: browserView.py プロジェクト: shauvik/webdiff
def captureScreen():
    '''
    @Description: Captures the screenshot
    @Return: Image
    '''
##    global global_c
    emptyClipboard()
    win32api.keybd_event(win32con.VK_SNAPSHOT, 1) #PrintScreen; 1-captures only foreground window
    timer = time.clock()
    print "Capturing at ", timer
    im = None
    while not isinstance(im, Image.Image):
        im = ImageGrab.grabclipboard()
        if (time.clock() - timer) > 5.0:
            print "Error capturing screenshot", time.clock()
            exit()
##    im.save("C:\\Screenshots\\%d.png"%(global_c), "PNG")
##    global_c +=1
    return im
コード例 #7
0
ファイル: upload.py プロジェクト: engie/webpaste
def getWin32ClipboardContents():
    """
    With thanks to http://mail.python.org/pipermail/python-list/2003-August/840896.html
    """
    import win32clipboard
    import win32con
    import types
    
    win32clipboard.OpenClipboard()
    types = {} 
    for name, val in win32con.__dict__.items():
        if name[:3] == "CF_" and name != "CF_SCREENFONTS":
            types[val] = name

    targets = []
    enum = 0
    while 1:
        enum = win32clipboard.EnumClipboardFormats( enum )
        if enum == 0:
            break
        if win32clipboard.IsClipboardFormatAvailable( enum ) == False:
            continue

        if not enum in types:
            name = win32clipboard.GetClipboardFormatName( enum )
            types[enum] = name
        targets.append( types[enum] )

    if "CF_BITMAP" in targets:
        import Image
        import ImageGrab
        im = ImageGrab.grabclipboard()

        import StringIO
        output = StringIO.StringIO()
        im.save(output, "PNG")

        return "clipboard.png", "image/png", output.getvalue()

    if "CF_TEXT" in targets:
        data = win32clipboard.GetClipboardData( win32con.CF_TEXT )
        return "clipboard.txt", "text/text", data
コード例 #8
0
    def menu_pasteImage(self):
        import sys
        if not (sys.platform.startswith('win')
                or sys.platform.startswith('mac')):
            print('Not supported on this platform...')
            return

        try:
            import ImageGrab
        except ImportError:
            from PIL import ImageGrab

        im = ImageGrab.grabclipboard()
        if not isinstance(im, Image.Image):
            print('Could not paste image.')
            return
        if im.mode != 'RGB':
            print('Error: For now, only RGB mode images are supported.')
            return
        self.imgInput = im
        self.updateInput()
コード例 #9
0
def run_osra(osra):
    sdf = " "
    filedes, filename = tempfile.mkstemp(suffix='.png')

    if os.name == "posix":
        import pygtk
        pygtk.require('2.0')
        import gtk, gobject
        clipboard = gtk.clipboard_get()
        image = clipboard.wait_for_image()
        if not image:
            return sdf
        try:
            image.save(filename, "png")
        except:
            return sdf
    else:
        import ImageGrab
        image = ImageGrab.grabclipboard()
        if not image:
            return sdf
        try:
            image.save(filename)
        except:
            return sdf

    try:
        stdout, stdin, stderr = popen2.popen3('"%s" -f sdf %s' %
                                              (osra, filename))
    except:
        os.remove(filename)
        return sdf

    sdf = stdout.read()
    #os.remove(filename)
    return sdf
コード例 #10
0
ファイル: img_test.py プロジェクト: leoinpisces/zyy_project
            for para in G_word_obj.ActiveDocument.Paragraphs:
                para.Range.Delete()
        except:
            print "delete failed"

        try:
            doc_file.ActiveWindow.Selection.PasteSpecial(
                False, False, False, False, 4, False, False)
        except:
            print "PasteSpecial failed"

        doc_file.Save()

        doc_file.Select()
        doc_file.ActiveWindow.Selection.CopyAsPicture()
        img = ImageGrab.grabclipboard()
        if isinstance(img, ImageGrab.Image.Image):
            print "image"
        else:
            print "not image"

        doc_file.Close()
    except:
        print "some error"
        G_word_obj.Quit()

    finally:
        G_word_obj.Quit()

    #img.save(r'F:\temp\test.jpg'.decode('utf-8').encode('cp936'),'jpg')
コード例 #11
0
 def getimage(self):
     self.image = ImageGrab.grabclipboard()
     return self.image is not None
コード例 #12
0
def printScreen():
    import win32api, win32con, ImageGrab
    win32api.keybd_event(win32con.VK_SNAPSHOT, 0) #use 1 for only the active window 0 for whole screen
    im = ImageGrab.grabclipboard()
    im.save("screenshot.jpg", "JPEG")
コード例 #13
0
ファイル: asst2htm.py プロジェクト: yindian/myutils
	if doc.images.length > 0:
		for item in doc.body.getElementsByTagName('img'):
			fname = fnquote(item.src) + '.bmp'
			if os.path.exists(fname):
				continue
			item.scrollIntoView()
			l = item.offsetLeft - item.offsetParent.scrollLeft
			t = item.offsetTop  - item.offsetParent.scrollTop
			w = item.offsetWidth
			h = item.offsetHeight
			l += wl
			t += wt
			time.sleep(0.05)
			win32api.keybd_event(win32con.VK_SNAPSHOT, 0)
			time.sleep(0.1)
			im = ImageGrab.grabclipboard()  
			im = im.crop((l, t, l+w, t+h))
			im.save(fname, "BMP")  
			print >> sys.stderr, fname, 'saved.'
	trycount = 0
	oldscrolltop = doc.body.scrollTop
	while doc.body.innerHTML.startswith(prefix):
		#doc.body.doScroll('scrollbarPageDown')
		win32api.keybd_event(win32con.VK_NEXT, 0)
		time.sleep(0.05)
		if doc.body.scrollTop == oldscrolltop:
			if trycount > 20:
				finished = True
				writelines(html[-1:])
				break
			time.sleep(0.05)
コード例 #14
0
ファイル: my_module.py プロジェクト: sulei1324/CODES-IN-LAB
    def capture_raw(self):
        try:
            dll = ctypes.cdll.LoadLibrary('CameraDll.dll')
        except Exception:
            print "Dll load error"
        else:
            try:
                print "aaaa"
                dll.CameraSubArea(0)
            except Exception:
                ref_images = []
                for i in xrange(10):
                    this_name = "./src/ref/%d.tif" % i
                    this_ref_image = cv.imread(this_name,
                                               cv.CV_LOAD_IMAGE_UNCHANGED)
                    ref_images.append(this_ref_image)
                record_txt = open(self.txt_name, 'a')
                image1 = ImageGrab.grabclipboard()
                self.im = np.array(image1)
                image1 = self.im
                cv.imwrite("./src/raw.tif", image1)
                retval, image1 = cv.threshold(image1, 50, 255,
                                              cv.THRESH_BINARY)
                image1 = cv.cvtColor(image1, cv.COLOR_BGR2GRAY)
                image1 = image1 > 10
                image1 = image1.astype(np.uint8)
                image1 = image1 * 255
                cv.imwrite("./src/bin.tif", image1)
                flag_in = False
                s = 0
                block_num = 0
                char_num_array = []
                for i in xrange(image1.shape[0]):
                    if np.all(image1[i, :] == 255):
                        if flag_in:
                            flag_in = False
                            block = image1[s:i, :]
                            block_name = "./src/%d_block.tif" % block_num
                            char_num = 0
                            s_char = 0
                            flag_block = False
                            for j in xrange(block.shape[1]):
                                if np.all(block[:, j] == 255):
                                    if flag_block:
                                        flag_block = False
                                        char_block = block[:, s_char:j]
                                        char_name = "./src/char_%d_%d.tif" % (
                                            block_num, char_num)
                                        cv.imwrite(char_name, char_block)
                                        char_num += 1
                                else:
                                    if not flag_block:
                                        s_char = j
                                        flag_block = True
                            cv.imwrite(block_name, block)
                            char_num_array.append(char_num)
                            block_num += 1
                    else:
                        if not flag_in:
                            s = i
                            flag_in = True

                for i in xrange(block_num):
                    char_num = char_num_array[i]
                    this_record = ""
                    for j in xrange(char_num):
                        char_name = "./src/char_%d_%d.tif" % (i, j)
                        this_char_image = cv.imread(char_name,
                                                    cv.CV_LOAD_IMAGE_UNCHANGED)
                        for k in xrange(10):
                            if np.all(this_char_image == ref_images[k]):
                                this_record += str(k)
                    record_txt.write(this_record + "\t")
                    self.cord += this_record + "\t"
                record_txt.write(self.note)
                record_txt.write("\n\r")
                record_txt.close()
        return
コード例 #15
0
def printScreen():
    import win32api, win32con, ImageGrab
    win32api.keybd_event(win32con.VK_SNAPSHOT, 0) #use 1 for only the active window 0 for whole screen
    im = ImageGrab.grabclipboard()
    im.save("screenshot.jpg", "JPEG")
コード例 #16
0
def screenshot():
	subprocess.Popen(_nirCmd, startupinfo=_cmdFlags).communicate()
	return ImageGrab.grabclipboard()
コード例 #17
0
 def getimage(self):
     self.image = ImageGrab.grabclipboard()
     return self.image is not None
コード例 #18
0
ファイル: screenshot.py プロジェクト: i-ghost/hlmv-autopaint
def screenshot():
    """User nircmd to save a screenshot of the active window to the clipboard and return it as a PIL image object"""
    subprocess.Popen("%s savescreenshot *clipboard*" % (_nirCmd), startupinfo=_cmdFlags).communicate()
    return ImageGrab.grabclipboard()