plotter/qgpib_plotter.py

changeset 35
3b7a38af5c42
parent 34
022e881b758e
child 36
cb4124e3e75b
--- a/plotter/qgpib_plotter.py	Sat Jan 26 11:39:30 2008 +0100
+++ b/plotter/qgpib_plotter.py	Sun Feb 03 23:39:27 2008 +0100
@@ -17,18 +17,54 @@
 sys.path.append(ldir)
 form_class, base_class = uic.loadUiType(os.path.join(ldir, "qhpgl_plotter.ui"))
 
-from qpreferences import PreferenceItem, AbstractPreferences, PreferencesEditor
+from qpreferences import BaseItem, IntItem, UnicodeItem, ColorItem
+from qpreferences import PointItem, SizeItem, ByteArrayItem
+from qpreferences import AbstractPreferences
+from qpreferenceseditor import PreferencesEditor
 
 class Preferences(AbstractPreferences):
     ORGANISATION="Logilab"
     APPLICATION="qgpib_plotter"
 
-    device = PreferenceItem('/dev/ttyUSB0', name=u'device', description=u'GPIB device')
-    address = PreferenceItem(5, name=u'GPIB address')
-    _pos = PreferenceItem(basetype=QtCore.QPoint)
-    _size = PreferenceItem(basetype=QtCore.QSize)
-    _appState = PreferenceItem(basetype=QtCore.QByteArray)
+    _pos = PointItem()
+    _size = SizeItem()
+    _appState = ByteArrayItem()
 
+    device = UnicodeItem(default='/dev/ttyUSB0',
+                         name=u'device',
+                         description=u'GPIB device',
+                         group="GPIB settings")
+    address = IntItem(default=5, min=0, max=16,
+                      name=u'GPIB address',
+                      group="GPIB settings")
+    
+    background = ColorItem(default=QtGui.QColor("white"),
+                           name="Background",
+                           group="Colors")
+    color0 = ColorItem(default=QtGui.QColor("black"),
+                       name="Pen #0",
+                       group="Colors")
+    color1 = ColorItem(default=QtGui.QColor("green"),
+                       name="Pen #1",
+                       group="Colors")
+    color2 = ColorItem(default=QtGui.QColor("red"),
+                       name="Pen #2",
+                       group="Colors")
+    color3 = ColorItem(default=QtGui.QColor("blue"),
+                       name="Pen #3",
+                       group="Colors")
+    color4 = ColorItem(default=QtGui.QColor("yellow"),
+                       name="Pen #4",
+                       group="Colors")
+    color5 = ColorItem(default=QtGui.QColor("cyan"),
+                       name="Pen #5",
+                       group="Colors")
+    color6 = ColorItem(default=QtGui.QColor("magenta"),
+                       name="Pen #6",
+                       group="Colors")
+    color7 = ColorItem(default=QtGui.QColor("darkred"),
+                       name="Pen #7",
+                       group="Colors")
     
 class QtHPGLPlotter(QtGui.QMainWindow, form_class):
     def __init__(self, parent=None):
@@ -43,7 +79,19 @@
             self.resize(self._prefs._size)
         if self._prefs._appState:
             self.restoreState(self._prefs._appState)
+        self.readPreferences()
 
+    def readPreferences(self):
+        bg = self._prefs.background
+        if bg and bg.isValid():
+            self.plotterWidget.qview.setBackgroundBrush(QtGui.QBrush(bg))
+        pen_colors = [self._prefs["color%d"%i] for i in range(8)]
+        print 
+        self.plotterWidget.pen_colors = pen_colors
+        
+    def replotCurrent(self):
+        self.currentPlotChanged(self.plotsView.currentIndex())
+        
     def setupUi(self):
         form_class.setupUi(self, self) # call qtdesigner generated form creation        
         # actions defined in designer
@@ -84,6 +132,8 @@
             
     def preferencesTriggered(self, checked=False):
         PreferencesEditor(self._prefs, self).exec_()
+        self.readPreferences()
+        self.replotCurrent()
 
     def quitTriggered(self, checked=False):
         self.close()

mercurial