[Sugar-devel] [PATCH] Fixes to the record UI

anishmangal2002 at gmail.com anishmangal2002 at gmail.com
Tue Jun 8 14:52:19 EDT 2010


From: anishmangal2002 <anishmangal2002 at gmail.com>

How the existing UI works:
The record UI consists of many windows/widgets. In a particular
mode or view, it displays and resizes the widgets appropriate for that
view and tries to hide the other windows by moving them off-screen.
Now, on sugar-0.88 (and probably on versions 0.86>), while trying to
move the widgets off-screen, they actually get dumped at the
bottom-right corner. Hence, if a user runs the existing Record
activity on 0.88, he will observe that the bottom right quadrant of the
screen is 'corrupted'.

Fix description:
The patch works by hiding or resizing (to size 1px by 1px) the
widgets not required in a particular view/mode. The updateVideoComponents
method has been modified to hide the widgets not required in a
particular view. Widgets that can't be hidden are resized to
1 x 1 pixel.

Additionally, this patch also fixes the naming of some variables
(s/butt/button/g).

Tested successfully on sugar-emulator-0.88, soas-mirabelle and
xo1-f11-0.88.

Signed-off-by: anishmangal2002 <anishmangal2002 at gmail.com>
---
 button.py    |   10 ++--
 model.py     |    2 +
 p5_button.py |   30 +++++-----
 ui.py        |  199 +++++++++++++++++++++++++++++++---------------------------
 4 files changed, 129 insertions(+), 112 deletions(-)

diff --git a/button.py b/button.py
index 14b9700..2b0e85c 100644
--- a/button.py
+++ b/button.py
@@ -62,12 +62,12 @@ class RecdButton(TrayButton, gobject.GObject):
         return img
 
 
-    def setButtClickedId( self, id ):
-        self.BUTT_CLICKED_ID = id
+    def setButtonClickedId( self, id ):
+        self.BUTTON_CLICKED_ID = id
 
 
-    def getButtClickedId( self ):
-        return self.BUTT_CLICKED_ID
+    def getButtonClickedId( self ):
+        return self.BUTTON_CLICKED_ID
 
 
     def setup_rollover_options( self, info ):
@@ -105,4 +105,4 @@ class RecdButton(TrayButton, gobject.GObject):
 
 
     def _itemCopyToClipboardCb(self, widget):
-        self.ui.copyToClipboard( self.recd )
\ No newline at end of file
+        self.ui.copyToClipboard( self.recd )
diff --git a/model.py b/model.py
index b7f592b..e24752e 100644
--- a/model.py
+++ b/model.py
@@ -323,6 +323,8 @@ class Model:
     def startTakingPhoto( self ):
         self.setUpdating( True )
         self.ca.glive.takePhoto()
+        self.ca.ui.FULLSCREEN = False
+        self.ca.ui.updateVideoComponents()
 
 
     def savePhoto( self, pixbuf ):
diff --git a/p5_button.py b/p5_button.py
index cf76a34..a8e10c5 100644
--- a/p5_button.py
+++ b/p5_button.py
@@ -25,7 +25,7 @@ class P5Button(P5):
     def __init__(self):
         P5.__init__(self)
         self.noloop()
-        self._butts = []
+        self._buttons = []
         self._buttonPressed = False
 
 
@@ -34,10 +34,10 @@ class P5Button(P5):
 
         #iterate through the buttons to see if you've pressed any down
         bp = False
-        for i in range ( 0, len(self._butts) ):
-            if (self._butts[i]._enabled):
-                contains = self._butts[i].contains(event.x, event.y)
-                self._butts[i]._pressed = contains
+        for i in range ( 0, len(self._buttons) ):
+            if (self._buttons[i]._enabled):
+                contains = self._buttons[i].contains(event.x, event.y)
+                self._buttons[i]._pressed = contains
                 if (contains):
                     bp = True
 
@@ -51,16 +51,16 @@ class P5Button(P5):
 
         pressed = []
         #iterate through the buttons to see if you've released on any
