Ejemplo n.º 1
0
class OpPanel(Operation):
    """This is the main panel for directory manipulations.

    It holds the notebook holding all directory panels.
    """
    def __init_sizer(self, parent):
        #smallestSize = parent.rightSizer.GetSize() - parent.rightTopSizer.GetSize() - (10,10)
        superSizer = wx.BoxSizer(wx.VERTICAL)
        #superSizer.SetMinSize(smallestSize)
        superSizer.Add(self.notebook, 0, wx.EXPAND)
        self.SetSizerAndFit(superSizer)

    def __init_ctrls(self, prnt):
        wx.Panel.__init__(self,
                          id=-1,
                          name=u'Panel',
                          parent=prnt,
                          style=wx.TAB_TRAVERSAL)
        self.notebook = Notebook(self, main)
        self.directoryToolsPanel = directoryTools.Panel(self.notebook, main)
        self.notebook.init_pages(self.directoryToolsPanel,
                                 _(u"Directory settings"), u'directory.ico')
        self.numberingPanel = self.notebook.numbering
        self.dateTimePanel = self.notebook.dateTime

    def __init__(self, parent, main_window, params={}):
        Operation.__init__(self, params)
        global main
        main = main_window
        self.set_as_path_only()
        self.__init_ctrls(parent)
        self.__init_sizer(parent)
        self.update_parameters(self.directoryToolsPanel.params)

    def on_config_load(self):
        """Update GUI elements, settings after config load."""
        self.numberingPanel.on_config_load()
        self.dateTimePanel.get_from_item_checkbox(False)

    def __add_path(self, newPath, path):
        """Extra operation for absolute paths."""
        recurPath = ''
        recur = self.directoryToolsPanel.pathRecur.GetValue()
        path = path.split(os.sep)
        # remove drive letter
        if wx.Platform == '__WXMSW__':
            path = path[1:]

        # inverse the selection or not
        if not self.directoryToolsPanel.inverse.GetValue():
            if recur <= 0:
                recur -= 1
            path = path[-recur:]
        else:
            path = path[:-recur]

        # reassemble path
        for segment in path:
            recurPath = os.path.join(recurPath, segment)
        newPath = newPath.replace(self.params['pathStructTxt'], recurPath)
        return newPath

    def __add_file_name(self, newPath, name, ext):
        if self.directoryToolsPanel.useFileExt.GetValue(
        ) and self.directoryToolsPanel.useFileName.GetValue():
            if ext:
                ext = '.' + ext
            parsedName = name + ext
        elif self.directoryToolsPanel.useFileName.GetValue():
            parsedName = name
        elif self.directoryToolsPanel.useFileExt.GetValue():
            parsedName = ext
        else:
            parsedName = ''

        newPath = newPath.replace(self.params['nameTxt'], parsedName)
        return newPath

    def reset_counter(self, c):
        """Reset the numbering counter for the operation."""
        utils.reset_counter(self, self.directoryToolsPanel, c)

    def rename_item(self, path, name, ext, original):
        """Create the new path."""
        rejoin = False
        operations = self.directoryToolsPanel.opButtonsPanel
        newPath = self.directoryToolsPanel.directoryText.GetValue()
        params = self.params

        # absolute path
        if os.path.isabs(newPath):
            split = os.path.splitdrive(newPath)
            newPath = split[1]
            rejoin = True

        # add path structure
        if params['pathStructTxt'] in newPath:
            newPath = self.__add_path(newPath, path)

        # add filename
        if params['nameTxt'] in newPath:
            newPath = self.__add_file_name(newPath, name, ext)

        newPath = operations.parse_input(newPath, original, self)

        if rejoin:
            newPath = os.path.join(split[0], newPath)
        else:
            newPath = os.path.join(path, newPath)

        return (newPath, name, ext)
