tweaks so torrentnotification plugin doesnt crash win32 client

This commit is contained in:
Marcos Pinto 2007-09-11 19:20:41 +00:00
commit 120b3335b4
2 changed files with 59 additions and 54 deletions

View file

@ -88,22 +88,24 @@ class TorrentNotification:
self.interface.tray_icon.set_blinking(True) self.interface.tray_icon.set_blinking(True)
def show_notification(self, event): def show_notification(self, event):
import pynotify import platform
if platform.system() != "Windows":
import pynotify
file_info = self.interface.manager.get_torrent_file_info(event['unique_ID']) file_info = self.interface.manager.get_torrent_file_info(event['unique_ID'])
filelist = "" filelist = ""
for file in file_info[:10]: for file in file_info[:10]:
filelist += file['path'] + "\n" filelist += file['path'] + "\n"
if len(file_info) > 10: if len(file_info) > 10:
filelist += '...' filelist += '...'
if pynotify.init("Deluge"): if pynotify.init("Deluge"):
n = pynotify.Notification(_("Torrent complete"), n = pynotify.Notification(_("Torrent complete"),
_("Files") + ":\n" + filelist) _("Files") + ":\n" + filelist)
n.set_icon_from_pixbuf(deluge.common.get_logo(48)) n.set_icon_from_pixbuf(deluge.common.get_logo(48))
n.show() n.show()
else: else:
print "there was a problem initializing the pynotify module" pass
def configure(self, window): def configure(self, window):
import os.path import os.path
@ -131,18 +133,21 @@ class TorrentNotification:
self.glade.get_widget("sound_path_button").set_sensitive(value) self.glade.get_widget("sound_path_button").set_sensitive(value)
def play_sound(self): def play_sound(self):
import pygame import platform
import os.path if platform.system() != "Windows":
import sys import pygame
pygame.init() import os.path
try: import sys
name = self.config.get("sound_path") pygame.init()
except: try:
print "no file set" name = self.config.get("sound_path")
return except:
try: print "no file set"
alert_sound = pygame.mixer.music try:
alert_sound.load(name) alert_sound = pygame.mixer.music
alert_sound.play() alert_sound.load(name)
except pygame.error, message: alert_sound.play()
print 'Cannot load sound:' except pygame.error, message:
print 'Cannot load sound:'
else:
pass

View file

@ -21,30 +21,6 @@
<widget class="GtkTable" id="table1"> <widget class="GtkTable" id="table1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="n_rows">3</property> <property name="n_rows">3</property>
<child>
<widget class="GtkCheckButton" id="chk_notification">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Enable popup notification (requires python-notify)</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="chk_tray_blink">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Enable blinking tray icon</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
</child>
<child> <child>
<widget class="GtkHBox" id="hbox1"> <widget class="GtkHBox" id="hbox1">
<property name="visible">True</property> <property name="visible">True</property>
@ -53,7 +29,7 @@
<widget class="GtkCheckButton" id="chk_sound"> <widget class="GtkCheckButton" id="chk_sound">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="label" translatable="yes">Enable event sound (requires pygame)</property> <property name="label" translatable="yes">Enable event sound (requires pygame, not available on Win32)</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="response_id">0</property> <property name="response_id">0</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
@ -76,6 +52,30 @@
<property name="bottom_attach">3</property> <property name="bottom_attach">3</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkCheckButton" id="chk_tray_blink">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Enable blinking tray icon</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
</child>
<child>
<widget class="GtkCheckButton" id="chk_notification">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Enable popup notification (requires python-notify, not available on Win32)</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>