예제 #1
0
 def change_language(self, language, event):
     """Write given language to 'language.ini' file."""
     try:
         langFile = codecs.open(utils.get_user_path(u'language.ini'), 'w', 'utf-8')
     except IOError, error:
         utils.make_err_msg(unicode(error), u"Error")
         pass
예제 #2
0
 def change_language(self, language, event):
     """Write given language to 'language.ini' file."""
     try:
         langFile = codecs.open(utils.get_user_path(u'language.ini'), 'w', 'utf-8')
     except IOError, error:
         utils.make_err_msg(unicode(error), u"Error")
         pass
예제 #3
0
 def _show_rename_error(self, i, err, original, renamed):
     """Show renaming errors."""
     err = err.decode(sys.getfilesystemencoding())
     # set item as bad
     main.toRename[i][1][1] = None
     self._set_display(i)
     # show error message
     main.set_status_msg(_("Renaming Failed : %s") % err, u'failed')
     utils.make_err_msg(_(u"Error renaming:\n%s \n\nto:\n%s \n\nReason: %s")\
                        % (original[0], renamed[0], err),
                        _(u"Renaming Failed !!"))
예제 #4
0
 def get(self, preference):
     """
     Attempt to load a preference setting
     Load or recreate preference file if needed.
     """
     try:
         return self.prefs[preference]
     except KeyError:
         if not self.key_error:
             msg = _(u"\nThe preferences file is outdated or corrupt.")
             msg += u"\n%s" % self.prefFilePath
             utils.make_err_msg(msg, _(u"Problem with preferences"))
         # set this here so we don't see the message for evey missing key
         self.key_error = True
         raise KeyError
예제 #5
0
    def undo_last_rename(self, event):
        """
        Grabs names from .bak files and reverts them to their originals.

        Keep this separate from csv file functions for safety and stability.
        """

        original = []
        renamed = []
        utils.set_busy(True)
        try:
            originalFile = codecs.open(
                utils.get_user_path(u'undo/original.bak'), 'r', 'utf-8')
            renamedFile = codecs.open(utils.get_user_path(u'undo/renamed.bak'),
                                      'r', 'utf-8')
            for line in originalFile:
                original.append([line.strip(), False])
            for line in renamedFile:
                renamed.append([line.strip(), 1])

        except IOError as error:
            utils.make_err_msg(_(u"%s\n\nUndo Failed !!") % error, _(u"Error"))
            pass
        else:

            def get_name(x):
                return x[0]

            commonPrefix = os.path.commonprefix(map(get_name,
                                                    original)).rstrip(os.sep)
            if os.path.exists(commonPrefix):
                main.picker.view.path.SetValue(commonPrefix)
                main.picker.view.dirPicker.SetPath(commonPrefix)

            if not len(original) == 0:
                main.toRename = zip(
                    renamed, original)  #reverse order from original rename!
                main.currentItem = None
                main.display_results()
                main.rename_items(u'undo')
                main.menuFile.SaveLog.Enable(False)
            else:
                main.set_status_msg(_(u"Nothing to undo"), u'eyes')

        main.bottomWindow.set_undo_redo_type('check')
        utils.set_busy(False)
예제 #6
0
 def get(self, preference, strict=True):
     """
     Attempt to load a preference setting
     Load or recreate preference file if needed.
     """
     if not self.prefs:
         self.__load_preferences()
     try:
         return self.prefs[preference]
     except KeyError:
         if not strict:
             pass
         else:
             msg = _(u"\nThe preferences file is outdated or corrupt.")
             msg += _(u"\nWill now recreate the preferences file.")
             utils.make_err_msg(msg, _(u"Problem with preferences"))
             self.__create_new()
             self.__load_preferences()
             return self.get(preference)
예제 #7
0
    def get(self, preference, strict=True):
        """Attempt to load a preference setting

        Load or recreate preference file if needed.
        """
        if not self.prefs:
            self.__load_preferences()
        try:
            return self.prefs[preference]
        except KeyError:
            if not strict:
                pass
            else:
                msg = _(u"\nThe preferences file is outdated or corrupt.")
                msg += _(u"\nWill now recreate the preferences file.")
                utils.make_err_msg(msg, _(u"Problem with preferences"))
                self.__create_new()
                self.__load_preferences()
                return self.get(preference)