Ejemplo n.º 2
0
class OpPanel(Operation):
    """This panel controls inserts."""
    
    def __init_sizer(self, parent):
        #smallestSize = parent.rightSizer.GetSize() - parent.rightTopSizer.GetSize() - (10,10)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        #mainSizer.SetMinSize(smallestSize)
        mainSizer.Add(self.notebook, 0, wx.EXPAND)
        self.SetSizerAndFit(mainSizer)

    def __init_ctrls(self, prnt):
        wx.Panel.__init__(self, id=-1, name=u'Panel', parent=prnt,
                          style=wx.TAB_TRAVERSAL)
        self.notebook = Notebook(self, main)
        self.insertToolsPanel = insertTools.Panel(self.notebook, main)
        self.notebook.init_pages(self.insertToolsPanel,
                                 _(u"Insert settings"), u'insert.ico')
        self.numberingPanel = self.notebook.numbering
        self.dateTimePanel = self.notebook.dateTime


    def __init__(self, parent, main_window, params={}):
        Operation.__init__(self, params)
        global main
        main = main_window
        self.__init_ctrls(parent)
        self.__init_sizer(parent)

    def on_config_load(self):
        """Update GUI elements, settings after config load."""
        self.insertToolsPanel.activate_options(False)
        self.numberingPanel.on_config_load()
        self.dateTimePanel.get_from_item_checkbox(False)

    def reset_counter(self, c):
        """Reset the numbering counter for the operation."""
        utils.reset_counter(self, self.insertToolsPanel, c)

    def rename_item(self, path, name, ext, original):
        """Insert into name."""
        newName = self.join_ext(name, ext)
        if not newName:
            return path, name, ext

        insert = self.insertToolsPanel
        operations = insert.opButtonsPanel
        parsedText = operations.parse_input(insert.Text.GetValue(), original, self)
        # prefix
        if insert.prefix.GetValue():
            newName = parsedText + name
        # suffix
        elif insert.suffix.GetValue():
            newName = name + parsedText
        # exact position
        elif insert.position.GetValue():
            pos = insert.positionPos.GetValue()
            if pos == -1:
                newName += parsedText
            elif pos < -1:
                newName = newName[:pos + 1] + parsedText + newName[pos + 1:]
            else:
                newName = newName[:pos] + parsedText + newName[pos:]

        # insert before/after a character:
        elif insert.after.GetValue() or insert.before.GetValue():
            good2go = False
            textMatch = insert.BAtextMatch.GetValue()
            # text search
            if not insert.regExpPanel.regExpr.GetValue():
                try:
                    insertAt = newName.index(textMatch)
                except ValueError:
                    pass
                else:
                    if insert.after.GetValue():
                        insertAt += len(textMatch)
                    good2go = True
            # regular expression search
            else:
                insertRE = insert.regExpPanel.create_regex(textMatch)
                try:
                    insertAt = insertRE.search(newName).end()
                except AttributeError:
                    pass
                else:
                    if insert.before.GetValue():
                        insertAt -= len(textMatch)
                    good2go = True

            if good2go:
                newName = newName[:insertAt] + parsedText + newName[insertAt:]

        # insert in between 2 characters:
        # (copy of search.py function)
        elif insert.between.GetValue():
            good2go = False
            if insert.regExpPanel.regExpr.GetValue():
                mod1 = insert.regExpPanel.create_regex(insert.BTWtextMatch1.GetValue())
                mod2 = insert.regExpPanel.create_regex(insert.BTWtextMatch2.GetValue())
                try:
                    frm = mod1.search(newName).end()
                    to = mod2.search(newName, frm).start()
                except AttributeError:
                    pass
                else:
                    good2go = True
            else:
                match1 = insert.BTWtextMatch1.GetValue()
                match2 = insert.BTWtextMatch2.GetValue()
                try:
                    frm = newName.index(match1) + len(match1)
                    to = newName.index(match2, frm)
                except ValueError:
                    pass
                else:
                    good2go = True
            if good2go:
                newName = newName[:frm] + parsedText + newName[to:]

        name, ext = self.split_ext(newName, name, ext)

        return path, name, ext
