clean up adding via url and make enter submit it instead of having to click ok

This commit is contained in:
Marcos Pinto 2007-09-30 03:49:30 +00:00
parent 234e6827e8
commit 466292d38e
1 changed files with 18 additions and 7 deletions

View File

@ -42,14 +42,24 @@ import pkg_resources
class AddTorrentUrl:
def __init__(self, parent=None):
"""Set up url dialog"""
self.dlg = gtk.Dialog(title=_("Add torrent from URL"), parent=None,
buttons=(gtk.STOCK_CANCEL, 0, gtk.STOCK_OK, 1))
self.dlg = gtk.Dialog(_("Add torrent from URL"), None, 0, \
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,gtk.STOCK_OK, gtk.RESPONSE_OK))
self.dlg.set_default_response(gtk.RESPONSE_OK)
self.dlg.set_icon(deluge.common.get_logo(32))
self.dlg.set_default_response(1)
label = gtk.Label(_("Enter the URL of the .torrent to download"))
self.entry = gtk.Entry()
self.entry.connect("activate", lambda w : self.dlg.response\
(gtk.RESPONSE_OK))
self.dlg.vbox.pack_start(label)
self.dlg.vbox.pack_start(self.entry)
if deluge.common.windows_check():
import win32clipboard as clip
import win32con
clip.OpenClipboard()
text = clip.GetClipboardData(win32con.CF_UNICODETEXT)
clip.CloseClipboard()
else:
clip = gtk.clipboard_get(selection='PRIMARY')
text = clip.wait_for_text()
if text:
@ -61,9 +71,10 @@ class AddTorrentUrl:
"""Show url dialog and add torrent"""
self.dlg.show_all()
self.response = self.dlg.run()
url = self.entry.get_text()
if self.response == gtk.RESPONSE_OK:
url = self.entry.get_text().decode("utf_8")
self.dlg.destroy()
if self.response == 1:
return url
else:
self.dlg.destroy()
return None