[libcamera-devel,3/5] py: cam: Cleanups
diff mbox series

Message ID 20220519103347.33295-4-tomi.valkeinen@ideasonboard.com
State Accepted
Headers show
Series
  • More misc Python patches
Related show

Commit Message

Tomi Valkeinen May 19, 2022, 10:33 a.m. UTC
No functional changes. Drop unused variables, reduce typechecker
warnings.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 src/py/cam/cam.py      |  2 +-
 src/py/cam/cam_qt.py   | 13 ++-----------
 src/py/cam/cam_qtgl.py |  9 ++-------
 3 files changed, 5 insertions(+), 19 deletions(-)

Comments

Laurent Pinchart May 19, 2022, 10:49 a.m. UTC | #1
Hi Tomi,

Thank you for the patch.

On Thu, May 19, 2022 at 01:33:45PM +0300, Tomi Valkeinen wrote:
> No functional changes.

That's nearly true, see below.

> Drop unused variables, reduce typechecker
> warnings.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  src/py/cam/cam.py      |  2 +-
>  src/py/cam/cam_qt.py   | 13 ++-----------
>  src/py/cam/cam_qtgl.py |  9 ++-------
>  3 files changed, 5 insertions(+), 19 deletions(-)
> 
> diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py
> index 2f0690b5..e2bc78da 100755
> --- a/src/py/cam/cam.py
> +++ b/src/py/cam/cam.py
> @@ -304,7 +304,7 @@ def event_handler(state):
>  
>          running = any(ctx['reqs-completed'] < ctx['opt-capture'] for ctx in contexts)
>          return running
> -    except Exception as e:
> +    except Exception:
>          traceback.print_exc()
>          return False
>  
> diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py
> index 0a25a823..8dc6f92e 100644
> --- a/src/py/cam/cam_qt.py
> +++ b/src/py/cam/cam_qt.py
> @@ -184,14 +184,8 @@ class QtRenderer:
>          windows = []
>  
>          for ctx in self.contexts:
> -            camera = ctx['camera']
> -
>              for stream in ctx['streams']:
> -                fmt = stream.configuration.pixel_format
> -                size = stream.configuration.size
> -
>                  window = MainWindow(ctx, stream)
> -                window.setAttribute(QtCore.Qt.WA_ShowWithoutActivating)

Isn't this one a functional change, and should it be split to a separate
patch ?

