Skip to content

Commit

Permalink
STY: Changing from 2 spaces to 4 spaces at indentation (#88)
Browse files Browse the repository at this point in the history
* STY: 2 - 4 spaces at application.py

* STY: 2 - 4 spaces at data_plugins

* STY: 2 - 4 spaces at display_module and main_window.py

* STY: 2 - 4 spaces at utilities

* STY: 2 - 4 spaces at widgets

* STY: 2 - 4 spaces at examples

* STY: 2 - 4 spaces at designer_plugin, pydm and testing-ioc

* STY: Fix for places where 4 became 8! =(

* STY: Fix for places where 4 spaces became 8. Comparison to None should be 'if cond is not None:' or 'if cond is None:'.

* STY: Fixing a couple of that were not found before.

* CI: Adding landscape.yml file for landscape.io integration.

* CI: Adding landscape Code Health badge to README.md
  • Loading branch information
hhslepicka authored and mattgibbs committed Aug 8, 2017
1 parent b7dc807 commit 6b19043
Show file tree
Hide file tree
Showing 55 changed files with 4,394 additions and 4,371 deletions.
16 changes: 16 additions & 0 deletions .landscape.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
test-warnings: no
strictness: medium
python-targets:
- 2
- 3
ignore-paths:
- pydm/__init__.py
- pydm/_version.py
- designer_plugin.py
- testing-ioc.py
- versioneer.py
- examples/*
- setup.py
pylint:
disable:
- protected-access
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Code Health](https://landscape.io/github/slaclab/pydm/master/landscape.svg?style=flat)](https://landscape.io/github/slaclab/pydm/master)

# pydm: Python Display Manager
pydm is a PyQt-based framework for building user interfaces for control systems. The goal is to provide a no-code, drag-and-drop system to make simple screens, as well as a straightforward python framework to build complex applications.

Expand All @@ -23,4 +25,4 @@ There isn't any documentation yet, hopefully looking at the examples can get you

# Widget Designer Plugins
pydm widgets are written in Python, and are loaded into Qt Designer via the PyQt Designer Plugin.
If you want to use the pydm widgets in Qt Designer, add the pydm directory (which holds designer_plugin.py) to your PYQTDESIGNERPATH environment variable. Eventually, this will happen automatically in some kind of setup script.
If you want to use the pydm widgets in Qt Designer, add the pydm directory (which holds designer_plugin.py) to your PYQTDESIGNERPATH environment variable. Eventually, this will happen automatically in some kind of setup script.
2 changes: 1 addition & 1 deletion designer_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
from pydm.widgets.spinbox_qtplugin import PyDMSpinboxplugin
from pydm.widgets.drawing_qtplugin import *
from pydm.widgets.byte_qtplugin import PyDMByteIndicatorPlugin
from pydm.widgets.symbol_qtplugin import PyDMSymbolPlugin
from pydm.widgets.symbol_qtplugin import PyDMSymbolPlugin
920 changes: 460 additions & 460 deletions examples/camviewer/camviewer.py

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions examples/camviewer/marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def boundingRect(self):
return self.shape().boundingRect()

def getArrayRegion(self, data, img, axes=(0,1)):
#img_point = self.mapToItem(img, self.pos())
coords = self.getPixelCoords()
ystrip = data[coords[0],:]
xstrip = data[:,coords[1]]
return ([xstrip,ystrip], coords)
#img_point = self.mapToItem(img, self.pos())
coords = self.getPixelCoords()
ystrip = data[coords[0],:]
xstrip = data[:,coords[1]]
return ([xstrip,ystrip], coords)

def getPixelCoords(self):
img_point = self.pos()
return (int(img_point.x()), int(img_point.y()))
img_point = self.pos()
return (int(img_point.x()), int(img_point.y()))

def shape(self):
if self._shape is None:
Expand All @@ -56,4 +56,4 @@ def paint(self, p, *args):
p.setRenderHint(QtGui.QPainter.Antialiasing)
p.setPen(self.currentPen)
p.drawLine(Point(0, -radius), Point(0, radius))
p.drawLine(Point(-radius, 0), Point(radius, 0))
p.drawLine(Point(-radius, 0), Point(radius, 0))
72 changes: 36 additions & 36 deletions examples/image_processing/image_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@
from pyqtgraph import mkPen

class ImageViewer(Display):
def __init__(self, parent=None, args=None):
super(ImageViewer, self).__init__(parent=parent, args=args)
self.image_channel = "ca://MTEST:TwoSpotImage"
self.image_width_channel = "ca://MTEST:ImageWidth"
self.ui.imageView.widthChannel = self.image_width_channel
self.ui.imageView.image_channel = ""
self.markers = []
def __init__(self, parent=None, args=None):
super(ImageViewer, self).__init__(parent=parent, args=args)
self.image_channel = "ca://MTEST:TwoSpotImage"
self.image_width_channel = "ca://MTEST:ImageWidth"
self.ui.imageView.widthChannel = self.image_width_channel
self.ui.imageView.image_channel = ""
self.markers = []

def ui_filename(self):
return 'image_view.ui'

def ui_filepath(self):
return path.join(path.dirname(path.realpath(__file__)), self.ui_filename())

def ui_filename(self):
return 'image_view.ui'
@pyqtSlot(np.ndarray)
def new_image_received(self, new_waveform):
#Reshape the 1D waveform into 2D
img = new_waveform.reshape((int(512),-1), order='C')
#Find blobs in the image with scikit-image
blobs= blob_doh(img, max_sigma=512, min_sigma=64, threshold=.02)
#Remove any existing blob markers
for m in self.markers:
self.ui.imageView.getView().removeItem(m)
self.markers = []
#For each blob, add a blob marker to the image
for blob in blobs:
x, y, size = blob
m = ImageMarker((y,x), size=size, pen=mkPen((100,100,255), width=3))
self.ui.imageView.getView().addItem(m)
self.markers.append(m)
#Show number of blobs in text label
self.ui.numBlobsLabel.setText(str(len(blobs)))
#Send the original image data to the image widget
self.ui.imageView.receiveImageWaveform(new_waveform)

def ui_filepath(self):
return path.join(path.dirname(path.realpath(__file__)), self.ui_filename())

@pyqtSlot(np.ndarray)
def new_image_received(self, new_waveform):
#Reshape the 1D waveform into 2D
img = new_waveform.reshape((int(512),-1), order='C')
#Find blobs in the image with scikit-image
blobs= blob_doh(img, max_sigma=512, min_sigma=64, threshold=.02)
#Remove any existing blob markers
for m in self.markers:
self.ui.imageView.getView().removeItem(m)
self.markers = []
#For each blob, add a blob marker to the image
for blob in blobs:
x, y, size = blob
m = ImageMarker((y,x), size=size, pen=mkPen((100,100,255), width=3))
self.ui.imageView.getView().addItem(m)
self.markers.append(m)
#Show number of blobs in text label
self.ui.numBlobsLabel.setText(str(len(blobs)))
#Send the original image data to the image widget
self.ui.imageView.receiveImageWaveform(new_waveform)

def channels(self):
return [PyDMChannel(address=self.image_channel, waveform_slot=self.new_image_received)]
def channels(self):
return [PyDMChannel(address=self.image_channel, waveform_slot=self.new_image_received)]

intelclass = ImageViewer
intelclass = ImageViewer
16 changes: 8 additions & 8 deletions examples/image_processing/marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def boundingRect(self):
return self.shape().boundingRect()

def getArrayRegion(self, data, img, axes=(0,1)):
#img_point = self.mapToItem(img, self.pos())
coords = self.getPixelCoords()
ystrip = data[coords[0],:]
xstrip = data[:,coords[1]]
return ([xstrip,ystrip], coords)
#img_point = self.mapToItem(img, self.pos())
coords = self.getPixelCoords()
ystrip = data[coords[0],:]
xstrip = data[:,coords[1]]
return ([xstrip,ystrip], coords)

def getPixelCoords(self):
img_point = self.pos()
return (int(img_point.x()), int(img_point.y()))
img_point = self.pos()
return (int(img_point.x()), int(img_point.y()))

def shape(self):
if self._shape is None:
Expand All @@ -56,4 +56,4 @@ def paint(self, p, *args):
p.setRenderHint(QtGui.QPainter.Antialiasing)
p.setPen(self.currentPen)
p.drawLine(Point(0, -radius), Point(0, radius))
p.drawLine(Point(-radius, 0), Point(radius, 0))
p.drawLine(Point(-radius, 0), Point(radius, 0))
16 changes: 8 additions & 8 deletions examples/macros/macros_and_python/macro_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from pydm import Display

class MacroAddition(Display):
def __init__(self, parent=None, args=None, macros=None):
super(MacroAddition, self).__init__(parent=parent, macros=macros)
self.ui.resultLabel.setText("{}".format(float(macros['a']) + float(macros['b'])))

def ui_filename(self):
return 'macro_addition.ui'
def __init__(self, parent=None, args=None, macros=None):
super(MacroAddition, self).__init__(parent=parent, macros=macros)
self.ui.resultLabel.setText("{}".format(float(macros['a']) + float(macros['b'])))

def ui_filepath(self):
return path.join(path.dirname(path.realpath(__file__)), self.ui_filename())
def ui_filename(self):
return 'macro_addition.ui'

def ui_filepath(self):
return path.join(path.dirname(path.realpath(__file__)), self.ui_filename())
16 changes: 8 additions & 8 deletions examples/macros/nested_embedded_windows/macro_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from pydm import Display

class MacroAddition(Display):
def __init__(self, parent=None, args=None, macros=None):
super(MacroAddition, self).__init__(parent=parent, macros=macros)
self.ui.resultLabel.setText("{}".format(float(macros['a']) + float(macros['b'])))

def ui_filename(self):
return 'macro_addition.ui'
def __init__(self, parent=None, args=None, macros=None):
super(MacroAddition, self).__init__(parent=parent, macros=macros)
self.ui.resultLabel.setText("{}".format(float(macros['a']) + float(macros['b'])))

def ui_filepath(self):
return path.join(path.dirname(path.realpath(__file__)), self.ui_filename())
def ui_filename(self):
return 'macro_addition.ui'

def ui_filepath(self):
return path.join(path.dirname(path.realpath(__file__)), self.ui_filename())
2 changes: 1 addition & 1 deletion examples/positioner/cams.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def real2cams(coords):
valid = True

return (p1*180./np.pi, p2*180./np.pi, p3*180./np.pi, valid)


2 changes: 1 addition & 1 deletion examples/positioner/positioner_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ def __init__(self):
driver = myDriver()
print "Server is running... (ctrl+c to close)"
while True:
server.process(0.1)
server.process(0.1)
118 changes: 59 additions & 59 deletions examples/positioner/positioner_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,67 @@
from pydm import Display

class Positioner(Display):
def __init__(self, parent=None, args=None):
super(Positioner, self).__init__(parent=parent, args=args)
self.moving = False
self.ui.pushButton.clicked.connect(self.move_motors)
self.motor1pv = epics.PV("MOTOR:1:VAL")
self.motor2pv = epics.PV("MOTOR:2:VAL")
self.motor3pv = epics.PV("MOTOR:3:VAL")
self.motor_pvs = (self.motor1pv, self.motor2pv, self.motor3pv)
self.ui.xPosTextEntry.textChanged.connect(self.desired_position_changed)
self.ui.yPosTextEntry.textChanged.connect(self.desired_position_changed)
self.ui.zPosTextEntry.textChanged.connect(self.desired_position_changed)

@property
def display_manager_window(self):
return self.window()

@pyqtSlot()
def move_motors(self):
if self.moving:
return

self.moving = True
self.ui.pushButton.setEnabled(False)
self.display_manager_window.statusBar().showMessage("Moving motors...")
self.motor1pv.put(self.m1des)
self.motor2pv.put(self.m2des)
self.motor3pv.put(self.m3des)
def __init__(self, parent=None, args=None):
super(Positioner, self).__init__(parent=parent, args=args)
self.moving = False
self.ui.pushButton.clicked.connect(self.move_motors)
self.motor1pv = epics.PV("MOTOR:1:VAL")
self.motor2pv = epics.PV("MOTOR:2:VAL")
self.motor3pv = epics.PV("MOTOR:3:VAL")
self.motor_pvs = (self.motor1pv, self.motor2pv, self.motor3pv)
self.ui.xPosTextEntry.textChanged.connect(self.desired_position_changed)
self.ui.yPosTextEntry.textChanged.connect(self.desired_position_changed)
self.ui.zPosTextEntry.textChanged.connect(self.desired_position_changed)

waiting = True
while waiting:
time.sleep(0.001)
waiting = not all([pv.put_complete for pv in self.motor_pvs])
self.display_manager_window.statusBar().showMessage("Motor move complete.", 2000)
self.ui.pushButton.setEnabled(True)
self.moving = False

@pyqtSlot(str)
def desired_position_changed(self):
x = self.ui.xPosTextEntry.text()
y = self.ui.yPosTextEntry.text()
theta = self.ui.zPosTextEntry.text()
try:
x = float(x)
y = float(y)
theta = float(theta)
except ValueError:
self.ui.pushButton.setEnabled(False)
self.display_manager_window.statusBar().showMessage("Cannot calculate new position, desired position is invalid.")
return
@property
def display_manager_window(self):
return self.window()

@pyqtSlot()
def move_motors(self):
if self.moving:
return

self.moving = True
self.ui.pushButton.setEnabled(False)
self.display_manager_window.statusBar().showMessage("Moving motors...")
self.motor1pv.put(self.m1des)
self.motor2pv.put(self.m2des)
self.motor3pv.put(self.m3des)

waiting = True
while waiting:
time.sleep(0.001)
waiting = not all([pv.put_complete for pv in self.motor_pvs])
self.display_manager_window.statusBar().showMessage("Motor move complete.", 2000)
self.ui.pushButton.setEnabled(True)
self.moving = False

self.display_manager_window.statusBar().showMessage("Calculating new position...", 1000)
(self.m1des, self.m2des, self.m3des, valid) = cams.real2cams((x,y,theta))
self.ui.motor1DesLabel.setText('%.3f' % self.m1des)
self.ui.motor2DesLabel.setText('%.3f' % self.m2des)
self.ui.motor3DesLabel.setText('%.3f' % self.m3des)
self.ui.pushButton.setEnabled(valid)

def ui_filename(self):
return 'positioner-widget.ui'
@pyqtSlot(str)
def desired_position_changed(self):
x = self.ui.xPosTextEntry.text()
y = self.ui.yPosTextEntry.text()
theta = self.ui.zPosTextEntry.text()
try:
x = float(x)
y = float(y)
theta = float(theta)
except ValueError:
self.ui.pushButton.setEnabled(False)
self.display_manager_window.statusBar().showMessage("Cannot calculate new position, desired position is invalid.")
return

self.display_manager_window.statusBar().showMessage("Calculating new position...", 1000)
(self.m1des, self.m2des, self.m3des, valid) = cams.real2cams((x,y,theta))
self.ui.motor1DesLabel.setText('%.3f' % self.m1des)
self.ui.motor2DesLabel.setText('%.3f' % self.m2des)
self.ui.motor3DesLabel.setText('%.3f' % self.m3des)
self.ui.pushButton.setEnabled(valid)

def ui_filepath(self):
return path.join(path.dirname(path.realpath(__file__)), self.ui_filename())
def ui_filename(self):
return 'positioner-widget.ui'

def ui_filepath(self):
return path.join(path.dirname(path.realpath(__file__)), self.ui_filename())

intelclass = Positioner
28 changes: 14 additions & 14 deletions pydm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import json

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Python Display Manager")
parser.add_argument('displayfile', help='A PyDM file to display. Can be either a Qt .ui file, or a Python file.', nargs='?', default=None)
parser.add_argument('--perfmon', action='store_true', help='Enable performance monitoring, and print CPU usage to the terminal.')
parser.add_argument('-m', '--macro', help='Specify macro replacements to use, in JSON object format. Reminder: JSON requires double quotes for strings, so you should wrap this whole argument in single quotes. Example: -m \'{"sector": "LI25", "facility": "LCLS"}')
parser.add_argument('display_args', help='Arguments to be passed to the PyDM client application (which is a QApplication subclass).', nargs=argparse.REMAINDER)
pydm_args = parser.parse_args()
macros = None
if pydm_args.macro is not None:
try:
macros = json.loads(pydm_args.macro)
except ValueError:
raise ValueError("Could not parse macro argument as JSON.")
app = PyDMApplication(ui_file=pydm_args.displayfile, command_line_args=pydm_args.display_args, perfmon=pydm_args.perfmon, macros=macros)
sys.exit(app.exec_())
parser = argparse.ArgumentParser(description="Python Display Manager")
parser.add_argument('displayfile', help='A PyDM file to display. Can be either a Qt .ui file, or a Python file.', nargs='?', default=None)
parser.add_argument('--perfmon', action='store_true', help='Enable performance monitoring, and print CPU usage to the terminal.')
parser.add_argument('-m', '--macro', help='Specify macro replacements to use, in JSON object format. Reminder: JSON requires double quotes for strings, so you should wrap this whole argument in single quotes. Example: -m \'{"sector": "LI25", "facility": "LCLS"}')
parser.add_argument('display_args', help='Arguments to be passed to the PyDM client application (which is a QApplication subclass).', nargs=argparse.REMAINDER)
pydm_args = parser.parse_args()
macros = None
if pydm_args.macro is not None:
try:
macros = json.loads(pydm_args.macro)
except ValueError:
raise ValueError("Could not parse macro argument as JSON.")
app = PyDMApplication(ui_file=pydm_args.displayfile, command_line_args=pydm_args.display_args, perfmon=pydm_args.perfmon, macros=macros)
sys.exit(app.exec_())
Loading

0 comments on commit 6b19043

Please sign in to comment.