Ejemplo n.º 3
0
class OpPanel(Operation):
    """This is the main panel for directory manipulations.

    It holds the notebook holding all directory panels.
    """

    def __init_sizer(self, parent):
        #smallestSize = parent.rightSizer.GetSize() - parent.rightTopSizer.GetSize() - (10,10)
        superSizer = wx.BoxSizer(wx.VERTICAL)
        #superSizer.SetMinSize(smallestSize)
        superSizer.Add(self.notebook, 0, wx.EXPAND)
        self.SetSizerAndFit(superSizer)

    def __init_ctrls(self, prnt):
        wx.Panel.__init__(self, id=-1, name=u'Panel', parent=prnt,
                          style=wx.TAB_TRAVERSAL)
        self.notebook = Notebook(self, main)
        self.directoryToolsPanel = directoryTools.Panel(self.notebook, main)
        self.notebook.init_pages(self.directoryToolsPanel,
                                 _(u"Directory settings"), u'directory.ico')
        self.numberingPanel = self.notebook.numbering
        self.dateTimePanel = self.notebook.dateTime


    def __init__(self, parent, main_window, params={}):
        Operation.__init__(self, params)
        global main
        main = main_window
        self.set_as_path_only()
        self.__init_ctrls(parent)
        self.__init_sizer(parent)
        self.update_parameters(self.directoryToolsPanel.params)

    def on_config_load(self):
        """Update GUI elements, settings after config load."""
        self.numberingPanel.on_config_load()
        self.dateTimePanel.get_from_item_checkbox(False)

    def __add_path(self, newPath, path):
        """Extra operation for absolute paths."""
        recurPath = ''
        recur = self.directoryToolsPanel.pathRecur.GetValue()
        path = path.split(os.sep)
        # remove drive letter
        if wx.Platform == '__WXMSW__':
            path = path[1:]

        # inverse the selection or not
        if not self.directoryToolsPanel.inverse.GetValue():
            if recur <= 0:
                recur -= 1
            path = path[-recur:]
        else:
            path = path[:-recur]

        # reassemble path
        for segment in path:
            recurPath = os.path.join(recurPath, segment)
        newPath = newPath.replace(self.params['pathStructTxt'], recurPath)
        return newPath

    def __add_file_name(self, newPath, name, ext):
        if self.directoryToolsPanel.useFileExt.GetValue() and self.directoryToolsPanel.useFileName.GetValue():
            if ext:
                ext = '.' + ext
            parsedName = name + ext
        elif self.directoryToolsPanel.useFileName.GetValue():
            parsedName = name
        elif self.directoryToolsPanel.useFileExt.GetValue():
            parsedName = ext
        else:
            parsedName = ''

        newPath = newPath.replace(self.params['nameTxt'], parsedName)
        return newPath

    def reset_counter(self, c):
        """Reset the numbering counter for the operation."""
        utils.reset_counter(self, self.directoryToolsPanel, c)

    def rename_item(self, path, name, ext, original):
        """Create the new path."""
        rejoin = False
        operations = self.directoryToolsPanel.opButtonsPanel
        newPath = self.directoryToolsPanel.directoryText.GetValue()
        params = self.params

        # absolute path
        if os.path.isabs(newPath):
            split = os.path.splitdrive(newPath)
            newPath = split[1]
            rejoin = True

        # add path structure
        if params['pathStructTxt'] in newPath:
            newPath = self.__add_path(newPath, path)

        # add filename
        if params['nameTxt'] in newPath:
            newPath = self.__add_file_name(newPath, name, ext)

        newPath = operations.parse_input(newPath, original, self)

        if rejoin:
            newPath = os.path.join(split[0], newPath)
        else:
            newPath = os.path.join(path, newPath)

        return (newPath, name, ext)
