Skip to content

Commit

Permalink
Merge branch 'manageImageList'
Browse files Browse the repository at this point in the history
  • Loading branch information
aaclause committed Dec 28, 2023
2 parents 4e69734 + 4e3b7c4 commit 3ec2842
Show file tree
Hide file tree
Showing 3 changed files with 430 additions and 129 deletions.
26 changes: 24 additions & 2 deletions addon/globalPlugins/openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def script_showMainDialog(self, gesture):

@script(
gesture="kb:nvda+e",
# Translators: This is the description of a command to take a screenshot and describe it.
description=_("Take a screenshot and describe it")
)
def script_recognizeScreen(self, gesture):
Expand All @@ -451,11 +452,17 @@ def script_recognizeScreen(self, gesture):
maindialog.OpenAIDlg,
client=self.getClient(),
conf=conf,
pathList=[tmpPath]
pathList=[
(
tmpPath,
# Translators: This is the name of the screenshot to be described.
_("Screenshot"))
]
)

@script(
gesture="kb:nvda+o",
# Translators: This is the description of a command to grab the current navigator object and describe it.
description=_("Grab the current navigator object and describe it")
)
def script_recognizeObject(self, gesture):
Expand All @@ -466,6 +473,7 @@ def script_recognizeObject(self, gesture):
with mss.mss() as sct:
tmpPath = os.path.join(DATA_DIR, "object.png")
nav = api.getNavigatorObject()
name = nav.name
nav.scrollIntoView()
if (
nav.role == controlTypes.ROLE_LINK
Expand All @@ -479,11 +487,25 @@ def script_recognizeObject(self, gesture):
sct_img = sct.grab(monitor)
mss.tools.to_png(sct_img.rgb, sct_img.size, output=tmpPath)
from . import maindialog
# Translators: This is the name of the screenshot to be described.
default_name = _("Navigator Object")
name = nav.name
if (
not name
or not name.strip()
or '\n' in name
or len(name) > 80
):
name = default_name
else:
name = "%s (%s)" % (name.strip(), default_name)
gui.mainFrame.popupSettingsDialog(
maindialog.OpenAIDlg,
client=self.getClient(),
conf=conf,
pathList=[tmpPath]
pathList=[
(tmpPath, name)
]
)

@script(
Expand Down
9 changes: 9 additions & 0 deletions addon/globalPlugins/openai/imagehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
sys.path.insert(0, additionalLibsPath)
from openai import OpenAI
from PIL import Image
import fractions
sys.path.remove(additionalLibsPath)

def get_image_dimensions(path):
"""
Get the dimensions of an image.
"""
img = Image.open(path)
return img.size


def resize_image(
src: str,
max_width: int = 0,
Expand Down
Loading

0 comments on commit 3ec2842

Please sign in to comment.