Fixes one typo that was causing an error in handle_events and adds attribute self.update_interface to DelugeGTK class so that plugins can determine whether or not to update information for the interface - micah

This commit is contained in:
Marcos Pinto 2007-07-20 18:36:16 +00:00
parent 938c1fed43
commit a6e8db9bb0
3 changed files with 84 additions and 76 deletions

View File

@ -51,82 +51,85 @@ class plugin_NetGraph:
break break
def update(self): def update(self):
import gtk if self.parent.update_interface:
session_info = self.core.get_state() import gtk
self.savedUpSpeeds.insert(0, session_info['upload_rate']) session_info = self.core.get_state()
if len(self.savedUpSpeeds) > self.length: self.savedUpSpeeds.insert(0, session_info['upload_rate'])
self.savedUpSpeeds.pop() if len(self.savedUpSpeeds) > self.length:
self.savedDownSpeeds.insert(0, session_info['download_rate']) self.savedUpSpeeds.pop()
if len(self.savedDownSpeeds) > self.length: self.savedDownSpeeds.insert(0, session_info['download_rate'])
self.savedDownSpeeds.pop() if len(self.savedDownSpeeds) > self.length:
self.savedDownSpeeds.pop()
if not self.parentNotebook.get_nth_page(self.parentNotebook.get_current_page()) == \
self.topWidget and not self.bootupRuns > 0:
return
self.bootupRuns = max(self.bootupRuns - 1, 0)
extraWidth = self.scrolledWindow.get_vscrollbar().get_allocation().width * 1.5
extraHeight = self.scrolledWindow.get_hscrollbar().get_allocation().height * 1.5
allocation = self.scrolledWindow.get_allocation()
allocation.width = int(allocation.width) - extraWidth
allocation.height = int(allocation.height) - extraHeight
# Don't try to allocate a size too small, or you might crash
if allocation.width < 2 or allocation.height < 2:
return
# savedDownSpeeds = [1,2,3,2,1]
# savedUpSpeeds = [5,8,0,0,1,2]
# allocation = self.image.get_allocation()
# allocation.width = 300
# allocation.height = 200
if not allocation.width == self.width or not allocation.height == self.height:
# print "New Pixmap!"
self.width = allocation.width
self.height = allocation.height
self.networkPixmap = gtk.gdk.Pixmap(None, self.width, self.height, 24)
self.image.set_from_pixmap(self.networkPixmap, None)
self.ctx = self.networkPixmap.cairo_create()
self.networkPixmap.draw_rectangle(self.image.get_style().white_gc,True, 0, 0, self.width, self.height)
maxSpeed = max(max(self.savedDownSpeeds),max(self.savedUpSpeeds))
if maxSpeed == 0:
return
maxSpeed = maxSpeed*1.1 # Give some extra room on top
self.drawSpeedPoly(self.savedDownSpeeds, (0.5,1, 0.5, 1.0), maxSpeed, True)
self.drawSpeedPoly(self.savedDownSpeeds, (0, 0.75,0, 1.0), maxSpeed, False)
self.drawSpeedPoly(self.savedUpSpeeds, (0.33,0.33,1.0, 0.5), maxSpeed, True)
self.drawSpeedPoly(self.savedUpSpeeds, (0, 0, 1.0, 0.75), maxSpeed, False)
meanUpSpeed = sum(self.savedUpSpeeds) /len(self.savedUpSpeeds)
meanDownSpeed = sum(self.savedDownSpeeds)/len(self.savedDownSpeeds)
shownSpeed = max(meanUpSpeed, meanDownSpeed)
import deluge.common if not self.parentNotebook.get_nth_page(self.parentNotebook.get_current_page()) == \
self.topWidget and not self.bootupRuns > 0:
self.pangoLayout.set_text(deluge.common.fspeed(shownSpeed)) return
self.networkPixmap.draw_layout(self.image.get_style().black_gc,
4, self.bootupRuns = max(self.bootupRuns - 1, 0)
int(self.height - 1 - (self.height*shownSpeed/maxSpeed)),
self.pangoLayout) extraWidth = self.scrolledWindow.get_vscrollbar().get_allocation().width * 1.5
extraHeight = self.scrolledWindow.get_hscrollbar().get_allocation().height * 1.5
self.networkPixmap.draw_line(self.image.get_style().black_gc, allocation = self.scrolledWindow.get_allocation()
0, int(self.height - (self.height*shownSpeed/maxSpeed)), allocation.width = int(allocation.width) - extraWidth
self.width, int(self.height - (self.height*shownSpeed/maxSpeed))) allocation.height = int(allocation.height) - extraHeight
self.networkPixmap.draw_rectangle(self.image.get_style().black_gc,False, 0, 0, self.width-1, self.height-1)
self.image.queue_draw()
# Don't try to allocate a size too small, or you might crash
if allocation.width < 2 or allocation.height < 2:
return
# savedDownSpeeds = [1,2,3,2,1]
# savedUpSpeeds = [5,8,0,0,1,2]
# allocation = self.image.get_allocation()
# allocation.width = 300
# allocation.height = 200
if not allocation.width == self.width or not allocation.height == self.height:
# print "New Pixmap!"
self.width = allocation.width
self.height = allocation.height
self.networkPixmap = gtk.gdk.Pixmap(None, self.width, self.height, 24)
self.image.set_from_pixmap(self.networkPixmap, None)
self.ctx = self.networkPixmap.cairo_create()
self.networkPixmap.draw_rectangle(self.image.get_style().white_gc,True, 0, 0, self.width, self.height)
maxSpeed = max(max(self.savedDownSpeeds),max(self.savedUpSpeeds))
if maxSpeed == 0:
return
maxSpeed = maxSpeed*1.1 # Give some extra room on top
self.drawSpeedPoly(self.savedDownSpeeds, (0.5,1, 0.5, 1.0), maxSpeed, True)
self.drawSpeedPoly(self.savedDownSpeeds, (0, 0.75,0, 1.0), maxSpeed, False)
self.drawSpeedPoly(self.savedUpSpeeds, (0.33,0.33,1.0, 0.5), maxSpeed, True)
self.drawSpeedPoly(self.savedUpSpeeds, (0, 0, 1.0, 0.75), maxSpeed, False)
meanUpSpeed = sum(self.savedUpSpeeds) /len(self.savedUpSpeeds)
meanDownSpeed = sum(self.savedDownSpeeds)/len(self.savedDownSpeeds)
shownSpeed = max(meanUpSpeed, meanDownSpeed)
import deluge.common
self.pangoLayout.set_text(deluge.common.fspeed(shownSpeed))
self.networkPixmap.draw_layout(self.image.get_style().black_gc,
4,
int(self.height - 1 - (self.height*shownSpeed/maxSpeed)),
self.pangoLayout)
self.networkPixmap.draw_line(self.image.get_style().black_gc,
0,
int(self.height - (self.height*shownSpeed/maxSpeed)),
self.width,
int(self.height - (self.height*shownSpeed/maxSpeed)))
self.networkPixmap.draw_rectangle(self.image.get_style().black_gc,False, 0, 0, self.width-1, self.height-1)
self.image.queue_draw()
def tracePath(self, speeds, maxSpeed): def tracePath(self, speeds, maxSpeed):
lineWidth = 4 lineWidth = 4