예제 #8
0
    def undo_last_rename(self, event):
        """
        Grabs names from .bak files and reverts them to their originals.

        Keep this separate from csv file functions for safety and stability.
        """

        original = []
        renamed = []
        utils.set_busy(True)
        try:
            originalFile = codecs.open(utils.get_user_path(u'undo/original.bak'), 'r',
                                       'utf-8')
            renamedFile = codecs.open(utils.get_user_path(u'undo/renamed.bak'), 'r',
                                      'utf-8')
            for line in originalFile:
                original.append([line.strip(), False])
            for line in renamedFile:
                renamed.append([line.strip(), 1])

        except IOError as error:
            utils.make_err_msg(_(u"%s\n\nUndo Failed !!") % error, _(u"Error"))
            pass
        else:
            def get_name(x): return x[0]
            commonPrefix = os.path.commonprefix(map(get_name, original)).rstrip(os.sep)
            if os.path.exists(commonPrefix):
                main.picker.view.path.SetValue(commonPrefix)
                main.picker.view.dirPicker.SetPath(commonPrefix)

            if not len(original) == 0:
                main.toRename = zip(renamed, original)#reverse order from original rename!
                main.currentItem = None
                main.display_results()
                main.rename_items(u'undo')
                main.menuFile.SaveLog.Enable(False)
            else:
                main.set_status_msg(_(u"Nothing to undo"), u'eyes')

        main.bottomWindow.set_undo_redo_type('check')
        utils.set_busy(False)
예제 #9
0
    def __load_file(self, configFilePath):
        """Read file and apply settings."""
        app.debug_print("loading config file : %s" % configFilePath)
        # attempt to open config file
        try:
            xmldoc = codecs.open(configFilePath, 'r', 'utf-8')
            xmldoc = minidom.parseString(xmldoc.read().encode("utf-8"))
        except:
            utils.make_err_msg(
                               _(u"Invalid XML in config file : %s") % configFilePath,
                               _(u"Invalid Configuration")
                               )
        else:
            config = xmldoc.firstChild

            # set autopreview to false while loading config
            # avoids loading paths more than once
            v = main.bottomWindow.autoPreview.GetValue()
            main.bottomWindow.autoPreview.SetValue(False)

            # get original path
            oldPath = main.picker.view.path.GetValue()

            self.__load_config_xml(config)
            
            if self.loadError:
                utils.make_warn_msg(_(u"Not all settings could be loaded."))

            # Do not replace a set path if one is not set in the config
            newPath = main.picker.view.path.GetValue()            
            if oldPath and not newPath:
                main.picker.view.path.SetValue(oldPath)

            # preview
            main.bottomWindow.autoPreview.SetValue(v)
            if app.autoModeLevel != 0 or\
                (app.prefs.get('previewOnConfig') and app.autoModeLevel is False):
                    main.picker.view.reset_dirpicker_on_config_load()
예제 #10
0
    def __load_file(self, configFilePath):
        """Read file and apply settings."""
        app.debug_print("loading config file : %s" % configFilePath)
        # attempt to open config file
        try:
            xmldoc = codecs.open(configFilePath, 'r', 'utf-8')
            xmldoc = minidom.parseString(xmldoc.read().encode("utf-8"))
        except:
            utils.make_err_msg(
                _(u"Invalid XML in config file : %s") % configFilePath,
                _(u"Invalid Configuration"))
        else:
            config = xmldoc.firstChild

            # set autopreview to false while loading config
            # avoids loading paths more than once
            v = main.bottomWindow.autoPreview.GetValue()
            main.bottomWindow.autoPreview.SetValue(False)

            # get original path
            oldPath = main.picker.view.path.GetValue()

            self.__load_config_xml(config)

            if self.loadError:
                utils.make_warn_msg(_(u"Not all settings could be loaded."))

            # Do not replace a set path if one is not set in the config
            newPath = main.picker.view.path.GetValue()
            if oldPath and not newPath:
                main.picker.view.path.SetValue(oldPath)

            # preview
            main.bottomWindow.autoPreview.SetValue(v)
            if app.autoModeLevel != 0 or\
                (app.prefs.get('previewOnConfig') and app.autoModeLevel is False):
                main.picker.view.reset_dirpicker_on_config_load()
