当前位置: 首页>>代码示例>>Python>>正文


Python Notebook.init_pages方法代码示例

本文整理汇总了Python中notebook.Notebook.init_pages方法的典型用法代码示例。如果您正苦于以下问题:Python Notebook.init_pages方法的具体用法?Python Notebook.init_pages怎么用?Python Notebook.init_pages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在notebook.Notebook的用法示例。


在下文中一共展示了Notebook.init_pages方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: OpPanel

# 需要导入模块: from notebook import Notebook [as 别名]
# 或者: from notebook.Notebook import init_pages [as 别名]
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)
#.........这里部分代码省略.........
开发者ID:javierpra,项目名称:metamorphose2,代码行数:103,代码来源:directory.py

示例2: OpPanel

# 需要导入模块: from notebook import Notebook [as 别名]
# 或者: from notebook.Notebook import init_pages [as 别名]
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:
#.........这里部分代码省略.........
开发者ID:RavenB,项目名称:metamorphose2,代码行数:103,代码来源:insert.py

示例3: OpPanel

# 需要导入模块: from notebook import Notebook [as 别名]
# 或者: from notebook.Notebook import init_pages [as 别名]
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()
#.........这里部分代码省略.........
开发者ID:RavenB,项目名称:metamorphose2,代码行数:103,代码来源:replace.py


注:本文中的notebook.Notebook.init_pages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。