[plotter] flake8

Thu, 24 May 2018 23:22:37 +0200

author
David Douard <david.douard@logilab.fr>
date
Thu, 24 May 2018 23:22:37 +0200
changeset 104
916c255b3079
parent 103
ad9b6e53ca68
child 105
89123c2af2fd

[plotter] flake8

pygpibtoolkit/plotter/gpib_plotter.py file | annotate | diff | comparison | revisions
pygpibtoolkit/plotter/hpgl_mpl.py file | annotate | diff | comparison | revisions
pygpibtoolkit/plotter/hpgl_parser.py file | annotate | diff | comparison | revisions
pygpibtoolkit/plotter/hpgl_qt.py file | annotate | diff | comparison | revisions
pygpibtoolkit/plotter/qgpib_plotter.py file | annotate | diff | comparison | revisions
--- a/pygpibtoolkit/plotter/gpib_plotter.py	Thu May 24 23:10:06 2018 +0200
+++ b/pygpibtoolkit/plotter/gpib_plotter.py	Thu May 24 23:22:37 2018 +0200
@@ -16,7 +16,6 @@
 
 import sys
 import os
-import time
 from pygpibtoolkit import pygpib as gpib
 from pygpibtoolkit.prologix import GPIB
 
--- a/pygpibtoolkit/plotter/hpgl_mpl.py	Thu May 24 23:10:06 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-# -*- coding: utf-8 -*-
-import numpy
-import pylab
-
-from hpgl_parser import HPGLParser
-
-class HPGLmplPlotter(HPGLParser):
-    pens = "krbgcmyw"
-    lines = ['-', ':', '--', '-.', '.', '-', '-', '-']
-    def __init__(self, data):        
-        super(HPGLmplPlotter, self).__init__(data)
-        pylab.show()
-        
-    def plot_symbols(self, points):
-        x, y = points.T
-        pylab.plot(x, y, 'o')
-
-    def plot_lines(self, points):
-        x, y = points.T
-        pylab.plot(x, y, self.pens[self.pen]+self.lines[self.line_type])
-        
-if __name__ == "__main__":
-    import sys
-    data = open(sys.argv[1]).read()
-    HPGLmplPlotter(data)
-    
--- a/pygpibtoolkit/plotter/hpgl_parser.py	Thu May 24 23:10:06 2018 +0200
+++ b/pygpibtoolkit/plotter/hpgl_parser.py	Thu May 24 23:22:37 2018 +0200
@@ -36,7 +36,7 @@
         self.idx = 0
         self.IN()
         while self.idx < len(data):
-            while data[self.idx] in [';','\n','\r', '\a', ' ']:
+            while data[self.idx] in ';\n\r\a ':
                 self.idx += 1
             if data[self.idx] == chr(0x03):
                 self.ESC()
@@ -48,7 +48,7 @@
                 except AttributeError:
                     print("WARNING: received unknown command %s" % repr(cmd))
 
-            while self.idx < len(data) and data[self.idx] in [';','\n','\r', '\a', ' ']:
+            while self.idx < len(data) and data[self.idx] in ';\n\r\a ':
                 self.idx += 1
 
     def user_to_abs(self, pos):
@@ -76,13 +76,13 @@
         return val
 
     def polyline(self, values):
-        if (len(values)%2) == 1:
+        if (len(values) % 2) == 1:
             # this is a syntax error in the HPGL data
             values = values[:-1]
         values = numpy.array(values).reshape(-1, 2)
         # TODO use scaling
         # do plots
-        values = numpy.r_[[self.pos], values] #add self.pos as 1st value
+        values = numpy.r_[[self.pos], values]  # add self.pos as 1st value
         if self.plot_mode == 'relative':
             values = values.cumsum(axis=0)
         if self.symbol_mode:
@@ -95,19 +95,20 @@
         pass
 
     def get_window_for_paper(self):
-        return 0,100,0,100
+        return (0, 100, 0, 100)
+
     def get_scaling_points_for_paper(self):
-        return 0,100,0,100
+        return (0, 100, 0, 100)
 
     # effective plot methods; to be defined in subclasses (backends)
     def plot_symbols(self, points):
         pass
+
     def plot_lines(self, points):
         pass
 
     # HPGL-related methods
     def ESC(self):
-        # print "ESC"
         self.idx += 1
 
     def OE(self):
@@ -116,7 +117,8 @@
 
     def EC(self):
         """? what's this """