예제 #11
0
    def refresh(self, event):
        """
        Grab items from a specified directory, either as a listing or as a
        walk, and filter out entries based on user settings.
        Files and folders are seperated for proper sorting.
        Called, depending on user preferences,
        from almost every widget in the picker panel, and from
        the main application class.
        """
        files = [] #files will go here
        folders = [] #folders will go here
        error = False
        params = self.params.load()

        if params.root is False:
            self.clear_all()
        # OK, load items up:
        else:
            self._set_initial()
            main.set_status_msg(_(u"Getting directory contents please wait ..."), u'wait')

            if app.showTimes:
                t = time.time()

            filter, useRE = self._get_filter(params)

            # create the search (filtering) operations ...
            notType = params.notType

            # normal filtering:
            if filter and not useRE:
                def _filter_folders(entry):
                    if filter in entry.lower() and not notType:
                        folders.append(entry)
                    if filter not in entry.lower() and notType:
                        folders.append(entry)
                def _filter_files(entry):
                    if filter in entry.lower() and not notType:
                        files.append(entry)
                    if filter not in entry.lower() and notType:
                        files.append(entry)
            # regular expression filtering
            elif filter and useRE:
                def _filter_folders(entry):
                    if filter.search(entry) and not notType:
                        folders.append(entry)
                    if not filter.search(entry) and notType:
                        folders.append(entry)
                def _filter_files(entry):
                    if filter.search(entry) and not notType:
                        files.append(entry)
                    if not filter.search(entry) and notType:
                        files.append(entry)
            # no filtering:
            else:
                def _filter_folders(entry):
                    folders.append(entry)
                def _filter_files(entry):
                    files.append(entry)

            # define here for speed boost
            def isdir(entry):
                join = os.path.join(params.root, entry)
                return os.path.isdir(join)

            def get_encoded_name(filename):
                filename = filename.decode(sys.getfilesystemencoding(), 'replace')
                return filename

            # Now to get the items according to operations defined above

            # retrieve items by walking
            if params.walkIt:
                maxDepth = params.walkDepth

                if params.foldersOn:
                    app.recursiveFolderOn = True

                try:
                    for dirpath, dirnames, filenames in os.walk(params.root):
                        base = dirpath.replace(params.root, '')
                        if maxDepth != 0 and len(base.split(os.path.sep)) > maxDepth:
                            continue
                        # grab files
                        if params.filesOn:
                            for entry in filenames:
                                entry = os.path.join(base, entry)
                                _filter_files(entry)
                        # grab folders
                        if params.foldersOn:
                            for entry in dirnames:
                                entry = os.path.join(base, entry)
                                _filter_folders(entry)

                except UnicodeDecodeError as err:
                    entry = err[1].decode(sys.getfilesystemencoding(), 'replace')
                    msg = _("The item '%s' has an encoding error.\nUnable to process this path in recursive mode, please correct the name and try again.")\
                        % entry
                    utils.make_err_msg(msg, _("Unable to load item"))
                    error = True
                    pass
                except:
                    main.set_status_msg(_(u"Cannot read path!"), u'warn')
                    error = True
                    pass
                else:
                    main.set_status_msg(_(u"Retrieved %s items from directory") % len(files), u'wait')
            # normal retrieval
            else:
                encodingError = False
                try:
                    listedDir = os.listdir(params.root)
                except:
                    main.set_status_msg(_(u"Cannot read path!"), u'warn')
                    error = True
                    pass
                else:
                    # loop through items in directory
                    for entry in listedDir:
                        try:
                            isFolder = isdir(entry)
                        except UnicodeDecodeError:
                            entry = entry.decode(sys.getfilesystemencoding(), 'replace')
                            isFolder = isdir(entry)
                            encodingError = True
                        # load folders if set:
                        if params.foldersOn and isFolder:
                            _filter_folders(entry)
                        # load files if set:
                        if params.filesOn and not isFolder:
                            _filter_files(entry)
                    if encodingError:
                        utils.make_err_msg(_("At least one item has an encoding error in its name. You will not be able to modify these."),
                                           _("Encoding Error"))

            if error is not True:
                self.add_items_to_panel(folders, files)
                main.set_status_msg(_(u"Retrieved %s items from directory") % self.count_panel_items(),
                                    u'complete')

                # after retrieval:
                self.enable_panel_widget('selectAll', True)
                main.menuPicker.getAllMenu.Enable(True)

            main.bottomWindow.display.DeleteAllItems()
            utils.set_busy(False)
            main.Refresh()

            # output time taken if set
            if app.showTimes:
                print("%s items load : %s" % (self.count_panel_items(), (time.time() - t)))

            if app.prefs.get(u'autoSelectAll'):
                self.select_all()
