mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Fix file path issues
This commit is contained in:
parent
baad7f834c
commit
f896cfb154
4 changed files with 26 additions and 3 deletions
|
|
@ -104,6 +104,9 @@ class BeeSettings(QtCore.QSettings):
|
|||
constants.APPNAME,
|
||||
constants.APPNAME)
|
||||
|
||||
def fileName(self):
|
||||
return os.path.normpath(super().fileName())
|
||||
|
||||
def get_settings_dir(self): # pragma: no cover
|
||||
args = CommandlineArgs()
|
||||
return args.settings_dir
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from urllib import request
|
|||
from PyQt6 import QtGui
|
||||
|
||||
import exif
|
||||
import plum
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -37,7 +38,11 @@ def exif_rotated_image(path=None):
|
|||
return img
|
||||
|
||||
with open(path, 'rb') as f:
|
||||
exifimg = exif.Image(f)
|
||||
try:
|
||||
exifimg = exif.Image(f)
|
||||
except plum.UnpackError:
|
||||
logger.info(f'Exif parser failed on image: {path}')
|
||||
return img
|
||||
|
||||
if 'orientation' in exifimg.list_all():
|
||||
orientation = exifimg.orientation
|
||||
|
|
@ -73,9 +78,11 @@ def exif_rotated_image(path=None):
|
|||
|
||||
def load_image(path):
|
||||
if isinstance(path, str):
|
||||
path = os.path.normpath(path)
|
||||
return (exif_rotated_image(path), path)
|
||||
if path.isLocalFile():
|
||||
return (exif_rotated_image(path.path()), path.path())
|
||||
path = os.path.normpath(path.toLocalFile())
|
||||
return (exif_rotated_image(path), path)
|
||||
|
||||
img = exif_rotated_image()
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import logging
|
||||
import os
|
||||
import os.path
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
from PyQt6.QtCore import Qt
|
||||
|
|
@ -313,6 +314,7 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
|
|||
caption='Open file',
|
||||
filter=f'{constants.APPNAME} File (*.bee)')
|
||||
if filename:
|
||||
filename = os.path.normpath(filename)
|
||||
self.open_from_file(filename)
|
||||
self.filename = filename
|
||||
|
||||
|
|
@ -660,4 +662,5 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
|
|||
item = BeePixmapItem(img)
|
||||
pos = self.mapToScene(pos)
|
||||
self.undo_stack.push(commands.InsertItems(self.scene, [item], pos))
|
||||
logger.info('Drop not an image')
|
||||
else:
|
||||
logger.info('Drop not an image')
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
import math
|
||||
import os.path
|
||||
from unittest.mock import patch
|
||||
|
||||
import httpretty
|
||||
import pytest
|
||||
|
||||
import plum
|
||||
|
||||
from PyQt6 import QtCore, QtGui
|
||||
|
||||
from beeref.fileio.image import exif_rotated_image, load_image
|
||||
|
|
@ -19,6 +22,13 @@ def test_exif_rotated_image_not_a_file(qapp):
|
|||
assert img.isNull() is True
|
||||
|
||||
|
||||
def test_exif_rotated_image_exif_unpack_error(qapp, imgfilename3x3):
|
||||
with patch('beeref.fileio.image.exif.Image') as exif_mock:
|
||||
exif_mock.raise_error = plum.UnpackError()
|
||||
img = exif_rotated_image(imgfilename3x3)
|
||||
assert img.isNull() is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('path,expected',
|
||||
[('test3x3.png', 'test3x3.png'),
|
||||
('test3x3_orientation1.jpg', 'test3x3.jpg'),
|
||||
|
|
|
|||
Loading…
Reference in a new issue