Skip to content

Commit

Permalink
Merge pull request #194 from thenaterhood/dev
Browse files Browse the repository at this point in the history
Next Release
  • Loading branch information
thenaterhood authored Jul 12, 2024
2 parents e32d190 + c038cac commit 5f05a4b
Show file tree
Hide file tree
Showing 43 changed files with 1,293 additions and 964 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
# uses: cclauss/GitHub-Action-for-pylint@8ef4d22e119fb1cdc0f58f2e95cb1f8d8b0d55e6
uses: cclauss/[email protected]
with:
args: '"pylint src/ --disable=import-error --disable=no-self-use --disable=no-else-return --disable=too-many-public-methods --disable=too-many-instance-attributes --disable=duplicate-code --disable=useless-object-inheritance --disable=too-few-public-methods"'
args: '"pylint src/ --disable=import-error --disable=no-self-use --disable=no-else-return --disable=too-many-public-methods --disable=too-many-instance-attributes --disable=duplicate-code --disable=useless-object-inheritance --disable=too-few-public-methods" --disable=missing-module-docstring'

pytest:

Expand Down
4 changes: 2 additions & 2 deletions specs/gscreenshot.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%define name gscreenshot
%define version 3.5.1
%define unmangled_version 3.5.1
%define version 3.6.0
%define unmangled_version 3.6.0
%define release 1

Summary: A simple screenshot tool
Expand Down
6 changes: 2 additions & 4 deletions src/gscreenshot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from PIL import Image
from gscreenshot.compat import get_resource_file, get_resource_string, get_version
from gscreenshot.screenshot import ScreenshotCollection
from gscreenshot.screenshooter import Screenshooter
from gscreenshot.screenshooter.factory import ScreenshooterFactory
from gscreenshot.screenshooter import Screenshooter, get_screenshooter
from gscreenshot.util import session_is_wayland

_ = gettext.gettext
Expand Down Expand Up @@ -70,8 +69,7 @@ def __init__(self, screenshooter=None):
# of crashing if there's a locale issue.
pass

screenshooter_factory = ScreenshooterFactory(screenshooter)
self.screenshooter = screenshooter_factory.create()
self.screenshooter = get_screenshooter(screenshooter)
self._screenshots = ScreenshotCollection()

self._stamps = {}
Expand Down
26 changes: 4 additions & 22 deletions src/gscreenshot/cursor_locator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
'''
Interface class for integrating cursor locators
'''
import typing
from .factory import get_cursor_locator


class CursorLocator():
'''Parent class for cursor locator strategies'''

__utilityname__: str = "default"

def __init__(self):
"""constructor"""

def get_cursor_position(self) -> typing.Optional[typing.Tuple[int, int]]:
'''Return the cursor position as a tuple of (x, y)'''
raise NotImplementedError()

@staticmethod
def can_run() -> bool:
"""
Whether this cursor locator can run
"""
return True
__all__ = [
"get_cursor_locator",
]
39 changes: 39 additions & 0 deletions src/gscreenshot/cursor_locator/cursor_locator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'''
Interface class for integrating cursor locators
'''
import typing

from gscreenshot.scaling import get_scaling_factor


class CursorLocator():
'''Parent class for cursor locator strategies'''

__utilityname__: str = "default"

def __init__(self):
"""constructor"""

def get_cursor_position(self) -> typing.Optional[typing.Tuple[int, int]]:
'''Return the cursor position as a tuple of (x, y)'''
raise NotImplementedError()

def get_cursor_position_adjusted(self):
'''Return the cursor position adjusted for scaling'''
position = self.get_cursor_position()

if not position:
return None

scaling_factor = get_scaling_factor()
return (
round(position[0] * scaling_factor),
round(position[1] * scaling_factor)
)

@staticmethod
def can_run() -> bool:
"""
Whether this cursor locator can run
"""
return True
11 changes: 8 additions & 3 deletions src/gscreenshot/cursor_locator/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
'''

import typing
from gscreenshot.cursor_locator import CursorLocator
from gscreenshot.cursor_locator.gtk_cursor_locator import GtkCursorLocator
from gscreenshot.cursor_locator.x11_cursor_locator import X11CursorLocator
from gscreenshot.util import session_is_wayland
from .cursor_locator import CursorLocator
from .gtk_cursor_locator import GtkCursorLocator
from .x11_cursor_locator import X11CursorLocator


class NoSupportedCursorLocatorError(Exception):
"""NoSupportedCursorLocatorError"""


def get_cursor_locator(cursor_locator: typing.Optional[CursorLocator] = None):
"""Gets a workable cursor locator"""
return CursorLocatorFactory(cursor_locator).create()


class CursorLocatorFactory(object):
'''Selects and instantiates a usable cursor finder'''

Expand Down
26 changes: 12 additions & 14 deletions src/gscreenshot/cursor_locator/gtk_cursor_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#pylint: disable=wrong-import-position
#pylint: disable=ungrouped-imports
import typing
import pygtkcompat
pygtkcompat.enable()
pygtkcompat.enable_gtk(version='3.0')

from gi.repository import Gtk, Gdk
from gscreenshot.cursor_locator import CursorLocator
from gi import require_version
require_version('Gtk', '3.0')

from gi.repository import Gtk # type: ignore
from .cursor_locator import CursorLocator


class GtkCursorLocator(CursorLocator):
Expand All @@ -26,12 +26,12 @@ def get_cursor_position(self) -> typing.Optional[typing.Tuple[int, int]]:
Returns (x, y) or None.
"""
locator = GtkCursorLocatorWindow()
locator.show_all()
Gtk.main()
while Gtk.events_pending():
Gtk.main_iteration()

return locator.position
return locator.cursor_position

@staticmethod
def can_run() -> bool:
return True
Expand All @@ -42,9 +42,8 @@ class GtkCursorLocatorWindow(Gtk.Window):
GTK window for capturing the cursor position
'''
def __init__(self):
'''constructor'''
self.position = None
super().__init__()
self.cursor_position = None
self.set_title("gscreenshot")
self.set_position(Gtk.WindowPosition.CENTER)
self.fullscreen()
Expand All @@ -68,19 +67,18 @@ def __init__(self):
box.attach(help_text, 0, 0, 1, 1)
box.attach(help_subtext, 0, 1, 1, 1)
self.add(box)

