Exemple #1
0
    def onSaveMat(self):
        printCode   = True
        filename = asksaveasfilename(filetypes=[('Matlab mat files', '*.mat')])
        if not filename:
            return
            
        def linkFunc(filename):
            printCode   = True
            clipboard   = Application.instance.clipboard
            clipboard.clear()
            clipboard.append(autoSubs('load $filename'))

        self.__topwin.saveMat(filename)
        tip = [
            {
                'type':'text', 
                'content':autoSubs('''The correlation matrix has been saved in the mat file "$filename" successully.
You can extract the data in Matlab using the following command:''')
            },
            {
                'type':'link', 
                'content':autoSubs('>> load $filename'),
                'command':lambda dumb: linkFunc(filename=filename)
            },
            {
                'type':'text', 
                'content':'''and variable named "R" will appear in your Matlab workspace.
(Click the underlined Matlab command and copy it to the clipboard)'''
            }
        ]
        self._app.printTip(tip)  
Exemple #2
0
    def onSaveMat(self):
        printCode = True
        filename = asksaveasfilename(filetypes=[('Matlab mat files', '*.mat')])
        if not filename:
            return

        def linkFunc(filename):
            printCode = True
            clipboard = Application.instance.clipboard
            clipboard.clear()
            clipboard.append(autoSubs('load $filename'))

        self.__topwin.saveMat(filename)
        tip = [{
            'type':
            'text',
            'content':
            autoSubs(
                '''The correlation matrix has been saved in the mat file "$filename" successully.
You can extract the data in Matlab using the following command:''')
        }, {
            'type': 'link',
            'content': autoSubs('>> load $filename'),
            'command': lambda dumb: linkFunc(filename=filename)
        }, {
            'type':
            'text',
            'content':
            '''and variable named "R" will appear in your Matlab workspace.
(Click the underlined Matlab command and copy it to the clipboard)'''
        }]
        self._app.printTip(tip)
Exemple #3
0
 def onSolveClick(self):
     t1  = time.clock()
     if self.__bParallel.get():
         self.parallelRun()
     else:
         self.serialRun()        
     deltaT  = time.clock() - t1
     print(autoSubs('Total time consumption: $deltaT (s)'))
Exemple #4
0
    def onExportMatlabScript(self):
        printCode = True
        filename = asksaveasfilename(filetypes=[('Matlab script files',
                                                 '*.m')])
        if not filename:
            return
        self.__topwin.figureBook.exportMatlabScript(filename)
        self._app.printTip(
            autoSubs('''A Matlab script file has been saved as $filename.
By running this script, Matlab will literally "re-plot" the curves shown here.'''
                     ))
Exemple #5
0
 def __setattr__(self, key, val):
     if '_attributeLock' not in self.__dict__:
         # This circumstance happens when __setattr__ called before __init__ being called.
         object.__setattr__(self, '_attributeLock', set())
     if 'autoLockAttribute' not in self.__dict__:
         object.__setattr__(self, 'autoLockAttribute', False)
     if key in self._attributeLock:
         raise AttributeError, autoSubs('Attribute "$key" is unchangeable.')
     if isinstance(val, ModelNode) and not val.isRoot and val.parentNode==None:
         val.nodeName = val.nodeName if val.nodeName else key
         object.__setattr__(val, 'parentNode', self)
         
         # The autolock mechanism will lock the node after you attach it to the model tree.
         # A child node cannot change its parent
         val.lockAttribute('parentNode')
         # and the parent node's child node cannot be re-assinged. 
         self.lockAttribute(key)
                 
     object.__setattr__(self, key, val)
     if self.autoLockAttribute and key != 'autoLockAttribute': # autoLockAttribute cannot be locked
         self.lockAttribute(key)        
Exemple #6
0
    def onExportMatlabScript(self):
        printCode = True
        filename = asksaveasfilename(filetypes=[("Matlab script files", "*.m")])
        if not filename:
            return
        self.__topwin.figureBook.exportMatlabScript(filename)
        self._app.printTip(
            autoSubs(
                """A Matlab script file has been saved as $filename.
By running this script, Matlab will literally "re-plot" the curves shown here."""
            )
        )