-        for i in range ( 0, len(self._butts) ):
-            if (self._butts[i]._enabled):
-                if (self._butts[i]._pressed):
-                    if (self._butts[i].contains(event.x, event.y)):
-                        pressed.append( self._butts[i] )
-
-                    if (self._butts[i]._toggle):
-                        self._butts[i]._pressed = not self._butts[i]._pressed
+        for i in range ( 0, len(self._buttons) ):
+            if (self._buttons[i]._enabled):
+                if (self._buttons[i]._pressed):
+                    if (self._buttons[i].contains(event.x, event.y)):
+                        pressed.append( self._buttons[i] )
+
+                    if (self._buttons[i]._toggle):
+                        self._buttons[i]._pressed = not self._buttons[i]._pressed
                     else:
-                        self._butts[i]._pressed = False
+                        self._buttons[i]._pressed = False
 
         for i in range( 0, len(pressed) ):
             pressed[i].doPressed()
@@ -170,4 +170,4 @@ class Button:
 
 
     def isImg( self ):
-        return self._img != None
\ No newline at end of file
+        return self._img != None
diff --git a/ui.py b/ui.py
index d89b819..e723f66 100644
--- a/ui.py
+++ b/ui.py
@@ -92,7 +92,7 @@ class UI:
         self.maxw = 49
         self.maxh = 49
         self.controlBarHt = 60
-        self.recordButtWd = 55
+        self.recordButtonWd = 55
         self.pipw = self.__class__.dim_PIPW
         self.piph = self.__class__.dim_PIPH
 
@@ -335,7 +335,7 @@ class UI:
         self.tagsBuffer = gtk.TextBuffer()
         self.tagsBuffer.connect('changed', self._tagsBufferEditedCb)
         self.tagsField = gtk.TextView(self.tagsBuffer)
-        self.tagsField.set_size_request( 100, 100 )
+        self.tagsField.set_size_request( 50, 50 )
         self.tagsPanel.pack_start(self.tagsField, expand=True)
         self.infoBoxTopLeft.pack_start(self.tagsPanel, expand=True)
 
@@ -369,7 +369,6 @@ class UI:
         self.centered = True
         self.setUp()
 
-
     def _mapEventCb( self, widget, event ):
         #when your parent window is ready, turn on the feed of live video
         self.liveVideoWindow.disconnect(self.MAP_EVENT_ID)
@@ -461,9 +460,11 @@ class UI:
         self.slowLiveVideoWindow.connect("visibility-notify-event", self._visibleNotifyCb)
 
         self.recordWindow = RecordWindow(self)
+        self.recordWindow.set_geometry_hints(min_width=1, min_height=1)
         self.addToWindowStack( self.recordWindow, self.windowStack[len(self.windowStack)-1] )
 
         self.progressWindow = ProgressWindow(self)
+        self.progressWindow.set_geometry_hints(min_width=1, min_height=1)
         self.addToWindowStack( self.progressWindow, self.windowStack[len(self.windowStack)-1] )
 
         self.maxWindow = gtk.Window()
@@ -471,9 +472,11 @@ class UI:
         self.maxWindow.modify_bg( gtk.STATE_INSENSITIVE, Constants.colorBlack.gColor )
         maxButton = MaxButton(self)
         self.maxWindow.add( maxButton )
+        self.maxWindow.set_geometry_hints(min_width=1, min_height=1)
         self.addToWindowStack( self.maxWindow, self.windowStack[len(self.windowStack)-1] )
 
         self.scrubWindow = ScrubberWindow(self)
+        self.scrubWindow.set_geometry_hints(min_width=1, min_height=1)
         self.addToWindowStack( self.scrubWindow, self.windowStack[len(self.windowStack)-1] )
 
         self.infWindow = gtk.Window()
@@ -492,6 +495,7 @@ class UI:
 
 
     def _visibleNotifyCb( self, widget, event ):
+        logging.debug("_visibleNotifyCb")
 
         if (self.LAUNCHING):
             return
@@ -525,6 +529,31 @@ class UI:
             else:
                 self.ca.stopPipes()
 