self.connect("button_press_event", self.on_button_press)
self.connect("key-press-event", self.on_keypress)
self.connect("destroy", Gtk.main_quit)

self.set_events(Gdk.POINTER_MOTION_MASK
| Gdk.BUTTON_PRESS_MASK)
self.show_all()

def on_button_press(self, _widget, event):
'''handle button press'''
self.position = (int(event.x), int(event.y))
self.cursor_position = (int(event.x), int(event.y))
self.destroy()
Gtk.main_quit()

def on_keypress(self, _widget, _event):
'''handle keypress'''
self.destroy()
Gtk.main_quit()
2 changes: 1 addition & 1 deletion src/gscreenshot/cursor_locator/x11_cursor_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
except ImportError:
display = None

from gscreenshot.cursor_locator import CursorLocator
from .cursor_locator import CursorLocator


class X11CursorLocator(CursorLocator):
Expand Down
25 changes: 13 additions & 12 deletions src/gscreenshot/frontend/gtk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
import threading
import typing
from time import sleep
import pygtkcompat
from PIL import Image
from gscreenshot import Gscreenshot, GscreenshotClipboardException
from gscreenshot.compat import get_resource_file, get_resource_string
from gscreenshot.frontend.gtk.dialogs import OpenWithDialog, WarningDialog
from gscreenshot.frontend.gtk.dialogs import FileSaveDialog, FileOpenDialog
from gscreenshot.frontend.gtk.view import View
from gscreenshot.screenshooter.exceptions import NoSupportedScreenshooterError
from gscreenshot.screenshot.effects.crop import CropEffect
from gscreenshot.screenshot.effects import CropEffect

pygtkcompat.enable()
pygtkcompat.enable_gtk(version='3.0')
from gi import require_version
require_version('Gtk', '3.0')
from gi.repository import Gdk
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import GdkPixbuf

i18n = gettext.gettext

Expand Down Expand Up @@ -458,8 +458,9 @@ def on_button_about_clicked(self, *_):
about.set_version(version)

png_filename = get_resource_file("gscreenshot.resources.pixmaps", "gscreenshot.png")
logo = Image.open(png_filename)
about.set_logo(
Gtk.gdk.pixbuf_new_from_file(str(png_filename))
self._image_to_pixbuf(logo)
)

self._view.run_dialog(about)
Expand Down Expand Up @@ -489,7 +490,7 @@ def _image_to_pixbuf(self, image):
pixbuf = None
for img_format in [("pnm", "ppm"), ("png", "png"), ("jpeg", "jpeg")]:
try:
loader = Gtk.gdk.PixbufLoader(img_format[0])
loader = GdkPixbuf.PixbufLoader()
descriptor = io.BytesIO()
image = image.convert("RGB")
image.save(descriptor, img_format[1])
Expand All @@ -498,6 +499,7 @@ def _image_to_pixbuf(self, image):

loader.write(contents)
pixbuf = loader.get_pixbuf()
break
except GLib.GError:
continue
finally:
Expand Down Expand Up @@ -584,13 +586,13 @@ def main():
window.connect("key-press-event", presenter.handle_keypress)

keymappings = {
Gtk.gdk.keyval_to_lower(Gtk.gdk.keyval_from_name('Escape')):
Gdk.keyval_to_lower(Gdk.keyval_from_name('Escape')):
presenter.on_button_quit_clicked,
Gtk.gdk.keyval_to_lower(Gtk.gdk.keyval_from_name('F11')):
Gdk.keyval_to_lower(Gdk.keyval_from_name('F11')):
presenter.on_fullscreen_toggle,
Gtk.gdk.keyval_to_lower(Gtk.gdk.keyval_from_name('Right')):
Gdk.keyval_to_lower(Gdk.keyval_from_name('Right')):
presenter.on_preview_next_clicked,
Gtk.gdk.keyval_to_lower(Gtk.gdk.keyval_from_name('Left')):
Gdk.keyval_to_lower(Gdk.keyval_from_name('Left')):
presenter.on_preview_prev_clicked,
# Handled in Glade - just here for reference
#Gtk.gdk.keyval_to_lower(Gtk.gdk.keyval_from_name('Insert')):
Expand All @@ -601,7 +603,6 @@ def main():
view.connect_signals(presenter)
view.run()

GObject.threads_init() # Start background threads.
Gtk.main()

if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 5f05a4b

Please sign in to comment.