Skip to content

Commit eb43c2c

Browse files
authored
Merge pull request #1810 from wkentaro/fix/show_error_dialog_when_image_file_fails_to_open
fix: show error dialog when image file fails to open
2 parents 3c0ed18 + f80bf85 commit eb43c2c

30 files changed

+156
-77
lines changed

labelme/_label_file.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ def __init__(self, filename=None):
139139

140140
@staticmethod
141141
def load_image_file(filename):
142-
try:
143-
image_pil = PIL.Image.open(filename)
144-
except OSError:
145-
logger.error(f"Failed opening image file: {filename}")
146-
return
142+
image_pil = PIL.Image.open(filename)
147143

148144
# apply orientation to image according to exif
149145
image_pil = utils.apply_exif_orientation(image_pil)

labelme/app.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,8 @@ def _load_file(self, filename=None):
17971797
self.errorMessage(
17981798
self.tr("Error opening file"),
17991799
self.tr(
1800-
"<p><b>%s</b></p><p>Make sure <i>%s</i> is a valid label file."
1800+
"<p><b>%s</b></p>"
1801+
"<p>Make sure <i>%s</i> is a valid label file.</p>"
18011802
)
18021803
% (e, label_file),
18031804
)
@@ -1812,7 +1813,19 @@ def _load_file(self, filename=None):
18121813
)
18131814
self._other_data = self.labelFile.otherData
18141815
else:
1815-
self.imageData = LabelFile.load_image_file(filename)
1816+
try:
1817+
self.imageData = LabelFile.load_image_file(filename)
1818+
except OSError as e:
1819+
self.errorMessage(
1820+
self.tr("Error opening file"),
1821+
self.tr(
1822+
"<p><b>%s</b></p>"
1823+
"<p>Make sure <i>%s</i> is a valid image file.</p>"
1824+
)
1825+
% (e, filename),
1826+
)
1827+
self.show_status_message(self.tr("Error reading %s") % filename)
1828+
return False
18161829
if self.imageData:
18171830
self.imagePath = filename
18181831
self.labelFile = None

labelme/translate/de_DE.qm

278 Bytes
Binary file not shown.

labelme/translate/de_DE.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,6 @@ Polygone</translation>
704704
<source>Loading %s...</source>
705705
<translation>%s wird geladen...</translation>
706706
</message>
707-
<message>
708-
<location filename="../app.py" line="0"/>
709-
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid label file.</source>
710-
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Stellen Sie sicher, dass &lt;i&gt;%s&lt;/i&gt; eine gültige Beschriftungsdatei ist.&lt;/p&gt;</translation>
711-
</message>
712707
<message>
713708
<location filename="../app.py" line="0"/>
714709
<source>Error reading %s</source>
@@ -825,5 +820,15 @@ Um den Einstellungseditor zu verwenden, starten Sie Labelme mit einer Konfigurat
825820
<source>Errors were found while loading the configuration. Please review the errors below and reload your configuration or ignore the erroneous lines.</source>
826821
<translation>Beim Laden der Konfiguration wurden Fehler gefunden. Bitte überprüfen Sie die folgenden Fehler und laden Sie Ihre Konfiguration neu oder ignorieren Sie die fehlerhaften Zeilen.</translation>
827822
</message>
823+
<message>
824+
<location filename="../app.py" line="0"/>
825+
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid label file.&lt;/p&gt;</source>
826+
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Stellen Sie sicher, dass &lt;i&gt;%s&lt;/i&gt; eine gültige Beschriftungsdatei ist.&lt;/p&gt;</translation>
827+
</message>
828+
<message>
829+
<location filename="../app.py" line="0"/>
830+
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid image file.&lt;/p&gt;</source>
831+
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Stellen Sie sicher, dass &lt;i&gt;%s&lt;/i&gt; eine gültige Bilddatei ist.&lt;/p&gt;</translation>
832+
</message>
828833
</context>
829834
</TS>

labelme/translate/es_ES.qm

280 Bytes
Binary file not shown.

