Esempio n. 1
0
    def onAddNewText(self, e=None):
        from ifigure.mto.py_file import PyText
        obj = PyText()
        iname = self.get_next_name('untitled')

        parent = self.get_app()
        ret, name = dialog.textentry(parent,
                                     "Enter a text name", "New text...", iname)
        self.add_child(name, obj)
        obj.mk_owndir()
        path = os.path.join(obj.owndir(), obj.name + '.txt')
        print(('creating file ', path))
        open(path, 'a').close()
        obj.set_path_pathmode(path)
        obj.store_mtime()

        w = None if e is None else e.GetEventObject()
        from ifigure.mto.treedict import str_td
        path = str_td(path)
        path.td = obj.get_full_path()
        ifigure.events.SendEditFileEvent(self, w=w, file=path)

        if e is not None:
            e.Skip()
        return obj
Esempio n. 2
0
    def onAddNewModule(self, e=None, module_type=None):
        '''
        new module
        copy template to owndir
        open it by editor
        '''

        import ifigure.mto.py_module as py_module
        if module_type is None:
            dlg = wx.MessageDialog(self.get_app(),
                                   "Does the new module have its own directory? \n"
                                   "Or does it share the same directory as its parent? \n",
                                   "NewModule", wx.YES_NO | wx.ICON_INFORMATION)
            ans = dlg.ShowModal()
            dlg.Destroy()
            module_type = 1 if ans == wx.ID_YES else 2

        child = py_module.PyModule()
        if module_type == 1:
            temp = os.path.join(
                ifigure.__path__[0], 'template', 'new_module.py')
            child._can_have_child = True
            child._has_private_owndir = True
        else:
            temp = os.path.join(
                ifigure.__path__[0], 'template', 'new_module_nochild.py')
            child._can_have_child = False
            child._has_private_owndir = False
        name = self.get_next_name(child.get_namebase())
        idx = self.add_child(name, child)

        child.mk_owndir()
        dest = os.path.join(child.owndir(), name+'.py')
        shutil.copyfile(temp, dest)

        print(('loading...', dest))
        child.load_module(dest)

        w = None
        if e is not None:
            w = e.GetEventObject()
        from ifigure.mto.treedict import str_td
        dest = str_td(dest)
        dest.td = child.get_full_path()
        ifigure.events.SendEditFileEvent(self, w=w, file=dest)

        if e is not None:
            e.Skip()
        return child
Esempio n. 3
0
    def onEditScript(self, e):
        fpath=FileHolder.path2fullpath(self)
        if fpath == '': return
        self._script.load_script(fpath)
#        app = self.get_root_parent().app
#        if app.helper.setting['use_editor']:
#            txt = app.helper.setting['editor'].format(fpath) 
#            print txt
#            os.system(txt)
###        else:
        from ifigure.mto.treedict import str_td
        fpath = str_td(fpath)
        fpath.td = self.get_full_path()
        ifigure.events.SendEditFileEvent(self, 
                                         w=e.GetEventObject(),
                                         file=fpath)
Esempio n. 4
0
 def onEditScript(self, e):
     fpath = FileHolder.path2fullpath(self)
     if fpath == '': return
     self._script.load_script(fpath)
     #        app = self.get_root_parent().app
     #        if app.helper.setting['use_editor']:
     #            txt = app.helper.setting['editor'].format(fpath)
     #            print txt
     #            os.system(txt)
     ###        else:
     from ifigure.mto.treedict import str_td
     fpath = str_td(fpath)
     fpath.td = self.get_full_path()
     ifigure.events.SendEditFileEvent(self,
                                      w=e.GetEventObject(),
                                      file=fpath)
Esempio n. 5
0
    def onAddNewScript(self, e=None, name='', temp='', parent=None, dest=None):
        # new script
        # copy template to owndir
        # open it by editor
        import ifigure.mto.py_script as py_script
        if temp == '':
            temp = os.path.join(
                ifigure.__path__[0], 'template', 'script', '_blank_script.py')

        child = py_script.PyScript()
        if name == '':
            iname = '_'.join([x for x in os.path.basename(temp)[
                             :-3].split('_') if len(x) != 0])
            if parent is None:
                parent = self.get_app()
            ret, name = dialog.textentry(parent,
                                         "Enter a script name", "New Script...", iname)
            if not ret:
                return
            if self.has_child(name):
                name = self.get_next_name(name)
        idx = self.add_child(name, child)

        if dest is None:
            child.mk_owndir()
            dest = child.owndir()
        dest = os.path.join(dest, name+'.py')
        i = 1
        while os.path.exists(dest):
            name0 = name+str(i)+'.py'
            dest = os.path.join(child.owndir(), name0)
            i = i + 1
        shutil.copyfile(temp, dest)
        child.load_script(dest)

        w = None
        if e is not None:
            w = e.GetEventObject()
        from ifigure.mto.treedict import str_td
        dest = str_td(dest)
        dest.td = child.get_full_path()
        ifigure.events.SendEditFileEvent(self, w=w, file=dest)

        if e is not None:
            e.Skip()
        return child
