gget r37 - in trunk: . gget
- From: johans svn gnome org
- To: svn-commits-list gnome org
- Subject: gget r37 - in trunk: . gget
- Date: Mon, 21 Jul 2008 23:02:56 +0000 (UTC)
Author: johans
Date: Mon Jul 21 23:02:55 2008
New Revision: 37
URL: http://svn.gnome.org/viewvc/gget?rev=37&view=rev
Log:
Added a new status icon which uses the old eg.trayicon module instead of gtk.StatusIcon. Its necessary since we want to support paste of URLs on the status icon.
Added:
trunk/gget/TrayIcon.py
Modified:
trunk/configure.ac
trunk/gget/AddDownloadDialog.py
trunk/gget/Configuration.py
trunk/gget/GUI.py
trunk/gget/Main.py
trunk/gget/Makefile.am
trunk/gget/Notification.py
trunk/gget/PreferencesDialog.py
trunk/gget/Utils.py
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Mon Jul 21 23:02:55 2008
@@ -52,6 +52,7 @@
pygtk-2.0 >= 2.10.0
pygobject-2.0 >= 2.12.0
gnome-python-2.0 >= 2.16.0
+ gnome-python-extras-2.0 >= 2.14.2
notify-python >= 0.1.1)
AC_OUTPUT([
Modified: trunk/gget/AddDownloadDialog.py
==============================================================================
--- trunk/gget/AddDownloadDialog.py (original)
+++ trunk/gget/AddDownloadDialog.py Mon Jul 21 23:02:55 2008
@@ -40,11 +40,10 @@
self.owner_change_id = self.clipboard.connect("owner-change",
self.__clipboard_owner_change)
- self.__valid_uri = False
- if uri != "":
+ if uri:
self.uri_entry.set_text(uri)
else:
- self.__set_uri_from_clipboard(self.clipboard)
+ self.uri_entry.set_text(GUI.get_uri_from_clipboard() or "")
folder = Utils.get_folder_for_extension(uri)
if not folder:
@@ -71,28 +70,15 @@
def __uri_entry_changed(self, entry):
uri = entry.get_text()
- if len(uri) > 0 and (self.__valid_uri or self.__is_valid_uri(uri)):
+ if len(uri) > 0 and Utils.is_supported_uri(uri):
self.add_button.set_sensitive(True)
else:
self.add_button.set_sensitive(False)
def __clipboard_owner_change(self, clipboard, event):
- self.__set_uri_from_clipboard(clipboard)
-
- def __set_uri_from_clipboard(self, clipboard):
- if clipboard.wait_is_text_available():
- uri = clipboard.wait_for_text()
- if uri and self.__is_valid_uri(uri):
- self.uri_entry.set_text(uri)
-
- def __is_valid_uri(self, uri):
- uri = gnomevfs.make_uri_from_shell_arg(uri)
- scheme = gnomevfs.get_uri_scheme(uri)
- if scheme in ["file", "http", "https", "ftp"]:
- self.__valid_uri = True
- return True
- self.__valid_uri = False
- return False
+ uri = GUI.get_uri_from_clipboard()
+ if uri:
+ self.uri_entry.set_text(uri)
def __uri_entry_activate(self, entry):
self.add_button.clicked()
Modified: trunk/gget/Configuration.py
==============================================================================
--- trunk/gget/Configuration.py (original)
+++ trunk/gget/Configuration.py Mon Jul 21 23:02:55 2008
@@ -24,7 +24,7 @@
import gconf
-from GUI import ErrorDialog
+import GUI
DIR_GGET = "/apps/gget"
DIR_GNOME = "/desktop/gnome"
@@ -144,7 +144,7 @@
self.client.add_dir(DIR_GGET, gconf.CLIENT_PRELOAD_RECURSIVE)
self.debug = args[0] or os.getenv("GGET_DEBUG")
else:
- ed = ErrorDialog(_("Could not find configuration directory in GConf"), _("Please make sure that gget.schemas was correctly installed."))
+ ed = GUI.ErrorDialog(_("Could not find configuration directory in GConf"), _("Please make sure that gget.schemas was correctly installed."))
ed.run()
sys.exit(1)
Modified: trunk/gget/GUI.py
==============================================================================
--- trunk/gget/GUI.py (original)
+++ trunk/gget/GUI.py Mon Jul 21 23:02:55 2008
@@ -27,6 +27,7 @@
import gnomevfs
import gnome.ui
+import Utils
from gget import NAME, DATA_DIR, LOCALE_DIR, IMAGES_DIR
gtk.glade.bindtextdomain(NAME.lower(), LOCALE_DIR)
@@ -109,6 +110,14 @@
uri = gnomevfs.make_uri_from_input_with_dirs(file, 2)
gnome.ui.url_show_on_screen(uri, screen)
+def get_uri_from_clipboard():
+ clipboard = gtk.Clipboard(selection="PRIMARY")
+ if clipboard.wait_is_text_available():
+ uri = clipboard.wait_for_text()
+ if uri and Utils.is_supported_uri(uri):
+ return uri
+ return None
+
class ErrorDialog(gtk.MessageDialog):
def __init__(self, primary_msg, secondary_msg):
gtk.MessageDialog.__init__(self, parent=None,
Modified: trunk/gget/Main.py
==============================================================================
--- trunk/gget/Main.py (original)
+++ trunk/gget/Main.py Mon Jul 21 23:02:55 2008
@@ -36,7 +36,7 @@
from DownloadList import DownloadList
from DownloadManager import DownloadManager
from MainWindow import MainWindow
-from StatusIcon import StatusIcon
+from TrayIcon import TrayIcon
from Configuration import Configuration
from gget import NAME, VERSION, LOCALE_DIR
@@ -78,7 +78,7 @@
if config.show_main_window:
main_window.window.show()
- status_icon = StatusIcon(main_window)
+ status_icon = TrayIcon(main_window)
if not config.show_status_icon:
status_icon.icon.set_visible(False)
Modified: trunk/gget/Makefile.am
==============================================================================
--- trunk/gget/Makefile.am (original)
+++ trunk/gget/Makefile.am Mon Jul 21 23:02:55 2008
@@ -16,6 +16,7 @@
Notification.py \
PreferencesDialog.py \
StatusIcon.py \
+ TrayIcon.py \
Utils.py
DISTCLEANFILES = __init__.py
Modified: trunk/gget/Notification.py
==============================================================================
--- trunk/gget/Notification.py (original)
+++ trunk/gget/Notification.py Mon Jul 21 23:02:55 2008
@@ -26,7 +26,7 @@
import GUI
from gget import NAME
-from StatusIcon import StatusIcon
+from TrayIcon import TrayIcon
from Configuration import Configuration
try:
import pynotify
@@ -60,7 +60,11 @@
# Position notification at status icon if its shown
if self.config.show_status_icon:
- self.notification.attach_to_status_icon(self.status_icon.icon)
+ # self.notification.attach_to_status_icon(self.status_icon.icon)
+ (x, y) = self.__get_position()
+ self.notification.set_hint_int32("x", x)
+ self.notification.set_hint_int32("y", y)
+
self.notification.set_timeout(TIMEOUT) # One minute
@@ -85,4 +89,12 @@
def __closed(self, notification):
notification.close()
+ def __get_position(self):
+ x, y = self.status_icon.image.window.get_position()
+ x_, y_, width, height, depth = self.status_icon.image.window.get_geometry()
+ x_position = x + (width / 2)
+ y_position = y + (height / 2)
+
+ return (x_position, y_position)
+
# vim: set sw=4 et sts=4 tw=79 fo+=l:
Modified: trunk/gget/PreferencesDialog.py
==============================================================================
--- trunk/gget/PreferencesDialog.py (original)
+++ trunk/gget/PreferencesDialog.py Mon Jul 21 23:02:55 2008
@@ -28,7 +28,7 @@
import Configuration
import GUI
-from StatusIcon import StatusIcon
+from TrayIcon import TrayIcon
from gget import NAME
AUTOSTART_DIR = "~/.config/autostart"
@@ -258,8 +258,13 @@
self.status_icon_checkbutton.set_active(True)
elif entry.value.type == gconf.VALUE_BOOL:
value = entry.value.get_bool()
- status_icon = StatusIcon()
- status_icon.icon.set_visible(value)
+ status_icon = TrayIcon()
+ # status_icon.icon.set_visible(value)
+ if value:
+ status_icon.icon.show_all()
+ else:
+ status_icon.icon.hide_all()
+
self.status_icon_checkbutton.set_active(value)
# Main window must be showed if no status icon is showed
if not value:
Added: trunk/gget/TrayIcon.py
==============================================================================
--- (empty file)
+++ trunk/gget/TrayIcon.py Mon Jul 21 23:02:55 2008
@@ -0,0 +1,122 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2008 Johan Svedberg <johan svedberg com>
+
+# This file is part of gget.
+
+# gget is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# gget is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with gget; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+
+import gtk
+import egg.trayicon
+
+import AddDownloadDialog
+import GUI
+from Configuration import Configuration
+from gget import NAME
+
+class TrayIcon(object):
+ """Singleton representing the tray icon"""
+
+ instance = None
+
+ def __new__(type, *args):
+ if TrayIcon.instance is None:
+ TrayIcon.instance = object.__new__(type)
+ TrayIcon.instance.__init(*args)
+ return TrayIcon.instance
+
+ def __init(self, *args):
+ self.main_window = args[0]
+ self.config = Configuration()
+
+ self.icon = egg.trayicon.TrayIcon(NAME)
+
+ self.eb = gtk.EventBox()
+ self.eb.set_visible_window(False)
+ self.eb.set_events(gtk.gdk.POINTER_MOTION_MASK)
+
+ self.image = gtk.Image()
+ self.image.set_from_icon_name(NAME.lower(), gtk.ICON_SIZE_BUTTON)
+ self.eb.add(self.image)
+ self.icon.add(self.eb)
+
+ self.__build_context_menu()
+
+ self.__connect_widgets()
+
+ self.icon.show_all()
+
+ def __build_context_menu(self):
+ self.context_menu = gtk.Menu()
+
+ self.add_imi = gtk.ImageMenuItem(gtk.STOCK_ADD)
+ self.add_imi.show()
+ self.context_menu.append(self.add_imi)
+
+ separator = gtk.SeparatorMenuItem()
+ separator.show()
+ self.context_menu.append(separator)
+
+ self.preferences_imi = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
+ self.preferences_imi.show()
+ self.context_menu.append(self.preferences_imi)
+
+ separator = gtk.SeparatorMenuItem()
+ separator.show()
+ self.context_menu.append(separator)
+
+ self.quit_imi = gtk.ImageMenuItem(gtk.STOCK_QUIT)
+ self.quit_imi.show()
+ self.context_menu.append(self.quit_imi)
+
+ def __connect_widgets(self):
+ self.eb.connect('button-press-event', self.__button_press_event)
+
+ self.add_imi.connect("activate",
+ self.main_window.show_add_download_dialog)
+ self.preferences_imi.connect("activate",
+ self.main_window.preferences_menu_item_activate)
+ self.quit_imi.connect("activate", self.main_window.quit)
+
+ def __button_press_event(self, widget, event):
+ if event.type != gtk.gdk.BUTTON_PRESS:
+ return
+ if event.button == 1: # Left click
+ self.__left_click()
+ elif event.button == 2: # Middle click
+ self.__middle_click()
+ elif event.button == 3: # Right click
+ self.__right_click(event)
+
+ def __left_click(self):
+ if self.main_window.window.get_property("visible"):
+ self.main_window.window.hide()
+ else:
+ self.main_window.window.present()
+
+ def __middle_click(self):
+ if self.config.ask_for_location:
+ add = AddDownloadDialog.AddDownloadDialog()
+ add.dialog.show()
+ else:
+ uri = GUI.get_uri_from_clipboard()
+ if uri:
+ self.main_window.download_list.add_download(uri,
+ self.config.default_folder)
+
+ def __right_click(self, event):
+ self.context_menu.popup(None, None, None, event.button, event.time)
+
+# vim: set sw=4 et sts=4 tw=79 fo+=l:
Modified: trunk/gget/Utils.py
==============================================================================
--- trunk/gget/Utils.py (original)
+++ trunk/gget/Utils.py Mon Jul 21 23:02:55 2008
@@ -22,6 +22,7 @@
import os.path
import time
+import gnomevfs
import dbus
import dbus.glib
@@ -63,6 +64,20 @@
if level and (not element.tail or not element.tail.strip()):
element.tail = i
+def is_supported_uri(uri):
+ if not uri:
+ return False
+ uri = gnomevfs.make_uri_from_shell_arg(uri)
+ scheme = gnomevfs.get_uri_scheme(uri)
+ # If the scheme is a file check if the file exists
+ if scheme == "file":
+ try:
+ local_path = gnomevfs.get_local_path_from_uri(uri)
+ return os.path.isfile(local_path)
+ except Exception, e:
+ return False
+ return scheme in ["http", "https", "ftp"]
+
def take_dbus_name(name, replace=False, on_name_lost=None, bus=None):
target_bus = bus or dbus.Bus()
proxy = bus_proxy(bus=target_bus)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]