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