+    def resizeWindows( self ):
+        if self.ca.m.MODE == Constants.MODE_AUDIO:
+            self.maxWindow.resize( 1, 1 )
+        else:
+            maxDim = self.getMaxDim( self.FULLSCREEN )
+            self.maxWindow.resize( maxDim[0], maxDim[1] )
+
+        if self.LIVEMODE:
+            self.pipBgdWindow.resize( 1, 1 )
+            self.playOggWindow.resize( 1, 1 )
+            self.livePhotoWindow.resize( 1, 1 )
+            self.slowLiveVideoWindow.resize( 1, 1 )
+            self.infWindow.resize( 1, 1 )
+            if self.ca.m.MODE == Constants.MODE_PHOTO:
+                self.progressWindow.resize( 1, 1 )
+        else:
+            pgdDim = self.getPgdDim( self.FULLSCREEN )
+            self.pipBgdWindow.resize( pgdDim[0], pgdDim[1] )
+            self.progressWindow.resize( 1, 1 )
+            self.recordWindow.resize( 1, 1 )
+            if self.ca.m.MODE == Constants.MODE_PHOTO:
+                self.playOggWindow.resize( 1, 1 )
+                self.scrubWindow.resize( 1, 1 )
+            elif self.ca.m.MODE == Constants.MODE_VIDEO:
+                self.liveVideoWindow.resize( 1, 1 )
 
     def setUpWindowsSizes( self ):
         pipDim = self.getPipDim(False)
@@ -597,30 +626,6 @@ class UI:
                 if (self.HIDE_WIDGET_TIMEOUT_ID != 0):
                     gobject.source_remove( self.HIDE_WIDGET_TIMEOUT_ID )
 
-
-    def hideWidgets( self ):
-        self.moveWinOffscreen( self.maxWindow )
-        self.moveWinOffscreen( self.pipBgdWindow )
-        self.moveWinOffscreen( self.infWindow )
-        self.moveWinOffscreen( self.slowLiveVideoWindow )
-
-        if (self.FULLSCREEN):
-            self.moveWinOffscreen( self.recordWindow )
-            self.moveWinOffscreen( self.progressWindow )
-            self.moveWinOffscreen( self.scrubWindow )
-
-        if (self.ca.m.MODE == Constants.MODE_PHOTO):
-            if (not self.LIVEMODE):
-                self.moveWinOffscreen( self.liveVideoWindow )
-        elif (self.ca.m.MODE == Constants.MODE_VIDEO):
-            if (not self.LIVEMODE):
-                self.moveWinOffscreen( self.liveVideoWindow )
-        elif (self.ca.m.MODE == Constants.MODE_AUDIO):
-            if (not self.LIVEMODE):
-                self.moveWinOffscreen( self.liveVideoWindow )
-        self.LAST_MODE = -1
-
-
     def _mouseMightaMovedCb( self ):
         x, y = self.ca.get_pointer()
         passedTime = 0
@@ -637,18 +642,6 @@ class UI:
             self.hideWidgetsTimer = time.time()
             passedTime = 0
 
-        if (passedTime >= 3):
-            if (not self.hiddenWidgets):
-                if (self.mouseInWidget(x,y)):
-                    self.hideWidgetsTimer = time.time()
-                elif (self.RECD_INFO_ON):
-                    self.hideWidgetsTimer = time.time()
-                elif (self.UPDATE_TIMER_ID != 0):
-                    self.hideWidgetsTimer = time.time()
-                else:
-                    self.hideWidgets()
-                    self.hiddenWidgets = True
-
         self.mx = x
         self.my = y
         return True
@@ -680,6 +673,7 @@ class UI:
 
 
     def _mediaClickedForPlayback(self, widget, event):
+        logging.debug("_mediaClickedForPlayback")
         if (not self.LIVEMODE):
             if (self.shownRecd != None):
                 if (self.ca.m.MODE != Constants.MODE_PHOTO):
@@ -875,18 +869,18 @@ class UI:
         kids = self.thumbTray.get_children()
         for i in range (0, len(kids)):
             if (self.ca.m.UPDATING or self.ca.m.RECORDING):
