diff --git a/labelImg.py b/labelImg.py index 9616f88d..d863ab61 100755 --- a/labelImg.py +++ b/labelImg.py @@ -8,6 +8,8 @@ import platform import re import sys import subprocess +import shutil +import webbrowser as wb from functools import partial from collections import defaultdict @@ -83,6 +85,8 @@ class MainWindow(QMainWindow, WindowMixin): self.settings.load() settings = self.settings + self.os_name = platform.system() + # Load string bundle for i18n self.string_bundle = StringBundle.get_bundle() get_str = lambda str_id: self.string_bundle.get_string(str_id) @@ -104,7 +108,7 @@ class MainWindow(QMainWindow, WindowMixin): self._no_selection_slot = False self._beginner = True - self.screencast_viewer = self.get_available_screencast_viewer() + self.screencast_viewer = self.get_available_screencast_viewer() # deprecated self.screencast = "https://youtu.be/p0nR2YsCY_U" # Load predefined classes to the list @@ -286,8 +290,12 @@ class MainWindow(QMainWindow, WindowMixin): 'Ctrl+A', 'hide', get_str('showAllBoxDetail'), enabled=False) - help = action(get_str('tutorial'), self.show_tutorial_dialog, None, 'help', get_str('tutorialDetail')) + # help = action(get_str('tutorial'), self.show_tutorial_dialog, None, 'help', get_str('tutorialDetail')) + # show_info = action(get_str('info'), self.show_info_dialog, None, 'help', get_str('info')) + help_default = action(get_str('tutorialDefault'), self.show_default_tutorial_dialog, None, 'help', get_str('tutorialDetail')) + help_chrome = action(get_str('tutorialChrome'), self.show_chrome_tutorial_dialog, None, 'help', get_str('tutorialDetail')) show_info = action(get_str('info'), self.show_info_dialog, None, 'help', get_str('info')) + # show_shortcuts = action(get_str('shortcut'), self.show_shortcuts_dialog, None, 'help', get_str('shortcut')) zoom = QWidgetAction(self) zoom.setDefaultWidget(self.zoom_widget) @@ -397,7 +405,12 @@ class MainWindow(QMainWindow, WindowMixin): add_actions(self.menus.file, (open, open_dir, change_save_dir, open_annotation, copy_prev_bounding, self.menus.recentFiles, save, save_format, save_as, close, reset_all, delete_image, quit)) - add_actions(self.menus.help, (help, show_info)) + if self.os_name == "Windows": + # add_actions(self.menus.help, (help_default, help_chrome, show_info, show_shortcuts)) + add_actions(self.menus.help, (help_default, help_chrome, show_info)) + else: + # add_actions(self.menus.help, (help_default, show_info, show_shortcuts)) + add_actions(self.menus.help, (help_default, show_info)) add_actions(self.menus.view, ( self.auto_saving, self.single_class_mode, @@ -635,24 +648,51 @@ class MainWindow(QMainWindow, WindowMixin): return not self.beginner() def get_available_screencast_viewer(self): - os_name = platform.system() + # deprecated, use webbrowser instead + # os_name = platform.system() - if os_name == 'Windows': - return ['C:\\Program Files\\Internet Explorer\\iexplore.exe'] - elif os_name == 'Linux': + if self.os_name == 'Windows': + return ['C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'] + elif self.os_name == 'Linux': return ['xdg-open'] - elif os_name == 'Darwin': + elif self.os_name == 'Darwin': return ['open'] # Callbacks # - def show_tutorial_dialog(self): - subprocess.Popen(self.screencast_viewer + [self.screencast]) + # def show_tutorial_dialog(self): + # subprocess.Popen(self.screencast_viewer + [self.screencast]) + def show_tutorial_dialog(self, browser='default'): + if browser.lower() == 'default': + wb.open(self.screencast, new=2) + elif browser.lower() == 'chrome' and self.os_name == 'Windows': + if shutil.which(browser.lower()): # 'chrome' not in wb._browsers in windows + wb.register('chrome', None, wb.BackgroundBrowser('chrome')) + else: + chrome_path="D:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" + if os.path.isfile(chrome_path): + wb.register('chrome', None, wb.BackgroundBrowser(chrome_path)) + try: + wb.get('chrome').open(self.screencast, new=2) + except: + wb.open(self.screencast, new=2) + elif browser.lower() in wb._browsers: + wb.get(browser.lower()).open(self.screencast, new=2) + + def show_default_tutorial_dialog(self): + self.show_tutorial_dialog(browser='default') + + def show_chrome_tutorial_dialog(self): + self.show_tutorial_dialog(browser='chrome') def show_info_dialog(self): from libs.__init__ import __version__ msg = u'Name:{0} \nApp Version:{1} \n{2} '.format(__appname__, __version__, sys.version_info) QMessageBox.information(self, u'Information', msg) + def show_shortcuts_dialog(self): + msg = u'To write....' # TODO + QMessageBox.information(self, u'Shortcuts', msg) + def create_shape(self): assert self.beginner() self.canvas.set_editing(False) @@ -1428,15 +1468,12 @@ class MainWindow(QMainWindow, WindowMixin): def delete_image(self): delete_path = self.file_path if delete_path is not None: - del self.m_img_list[self.cur_img_idx] - self.file_list_widget.takeItem(self.cur_img_idx) - - self.cur_img_idx -= 1 # self.open_next_img will increment idx. - self.img_count -= 1 self.open_next_image() - + self.cur_img_idx -= 1 + self.img_count -= 1 if os.path.exists(delete_path): os.remove(delete_path) + self.import_dir_images(self.last_open_dir) def reset_all(self): self.settings.reset() diff --git a/libs/stringBundle.py b/libs/stringBundle.py index dfd78590..55440256 100644 --- a/libs/stringBundle.py +++ b/libs/stringBundle.py @@ -1,5 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +""" +if items were added in files in the resources/strings folder, +then execute "pyrcc5 resources.qrc -o resources.py" in the root directory +and execute "pyrcc5 ../resources.qrc -o resources.py" in the libs directory +""" import re import os import sys diff --git a/resources/strings/strings-zh-CN.properties b/resources/strings/strings-zh-CN.properties index 65efebd0..09fb4613 100644 --- a/resources/strings/strings-zh-CN.properties +++ b/resources/strings/strings-zh-CN.properties @@ -12,7 +12,10 @@ verifyImgDetail=验证图像 saveDetail=保存标签文件 openFileDetail=打开图像文件 fitWidthDetail=调整宽度适应到窗口宽度 -tutorial=YouTube教学 +tutorialDefault=YouTube教学(Default Web Browser, Recommended) +tutorialChrome=YouTube教学(Chrome) +info=版本信息 +shortcut=快捷键 editLabel=编辑标签 openAnnotationDetail=打开标签文件 quit=退出 diff --git a/resources/strings/strings-zh-TW.properties b/resources/strings/strings-zh-TW.properties index 119d4051..313d46bf 100644 --- a/resources/strings/strings-zh-TW.properties +++ b/resources/strings/strings-zh-TW.properties @@ -12,7 +12,10 @@ verifyImgDetail=驗證圖像 saveDetail=將標籤存到 openFileDetail=打開圖像 fitWidthDetail=調整到窗口寬度 -tutorial=YouTube教學 +tutorialDefault=YouTube教學(Default Web Browser, Recommended) +tutorialChrome=YouTube教學(Chrome) +info=版本信息 +shortcut=快捷鍵 editLabel=編輯標籤 openAnnotationDetail=打開標籤文件 quit=結束 diff --git a/resources/strings/strings.properties b/resources/strings/strings.properties index d684e4ad..a24864aa 100644 --- a/resources/strings/strings.properties +++ b/resources/strings/strings.properties @@ -33,9 +33,11 @@ delBox=Delete RectBox delBoxDetail=Remove the box dupBox=Duplicate RectBox dupBoxDetail=Create a duplicate of the selected box -tutorial=Tutorial +tutorialDefault=Tutorial(Default Web Browser, Recommended) +tutorialChrome=Tutorial(Chrome) tutorialDetail=Show demo info=Information +shortcut=Keyboard shortcuts zoomin=Zoom In zoominDetail=Increase zoom level zoomout=Zoom Out