Esempio n. 6
0
    def onAddNewModule(self, e=None, module_type=None):
        '''
        new module
        copy template to owndir
        open it by editor
        '''

        import ifigure.mto.py_module as py_module
        if module_type is None:
             dlg = wx.MessageDialog(self.get_app(),
                      "Does the new module have its own directory? \n"
                      "Or does it share the same directory as its parent? \n", 
                      "NewModule", wx.YES_NO | wx.ICON_INFORMATION)
             ans = dlg.ShowModal()
             dlg.Destroy() 
             module_type = 1 if ans == wx.ID_YES else 2

        child=py_module.PyModule()
        if module_type == 1:
            temp=os.path.join(ifigure.__path__[0], 'template', 'new_module.py')
            child._can_have_child = True
            child._has_private_owndir = True
        else:
            temp=os.path.join(ifigure.__path__[0], 'template', 'new_module_nochild.py')
            child._can_have_child = False
            child._has_private_owndir = False
        name=self.get_next_name(child.get_namebase())
        idx=self.add_child(name, child)

        child.mk_owndir()
        dest = os.path.join(child.owndir(), name+'.py')
        shutil.copyfile(temp, dest)        

        print('loading...', dest)
        child.load_module(dest)

        w = None
        if e is not None: w = e.GetEventObject()
        from ifigure.mto.treedict import str_td
        dest = str_td(dest)
        dest.td = child.get_full_path()
        ifigure.events.SendEditFileEvent(self, w=w, file=dest)

        if e is not None: e.Skip()
        return child
Esempio n. 7
0
    def onAddNewScript(self, e=None, name='', temp='', parent=None, dest=None):
        # new script 
        # copy template to owndir
        # open it by editor
        import ifigure.mto.py_script as py_script
        if temp == '':
           temp=os.path.join(ifigure.__path__[0], 'template', 'script', '_blank_script.py')

        child=py_script.PyScript()
        if name is '':
            iname = '_'.join([x for x in os.path.basename(temp)[:-3].split('_') if len(x) !=0])
            if parent is None:
                parent = self.get_app()
            ret, name = dialog.textentry(parent, 
                            "Enter a script name", "New Script...", iname)
            if not ret: return
            if self.has_child(name):
                 name=self.get_next_name(name)
        idx=self.add_child(name, child)

        if dest is None:
            child.mk_owndir()
            dest = child.owndir()
        dest = os.path.join(dest, name+'.py')
        i = 1
        while os.path.exists(dest):
            name0 = name+str(i)+'.py'
            dest = os.path.join(child.owndir(), name0)
            i = i + 1
        shutil.copyfile(temp, dest)        
        child.load_script(dest)    

        w = None
        if e is not None: w = e.GetEventObject()
        from ifigure.mto.treedict import str_td
        dest = str_td(dest)
        dest.td = child.get_full_path()
        ifigure.events.SendEditFileEvent(self, w=w, file=dest)

        if e is not None: e.Skip()
        return child
Esempio n. 8
0
    def onAddNewText(self, e=None):
         from ifigure.mto.py_file import PyText
         obj = PyText()
         iname=self.get_next_name('untitled')

         parent = self.get_app()
         ret, name = dialog.textentry(parent, 
                     "Enter a text name", "New text...", iname)
         self.add_child(name, obj)
         obj.mk_owndir()
         path = os.path.join(obj.owndir(), obj.name + '.txt')
         print('creating file ', path)
         open(path, 'a').close()
         obj.set_path_pathmode(path)
         obj.store_mtime()

         w = None if e is None else e.GetEventObject()
         from ifigure.mto.treedict import str_td
         path = str_td(path)
         path.td = obj.get_full_path()
         ifigure.events.SendEditFileEvent(self, w=w, file=path)

         if e is not None: e.Skip()
         return obj