-                if (kids[i].getButtClickedId() != 0):
-                    kids[i].disconnect( kids[i].getButtClickedId() )
-                    kids[i].setButtClickedId(0)
+                if (kids[i].getButtonClickedId() != 0):
+                    kids[i].disconnect( kids[i].getButtonClickedId() )
+                    kids[i].setButtonClickedId(0)
             else:
-                if (kids[i].getButtClickedId() == 0):
-                    BUTT_CLICKED_ID = kids[i].connect( "clicked", self._thumbClicked, kids[i].recd )
-                    kids[i].setButtClickedId(BUTT_CLICKED_ID)
+                if (kids[i].getButtonClickedId() == 0):
+                    BUTTON_CLICKED_ID = kids[i].connect( "clicked", self._thumbClicked, kids[i].recd )
+                    kids[i].setButtonClickedId(BUTTON_CLICKED_ID)
 
 
     def hideAllWindows( self ):
         for i in range (0, len(self.windowStack)):
-            self.moveWinOffscreen( self.windowStack[i] )
+            self.windowStack[i].hide_all()
 
 
     def _liveButtonReleaseCb(self, widget, event):
@@ -1003,6 +997,7 @@ class UI:
         self.doMouseListener( True )
         self.showLiveVideoTags()
         self.LAST_MODE = -1 #force an update
+
         self.updateVideoComponents()
         self.resetWidgetFadeTimer()
 
@@ -1010,7 +1005,8 @@ class UI:
     def startLiveVideo(self, force):
         #We need to know which window and which pipe here
 
-        #if returning from another activity, active won't be false and needs to be to get started
+        #if returning from another activity, active won't be false
+        #and needs to be to get started
         if (self.ca.glive.window == self.liveVideoWindow
             and self.ca.props.active
             and not force):
@@ -1025,14 +1021,6 @@ class UI:
         self.FULLSCREEN = not self.FULLSCREEN
         self.updateVideoComponents()
 
-
-    def moveWinOffscreen( self, win ):
-        #we move offscreen to resize or else we get flashes on screen, and setting hide() doesn't allow resize & moves
-        offW = (gtk.gdk.screen_width() + 100)
-        offH = (gtk.gdk.screen_height() + 100)
-        self.smartMove(win, offW, offH)
-
-
     def setImgLocDim( self, win ):
         imgDim = self.getImgDim( self.FULLSCREEN )
         self.smartResize( win, imgDim[0], imgDim[1] )
@@ -1175,12 +1163,12 @@ class UI:
             if (self.ca.m.MODE == Constants.MODE_PHOTO):
                 return [self.vw, self.controlBarHt]
             else:
-                return [self.recordButtWd, self.controlBarHt]
+                return [self.recordButtonWd, self.controlBarHt]
         else:
             if (self.ca.m.MODE == Constants.MODE_PHOTO):
                 return [gtk.gdk.screen_width()-(self.inset*2), self.controlBarHt]
             else:
-                return [self.recordButtWd, self.controlBarHt]
+                return [self.recordButtonWd, self.controlBarHt]
 
 
     def getInbLoc( self, full ):
@@ -1253,16 +1241,16 @@ class UI:
 
     def getPrgDim( self, full ):
         if (not full):
-            return [self.vw-self.recordButtWd, self.controlBarHt]
+            return [self.vw-self.recordButtonWd, self.controlBarHt]
         else:
-            return [gtk.gdk.screen_width()-(self.inset+self.inset+self.recordButtWd), self.controlBarHt]
+            return [gtk.gdk.screen_width()-(self.inset+self.inset+self.recordButtonWd), self.controlBarHt]
 
 
     def getPrgLoc( self, full ):
         if (not full):
-            return [self.centerBoxPos[0]+self.recordButtWd, self.centerBoxPos[1]+self.vh]
+            return [self.centerBoxPos[0]+self.recordButtonWd, self.centerBoxPos[1]+self.vh]
         else:
-            return [self.inset+self.recordButtWd, gtk.gdk.screen_height()-(self.inset+self.controlBarHt)]
+            return [self.inset+self.recordButtonWd, gtk.gdk.screen_height()-(self.inset+self.controlBarHt)]
 
 
     def getLoc( self, pos, full ):
