Skip to content

Commit

Permalink
ENH: Open in Designer now also opens the PY file associated with the …
Browse files Browse the repository at this point in the history
…screen. (#187)

* ENH: Open in Designer now also opens the PY file associated with the screen.

* ENH: Changing the Menu text accordingly for Open in Editor and Text Editor as suggested by @mgibbs.
FIX: We cant use 'intelclass' as a generic name when loading files, this was causing problems with Open File. Changed to uuid.uuid4()

* ENH: Adding better way to find the QT Binary location thanks to @mgibbs
  • Loading branch information
hhslepicka authored and mattgibbs committed Dec 13, 2017
1 parent 3525bdd commit 9a3527e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 51 deletions.
21 changes: 21 additions & 0 deletions examples/code_only/code_only.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pydm import Display
from pydm.PyQt.QtGui import QLabel, QVBoxLayout, QHBoxLayout

class MyDisplay(Display):
def __init__(self, parent=None, args=[]):
super(MyDisplay, self).__init__(parent=parent, args=args)
self.setup_ui()

def setup_ui(self):
main = QHBoxLayout()
sub = QVBoxLayout()
for i in range(10):
sub.addWidget(QLabel(str(i)))
main.addLayout(sub)
self.setLayout(main)

def ui_filename(self):
return None

def ui_filepath(self):
return None
52 changes: 26 additions & 26 deletions examples/home.ui
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>216</width>
<height>782</height>
<width>213</width>
<height>560</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand All @@ -95,7 +95,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Byte Indicator</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -117,7 +117,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Checkbox</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -139,7 +139,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Drawing Widgets</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -161,7 +161,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Embedded Display</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -183,7 +183,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Enum Combo Box</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -205,7 +205,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Image View</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -227,7 +227,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Label</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -249,7 +249,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Line Edit</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -265,7 +265,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Push Button</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -281,7 +281,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Related Display Button</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -297,7 +297,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Shell Command Button</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -313,7 +313,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Slider</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -329,7 +329,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Spinbox</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -345,7 +345,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Symbol</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -361,7 +361,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Time Plot</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -377,7 +377,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Waveform Plot</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -393,7 +393,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Waveform Table</string>
</property>
<property name="displayFilename" stdset="0">
Expand Down Expand Up @@ -436,7 +436,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>358</width>
<width>366</width>
<height>443</height>
</rect>
</property>
Expand All @@ -458,7 +458,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Macro Variables in Embedded Displays</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -480,7 +480,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Macro Variables and Related Display Buttons</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -502,7 +502,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Nested Embedded Displays</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -524,7 +524,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Python-based Display: Image Processing</string>
</property>
<property name="displayFilename" stdset="0">
Expand All @@ -546,7 +546,7 @@
<property name="whatsThis">
<string/>
</property>
<property name="text" stdset="0">
<property name="text">
<string>Python-based Display: Camera View Application</string>
</property>
<property name="displayFilename" stdset="0">
Expand Down Expand Up @@ -581,7 +581,7 @@
<customwidgets>
<customwidget>
<class>PyDMRelatedDisplayButton</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>pydm.widgets.related_display_button</header>
</customwidget>
</customwidgets>
Expand Down
11 changes: 9 additions & 2 deletions pydm/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import imp
import sys
import uuid
import signal
import subprocess
import re
Expand Down Expand Up @@ -250,7 +251,12 @@ def make_window(self, ui_file, macros=None, command_line_args=None):
main_window.move(main_window.x() + 10, main_window.y() + 10)

def close_window(self, window):
del self.windows[window]
try:
del self.windows[window]
except KeyError:
# If window is no longer at self.windows
# it means that we already closed it.
pass

def load_ui_file(self, uifile, macros=None):
"""
Expand Down Expand Up @@ -310,9 +316,10 @@ def load_py_file(self, pyfile, args=None, macros=None):
# Add the intelligence module directory to the python path, so that submodules can be loaded. Eventually, this should go away, and intelligence modules should behave as real python modules.
module_dir = os.path.dirname(os.path.abspath(pyfile))
sys.path.append(module_dir)
temp_name = str(uuid.uuid4())

# Now load the intelligence module.
module = imp.load_source('intelclass', pyfile)
module = imp.load_source(temp_name, pyfile)
self.__sanity_check_pyqt(module)
if hasattr(module, 'intelclass'):
cls = module.intelclass
Expand Down
11 changes: 6 additions & 5 deletions pydm/display_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def ui_filename(self):
def load_ui(self, parent=None, macros=None):
if self.ui:
return self.ui
if macros is not None:
f = macro.substitute_in_file(self.ui_filepath(), macros)
else:
f = self.ui_filepath()
self.ui = uic.loadUi(f, baseinstance=self)
if self.ui_filepath() is not None and self.ui_filepath() != "":
if macros is not None:
f = macro.substitute_in_file(self.ui_filepath(), macros)
else:
f = self.ui_filepath()
self.ui = uic.loadUi(f, baseinstance=self)
Loading

0 comments on commit 9a3527e

Please sign in to comment.