本文整理汇总了Python中efl.elementary.entry.Entry.file_save方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.file_save方法的具体用法?Python Entry.file_save怎么用?Python Entry.file_save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类efl.elementary.entry.Entry
的用法示例。
在下文中一共展示了Entry.file_save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Interface
# 需要导入模块: from efl.elementary.entry import Entry [as 别名]
# 或者: from efl.elementary.entry.Entry import file_save [as 别名]
#.........这里部分代码省略.........
def curChanged(self, entry, label):
# get linear index into current text
index = entry.cursor_pos_get()
# Replace <br /> tag with single char
# to simplify (line, col) calculation
tmp_text = entry.entry_get().replace("<br/>", "\n")
line = tmp_text[:index].count("\n") + 1
col = len(tmp_text[:index].split("\n")[-1]) + 1
# Update label text with line, col
label.text = "Ln {0} Col {1} ".format(line, col)
def textEdited(self, obj):
current_file = self.mainEn.file[0]
current_file = \
os.path.basename(current_file) if \
current_file and not self.isNewFile else \
"Untitled"
self.mainWindow.title = "*%s - ePad" % (current_file)
self.isSaved = False
def fileSelected(self, fs, file_selected, onStartup=False):
if not onStartup:
self.flip.go(ELM_FLIP_INTERACTION_ROTATE)
print(file_selected)
IsSave = fs.is_save_get()
if file_selected:
if IsSave:
newfile = open(file_selected, 'w')
tmp_text = self.mainEn.entry_get()
newfile.write(tmp_text)
newfile.close()
self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8)
self.mainEn.entry_set(tmp_text)
self.mainEn.file_save()
self.mainWindow.title_set("%s - ePad"
% os.path.basename(file_selected))
self.isSaved = True
self.isNewFile = False
else:
try:
self.mainEn.file_set(file_selected,
ELM_TEXT_FORMAT_PLAIN_UTF8)
except RuntimeError:
print("Empty file: {0}".format(file_selected))
self.mainWindow.title_set("%s - ePad"
% os.path.basename(file_selected))
def newFile(self, obj=None, ignoreSave=False):
if self.isSaved is True or ignoreSave is True:
trans = Transit()
trans.object_add(self.mainEn)
trans.auto_reverse = True
trans.effect_wipe_add(
ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT)
trans.duration = 0.5
trans.go()
time.sleep(0.5)
self.mainWindow.title_set("Untitled - ePad")
self.mainEn.delete()
self.entryInit()
self.isNewFile = True
示例2: Interface
# 需要导入模块: from efl.elementary.entry import Entry [as 别名]
# 或者: from efl.elementary.entry.Entry import file_save [as 别名]
#.........这里部分代码省略.........
def pastePress( self, obj, it ):
self.mainEn.selection_paste()
it.selected_set(False)
def cutPress( self, obj, it ):
self.mainEn.selection_cut()
it.selected_set(False)
def selectAllPress( self, obj, it ):
self.mainEn.select_all()
it.selected_set(False)
def textEdited( self, obj ):
ourFile = self.mainEn.file_get()[0]
if ourFile and not self.isNewFile:
self.mainWindow.title_set("*%s - ePad"%self.mainEn.file_get()[0].split("/")[len(self.mainEn.file_get()[0].split("/"))-1])
else:
self.mainWindow.title_set("*Untitlted - ePad")
self.isSaved = False
def fileSelected( self, fs, file_selected, onStartup=False ):
if not onStartup:
self.flip.go(ELM_FLIP_INTERACTION_ROTATE)
print(file_selected)
IsSave = fs.is_save_get()
if file_selected:
if IsSave:
newfile = open(file_selected,'w') # creates new file
tmp_text = self.mainEn.entry_get()
newfile.write(tmp_text)
newfile.close()
self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8)
self.mainEn.entry_set(tmp_text)
self.mainEn.file_save()
self.mainWindow.title_set("%s - ePad" % file_selected.split("/")[len(file_selected.split("/"))-1])
self.isSaved = True
self.isNewFile = False
else:
try:
self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8)
except RuntimeError:
print("Empty file: {0}".format(file_selected))
self.mainWindow.title_set("%s - ePad" % file_selected.split("/")[len(file_selected.split("/"))-1])
def aboutPress( self, obj, it ):
#About popup
self.popupAbout = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH)
self.popupAbout.text = "ePad - A simple text editor written in python and elementary<br><br> " \
"By: Jeff Hoogland"
bt = Button(self.mainWindow, text="Done")
bt.callback_clicked_add(self.aboutClose)
self.popupAbout.part_content_set("button1", bt)
self.popupAbout.show()
it.selected_set(False)
def aboutClose( self, bt ):
self.popupAbout.delete()
def newFile( self , obj=None, ignoreSave=False ):
if self.isSaved == True or ignoreSave == True:
trans = Transit()
trans.object_add(self.mainEn)
trans.auto_reverse = True
trans.effect_wipe_add(
ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
示例3: Interface
# 需要导入模块: from efl.elementary.entry import Entry [as 别名]
# 或者: from efl.elementary.entry.Entry import file_save [as 别名]
#.........这里部分代码省略.........
self.confirmPopup.show()
def saveAs(self):
self.fileSelector.is_save_set(True)
self.fileLabel.text = "<b>Save new file to where:</b>"
self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS)
def saveFile(self, obj=False):
if self.mainEn.file_get()[0] is None or self.isNewFile:
self.saveAs()
else:
file_selected = self.mainEn.file_get()[0]
# Detect save errors as entry.file_save currently returns no errors
# even in the case where the file fails to save :(
try:
newfile = open(file_selected, 'w')
except IOError as err:
if err.errno == errno.EACCES:
errorMsg = ("Permision denied: <b>'%s'</b>."
"<br><br>Operation failed !!!"
% (file_selected))
errorPopup(self.mainWindow, errorMsg)
else:
errorMsg = ("ERROR: %s: '%s'"
"<br><br>Operation failed !!!"
% (err.strerror, file_selected))
errorPopup(self.mainWindow, errorMsg)
return
newfile.close()
# if entry is empty and the file does not exists then
# entry.file_save will destroy the file created about by the
# open statement above for some odd reason ...
if not self.mainEn.is_empty:
self.mainEn.file_save()
self.mainWindow.title_set("%s - ePad"
% os.path.basename(self.mainEn.file[0]))
self.isSaved = True
def doSelected(self, obj):
# Something I should avoid but here I prefer a polymorphic function
if isinstance(obj, Button):
file_selected = self.fileSelector.selected_get()
else:
file_selected = obj
IsSave = self.fileSelector.is_save_get()
if file_selected:
if IsSave:
try:
newfile = open(file_selected, 'w')
except IOError as err:
print("ERROR: {0}: '{1}'".format(err.strerror,
file_selected))
if err.errno == errno.EACCES:
errorMsg = ("Permision denied: <b>'%s'</b>."
"<br><br>Operation failed !!!</br>"
% (file_selected))
errorPopup(self.mainWindow, errorMsg)
else:
errorMsg = ("ERROR: %s: '%s'"
"<br><br>Operation failed !!!</br>"
% (err.strerror, file_selected))
errorPopup(self.mainWindow, errorMsg)
return
tmp_text = self.mainEn.entry_get()