本文整理汇总了Python中gi.repository.Gtk.STOCK_SAVE属性的典型用法代码示例。如果您正苦于以下问题:Python Gtk.STOCK_SAVE属性的具体用法?Python Gtk.STOCK_SAVE怎么用?Python Gtk.STOCK_SAVE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.STOCK_SAVE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: choose_file
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def choose_file(self):
""" Let user choose a file to save and return its path """
chooser = Gtk.NativeFileChooser(
title=_("Choose where to save your list"),
parent=self.export_dialog,
action=Gtk.FileChooserAction.SAVE,
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
chooser.set_do_overwrite_confirmation(True)
chooser.set_default_response(Gtk.ResponseType.OK)
chooser.set_current_folder(get_desktop_dir())
response = chooser.run()
filename = chooser.get_filename()
chooser.destroy()
if response == Gtk.ResponseType.OK:
return filename
else:
return None
# Preferences methods #########################################################
示例2: save_file_as
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def save_file_as(self, widget):
""" save the project's sqlite database """
dialog = Gtk.FileChooserDialog("Please choose a filename", None,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
dialog.set_filename("project")
file_filters.add_filter_database(dialog)
response = dialog.run()
if response == Gtk.ResponseType.OK:
file_selected = dialog.get_filename()
try:
shutil.copy(self.engine.database.db_loc, file_selected)
except: pass
elif response == Gtk.ResponseType.CANCEL:
dialog.destroy()
dialog.destroy()
示例3: file_chooser_save_action
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def file_chooser_save_action(self, on_success):
"""
Opens the file chooser and runs on_success upon completion of valid file choice.
:param on_success: A function to run upon selection of a filename. Takes 2
parameters: The instance of the application (App) and the chosen filename. This
gets run immediately in the same thread.
:return: None
"""
dialog = Gtk.FileChooserDialog("Save file", self.window,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
dialog.set_current_name("Untitled")
response = dialog.run()
if response == Gtk.ResponseType.OK:
filename = dialog.get_filename()
dialog.destroy()
on_success(self, filename)
elif response == Gtk.ResponseType.CANCEL:
self.info("Save cancelled.") # print("Cancel clicked")
dialog.destroy()
示例4: exportToCSV
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def exportToCSV(self, sender):
report = self.createReport(False)
if report == None:
return
content = ""
for key in report["heading"]:
content += key.replace(",", "") + ","
content += "\n"
for data in report["data"]:
for item in data:
content += item.replace(",", "") + ","
content += "\n"
dialog = Gtk.FileChooserDialog(None, self.window, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT))
res = dialog.run()
if res == Gtk.ResponseType.ACCEPT:
filename = os.path.splitext(dialog.get_filename())[0]
file = open(filename + ".csv", "w")
file.write(content)
file.close()
dialog.destroy()
示例5: exportToCSV
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def exportToCSV(self, sender):
report = self.createReport()
if report == None:
return
content = ""
for key in report["heading"]:
content += key.replace(",", "") + ","
content += "\n"
for data in report["data"]:
for item in data:
content += item.replace(",", "") + ","
content += "\n"
dialog = Gtk.FileChooserDialog(None, self.window, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT))
dialog.run()
filename = os.path.splitext(dialog.get_filename())[0]
file = open(filename + ".csv", "w")
file.write(content)
file.close()
dialog.destroy()
示例6: run_quick_save
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def run_quick_save(self, current_name=None):
"""
Display a dialog which asks the user where a file should be saved. The
value of target_path in the returned dictionary is an absolute path.
:param set current_name: The name of the file to save.
:return: A dictionary with target_uri and target_path keys representing the path choosen.
:rtype: dict
"""
self.set_action(Gtk.FileChooserAction.SAVE)
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
self.add_button(Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT)
self.set_do_overwrite_confirmation(True)
if current_name:
self.set_current_name(current_name)
self.show_all()
response = self.run()
if response == Gtk.ResponseType.CANCEL:
return None
target_path = self.get_filename()
if os.path.isfile(target_path):
if not os.access(target_path, os.W_OK):
gui_utilities.show_dialog_error('Permissions Error', self.parent, 'Can not write to the selected file.')
return None
elif not os.access(os.path.dirname(target_path), os.W_OK):
gui_utilities.show_dialog_error('Permissions Error', self.parent, 'Can not write to the selected path.')
return None
target_uri = self.get_uri()
return {'target_uri': target_uri, 'target_path': target_path}
示例7: create_buttons
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def create_buttons(self):
"""Creates and connects the Save, Cancel and Preview buttons"""
spacing = 0
button_box = Gtk.HButtonBox()
button_box.set_border_width(5)
button_box.set_layout(Gtk.ButtonBoxStyle.EDGE)
button_box.set_spacing(spacing)
self._cancel_button = Gtk.Button(stock=Gtk.STOCK_CANCEL)
self._cancel_button.set_tooltip_text("Don't save changes (ESC)")
button_box.add(self._cancel_button)
self._preview_button = Gtk.Button(label="Preview")
self._preview_button.set_tooltip_text("Show/ update preview (CTRL+P)")
button_box.add(self._preview_button)
self._ok_button = Gtk.Button(stock=Gtk.STOCK_SAVE)
self._ok_button.set_tooltip_text("Update or create new LaTeX output (CTRL+RETURN)")
button_box.add(self._ok_button)
self._cancel_button.connect("clicked", self.cb_cancel)
self._ok_button.connect("clicked", self.cb_ok)
self._preview_button.connect('clicked', self.update_preview)
return button_box
示例8: export_results
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def export_results(self, button):
"""
Export the results to a text file.
"""
chooser = Gtk.FileChooserDialog(
_("Export results to a text file"),
self.uistate.window,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
chooser.set_do_overwrite_confirmation(True)
while True:
value = chooser.run()
filename = chooser.get_filename()
if value == Gtk.ResponseType.OK:
if filename:
chooser.destroy()
break
else:
chooser.destroy()
return
try:
with io.open(filename, 'w') as report_file:
for title, model in zip(self.titles, self.models):
self.export_page(report_file, title, model)
except IOError as err:
WarningDialog(self.window_name,
_('Error when writing the report: %s') % err.strerror,
self.window)
示例9: export_results
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def export_results(self, _button):
"""
Export the results to a text file.
"""
chooser = Gtk.FileChooserDialog(
_("Export results to a text file"),
self.uistate.window,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
chooser.set_do_overwrite_confirmation(True)
while True:
value = chooser.run()
filename = chooser.get_filename()
if value == Gtk.ResponseType.OK:
if filename:
chooser.destroy()
break
else:
chooser.destroy()
return
try:
with io.open(filename, 'w') as report_file:
for title, model in zip(self.titles, self.models):
self.export_page(report_file, title, model)
except IOError as err:
WarningDialog(self.window_name,
_('Error when writing the report: %s') %
err.strerror, self.window)
示例10: save_as
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def save_as(self, widget):
self.window.set_sensitive(False)
chooser = Gtk.FileChooserDialog(title=None, action=Gtk.FileChooserAction.SAVE, buttons=(
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
self.set_file_chooser_path(chooser)
chooser.set_do_overwrite_confirmation(True)
title = self.name.split("/")[-1]
chooser.set_title("Save As: " + title)
response = chooser.run()
saved = True
if response == Gtk.ResponseType.OK:
file = open(chooser.get_filename(), 'w')
self.name = chooser.get_filename()
text = self.text_buffer.get_text(self.text_buffer.get_start_iter(), self.text_buffer.get_end_iter(), False)
file.write(text)
file.close()
self.text_buffer.set_modified(False)
title = self.name.split("/")[-1]
self.window.set_title("Remarkable: " + title)
else:
saved = False # User cancelled saving after choosing to save. Need to cancel quit operation now
chooser.destroy()
self.window.set_sensitive(True)
return saved
示例11: on_save_as_clicked
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def on_save_as_clicked(self, widget):
dialog = Gtk.FileChooserDialog(
_("Save as"), mainwindow(), Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE,
Gtk.ResponseType.ACCEPT))
dialog.set_current_folder(os.path.expanduser("~"))
response = dialog.run()
if response == Gtk.ResponseType.ACCEPT:
filename = dialog.get_filename()
else:
filename = None
dialog.destroy()
if filename is None:
return
self.progress_dialog.set_title(_("Save as"))
def save_as(cancel_event):
with open(filename, "w") as to_file:
self.process_records(self.save_records, cancel_event, to_file)
GLib.idle_add(self.progress_dialog.hide)
cancel_event = threading.Event()
loop = asyncio.get_event_loop()
loop.run_in_executor(None, save_as, cancel_event)
response = self.progress_dialog.run()
if response == Gtk.ResponseType.CANCEL:
cancel_event.set()
self.progress_dialog.hide()
示例12: get_save_dialog
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def get_save_dialog(export=False):
savedialog = Gtk.FileChooserDialog(
"", mainwindow(), Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE,
Gtk.ResponseType.ACCEPT))
savedialog.set_current_folder(os.path.expanduser("~"))
# Add widgets to the savedialog
savecombo = Gtk.ComboBox()
savecombo.set_name("savecombo")
crt = Gtk.CellRendererText()
savecombo.pack_start(crt, True)
savecombo.add_attribute(crt, 'text', 0)
crt = Gtk.CellRendererText()
savecombo.pack_start(crt, False)
savecombo.add_attribute(crt, 'text', 1)
if export:
savecombo.set_model(exportformats)
else:
savecombo.set_model(saveformats)
savecombo.set_active(1) # pgn
savedialog.set_extra_widget(savecombo)
return savedialog, savecombo
示例13: export_log
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def export_log(self, widget, log_id):
# export a log in a txt file
log = self.database.get_logs(log_id)
text = log.output
dialog = Gtk.FileChooserDialog("Please choose a filename", None,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
dialog.set_filename("export output")
file_filters.add_filter_txt(dialog)
response = dialog.run()
if response == Gtk.ResponseType.OK:
file_selected = dialog.get_filename()
try:
file = open(file_selected,"w")
for line in text:
file.write(line)
file.close()
except: pass
elif response == Gtk.ResponseType.CANCEL:
dialog.destroy()
dialog.destroy()
示例14: on_save_clicked
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def on_save_clicked(self, widget):
dialog = Gtk.FileChooserDialog("Please choose a filename to save", self,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
dialog.set_current_name("Untitled.png")
dialog.set_do_overwrite_confirmation(True)
response = dialog.run()
if response == Gtk.ResponseType.OK:
self.graph.save(dialog.get_filename(), dpi=600)
dialog.destroy()
示例15: create_file_dialog
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import STOCK_SAVE [as 别名]
def create_file_dialog(self, dialog_type, directory, allow_multiple, save_filename, file_types):
if dialog_type == FOLDER_DIALOG:
gtk_dialog_type = gtk.FileChooserAction.SELECT_FOLDER
title = localization['linux.openFolder']
button = gtk.STOCK_OPEN
elif dialog_type == OPEN_DIALOG:
gtk_dialog_type = gtk.FileChooserAction.OPEN
if allow_multiple:
title = localization['linux.openFiles']
else:
title = localization['linux.openFile']
button = gtk.STOCK_OPEN
elif dialog_type == SAVE_DIALOG:
gtk_dialog_type = gtk.FileChooserAction.SAVE
title = localization['global.saveFile']
button = gtk.STOCK_SAVE
dialog = gtk.FileChooserDialog(title, self.window, gtk_dialog_type,
(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL, button, gtk.ResponseType.OK))
dialog.set_select_multiple(allow_multiple)
dialog.set_current_folder(directory)
self._add_file_filters(dialog, file_types)
if dialog_type == SAVE_DIALOG:
dialog.set_current_name(save_filename)
response = dialog.run()
if response == gtk.ResponseType.OK:
file_name = dialog.get_filenames()
else:
file_name = None
dialog.destroy()
return file_name