Ejemplo n.º 4
0
class OpPanel(Operation):
    """This panel controls inserts."""
    def __init_sizer(self, parent):
        #smallestSize = parent.rightSizer.GetSize() - parent.rightTopSizer.GetSize() - (10,10)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        #mainSizer.SetMinSize(smallestSize)
        mainSizer.Add(self.notebook, 0, wx.EXPAND)
        self.SetSizerAndFit(mainSizer)

    def __init_ctrls(self, prnt):
        wx.Panel.__init__(self,
                          id=-1,
                          name=u'Panel',
                          parent=prnt,
                          style=wx.TAB_TRAVERSAL)
        self.notebook = Notebook(self, main)
        self.insertToolsPanel = insertTools.Panel(self.notebook, main)
        self.notebook.init_pages(self.insertToolsPanel, _(u"Insert settings"),
                                 u'insert.ico')
        self.numberingPanel = self.notebook.numbering
        self.dateTimePanel = self.notebook.dateTime

    def __init__(self, parent, main_window, params={}):
        Operation.__init__(self, params)
        global main
        main = main_window
        self.__init_ctrls(parent)
        self.__init_sizer(parent)

    def on_config_load(self):
        """Update GUI elements, settings after config load."""
        self.insertToolsPanel.activate_options(False)
        self.numberingPanel.on_config_load()
        self.dateTimePanel.get_from_item_checkbox(False)

    def reset_counter(self, c):
        """Reset the numbering counter for the operation."""
        utils.reset_counter(self, self.insertToolsPanel, c)

    def rename_item(self, path, name, ext, original):
        """Insert into name."""
        newName = self.join_ext(name, ext)
        if not newName:
            return path, name, ext

        insert = self.insertToolsPanel
        operations = insert.opButtonsPanel
        parsedText = operations.parse_input(insert.Text.GetValue(), original,
                                            self)
        # prefix
        if insert.prefix.GetValue():
            newName = parsedText + name
        # suffix
        elif insert.suffix.GetValue():
            newName = name + parsedText
        # exact position
        elif insert.position.GetValue():
            pos = insert.positionPos.GetValue()
            if pos == -1:
                newName += parsedText
            elif pos < -1:
                newName = newName[:pos + 1] + parsedText + newName[pos + 1:]
            else:
                newName = newName[:pos] + parsedText + newName[pos:]

        # insert before/after a character:
        elif insert.after.GetValue() or insert.before.GetValue():
            good2go = False
            textMatch = insert.BAtextMatch.GetValue()
            # text search
            if not insert.regExpPanel.regExpr.GetValue():
                try:
                    insertAt = newName.index(textMatch)
                except ValueError:
                    pass
                else:
                    if insert.after.GetValue():
                        insertAt += len(textMatch)
                    good2go = True
            # regular expression search
            else:
                insertRE = insert.regExpPanel.create_regex(textMatch)
                try:
                    insertAt = insertRE.search(newName).end()
                except AttributeError:
                    pass
                else:
                    if insert.before.GetValue():
                        insertAt -= len(textMatch)
                    good2go = True

            if good2go:
                newName = newName[:insertAt] + parsedText + newName[insertAt:]

        # insert in between 2 characters:
        # (copy of search.py function)
        elif insert.between.GetValue():
            good2go = False
            if insert.regExpPanel.regExpr.GetValue():
                mod1 = insert.regExpPanel.create_regex(
                    insert.BTWtextMatch1.GetValue())
                mod2 = insert.regExpPanel.create_regex(
                    insert.BTWtextMatch2.GetValue())
                try:
                    frm = mod1.search(newName).end()
                    to = mod2.search(newName, frm).start()
                except AttributeError:
                    pass
                else:
                    good2go = True
            else:
                match1 = insert.BTWtextMatch1.GetValue()
                match2 = insert.BTWtextMatch2.GetValue()
                try:
                    frm = newName.index(match1) + len(match1)
                    to = newName.index(match2, frm)
                except ValueError:
                    pass
                else:
                    good2go = True
            if good2go:
                newName = newName[:frm] + parsedText + newName[to:]

        name, ext = self.split_ext(newName, name, ext)

        return path, name, ext