예제 #12
0
    def __init__(self, prnt, options):
        # Important variables needed throughout the application classes
        self.warn = [] # warnings
        self.bad = [] # errors
        self.errorLog = [] # all errors go here
        self.items = [] # items to rename
        self.spacer = u" " * 6 # spacer for status messages (to clear image)
        # icons used for status bar messages
        self.statusImages = {
            u'failed': wx.Bitmap(utils.icon_path(u'failed_sb.ico'),
                                 wx.BITMAP_TYPE_ICO),
            u'wait': wx.Bitmap(utils.icon_path(u'wait.png'),
                               wx.BITMAP_TYPE_PNG),
            u'warn': wx.Bitmap(utils.icon_path(u'warn_sb.ico'),
                               wx.BITMAP_TYPE_ICO),
            u'complete': wx.Bitmap(utils.icon_path(u'complete.ico'),
                                   wx.BITMAP_TYPE_ICO),
            u'eyes': wx.Bitmap(utils.icon_path(u'eyes.png'),
                               wx.BITMAP_TYPE_PNG),
        }

        app.debug_print("Init MainWindow")
        wx.Frame.__init__(self, id=wxID_MAIN_WINDOW, name=u'MainWindow',
                          parent=prnt, style=wx.DEFAULT_FRAME_STYLE)
        app.debug_print("")

        app.debug_print("======== System Info =======")
        app.debug_print("Operating System: %s - %s - %s" % (platform.system(), platform.release(), platform.version()))
        app.debug_print("Python version: %s" % platform.python_version())
        app.debug_print("wxPython version: %s" % wx.version())
        app.debug_print("============================")
        app.debug_print("")

        # first run?
        utils.init_environment()

        self.set_language()

        # import these modules here since they need language settings activated
        global renamer
        import renamer
        global configs
        import configs
        global picker
        import picker
        global bottomWindow
        import bottomWindow

        # initialize preferences
        app.debug_print("======== Preferences =======")
        app.prefs = preferences.Methods()
        app.debug_print("============================")
        app.debug_print("")

        # build main GUI
        self.__init_ctrls(prnt)

        # clear undo if set in preferences:
        if app.prefs.get(u'clearUndo'):
            try:
                originalFile = codecs.open(utils.get_user_path(u'undo/original.bak'),
                                           'w', "utf-8")
                originalFile.write('')
                renamedFile = codecs.open(utils.get_user_path(u'undo/renamed.bak'),
                                          'w', "utf-8")
                renamedFile.write('')
            except IOError, error:
                utils.make_err_msg(_(u"%s\n\nCould not clear undo") % error,
                                   _(u"Error"))
                pass