-        values = self.extract_value()
+        # values = self.extract_value()
+        pass
 
     def OO(self):
         """idem"""
@@ -133,34 +135,34 @@
     def DF(self):
         """ Default """
         self.pen = 0
-        self.pen_width = 1 # 1/300 inch
-        self.pos = 0,0
+        self.pen_width = 1  # 1/300 inch
+        self.pos = (0, 0)
         self.char_set = "std"
         self.plot_mode = 'absolute'
-        self.char_direction = 1,0
-        self.line_type = 0 # 'solid'
-        self.pattern_len = 4 #percentage
+        self.char_direction = (1, 0)
+        self.line_type = 0  # 'solid'
+        self.pattern_len = 4  # percentage
         self.window = self.get_window_for_paper()
-        self.char_size = 0.75, 1.5 #percentages
+        self.char_size = (0.75, 1.5)  # percentages
         self.symbol_mode = False
-        self.tick_len = 0.5, 0.5 # %
+        self.tick_len = (0.5, 0.5)  # %
         self.std_char_set = 0
         self.alt_char_set = 0
         self.selected_char_set = 0
-        self.char_slant = 0 # degrees
+        self.char_slant = 0  # degrees
         self.scale = None
         self.str_terminator = chr(0x03)
-        self.chord_ang = 5 #degrees
-        self.fill_type = 'bidirectionnal', 1
-        self.fill_distance = 1 # %
-        self.fill_slant = 0 # degrees
-        self.pen_thickness = 0.3 # mm
+        self.chord_ang = 5  # degrees
+        self.fill_type = ('bidirectionnal', 1)
+        self.fill_distance = 1  # %
+        self.fill_slant = 0  # degrees
+        self.pen_thickness = 0.3  # mm
 
     def IN(self):
         """ Initialize """
         self.DF()
         self.pen_state = "up"
-        self.rotation = 0 #degrees
+        self.rotation = 0  # degrees
         self.scaling_points = self.get_scaling_points_for_paper()
 
     def IP(self):
@@ -188,7 +190,7 @@
         values = self.extract_value()
         if len(values) == 0:
             self.window = self.get_window_for_paper()
-        elif len(value) == 4:
+        elif len(values) == 4:
             self.window = tuple(values)
 
     def RO(self):
@@ -230,66 +232,67 @@
         values = self.extract_value()
         if len(values) in [3, 4]:
             x, y, qc = values[:3]
-            if len(values)==4:
-                qd = values[-1]
+            if len(values) == 4:
+                qd = values[-1]  # noqa
             else:
-                qd = self.chord_ang
+                qd = self.chord_ang  # noqa
             # TODO : plot arc
-            print("plotting an arc")
+            # print("plotting an arc")
+
     def AR(self):
         """ Arc Relative """
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def CI(self):
         """ Circle Plot"""
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def EA(self):
         """Edge Rectangle Absolute"""
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def ER(self):
         """Edge Rectangle Relative"""
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def EW(self):
         """ Edge Wedge """
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def RA(self):
         """ Fill Rectangle Absolute """
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def RR(self):
         """ Fill Rectangle Relative """
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def WG(self):
         """ Fill Wedge """
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def FT(self):
         """ Fill Type """
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def LT(self):
         """ Line Type """
         values = self.extract_value()
 
-        if len(values)==0:
-            self.line_type = 0 #'solid'
+        if len(values) == 0:
+            self.line_type = 0  # 'solid'
         else:
             self.line_type = values[0]
-            if len(values)>1:
+            if len(values) > 1:
                 self.pattern_len = values[1]
 
     def PW(self):
@@ -314,18 +317,20 @@
 
     def TL(self):
         """ Tick Len """
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
 
     def XT(self):
         """ X-axis Tick """
         # TODO
-        print("X ticks")
+        # print("X ticks")
+        pass
 
     def YT(self):
         """ X-axis Tick """
         # TODO
-        print("Y ticks")
+        # print("Y ticks")
+        pass
 
     def PT(self):
         """ Pen Thickness Select """
@@ -374,8 +379,8 @@
         x, y = self.pos
         values = values.split('\n')
         if self.char_size == "absolute":
-            x += len(values[-1]) * self.char_width *1016/2.54
-            y += (len(values)-1) * self.char_height *1016/2.54
+            x += len(values[-1]) * self.char_width * 1016 / 2.54
+            y += (len(values)-1) * self.char_height * 1016 / 2.54
         else:
             x0, x1, y0, y1 = self.scale
             dx = x1-x0