@@ -1316,6 +1304,7 @@ class UI:
             else:
                 #or, if there is no countdown, it might be because we are recording
                 self.clickShutter()
+                self.progressWindow.updateProgress( 1, Constants.istrFinishedRecording )
 
         else:
             #we're timing down something, but interrupted by user click or the timer completing
@@ -1455,15 +1444,42 @@ class UI:
         elif (self.TRANSCODING):
             pos.append({"position":"tmr", "window":self.progressWindow} )
 
-        for i in range (0, len(self.windowStack)):
-            self.windowStack[i].hide_all()
-
         self.hideAllWindows()
         self.updatePos( pos )
+        self.resizeWindows()
 
         for i in range (0, len(self.windowStack)):
             self.windowStack[i].show_all()
 
+        if self.ca.m.MODE == Constants.MODE_PHOTO:
+            if not self.LIVEMODE:
+                if self.RECD_INFO_ON == True:
+                    self.maxWindow.hide_all()
+                if self.FULLSCREEN:
+                    self.infWindow.hide_all()
+            else :
+                self.infWindow.hide_all()
+                self.scrubWindow.hide_all()
+        elif self.ca.m.MODE == Constants.MODE_VIDEO:
+            if not self.LIVEMODE:
+                if self.RECD_INFO_ON == True:
+                    self.scrubWindow.hide_all()
+                    self.maxWindow.hide_all()
+                if self.FULLSCREEN:
+                    self.infWindow.hide_all()
+            else :
+                self.infWindow.hide_all()
+                self.scrubWindow.hide_all()
+        elif self.ca.m.MODE == Constants.MODE_AUDIO:
+            if not self.LIVEMODE:
+                if self.RECD_INFO_ON == True:
+                    self.scrubWindow.hide_all()
+                if self.FULLSCREEN:
+                    self.infWindow.hide_all()
+            else:
+                self.infWindow.hide_all()
+                self.scrubWindow.hide_all()
+
         self.LAST_MODE = self.ca.m.MODE
         self.LAST_FULLSCREEN = self.FULLSCREEN
         self.LAST_LIVE = self.LIVEMODE
@@ -1548,16 +1564,16 @@ class UI:
             if (kids[i].recd == recd):
                 self.thumbTray.remove_item(kids[i])
                 kids[i].cleanUp()
-                kids[i].disconnect( kids[i].getButtClickedId() )
-                kids[i].setButtClickedId(0)
+                kids[i].disconnect( kids[i].getButtonClickedId() )
+                kids[i].setButtonClickedId(0)
 
 
     def addThumb( self, recd, forceScroll ):
-        butt = RecdButton( self, recd )
-        BUTT_CLICKED_ID = butt.connect( "clicked", self._thumbClicked, recd )
-        butt.setButtClickedId(BUTT_CLICKED_ID)
-        self.thumbTray.add_item( butt, len(self.thumbTray.get_children()) )
-        butt.show()
+        button = RecdButton( self, recd )
+        BUTTON_CLICKED_ID = button.connect( "clicked", self._thumbClicked, recd )
+        button.setButtonClickedId(BUTTON_CLICKED_ID)
+        self.thumbTray.add_item( button, len(self.thumbTray.get_children()) )
+        button.show()
         if (forceScroll):
             self.thumbTray.scroll_to_end()
 
@@ -1567,8 +1583,8 @@ class UI:
         for i in range (0, len(kids)):
             self.thumbTray.remove_item(kids[i])
             kids[i].cleanUp()
-            if (kids[i].getButtClickedId() != 0):
-                kids[i].disconnect( kids[i].getButtClickedId() )
+            if (kids[i].getButtonClickedId() != 0):
+                kids[i].disconnect( kids[i].getButtonClickedId() )
 
 
     def _thumbClicked( self, button, recd ):
@@ -1659,7 +1675,6 @@ class UI:
             if (self.RECD_INFO_ON):
                 self.bottomCenter.add( self.namePanel )
         self.bottomCenter.show_all()
-
         self.resetWidgetFadeTimer()
 
 
