From ff9763cf2be6f869982bb6176dbf8ea2aa7b4912 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 10 Jun 2010 16:53:53 +0100 Subject: [PATCH] Make pylint happy and simplify the handling of the savefile dialog --- terminatorlib/plugins/terminalshot.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/terminatorlib/plugins/terminalshot.py b/terminatorlib/plugins/terminalshot.py index 31785295..59692a6b 100755 --- a/terminatorlib/plugins/terminalshot.py +++ b/terminatorlib/plugins/terminalshot.py @@ -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 + def __init__(self): + 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()