Make pylint happy and simplify the handling of the savefile dialog

This commit is contained in:
Chris Jones 2010-06-10 16:53:53 +01:00
parent 44f99c7738
commit ff9763cf2b
1 changed files with 11 additions and 13 deletions

View File

@ -16,9 +16,12 @@ available = ['TerminalShot']
class TerminalShot(plugin.MenuItem): class TerminalShot(plugin.MenuItem):
"""Add custom commands to the terminal menu""" """Add custom commands to the terminal menu"""
capabilities = ['terminal_menu'] capabilities = ['terminal_menu']
dialog_action = gtk.FILE_CHOOSER_ACTION_SAVE
dialog_buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK)
def __init__(self): def __init__(self):
pass plugin.MenuItem.__init__(self)
def callback(self, menuitems, menu, terminal): def callback(self, menuitems, menu, terminal):
"""Add our menu items to the menu""" """Add our menu items to the menu"""
@ -26,16 +29,14 @@ class TerminalShot(plugin.MenuItem):
item.connect("activate", self.terminalshot, terminal) item.connect("activate", self.terminalshot, terminal)
menuitems.append(item) menuitems.append(item)
def terminalshot(self, widget, terminal): def terminalshot(self, _widget, terminal):
"""Handle the taking, prompting and saving of a terminalshot"""
# Grab a pixbuf of the terminal # Grab a pixbuf of the terminal
orig_pixbuf = widget_pixbuf(terminal) orig_pixbuf = widget_pixbuf(terminal)
dialog_action = gtk.FILE_CHOOSER_ACTION_SAVE
dialog_buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK)
savedialog = gtk.FileChooserDialog(title="Save image", savedialog = gtk.FileChooserDialog(title="Save image",
action=dialog_action, action=self.dialog_action,
buttons=dialog_buttons) buttons=self.dialog_buttons)
savedialog.set_do_overwrite_confirmation(True) savedialog.set_do_overwrite_confirmation(True)
savedialog.set_local_only(True) savedialog.set_local_only(True)
@ -48,12 +49,9 @@ class TerminalShot(plugin.MenuItem):
savedialog.show_all() savedialog.show_all()
response = savedialog.run() response = savedialog.run()
path = None path = None
if response not in [gtk.RESPONSE_NONE, gtk.RESPONSE_DELETE_EVENT, if response == gtk.RESPONSE_OK:
gtk.RESPONSE_CANCEL]:
path = os.path.join(savedialog.get_current_folder(), path = os.path.join(savedialog.get_current_folder(),
savedialog.get_filename()) savedialog.get_filename())
savedialog.destroy()
if path:
orig_pixbuf.save(path, 'png') orig_pixbuf.save(path, 'png')
savedialog.destroy()