Ejemplo n.º 5
0
class OpPanel(Operation):
    """Panel in charge of replacing matches with text or operations."""

    def __init_sizer(self, parent):
        #smallestSize = parent.rightSizer.GetSize() - parent.rightTopSizer.GetSize() - (10,10)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        #mainSizer.SetMinSize(smallestSize)
        mainSizer.Add(self.notebook, 0, wx.EXPAND)
        self.SetSizerAndFit(mainSizer)

    def __init_ctrls(self, prnt):
        wx.Panel.__init__(self, id=-1, name=u'Panel', parent=prnt,
                          style=wx.TAB_TRAVERSAL)
        self.notebook = Notebook(self, main)
        self.replaceToolsPanel = replaceTools.Panel(self.notebook, main)
        self.notebook.init_pages(self.replaceToolsPanel,
                                 _(u"Replace settings"), u'replace.ico')
        self.numberingPanel = self.notebook.numbering
        self.dateTimePanel = self.notebook.dateTime


    def __init__(self, parent, main_window, params={}):
        Operation.__init__(self, params)
        global main
        main = main_window
        self.__init_ctrls(parent)
        self.__init_sizer(parent)

    def on_config_load(self):
        """Update GUI elements, settings after config load."""
        self.replaceToolsPanel.on_load()
        self.numberingPanel.on_config_load()
        self.dateTimePanel.get_from_item_checkbox(False)

    def reset_counter(self, c):
        """Reset the numbering counter for the operation."""
        utils.reset_counter(self, self.replaceToolsPanel, c)

    def rename_item(self, path, name, ext, original):
        operations = self.replaceToolsPanel.opButtonsPanel
        newName = self.join_ext(name, ext)
        if not newName:
            return path, name, ext

        # basic settings
        search = self.replaceToolsPanel.search
        searchValues = search.searchValues
        text = self.replaceToolsPanel.repl_txt.GetValue()

        #- do nothing
        if searchValues[0] == u"text" and not searchValues[2] and not text:
            return path, name, ext

        #- search and replace when field not blank:
        elif searchValues[0] == u"text" and searchValues[2]:
            find = searchValues[2]
            parsedText = operations.parse_input(text, original, self)
            #case insensitive
            if not searchValues[1]:
                found = search.case_insensitive(newName)
                for match in found:
                    newName = newName.replace(match, parsedText)
            #case sensitive:
            else:
                newName = newName.replace(find, parsedText)
        
        #- replace everything if text field is blank:
        elif searchValues[0] == u"text":
            newName = operations.parse_input(text, original, self)

        #- replace using regular expression:
        elif searchValues[0] == u"reg-exp" and searchValues[1]:
            # need to first substiute, then parse for backreference support
            try:
                replaced = searchValues[2].sub(text, newName)
            except (sre_constants.error, AttributeError) as err:
                main.set_status_msg(_(u"Regular-Expression: %s") % err, u'warn')
                # so we know not to change status text after RE error msg:
                app.REmsg = True
                pass
            else:
                newName = operations.parse_input(replaced, original, self)

            # show RE error message from search, if any
            if search.REmsg:
                main.set_status_msg(search.REmsg, u'warn')
                app.REmsg = True

        #- replace in between
        elif searchValues[0] == u"between":
            positions = search.get_between_to_from(newName)
            if positions:
                frm = positions[0]
                to = positions[1]
                parsedText = operations.parse_input(text, original, self)
                newName = newName[:frm] + parsedText + newName[to:]

        #- replace by position:
        elif searchValues[0] == u"position":
            ss = search.repl_from.GetValue()
            sl = search.repl_len.GetValue()
            frm, to, tail = search.get_start_end_pos(ss, sl, newName)
            parsedText = operations.parse_input(text, original, self)
            newName = newName[:frm] + parsedText + tail

        name, ext = self.split_ext(newName, name, ext)
        return path, name, ext
