Window Region Grab completed
This commit is contained in:
parent
72913ebe78
commit
212f387ec4
@ -33,11 +33,14 @@ class ScreenshotController:
|
||||
event_system.subscribe("grab_entire_screen", self.grab_entire_screen)
|
||||
event_system.subscribe("grab_active_window", self.grab_active_window)
|
||||
event_system.subscribe("pass_to_region_handler", self.pass_to_region_handler)
|
||||
event_system.subscribe("grab_region_hide", self._grab_region_hide)
|
||||
event_system.subscribe("grab_region", self._grab_region)
|
||||
event_system.subscribe("grab_selected_monitor", self.grab_selected_monitor)
|
||||
|
||||
def _load_widgets(self):
|
||||
RegionWindow()
|
||||
|
||||
|
||||
def grab_entire_screen(self):
|
||||
logger.info("Grabbing Entire Screen...")
|
||||
window = settings.get_main_window()
|
||||
@ -61,12 +64,45 @@ class ScreenshotController:
|
||||
pb = Gdk.pixbuf_get_from_window(w, *w.get_geometry())
|
||||
pb.savev(settings.generate_screenshot_name(), "png", (), ())
|
||||
|
||||
|
||||
def pass_to_region_handler(self):
|
||||
logger.info("Grabbing Selected Region Stub...")
|
||||
# window = settings.get_main_window()
|
||||
# window.hide()
|
||||
logger.info("Passing to Region Handler...")
|
||||
window = settings.get_main_window()
|
||||
window.hide()
|
||||
event_system.emit("show_region_window")
|
||||
|
||||
def _grab_region_hide(self, region_window):
|
||||
region_window.hide()
|
||||
window = settings.get_main_window()
|
||||
window.show()
|
||||
|
||||
def _grab_region(self, region_window):
|
||||
logger.info("Grabbing Selected Region...")
|
||||
x, y = region_window.get_position()
|
||||
w, h = region_window.get_size()
|
||||
x2 = x + w
|
||||
y2 = y + h
|
||||
|
||||
def show_region_window():
|
||||
# NOTE: No clue why showing window has it move outta prior place.
|
||||
# So, move back to original spot before showing...
|
||||
region_window.move(x, y)
|
||||
region_window.show()
|
||||
|
||||
@daemon_threaded
|
||||
def do_bounding_box_grab(x1, y1, x2, y2):
|
||||
while region_window.is_visible():
|
||||
...
|
||||
|
||||
im = capture.grab(bbox = (x1, y1, x2, y2), childprocess = False)
|
||||
im.save( settings.generate_screenshot_name() )
|
||||
GLib.idle_add(show_region_window)
|
||||
|
||||
region_window.hide()
|
||||
offset = 1
|
||||
do_bounding_box_grab(x - offset, y - offset, x2 + offset, y2 + offset)
|
||||
|
||||
|
||||
def grab_selected_monitor(self):
|
||||
logger.info("Grabbing Monitor...")
|
||||
|
||||
|
@ -47,44 +47,65 @@ class BodyGrid(Gtk.Grid):
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
|
||||
def _load_widgets(self):
|
||||
drag_button = Gtk.Button("")
|
||||
close_button = Gtk.Button("x")
|
||||
grab_button = Gtk.Button("Grab")
|
||||
bottom_right = Gtk.Button("")
|
||||
# box = Gtk.Box()
|
||||
box2 = Gtk.Box()
|
||||
box3 = Gtk.Box()
|
||||
box4 = Gtk.Box()
|
||||
box5 = Gtk.Box()
|
||||
|
||||
ctx = drag_button.get_style_context()
|
||||
ctx.add_class("expand-button")
|
||||
ctx2 = bottom_right.get_style_context()
|
||||
ctx2.add_class("expand-button")
|
||||
|
||||
row, col = 1, 1
|
||||
self.attach(drag_button, col, row, 5, 1)
|
||||
row, col = 2, 1
|
||||
col, row = 1, 1
|
||||
self.attach(drag_button, col, row, 11, 1)
|
||||
col, row = 12, 1
|
||||
self.attach(close_button, col, row, 1, 1)
|
||||
col, row = 1, 2
|
||||
self.attach(box2, col, row, 5, 3)
|
||||
row, col = 5, 1
|
||||
col, row = 1, 5
|
||||
self.attach(box3, col, row, 4, 1)
|
||||
row, col = 5, 5
|
||||
col, row = 1, 12
|
||||
self.attach(box4, col, row, 3, 1)
|
||||
col, row = 5, 12
|
||||
self.attach(grab_button, col, row, 3, 1)
|
||||
col, row = 9, 12
|
||||
self.attach(box5, col, row, 3, 1)
|
||||
col, row = 12, 12
|
||||
self.attach(bottom_right, col, row, 1, 1)
|
||||
|
||||
drag_button.set_vexpand(True)
|
||||
drag_button.set_hexpand(True)
|
||||
close_button.set_vexpand(False)
|
||||
close_button.set_hexpand(False)
|
||||
box2.set_vexpand(True)
|
||||
box2.set_hexpand(True)
|
||||
box3.set_vexpand(True)
|
||||
box3.set_hexpand(True)
|
||||
|
||||
box4.set_vexpand(False)
|
||||
box4.set_hexpand(True)
|
||||
box5.set_vexpand(False)
|
||||
box5.set_hexpand(True)
|
||||
|
||||
drag_button.connect("button-press-event", self._press_event)
|
||||
drag_button.connect("motion-notify-event", self._move_motion_event)
|
||||
drag_button.connect("button-release-event", self._release_event)
|
||||
|
||||
close_button.connect("button-release-event", self._region_close)
|
||||
grab_button.connect("button-release-event", self._region_grab)
|
||||
bottom_right.connect("button-press-event", self._press_event)
|
||||
bottom_right.connect("motion-notify-event", self._resize_motion_event)
|
||||
bottom_right.connect("button-release-event", self._release_event)
|
||||
|
||||
|
||||
def _region_close(self, widget = None, eve = None):
|
||||
event_system.emit("grab_region_hide", (self._window,))
|
||||
|
||||
def _region_grab(self, widget = None, eve = None):
|
||||
event_system.emit("grab_region", (self._window,))
|
||||
|
||||
def _press_event(self, widget = None, eve = None):
|
||||
window = self.get_parent()
|
||||
cursor = Gdk.Cursor(Gdk.CursorType.CROSSHAIR)
|
||||
@ -95,15 +116,12 @@ class BodyGrid(Gtk.Grid):
|
||||
self._drag_start_y = eve.y_root
|
||||
|
||||
if self._current_x == 0:
|
||||
self._current_x, \
|
||||
self._current_y = self._window.get_position()
|
||||
self._current_x, self._current_y = self._window.get_position()
|
||||
|
||||
self._w1 = self._window.get_size()[0] # Ref window width
|
||||
self._h1 = self._window.get_size()[1] # Ref window height
|
||||
self._w1, self._h1 = self._window.get_size()
|
||||
|
||||
def _resize_motion_event(self, widget = None, eve = None):
|
||||
if self._update_block:
|
||||
return
|
||||
if self._update_block: return
|
||||
|
||||
x1 = self._drag_start_x
|
||||
y1 = self._drag_start_y
|
||||
@ -145,7 +163,6 @@ class BodyGrid(Gtk.Grid):
|
||||
self._drag_start_x = eve.x_root
|
||||
self._drag_start_y = eve.y_root
|
||||
|
||||
|
||||
self._update_block = True
|
||||
self._window.move(self._current_x, self._current_y)
|
||||
self._update_block = False
|
||||
|
Loading…
Reference in New Issue
Block a user