Exemple #7
0
    def __setattr__(self, key, val):
        if '_attributeLock' not in self.__dict__:
            # This circumstance happens when __setattr__ called before __init__ being called.
            object.__setattr__(self, '_attributeLock', set())
        if 'autoLockAttribute' not in self.__dict__:
            object.__setattr__(self, 'autoLockAttribute', False)
        if key in self._attributeLock:
            raise AttributeError, autoSubs('Attribute "$key" is unchangeable.')
        if isinstance(val,
                      ModelNode) and not val.isRoot and val.parentNode == None:
            val.nodeName = val.nodeName if val.nodeName else key
            object.__setattr__(val, 'parentNode', self)

            # The autolock mechanism will lock the node after you attach it to the model tree.
            # A child node cannot change its parent
            val.lockAttribute('parentNode')
            # and the parent node's child node cannot be re-assinged.
            self.lockAttribute(key)

        object.__setattr__(self, key, val)
        if self.autoLockAttribute and key != 'autoLockAttribute':  # autoLockAttribute cannot be locked
            self.lockAttribute(key)
Exemple #8
0
 def linkFunc(filename):
     printCode = True
     clipboard = Application.instance.clipboard
     clipboard.clear()
     clipboard.append(autoSubs('load $filename'))
Exemple #9
0
 def onKeyPress(self, evt, codeList=[]):       
     # Experimenting with idlelib's AutoComplete
     ##############################################################
     keysym = evt.keysym        
     if self.__autoComplete.autocompletewindow and \
             self.__autoComplete.autocompletewindow.is_active():
         if self.__autoComplete.autocompletewindow.keypress_event(evt) == 'break':
             return 'break'
         else:
             if keysym == 'Tab':
                 return 'break'
         
     if evt.keysym == 'Tab':
         return self.__autoComplete.autocomplete_event(evt)
     ##############################################################
     if evt.keycode not in range(16, 19) and evt.keycode not in range(33, 41):
         r, c    = self.getCursorPos()
         prompt  = self.text.get(autoSubs('$r.0'), autoSubs('$r.4'))
         if prompt != '>>> ' and prompt != '... ':
             return 'break'
         if evt.keycode==8 and c <= 4:
             return 'break'
         if c < 4:
             return 'break'
         rend, cend  = self.getCursorPos('end-1c')
         if r < rend:
             return 'break'                
         if evt.keycode == 13:
             app = Application.instance
             code    = self.text.get(autoSubs('$r.4'), autoSubs('$r.end'))
             try:
                 strippedCode     = code.strip()
                 if strippedCode and strippedCode[0] == '!':
                     # Execute a system command
                     app.execute(code)
                     self.promptSymbol   = '>>> '
                     self.updateContent(tag='', content='\n')
                     return 'break'
                 if strippedCode == '':
                     code    = '\n'.join(codeList)
                     del codeList[:]
                 strippedCode    = code.strip()
                 if strippedCode == '':
                     self.promptSymbol   = '>>> '
                     self.updateContent(tag='', content='\n') 
                 elif strippedCode[-1] in (':', '\\') or codeList:
                     codeList.append(code)
                     self.promptSymbol   = '... '
                     self.updateContent(tag='', content='\n')
                 else:
                     self.promptSymbol   = '>>> '
                     self.updateContent(tag='', content='\n')
                     try:
                         ret = app.execute(code)
                     except:
                         traceback.print_exc()
                     if ret != None:
                         self.updateContent(tag='RETVAL', content=repr(ret)+'\n')
 
             finally:
                 self.text.mark_set(INSERT, END)
                 self.text.see(END)
                 return 'break'            
Exemple #10
0
 def createWindow(self, moduleName, className):
     '''Create a tool window.'''
     mod = __import__(autoSubs('wavesynlib.toolwindows.$moduleName'), globals(), locals(), [className], -1)
     return self.windows.add(node=getattr(mod, className)())
Exemple #11
0
 def linkFunc(filename):
     printCode   = True
     clipboard   = Application.instance.clipboard
     clipboard.clear()
     clipboard.append(autoSubs('load $filename'))