View File

@ -612,7 +612,7 @@ class Manager:
tracker_status) tracker_status)
elif event['event_type'] is self.constants['EVENT_TRACKER_WARNING']: elif event['event_type'] is self.constants['EVENT_TRACKER_WARNING']:
# Probably will need proper formatting later, not tested yet # Probably will need proper formatting later, not tested yet
tracker_status = '%s: %s' % (N_("Warning", event["message"])) tracker_status = '%s: %s' % (N_("Warning"), event["message"])
self.set_supp_torrent_state_val(event['unique_ID'], self.set_supp_torrent_state_val(event['unique_ID'],
"tracker_status", "tracker_status",

View File

@ -121,6 +121,9 @@ class DelugeGTK:
# Boolean used in update method to help check whether gui # Boolean used in update method to help check whether gui
# should be updated and is set by the window_state_event method # should be updated and is set by the window_state_event method
self.is_minimized = False self.is_minimized = False
# Boolean set to true if window is not minimized and is "visible"
self.update_interface = True
def connect_signals(self): def connect_signals(self):
self.wtree.signal_autoconnect({ self.wtree.signal_autoconnect({
@ -815,6 +818,8 @@ class DelugeGTK:
# We need to apply the queue changes # We need to apply the queue changes
self.manager.apply_queue() self.manager.apply_queue()
self.update_interface = self.window.get_property("visible") and not self.is_minimized
# Handle the events # Handle the events
try: try:
self.manager.handle_events() self.manager.handle_events()
@ -835,7 +840,7 @@ class DelugeGTK:
self.plugins.update_active_plugins() self.plugins.update_active_plugins()
# only update gui if it's needed # only update gui if it's needed
if self.window.get_property("visible") and not self.is_minimized: if self.update_interface:
# Put the generated message into the statusbar # Put the generated message into the statusbar
# This gives plugins a chance to write to the # This gives plugins a chance to write to the