@@ -1913,22 +1928,22 @@ class ScrubberWindow(gtk.Window):
         self.add( self.hbox )
 
         self.button = gtk.Button()
-        buttBox = gtk.EventBox()
-        buttBox.add(self.button)
-        buttBox.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
+        buttonBox = gtk.EventBox()
+        buttonBox.add(self.button)
+        buttonBox.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
         self.button.set_image( Constants.recPlayImg )
         self.button.set_property('can-default', True)
         self.button.set_relief(gtk.RELIEF_NONE)
-        self.button.set_size_request( self.ui.recordButtWd, self.ui.recordButtWd )
-        buttBox.set_size_request( self.ui.recordButtWd, self.ui.recordButtWd )
+        self.button.set_size_request( self.ui.recordButtonWd, self.ui.recordButtonWd )
+        buttonBox.set_size_request( self.ui.recordButtonWd, self.ui.recordButtonWd )
         #self.button.set_border_width( UI.dim_INSET/2 )
         self.button.show()
 
-        buttBox.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
+        buttonBox.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
         self.button.modify_bg( gtk.STATE_ACTIVE, Constants.colorBlack.gColor )
 
         self.button.connect('clicked', self._buttonClickedCb)
-        self.hbox.pack_start(buttBox, expand=False)
+        self.hbox.pack_start(buttonBox, expand=False)
 
         self.adjustment = gtk.Adjustment(0.0, 0.00, 100.0, 0.1, 1.0, 1.0)
         self.hscale = gtk.HScale(self.adjustment)
@@ -2067,11 +2082,11 @@ class MaxButton(P5Button):
         xs.append(0)
         ys.append(self.ui.maxh)
         poly = Polygon( xs, ys )
-        butt = Button( poly, 0, 0)
-        butt.addActionListener( self )
+        button = Button( poly, 0, 0)
+        button.addActionListener( self )
         self.maxS = "max"
-        butt.setActionCommand( self.maxS )
-        self._butts.append( butt )
+        button.setActionCommand( self.maxS )
+        self._buttons.append( button )
 
 
     def draw(self, ctx, w, h):
@@ -2108,11 +2123,11 @@ class InfButton(P5Button):
         xs.append(0)
         ys.append(75)
         poly = Polygon( xs, ys )
-        butt = Button( poly, 0, 0)
-        butt.addActionListener( self )
+        button = Button( poly, 0, 0)
+        button.addActionListener( self )
         self.infS = "inf"
-        butt.setActionCommand( self.infS )
-        self._butts.append( butt )
+        button.setActionCommand( self.infS )
+        self._buttons.append( button )
 
 
     def draw(self, ctx, w, h):
@@ -2170,7 +2185,7 @@ class RecordWindow(gtk.Window):
         self.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
 
         self.shutterButton = RecordButton()
-        self.shutterButton.set_size_request(self.ui.recordButtWd, self.ui.recordButtWd)
+        self.shutterButton.set_size_request(self.ui.recordButtonWd, self.ui.recordButtonWd)
         self.shutterButton.set_relief(gtk.RELIEF_NONE)
         self.shutterButton.set_image( Constants.recImg )
         self.shutterButton.connect("clicked", self.ui._shutterClickCb)
@@ -2264,10 +2279,10 @@ class ProgressWindow(gtk.Window):
         self.progBar.modify_bg( gtk.STATE_PRELIGHT, Constants.colorBlack.gColor )
         self.progBar.modify_bg( gtk.STATE_SELECTED, Constants.colorBlack.gColor )
         self.progBar.modify_bg( gtk.STATE_INSENSITIVE, Constants.colorBlack.gColor )
-        vb.add( self.progBar )
+        vb.pack_start( self.progBar, True, True, 0 )
 
         hbox = gtk.HBox()
-        vb.add( hbox )
+        vb.pack_start( hbox, True, True, 0 )
         self.infoLabel = gtk.Label()
         self.infoLabel.set_alignment( 1, .5 )
         self.infoLabel.set_text( "<b><span foreground='black'>SPACE</span></b>")
-- 
1.7.0.4



More information about the Sugar-devel mailing list