Ejemplo n.º 6
0
class OpPanel(Operation):
    """Panel in charge of replacing matches with text or operations."""
    def __init_sizer(self, parent):
        #smallestSize = parent.rightSizer.GetSize() - parent.rightTopSizer.GetSize() - (10,10)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        #mainSizer.SetMinSize(smallestSize)
        mainSizer.Add(self.notebook, 0, wx.EXPAND)
        self.SetSizerAndFit(mainSizer)

    def __init_ctrls(self, prnt):
        wx.Panel.__init__(self,
                          id=-1,
                          name=u'Panel',
                          parent=prnt,
                          style=wx.TAB_TRAVERSAL)
        self.notebook = Notebook(self, main)
        self.replaceToolsPanel = replaceTools.Panel(self.notebook, main)
        self.notebook.init_pages(self.replaceToolsPanel,
                                 _(u"Replace settings"), u'replace.ico')
        self.numberingPanel = self.notebook.numbering
        self.dateTimePanel = self.notebook.dateTime

    def __init__(self, parent, main_window, params={}):
        Operation.__init__(self, params)
        global main
        main = main_window
        self.__init_ctrls(parent)
        self.__init_sizer(parent)

    def on_config_load(self):
        """Update GUI elements, settings after config load."""
        self.replaceToolsPanel.on_load()
        self.numberingPanel.on_config_load()
        self.dateTimePanel.get_from_item_checkbox(False)

    def reset_counter(self, c):
        """Reset the numbering counter for the operation."""
        utils.reset_counter(self, self.replaceToolsPanel, c)

    def rename_item(self, path, name, ext, original):
        operations = self.replaceToolsPanel.opButtonsPanel
        newName = self.join_ext(name, ext)
        if not newName:
            return path, name, ext

        # basic settings
        search = self.replaceToolsPanel.search
        searchValues = search.searchValues
        text = self.replaceToolsPanel.repl_txt.GetValue()

        #- do nothing
        if searchValues[0] == u"text" and not searchValues[2] and not text:
            return path, name, ext

        #- search and replace when field not blank:
        elif searchValues[0] == u"text" and searchValues[2]:
            find = searchValues[2]
            parsedText = operations.parse_input(text, original, self)
            #case insensitive
            if not searchValues[1]:
                found = search.case_insensitive(newName)
                for match in found:
                    newName = newName.replace(match, parsedText)
            #case sensitive:
            else:
                newName = newName.replace(find, parsedText)

        #- replace everything if text field is blank:
        elif searchValues[0] == u"text":
            newName = operations.parse_input(text, original, self)

        #- replace using regular expression:
        elif searchValues[0] == u"reg-exp" and searchValues[1]:
            # need to first substiute, then parse for backreference support
            try:
                replaced = searchValues[2].sub(text, newName)
            except (sre_constants.error, AttributeError) as err:
                main.set_status_msg(
                    _(u"Regular-Expression: %s") % err, u'warn')
                # so we know not to change status text after RE error msg:
                app.REmsg = True
                pass
            else:
                newName = operations.parse_input(replaced, original, self)

            # show RE error message from search, if any
            if search.REmsg:
                main.set_status_msg(search.REmsg, u'warn')
                app.REmsg = True

        #- replace in between
        elif searchValues[0] == u"between":
            positions = search.get_between_to_from(newName)
            if positions:
                frm = positions[0]
                to = positions[1]
                parsedText = operations.parse_input(text, original, self)
                newName = newName[:frm] + parsedText + newName[to:]

        #- replace by position:
        elif searchValues[0] == u"position":
            ss = search.repl_from.GetValue()
            sl = search.repl_len.GetValue()
            frm, to, tail = search.get_start_end_pos(ss, sl, newName)
            parsedText = operations.parse_input(text, original, self)
            newName = newName[:frm] + parsedText + tail

        name, ext = self.split_ext(newName, name, ext)
        return path, name, ext