~ubuntu-branches/ubuntu/wily/spyder/wily

« back to all changes in this revision

Viewing changes to spyderlib/plugins/editor.py

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2015-01-15 12:20:11 UTC
  • mfrom: (18.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150115122011-cc7j5dhy2h9uo13m
Tags: 2.3.2+dfsg-1ubuntu1
Backport patch to support pylint3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1467
1467
            editor = editorstack.clone_editor_from(finfo, set_current=False)
1468
1468
            self.register_widget_shortcuts("Editor", editor)
1469
1469
    
1470
 
    def new(self, fname=None, editorstack=None):
 
1470
    def new(self, fname=None, editorstack=None, text=None):
1471
1471
        """
1472
1472
        Create a new file - Untitled
1473
1473
        
1474
1474
        fname=None --> fname will be 'untitledXX.py' but do not create file
1475
1475
        fname=<basestring> --> create file
1476
1476
        """
1477
 
        # Creating template
1478
 
        text, enc = encoding.read(self.TEMPLATE_PATH)
1479
 
        encoding_match = re.search('-*- coding: ?([a-z0-9A-Z\-]*) -*-', text)
1480
 
        if encoding_match:
1481
 
            enc = encoding_match.group(1)
1482
 
        # Initialize template variables
1483
 
        # Windows
1484
 
        username = encoding.to_unicode_from_fs(os.environ.get('USERNAME',
1485
 
                                                              ''))
1486
 
        # Linux, Mac OS X
1487
 
        if not username:
1488
 
            username = encoding.to_unicode_from_fs(os.environ.get('USER',
1489
 
                                                                  '-'))
1490
 
        VARS = {
1491
 
            'date': time.ctime(),
1492
 
            'username': username,
1493
 
        }
1494
 
        try:
1495
 
            text = text % VARS
1496
 
        except:
1497
 
            pass
 
1477
        # If no text is provided, create default content
 
1478
        if text is None:
 
1479
            text, enc = encoding.read(self.TEMPLATE_PATH)
 
1480
            enc_match = re.search('-*- coding: ?([a-z0-9A-Z\-]*) -*-', text)
 
1481
            if enc_match:
 
1482
                enc = enc_match.group(1)
 
1483
            # Initialize template variables
 
1484
            # Windows
 
1485
            username = encoding.to_unicode_from_fs(os.environ.get('USERNAME',
 
1486
                                                                  ''))
 
1487
            # Linux, Mac OS X
 
1488
            if not username:
 
1489
                username = encoding.to_unicode_from_fs(os.environ.get('USER',
 
1490
                                                                      '-'))
 
1491
            VARS = {
 
1492
                'date': time.ctime(),
 
1493
                'username': username,
 
1494
            }
 
1495
            try:
 
1496
                text = text % VARS
 
1497
            except:
 
1498
                pass
 
1499
        else:
 
1500
            enc = encoding.read(self.TEMPLATE_PATH)[1]
 
1501
        
1498
1502
        create_fname = lambda n: to_text_string(_("untitled")) + ("%d.py" % n)
1499
1503
        # Creating editor widget
1500
1504
        if editorstack is None: