Author: duncan
Date: Sun Jan 21 15:04:00 2007
New Revision: 9033

Modified:
   branches/rel-1/freevo/src/plugins/idlebar/encoding.py

Log:
Enabled idlebar when there is space
Updates the skin on demand, more often for audio
Corrected positioning


Modified: branches/rel-1/freevo/src/plugins/idlebar/encoding.py
==============================================================================
--- branches/rel-1/freevo/src/plugins/idlebar/encoding.py       (original)
+++ branches/rel-1/freevo/src/plugins/idlebar/encoding.py       Sun Jan 21 
15:04:00 2007
@@ -22,7 +22,7 @@
 # Public License for more details.
 #
 # You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
+# with this program; if not, write to the Free Software Foundation, Inc., 
 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
 # -----------------------------------------------------------------------
@@ -33,15 +33,18 @@
 import time
 
 # freevo modules
+import skin
 from plugins.idlebar import IdleBarPlugin
 import plugin, config
 from util.marmalade import jellyToXML, unjellyFromXML
 from gui import Progressbar
+import rc
 
 DEBUG=config.DEBUG
 
 def returnFromJelly(status, response):
     """Un-serialize EncodingServer responses"""
+    _debug_('returnFromJelly(status, response)', 2)
     if status:
         return (status, unjellyFromXML(response))
     else:
@@ -55,32 +58,42 @@
     plugin.activate('idlebar.encoding', level=0)
     """
     def __init__(self):
+        _debug_('__init__(self)', 2)
         plugin.DaemonPlugin.__init__(self)
-        self.poll_interval = 300 # 1/10th seconds (30secs)
+        self.poll_interval = 10 # 1/10th seconds (30secs)
+        self.draw_interval = self.poll_interval
+        self.last_interval = self.poll_interval
+        self.lastdraw  = 0
+        self.lastpoll  = 0
         self.plugin_name = 'video.encodingstatus'
-        server_string = 'http://%s:%s/' % \
+        server_string  = 'http://%s:%s/' % \
                         (config.ENCODINGSERVER_IP, config.ENCODINGSERVER_PORT)
-        self.server   = xmlrpclib.Server(server_string, allow_none=1)
+        self.server    = xmlrpclib.Server(server_string, allow_none=1)
 
-        self.barimg   = os.path.join(config.ICON_DIR, 
'status/encoding_bar.png')
-        self.boximg   = os.path.join(config.ICON_DIR, 
'status/encoding_box.png')
-        self.image    = None
-        self.cacheimg = {}
-        self.muted    = False
-        self.encoding = -1
-        self.progress = 0
-        self.jobname  = 'test'
+        self.barimg    = os.path.join(config.ICON_DIR, 
'status/encoding_bar.png')
+        self.boximg    = os.path.join(config.ICON_DIR, 
'status/encoding_box.png')
+        self.boxborder = 3
+        self.padding   = 5 # internal padding for box vs text
+        self.image     = None
+        self.cacheimg  = {}
+        self.muted     = False
+        self.encoding  = -1
+        self.progress  = 0
+        self.jobname   = ''
         self.calculate = True
-        self.jobs     = ''
-        self.state    = 'Not Running'
-        self.text     = []
-        self.percent  = 0.0
-        self.running  = False
-        self.now      = None
-        #self.bar     = Progressbar(self.tx, y, 100, 20, full=100)
+        self.jobs      = ''
+        self.mode      = 'Not Running'
+        self.text      = []
+        self.percent   = 0.0
+        self.running   = False
+        self.drawtime  = 0
+        self.polltime  = 0
+        self.state     = 'noserver'
+        self.laststate = None
 
 
     def getprogress(self):
+        _debug_('getprogress(self)', 2)
         """Get the progress & pass information of the job currently encoding.
 
         This call returns False if no job is currently encoding (fx the queue 
is not active).
@@ -108,6 +121,7 @@
 
 
     def listjobs(self):
+        _debug_('listjobs(self)', 2)
         """Get a list with all jobs in the encoding queue and their current 
state
 
         Returns a list of tuples containing all the current queued jobs. When 
the queue is
@@ -126,6 +140,7 @@
 
 
     def getimage(self, image, osd, cache=False):
+        _debug_('getimage(self, image, osd, cache=False)', 2)
         if image.find(config.ICON_DIR) == 0 and 
image.find(osd.settings.icon_dir) == -1:
             new_image = os.path.join(osd.settings.icon_dir, 
image[len(config.ICON_DIR)+1:])
             if os.path.isfile(new_image):
@@ -139,20 +154,24 @@
 
 
     def settext(self):
+        _debug_('settext(self)', 2)
         """
         set the text
         """
         (status, jobs) = self.listjobs()
         if not status:
+            self.state = 'noserver'
             self.jobs = 'encoding server not running'
-            self.poll_interval = 5000
+            self.draw_interval = 5000
             self.running = False
             return 0;
         if not jobs:
+            self.state = 'nojobs'
             self.jobs = 'encoding server has no jobs'
-            self.poll_interval = 5000
+            self.draw_interval = 5000
             self.running = False
             return 0;
+        self.state = 'active'
         (idnr, jobname, jobstate) = jobs[0]
         joblist = jobname
         for job in jobs[1:]:
@@ -163,25 +182,33 @@
 
         self.text = []
         (status, progress) = self.getprogress();
-        if progress[1] == 0:
-            self.state = 'Not started'
-            self.poll_interval = 5000
-        elif progress[1] == 1:
-            self.state = 'Audio'
-            self.poll_interval = 10
-        elif progress[1] == 2:
-            self.state = 'Video-1'
-            self.poll_interval = 100
-        elif progress[1] == 3:
-            self.state = 'Video-2'
-            self.poll_interval = 100
-        elif progress[1] == 4:
-            self.state = 'Multiplexing'
-        self.text.append("%s %s%% %s" % (self.state, progress[2], progress[3]))
-        self.percent = progress[2] / 100.0
+        if status:
+            if progress[1] == 0:
+                self.mode = 'Not started'
+                self.state = 'active'
+                self.draw_interval = 5000
+            elif progress[1] == 1:
+                self.mode = 'Audio'
+                self.state = 'audio'
+                self.draw_interval = 200
+            elif progress[1] == 2:
+                self.mode = 'Video-1'
+                self.state = 'video'
+                self.draw_interval = 1000
+            elif progress[1] == 3:
+                self.mode = 'Video-2'
+                self.state = 'video'
+                self.draw_interval = 1000
+            elif progress[1] == 4:
+                self.mode = 'Multiplexing'
+                self.state = 'multiplexing'
+                self.draw_interval = 1000
+            self.text.append("%s %s%% %s" % (self.mode, progress[2], 
progress[3]))
+            self.percent = progress[2] / 100.0
 
 
-    def calculatesizes(self,osd,font):
+    def calculatesizes(self, osd, font):
+        _debug_('calculatesizes(self, osd, font)', 2)
         """
         sizecalcs is not necessery on every pass
         """
@@ -189,95 +216,105 @@
             self.idlebar = plugin.getbyname('idlebar')
             if self.idlebar:
                 self.idlebar_max = osd.width + osd.x
-                print 'idlebar_max:', self.idlebar_max, 'free_space:', 
self.idlebar.free_space
+                _debug_('idlebar_max=%s, free_space=%s' % (self.idlebar_max, 
self.idlebar.free_space), 2)
                 for p in plugin.get('idlebar'):
                     if hasattr(p, 'clock_left_position'):
                         self.idlebar_max = p.clock_left_position
 
-                if self.idlebar_max - self.idlebar.free_space < 250:
+                if self.idlebar_max - self.idlebar.free_space < 280:
                     _debug_('free space in idlebar to small, using normal 
detach')
                     self.idlebar = None
-        #DJW turned off idlebar for now
-        self.idlebar = None
+
+        #turn off idlebar for testing
+        #self.idlebar = None
+
+        if self.idlebar:
+            self.boxborder = 0
+            self.padding = 0
 
         if self.calculate:
             self.calculate = False
             self.font_h = font.font.height
-            pad_internal = 5 # internal padding for box vs text
 
-            if DEBUG >= 2:
-                print 'osd.width:', osd.width, 'osd.height:', osd.height, 
'osd.x:', osd.x, 'osd.y:', osd.y
+            _debug_('osd.width=%s, osd.height=%s, osd.x=%s, osd.y=%s' % 
(osd.width, osd.height, osd.x, osd.y), 2)
             screen_width = osd.width + 2*osd.x
             screen_height = osd.height + 2*osd.y
 
-            bar_width = font.font.stringsize(self.jobs)
-            bar_height = self.font_h
+            used_width = font.font.stringsize(self.jobs) - 1
+            used_height = self.font_h
             if self.running:
-                w,h = self.getimage(self.boximg, osd).get_size()
-                bar_width = max(bar_width, w)
-                bar_height += h
+                w, h = self.getimage(self.boximg, osd).get_size()
+                used_width = max(used_width, w)
+                used_height += h
                 for text in self.text:
-                    bar_width = max(bar_width, font.font.stringsize(text))
-                    bar_height += self.font_h
-            bar_width = max(bar_width, 200)
-            bar_width = min(bar_width, 400)
-
-            if DEBUG >= 2:
-                print 'screen_width:', screen_width, 'screen_height:', 
screen_height, \
-                    'bar_width:', bar_width, 'bar_height:', bar_height, 
'font_h:', self.font_h
-            self.boxh = bar_height + (pad_internal * 2)
-            self.boxw = bar_width + (pad_internal * 2)
-            self.by = screen_height - osd.y - self.boxh
+                    used_width = max(used_width, font.font.stringsize(text))
+                    used_height += self.font_h
+            # ensure that the box width is between min and max
+            used_width = max(used_width, 200)
+            used_width = min(used_width, 280)
+
+            _debug_('screen_width=%s, screen_height=%s, used_width=%s, 
used_height=%s, font_h=%s' % \
+                (screen_width, screen_height, used_width, used_height, 
self.font_h), 2)
+            self.boxw = used_width + (self.padding + self.boxborder) * 2
+            self.boxh = used_height + (self.padding + self.boxborder) * 2
             self.bx = osd.x
-            self.ty = self.by + pad_internal
-            self.tx = self.bx + pad_internal
-            self.texth = bar_height
-            self.textw = bar_width
-            if DEBUG >= 2:
-                print 'self.bx:', self.bx, 'self.by:', self.by, 'self.boxh:', 
self.boxh, 'self.boxw:', self.boxw 
-                print 'self.tx:', self.tx, 'self.ty:', self.ty, 'self.texth:', 
self.texth, 'self.textw:', self.textw
+            self.by = screen_height - osd.y - self.boxh
+            self.textw = used_width
+            self.texth = used_height
+            self.tx = self.bx + self.boxborder + self.padding
+            self.ty = self.by + self.boxborder + self.padding
 
         if self.idlebar:
-            self.by = osd.y
-            self.ty = self.by
             if self.image:
                 self.bx = self.idlebar.free_space + 70
             else:
                 self.bx = self.idlebar.free_space
-            self.tx = self.bx
-            self.textw = min(self.textw, self.idlebar_max - self.bx - 30)
+            self.by = osd.y
+            self.tx = self.bx + self.boxborder + self.padding
+            self.ty = self.by + self.boxborder + self.padding
+            #self.textw = min(self.textw, self.idlebar_max - self.bx - 30)
 
 
     def draw(self, (type, object), osd):
+        _debug_('draw(self, (type, object), osd)', 2)
+        now = time.time()
+        duration = now - self.drawtime
+        _debug_("draw=%.2f, interval=%s, state=%s" % (duration, 
self.draw_interval, self.state), 2)
+        self.drawtime = now
+        self.lastdraw = now
         font = osd.get_font('detachbar')
         if font == osd.get_font('default'):
             font = osd.get_font('info value')
 
         self.calculate = True
         self.settext()
-        self.calculatesizes(osd,font)
-
-        osd.drawroundbox(self.bx, self.by, self.boxw, self.boxh,
-            (0xf0ffffffL, 3, 0xb0000000L, 10))
-        #if not self.idlebar:
-        #    osd.drawroundbox(100, 100, 300, 300,
-        #        color=0xf0ffffffL, border_size=5, border_color=0xb0000000L, 
radius=10)
+        self.calculatesizes(osd, font)
 
+        _debug_('self:bx=%s, by=%s, boxh=%s, boxw=%s, border=%s, padding=%s' % 
\
+            (self.bx, self.by, self.boxh, self.boxw, self.boxborder, 
self.padding), 2)
+        if self.idlebar:
+            osd.drawroundbox(self.bx, self.by, self.boxw, self.boxh, 
+                (0xffffffffL, self.boxborder, 0x40ffff00L, 0))
+                #  A R G B                      A R G B 
+                #  background border_width      border     border_radius
+        else:
+            osd.drawroundbox(self.bx, self.by, self.boxw, self.boxh, 
+                (0xf0ffffffL, self.boxborder, 0xb0000000L, self.boxborder))
 
+        _debug_('self:tx=%s, ty=%s, texth=%s, textw=%s' % (self.tx, self.ty, 
self.texth, self.textw), 2)
         y = self.ty
         osd.write_text(self.jobs, font, None, self.tx, y, self.textw, 
self.font_h, 'center', 'center')
         if self.running:
             y += self.font_h
             encbar = self.getimage(self.barimg, osd, True)
             encbox = self.getimage(self.boximg, osd)
-            w,h = encbox.get_size()
-            encbox.blit(encbar, (3,3), (0, 0, (w * self.percent), h))
+            w, h = encbox.get_size()
+            encbox.blit(encbar, (3, 3), (0, 0, (w * self.percent), h))
             x = (self.textw - w) / 2
-            osd.drawroundbox(self.tx+x-2, y-2, w+4, h+4,
-                (0xf0ffffffL, 2, 0xb000ffffL, 0))
+            #osd.drawroundbox(self.tx+x-2, y-2, w+4, h+4, 
+            #    (0xf0ffffffL, 2, 0xb000ffffL, 0))
             osd.drawimage(encbox, (self.tx+x, y, -1, -1) )[0]
             y += h
-            #y += 20
             for text in self.text:
                 osd.write_text(text, font, None, self.tx, y, self.textw, 
self.font_h, 'center', 'center')
                 y += self.font_h
@@ -286,14 +323,25 @@
 
 
     def poll(self):
+        '''poll function'''
         now = time.time()
-        if self.now:
-            if DEBUG >= 2:
-                print "%.3f" % (now - self.now), self.poll_interval, self.state
-        self.now = now
-        #self.draw()
+        pollduration = now - self.lastpoll
+        drawduration = now - self.lastdraw
+        self.lastpoll = now
+        _debug_("poll(self): poll=%.2f, draw=%.2f, interval=%s, state=%s" % \
+            (pollduration, drawduration, self.draw_interval, self.state), 2)
+        if drawduration >= self.draw_interval / 100:
+            skin.redraw()
+
+        # this is how to change the poll interval on the fly
+        #if self.last_interval <> self.poll_interval:
+        #    self.last_interval = self.poll_interval
+        #    rc.unregister(self.poll)
+        #    rc.register(self.poll, True, self.poll_interval)
+        #    #print self.__dict__
 
 
     def update(self):
+        _debug_('update(self)', 2)
         bar = plugin.getbyname('idlebar')
         if bar: bar.poll()

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to