@@ -383,13 +388,12 @@
             x += len(values[-1]) * self.char_width / 100.0 * dx
             y += (len(values)-1) * self.char_height / 100.0 * dy
 
-        #print "LB pos[%s] %s -> %s"%(repr(values), self.pos, (x,y))
         self.pos = [x, y]
 
     def get_char_size(self):
         if self.char_size == "absolute":
-            x = self.char_width *1016/2.54
-            y = self.char_height *1016/2.54
+            x = self.char_width * 1016 / 2.54
+            y = self.char_height * 1016 / 2.54
         else:
             x0, x1, y0, y1 = self.scale
             dx = x1-x0
@@ -402,7 +406,7 @@
         """ Absolute Direction """
         values = self.extract_value()
         if len(values) == 0:
-            self.char_direction = 1.0, 0.0
+            self.char_direction = (1.0, 0.0)
         elif len(values) == 2:
             self.char_direction = values
 
@@ -410,7 +414,7 @@
         """ Relative Direction """
         values = self.extract_value()
         if len(values) == 0:
-            self.char_direction = 1.0, 0.0
+            self.char_direction = (1.0, 0.0)
         elif len(values) == 2:
             # TODO : compute as percentages
             self.char_direction = values
@@ -423,15 +427,14 @@
             values = 0, 1
         x, y = self.pos
         if self.char_size == "absolute":
-            x += values[0] * self.char_width *1016/2.54
-            y += values[1] * self.char_height *1016/2.54
+            x += values[0] * self.char_width * 1016 / 2.54
+            y += values[1] * self.char_height * 1016 / 2.54
         else:
             x0, x1, y0, y1 = self.scale
             dx = x1-x0
             dy = y1-y0
             x += values[0] * self.char_width / 100.0 * dx
             y += values[1] * self.char_height / 100.0 * dy
-        #print "CB pos[%s] %s -> %s"%(repr(values), self.pos, (x,y))
         self.pos = [x, y]
 
     def SI(self):
@@ -439,8 +442,8 @@
         values = self.extract_value()
         self.char_size = "absolute"
         if len(values) == 0:
-            self.char_width = 0.1879 # cm
-            self.char_height = 0.2690 # cm
+            self.char_width = 0.1879  # cm
+            self.char_height = 0.2690  # cm
         elif len(values) == 2:
             self.char_width, self.char_height = values
 
@@ -449,20 +452,23 @@
         values = self.extract_value()
         self.char_size = "relative"
         if len(values) == 0:
-            self.char_width = 0.75 # percentage
-            self.char_height = 1.5 # id
+            self.char_width = 0.75  # percentage
+            self.char_height = 1.5  # id
         elif len(values) == 2:
             self.char_width, self.char_height = values
 
     def SL(self):
         """ Character Slant """
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
+        pass
 
     def UC(self):
         """ User Defined Character """
-        values = self.extract_value()
+        # values = self.extract_value()
         # TODO
+        pass
+
 
 if __name__ == '__main__':
     import sys
--- a/pygpibtoolkit/plotter/hpgl_qt.py	Thu May 24 23:10:06 2018 +0200
+++ b/pygpibtoolkit/plotter/hpgl_qt.py	Thu May 24 23:22:37 2018 +0200
@@ -94,10 +94,6 @@
             color = QtGui.QColor(color)
         self.qpen.setColor(color)
 
-    #def parse(self, data):
-    #    super().parse(data)
-    #    self.resize(self.size())
-
     def parse(self, data):
         super().parse(data)
         self.update()
--- a/pygpibtoolkit/plotter/qgpib_plotter.py	Thu May 24 23:10:06 2018 +0200
+++ b/pygpibtoolkit/plotter/qgpib_plotter.py	Thu May 24 23:22:37 2018 +0200
@@ -45,8 +45,6 @@
         Ui_MainWindow as form_class)
 
 
-
-
 class Preferences(AbstractPreferences):
     ORGANISATION = "PyGPIBToolkit"
     APPLICATION = "qgpib_plotter"
@@ -307,7 +305,6 @@
         self.receivingButton.setIcon(icn)
 
 
-
 class GPIBReceiver(QtCore.QThread):
     plotStarted = pyqtSignal()
     plotReceived = pyqtSignal(int)

mercurial