>                  window.show()
>                  windows.append(window)
>  
> @@ -199,10 +193,10 @@ class QtRenderer:
>  
>      def run(self):
>          camnotif = QtCore.QSocketNotifier(self.cm.efd, QtCore.QSocketNotifier.Read)
> -        camnotif.activated.connect(lambda x: self.readcam())
> +        camnotif.activated.connect(lambda _: self.readcam())
>  
>          keynotif = QtCore.QSocketNotifier(sys.stdin.fileno(), QtCore.QSocketNotifier.Read)
> -        keynotif.activated.connect(lambda x: self.readkey())
> +        keynotif.activated.connect(lambda _: self.readkey())
>  
>          print('Capturing...')
>  
> @@ -292,9 +286,6 @@ class MainWindow(QtWidgets.QWidget):
>      def buf_to_qpixmap(self, stream, fb):
>          with fb.mmap() as mfb:
>              cfg = stream.configuration
> -            w = cfg.size.width
> -            h = cfg.size.height
> -            pitch = cfg.stride
>  
>              if cfg.pixel_format == libcam.formats.MJPEG:
>                  img = Image.open(BytesIO(mfb.planes[0]))
> diff --git a/src/py/cam/cam_qtgl.py b/src/py/cam/cam_qtgl.py
> index 4bbcda6c..3fb7dde3 100644
> --- a/src/py/cam/cam_qtgl.py
> +++ b/src/py/cam/cam_qtgl.py
> @@ -5,16 +5,11 @@ from PyQt5 import QtCore, QtWidgets
>  from PyQt5.QtCore import Qt
>  
>  import math
> -import numpy as np
>  import os
>  import sys
>  
>  os.environ['PYOPENGL_PLATFORM'] = 'egl'
>  
> -import OpenGL
> -# OpenGL.FULL_LOGGING = True
> -
> -from OpenGL import GL as gl
>  from OpenGL.EGL.EXT.image_dma_buf_import import *
>  from OpenGL.EGL.KHR.image import *
>  from OpenGL.EGL.VERSION.EGL_1_0 import *
> @@ -149,10 +144,10 @@ class QtRenderer:
>  
>      def run(self):
>          camnotif = QtCore.QSocketNotifier(self.state['cm'].efd, QtCore.QSocketNotifier.Read)
> -        camnotif.activated.connect(lambda x: self.readcam())
> +        camnotif.activated.connect(lambda _: self.readcam())
>  
>          keynotif = QtCore.QSocketNotifier(sys.stdin.fileno(), QtCore.QSocketNotifier.Read)
> -        keynotif.activated.connect(lambda x: self.readkey())
> +        keynotif.activated.connect(lambda _: self.readkey())
>  
>          print('Capturing...')
>
Tomi Valkeinen May 19, 2022, 10:51 a.m. UTC | #2
On 19/05/2022 13:49, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Thu, May 19, 2022 at 01:33:45PM +0300, Tomi Valkeinen wrote:
>> No functional changes.
> 
> That's nearly true, see below.
> 
>> Drop unused variables, reduce typechecker
>> warnings.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   src/py/cam/cam.py      |  2 +-
>>   src/py/cam/cam_qt.py   | 13 ++-----------
>>   src/py/cam/cam_qtgl.py |  9 ++-------
>>   3 files changed, 5 insertions(+), 19 deletions(-)
>>
>> diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py
>> index 2f0690b5..e2bc78da 100755
>> --- a/src/py/cam/cam.py
>> +++ b/src/py/cam/cam.py
>> @@ -304,7 +304,7 @@ def event_handler(state):
>>   
>>           running = any(ctx['reqs-completed'] < ctx['opt-capture'] for ctx in contexts)
>>           return running
>> -    except Exception as e:
>> +    except Exception:
>>           traceback.print_exc()
>>           return False
>>   
>> diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py
>> index 0a25a823..8dc6f92e 100644
>> --- a/src/py/cam/cam_qt.py
>> +++ b/src/py/cam/cam_qt.py
>> @@ -184,14 +184,8 @@ class QtRenderer:
>>           windows = []
>>   
>>           for ctx in self.contexts:
>> -            camera = ctx['camera']
>> -
>>               for stream in ctx['streams']:
>> -                fmt = stream.configuration.pixel_format
>> -                size = stream.configuration.size
>> -
>>                   window = MainWindow(ctx, stream)
>> -                window.setAttribute(QtCore.Qt.WA_ShowWithoutActivating)
> 
> Isn't this one a functional change, and should it be split to a separate
> patch ?

You're right, I missed that. I added WA_ShowWithoutActivating for 
debugging purposes at some point long time back, but then forgot to 
remove it.

I can separate it from this one.

  Tomi
Laurent Pinchart May 19, 2022, 10:53 a.m. UTC | #3
On Thu, May 19, 2022 at 01:51:51PM +0300, Tomi Valkeinen wrote:
> On 19/05/2022 13:49, Laurent Pinchart wrote:
> > On Thu, May 19, 2022 at 01:33:45PM +0300, Tomi Valkeinen wrote:
> >> No functional changes.
> > 
> > That's nearly true, see below.
> > 
> >> Drop unused variables, reduce typechecker
> >> warnings.
> >>
> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> >> ---
> >>   src/py/cam/cam.py      |  2 +-
> >>   src/py/cam/cam_qt.py   | 13 ++-----------
> >>   src/py/cam/cam_qtgl.py |  9 ++-------
> >>   3 files changed, 5 insertions(+), 19 deletions(-)
> >>
> >> diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py
> >> index 2f0690b5..e2bc78da 100755
> >> --- a/src/py/cam/cam.py
> >> +++ b/src/py/cam/cam.py
> >> @@ -304,7 +304,7 @@ def event_handler(state):
> >>   
> >>           running = any(ctx['reqs-completed'] < ctx['opt-capture'] for ctx in contexts)
> >>           return running
> >> -    except Exception as e:
> >> +    except Exception:
> >>           traceback.print_exc()
> >>           return False
> >>   
> >> diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py
> >> index 0a25a823..8dc6f92e 100644
> >> --- a/src/py/cam/cam_qt.py
> >> +++ b/src/py/cam/cam_qt.py
> >> @@ -184,14 +184,8 @@ class QtRenderer:
> >>           windows = []
> >>   
> >>           for ctx in self.contexts:
> >> -            camera = ctx['camera']
> >> -
> >>               for stream in ctx['streams']:
> >> -                fmt = stream.configuration.pixel_format
> >> -                size = stream.configuration.size
> >> -
> >>                   window = MainWindow(ctx, stream)
> >> -                window.setAttribute(QtCore.Qt.WA_ShowWithoutActivating)
> > 
> > Isn't this one a functional change, and should it be split to a separate
> > patch ?
> 
> You're right, I missed that. I added WA_ShowWithoutActivating for 
> debugging purposes at some point long time back, but then forgot to 
> remove it.
> 
> I can separate it from this one.