labelme/translate/es_ES.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,6 @@ Polygons</source>
688688
<source>Loading %s...</source>
689689
<translation>Cargando %s...</translation>
690690
</message>
691-
<message>
692-
<location filename="../app.py" line="0"/>
693-
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid label file.</source>
694-
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Asegúrate de que &lt;i&gt;%s&lt;/i&gt; sea un archivo de etiqueta válido.</translation>
695-
</message>
696691
<message>
697692
<location filename="../app.py" line="0"/>
698693
<source>Error reading %s</source>
@@ -819,5 +814,15 @@ Para usar el editor de preferencias, inicie Labelme con un archivo de configurac
819814
<source>Errors were found while loading the configuration. Please review the errors below and reload your configuration or ignore the erroneous lines.</source>
820815
<translation>Se encontraron errores al cargar la configuración. Por favor, revise los errores a continuación y recargue su configuración o ignore las líneas erróneas.</translation>
821816
</message>
817+
<message>
818+
<location filename="../app.py" line="0"/>
819+
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid label file.&lt;/p&gt;</source>
820+
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Asegúrate de que &lt;i&gt;%s&lt;/i&gt; sea un archivo de etiqueta válido.&lt;/p&gt;</translation>
821+
</message>
822+
<message>
823+
<location filename="../app.py" line="0"/>
824+
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid image file.&lt;/p&gt;</source>
825+
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Asegúrate de que &lt;i&gt;%s&lt;/i&gt; sea un archivo de imagen válido.&lt;/p&gt;</translation>
826+
</message>
822827
</context>
823828
</TS>

labelme/translate/fa_IR.qm

252 Bytes
Binary file not shown.

labelme/translate/fa_IR.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,6 @@ Polygons</source>
688688
<source>Loading %s...</source>
689689
<translation>در حال بارگذاری %s...</translation>
690690
</message>
691-
<message>
692-
<location filename="../app.py" line="0"/>
693-
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid label file.</source>
694-
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;مطمئن شوید &lt;i&gt;%s&lt;/i&gt; یک فایل برچسب معتبر است.</translation>
695-
</message>
696691
<message>
697692
<location filename="../app.py" line="0"/>
698693
<source>Error reading %s</source>
@@ -819,5 +814,15 @@ To use the preferences editor, start Labelme with a config file:
819814
<source>Errors were found while loading the configuration. Please review the errors below and reload your configuration or ignore the erroneous lines.</source>
820815
<translation>هنگام بارگیری پیکربندی خطاهایی یافت شد. لطفاً خطاهای زیر را بررسی کنید و پیکربندی خود را مجدداً بارگیری کنید یا خطوط نادرست را نادیده بگیرید.</translation>
821816
</message>
817+
<message>
818+
<location filename="../app.py" line="0"/>
819+
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid label file.&lt;/p&gt;</source>
820+
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;مطمئن شوید &lt;i&gt;%s&lt;/i&gt; یک فایل برچسب معتبر است.&lt;/p&gt;</translation>
821+
</message>
822+
<message>
823+
<location filename="../app.py" line="0"/>
824+
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid image file.&lt;/p&gt;</source>
825+
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;مطمئن شوید &lt;i&gt;%s&lt;/i&gt; یک فایل تصویر معتبر است.&lt;/p&gt;</translation>
826+
</message>
822827
</context>
823828
</TS>

labelme/translate/fr_FR.qm

272 Bytes
Binary file not shown.

labelme/translate/fr_FR.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,6 @@ les polygones</translation>
704704
<source>Loading %s...</source>
705705
<translation>Chargement de %s...</translation>
706706
</message>
707-
<message>
708-
<location filename="../app.py" line="0"/>
709-
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid label file.</source>
710-
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Assurez-vous que &lt;i&gt;%s&lt;/i&gt; est un fichier d'étiquettes valide.</translation>
711-
</message>
712707
<message>
713708
<location filename="../app.py" line="0"/>
714709
<source>Error reading %s</source>
@@ -835,5 +830,15 @@ Pour utiliser l'éditeur de préférences, démarrez Labelme avec un fichier de
835830
<source>Errors were found while loading the configuration. Please review the errors below and reload your configuration or ignore the erroneous lines.</source>
836831
<translation>Des erreurs ont été trouvées lors du chargement de la configuration. Veuillez examiner les erreurs ci-dessous et recharger votre configuration ou ignorer les lignes erronées.</translation>
837832
</message>
833+
<message>
834+
<location filename="../app.py" line="0"/>
835+
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid label file.&lt;/p&gt;</source>
836+
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Assurez-vous que &lt;i&gt;%s&lt;/i&gt; est un fichier d'étiquettes valide.&lt;/p&gt;</translation>
837+
</message>
838+
<message>
839+
<location filename="../app.py" line="0"/>
840+
<source>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Make sure &lt;i&gt;%s&lt;/i&gt; is a valid image file.&lt;/p&gt;</source>
841+
<translation>&lt;p&gt;&lt;b&gt;%s&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Assurez-vous que &lt;i&gt;%s&lt;/i&gt; est un fichier image valide.&lt;/p&gt;</translation>
842+
</message>
838843
</context>
839844
</TS>

0 commit comments

Comments
 (0)