예제 #13
0
    def __init__(self, prnt, options):
        # Important variables needed throughout the application classes
        self.warn = [] # warnings
        self.bad = [] # errors
        self.errorLog = [] # all errors go here
        self.items = [] # items to rename
        self.spacer = u" " * 6 # spacer for status messages (to clear image)
        # icons used for status bar messages
        self.statusImages = {
            u'failed': wx.Bitmap(utils.icon_path(u'failed_sb.ico'),
                                 wx.BITMAP_TYPE_ICO),
            u'wait': wx.Bitmap(utils.icon_path(u'wait.png'),
                               wx.BITMAP_TYPE_PNG),
            u'warn': wx.Bitmap(utils.icon_path(u'warn_sb.ico'),
                               wx.BITMAP_TYPE_ICO),
            u'complete': wx.Bitmap(utils.icon_path(u'complete.ico'),
                                   wx.BITMAP_TYPE_ICO),
            u'eyes': wx.Bitmap(utils.icon_path(u'eyes.png'),
                               wx.BITMAP_TYPE_PNG),
        }

        app.debug_print("Init MainWindow")
        wx.Frame.__init__(self, id=wxID_MAIN_WINDOW, name=u'MainWindow',
                          parent=prnt, style=wx.DEFAULT_FRAME_STYLE)
        app.debug_print("")

        app.debug_print("======== System Info =======")
        app.debug_print("Operating System: %s - %s - %s" % (platform.system(), platform.release(), platform.version()))
        app.debug_print("Python version: %s" % platform.python_version())
        app.debug_print("wxPython version: %s" % wx.version())
        app.debug_print("============================")
        app.debug_print("")

        # first run?
        utils.init_environment()

        self.set_language()

        # import these modules here since they need language settings activated
        global renamer
        import renamer
        global configs
        import configs
        global picker
        import picker
        global bottomWindow
        import bottomWindow

        # initialize preferences
        app.debug_print("======== Preferences =======")
        app.prefs = preferences.Methods()
        app.debug_print("============================")
        app.debug_print("")

        # build main GUI
        self.__init_ctrls(prnt)

        # clear undo if set in preferences:
        if app.prefs.get(u'clearUndo'):
            try:
                originalFile = codecs.open(utils.get_user_path(u'undo/original.bak'),
                                           'w', "utf-8")
                originalFile.write('')
                renamedFile = codecs.open(utils.get_user_path(u'undo/renamed.bak'),
                                          'w', "utf-8")
                renamedFile.write('')
            except IOError, error:
                utils.make_err_msg(_(u"%s\n\nCould not clear undo") % error,
                                   _(u"Error"))
                pass
예제 #14
0
wxWidgets picker panel and associated classes.
Only responsible for views, All interactions must be handled by picker Core
"""

import os

import app
import utils
import wx

try:
    from PIL import Image
except:
    utils.make_err_msg(
        _(
            "Python Imaging Library (PIL) not found.\nRefer to readme file for install instructions.\n\nYou will not be able to preview images."
        ),
        _("PIL needed"),
    )

[
    wxID_PICKERPANEL,
    wxID_PICKERPANELBROWSE,
    wxID_SELECTIONAREADIRPICKER,
    wxID_PICKERPANELDIVIDER1,
    wxID_PICKERPANELFILESON,
    wxID_PICKERPANELFILTERSEL,
    wxID_PICKERPANELFOLDERSON,
    wxID_PICKERPANELNOT_TYPE,
    wxID_PICKERPANELOK,
    wxID_PICKERPANELPATH,
    wxID_PICKERPANELPATH_HELP,
예제 #15
0
# GNU General Public License for more details.
"""
wxWidgets picker panel and associated classes.
Only responsible for views, All interactions must be handled by picker Core
"""

import os

import app
import utils
import wx
try:
    import Image
except:
    utils.make_err_msg(
        _("Python Imaging Library (PIL) not found.\nRefer to readme file for install instructions.\n\nYou will not be able to preview images."
          ), _("PIL needed"))

[
    wxID_PICKERPANEL,
    wxID_PICKERPANELBROWSE,
    wxID_SELECTIONAREADIRPICKER,
    wxID_PICKERPANELDIVIDER1,
    wxID_PICKERPANELFILESON,
    wxID_PICKERPANELFILTERSEL,
    wxID_PICKERPANELFOLDERSON,
    wxID_PICKERPANELNOT_TYPE,
    wxID_PICKERPANELOK,
    wxID_PICKERPANELPATH,
    wxID_PICKERPANELPATH_HELP,
    wxID_SELECTIONAREAFPICKER,