I'll drop that line from this patch, no need to resubmit, you can then
send another one on top.

Patch
diff mbox series

diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py
index 2f0690b5..e2bc78da 100755
--- a/src/py/cam/cam.py
+++ b/src/py/cam/cam.py
@@ -304,7 +304,7 @@  def event_handler(state):
 
         running = any(ctx['reqs-completed'] < ctx['opt-capture'] for ctx in contexts)
         return running
-    except Exception as e:
+    except Exception:
         traceback.print_exc()
         return False
 
diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py
index 0a25a823..8dc6f92e 100644
--- a/src/py/cam/cam_qt.py
+++ b/src/py/cam/cam_qt.py
@@ -184,14 +184,8 @@  class QtRenderer:
         windows = []
 
         for ctx in self.contexts:
-            camera = ctx['camera']
-
             for stream in ctx['streams']:
-                fmt = stream.configuration.pixel_format
-                size = stream.configuration.size
-
                 window = MainWindow(ctx, stream)
-                window.setAttribute(QtCore.Qt.WA_ShowWithoutActivating)
                 window.show()
                 windows.append(window)
 
@@ -199,10 +193,10 @@  class QtRenderer:
 
     def run(self):
         camnotif = QtCore.QSocketNotifier(self.cm.efd, QtCore.QSocketNotifier.Read)
-        camnotif.activated.connect(lambda x: self.readcam())
+        camnotif.activated.connect(lambda _: self.readcam())
 
         keynotif = QtCore.QSocketNotifier(sys.stdin.fileno(), QtCore.QSocketNotifier.Read)
-        keynotif.activated.connect(lambda x: self.readkey())
+        keynotif.activated.connect(lambda _: self.readkey())
 
         print('Capturing...')
 
@@ -292,9 +286,6 @@  class MainWindow(QtWidgets.QWidget):
     def buf_to_qpixmap(self, stream, fb):
         with fb.mmap() as mfb:
             cfg = stream.configuration
-            w = cfg.size.width
-            h = cfg.size.height
-            pitch = cfg.stride
 
             if cfg.pixel_format == libcam.formats.MJPEG:
                 img = Image.open(BytesIO(mfb.planes[0]))
diff --git a/src/py/cam/cam_qtgl.py b/src/py/cam/cam_qtgl.py
index 4bbcda6c..3fb7dde3 100644
--- a/src/py/cam/cam_qtgl.py
+++ b/src/py/cam/cam_qtgl.py
@@ -5,16 +5,11 @@  from PyQt5 import QtCore, QtWidgets
 from PyQt5.QtCore import Qt
 
 import math
-import numpy as np
 import os
 import sys
 
 os.environ['PYOPENGL_PLATFORM'] = 'egl'
 
-import OpenGL
-# OpenGL.FULL_LOGGING = True
-
-from OpenGL import GL as gl
 from OpenGL.EGL.EXT.image_dma_buf_import import *
 from OpenGL.EGL.KHR.image import *
 from OpenGL.EGL.VERSION.EGL_1_0 import *
@@ -149,10 +144,10 @@  class QtRenderer:
 
     def run(self):
         camnotif = QtCore.QSocketNotifier(self.state['cm'].efd, QtCore.QSocketNotifier.Read)
-        camnotif.activated.connect(lambda x: self.readcam())
+        camnotif.activated.connect(lambda _: self.readcam())
 
         keynotif = QtCore.QSocketNotifier(sys.stdin.fileno(), QtCore.QSocketNotifier.Read)
-        keynotif.activated.connect(lambda x: self.readkey())
+        keynotif.activated.connect(lambda _: self.readkey())
 
         print('Capturing...')