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):
"""Add custom commands to the 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):
pass
plugin.MenuItem.__init__(self)
def callback(self, menuitems, menu, terminal):
"""Add our menu items to the menu"""
@ -26,16 +29,14 @@ class TerminalShot(plugin.MenuItem):
item.connect("activate", self.terminalshot, terminal)
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
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",
action=dialog_action,
buttons=dialog_buttons)
action=self.dialog_action,
buttons=self.dialog_buttons)
savedialog.set_do_overwrite_confirmation(True)
savedialog.set_local_only(True)
@ -48,12 +49,9 @@ class TerminalShot(plugin.MenuItem):
savedialog.show_all()
response = savedialog.run()
path = None
if response not in [gtk.RESPONSE_NONE, gtk.RESPONSE_DELETE_EVENT,
gtk.RESPONSE_CANCEL]:
if response == gtk.RESPONSE_OK:
path = os.path.join(savedialog.get_current_folder(),
savedialog.get_filename())
savedialog.destroy()
if path:
orig_pixbuf.save(path, 'png')
savedialog.destroy()