Skip to content

Commit

Permalink
FIX: PyDM launcher and other issues with Windows (#199)
Browse files Browse the repository at this point in the history
* 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()

* FIX: Keep LF as line ending on pickle files.

* FIX: Normalize line endings for Pickle files.

* ENH: Adding path_info method to help solve issues between unix and windows for path and file info.

* FIX: Fix issue when opening a file under windows. Tested at a Windows 7 laptop in situations including paths with space on folder name.

* STY: PEP8.

* ENH: Switching to entry_points for the launch script in order to make it Universal across all the platforms (Windows included).

* MOV: Moving testing ioc and access rules to the examples folder under testing_ioc.

* ENH: Removing pydm and the scripts folder since now we are using the entry_points and the proper script is created.

* DOC: Updating the documentation to reflect the changes for the testing-ioc location.

* CI: Adding conda bld.bat file for Windows build.

* ENH: Removing pcaspy from setup.py.

* CI: Cleaning up travis.yml and adding OSX to the os targets.

* CI: Removing osx as Travis takes forever to run it. I will think about something later.
  • Loading branch information
hhslepicka authored and mattgibbs committed Dec 15, 2017
1 parent b75e5e9 commit a038fbe
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
@@ -1 +1,4 @@
pydm/_version.py export-subst

# Pickle files will always have LF endings on checkout
*.pkl binary
26 changes: 11 additions & 15 deletions .travis.yml
Expand Up @@ -2,32 +2,28 @@ language: python

env:
global:
# Variables just to silence pcaspy setup.
- EPICS_BASE=~
- EPICS_HOST_ARCH=linux-x86_64
- PYQT_VERSION=5
- OFFICIAL_REPO="slaclab/pydm"
- secure: "g7JqJMMB4LL0bM0h1rUN8bR2/CWt+jHLW+nknroyU6+kZc2oi6WLw7FSapCV23nJkyzoBZrvHokKBz/hml/lhp4wBuxWfm4E9h8qdyZgkA7OzWkJ2SxNvChi3mASLfvavkuIS/yCDxdhlcQsSNr3kdwkTRQuuKPqWuLzYLFHesCYOtWtRTn/9bzEPsvLp5/3ul+PY8ZsAdcdUEEJPgeW8P+JS960Jf4JsQ2QEl3ZOS3+l4SF7Z72yr0exmrWp8dt2rVuPXDLVHVos08Wx1tTL5Xwp8v33sAt9SHR40li+Q5KNHyA6ZC6Jgz7ZeDyxu39V7QvA55sF5+1J9UG0SrStmChbJ5lTeOx9wgxq6Ha8hrcsTaMPuk5eKcLvfZliSZ4lXxlSf8R/+HFrZNnS9DvrulWY/MVI4AdrON9RF9RDPGtfMyit8CKYOKp9XzKPDHeGFGZCfE9F0isLK/2YqIem63FwB1uFew6cFyRHIM1Ygtb7dzm/AE+dJhkY4iwR8jVnQF9qy7DwAAjbRohL40KvjcrZmn5rxH/VpPjxbifArEhtymYMgTGPfSgQAJO17yOcJdNKODZ/40qghlh0dv1loMxGPM73S9VLdsHqDQaaIptpQi2Z/y7pGVoiMPbZueQcSIkC04YKwJzKB1iCs2OQJ0g+kUdV4fFweMnUwa4umU="

matrix:
include:
- python: 2.7
env: PYQT_VERSION=5
- python: 3.5
env: PYQT_VERSION=5
- python: 3.6
env: PYQT_VERSION=5 BUILD_DOCS=1
- os: linux
python: 2.7
env: MC_URL="https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh"
- os: linux
python: 3.5
env: MC_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
- os: linux
python: 3.6
env: BUILD_DOCS=1 MC_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"

before_install:
# Make sure we have the tags no matter how far from them we are.
- git pull --unshallow
- sudo apt-get update
# We do this conditionally because it saves us some downloading if the
# version is the same.
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- wget $MC_URL -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
Expand Down
1 change: 1 addition & 0 deletions conda-recipe/bld.bat
@@ -0,0 +1 @@
"%PYTHON%" setup.py install
2 changes: 1 addition & 1 deletion docs/source/getting_started.rst
Expand Up @@ -151,7 +151,7 @@ somewhere.
We can test the display in PyDM by first running the testing IOC. Open up a new
terminal and run the command::

$ pydm-testing-ioc
$ python examples/testing_ioc/pydm-testing-ioc
to launch the IOC. Once the IOC is running, run the command::
Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 9 additions & 10 deletions pydm/application.py
Expand Up @@ -20,14 +20,15 @@
from .PyQt.QtGui import QApplication, QColor, QWidget, QToolTip, QClipboard
from .PyQt import uic
from .main_window import PyDMMainWindow
from .utilities import macro, which
from .utilities import macro, which, path_info
from . import data_plugins

DEFAULT_PROTOCOL = os.getenv("PYDM_DEFAULT_PROTOCOL")
if DEFAULT_PROTOCOL is not None:
# Get rid of the "://" part if it exists
DEFAULT_PROTOCOL = DEFAULT_PROTOCOL.split("://")[0]


class PyDMApplication(QApplication):
"""
PyDMApplication handles loading PyDM display files, opening
Expand Down Expand Up @@ -130,7 +131,6 @@ def exec_(self):
self.make_connections()
return super(PyDMApplication, self).exec_()


@pyqtSlot()
def get_CPU_usage(self):
"""
Expand Down Expand Up @@ -245,7 +245,7 @@ def make_window(self, ui_file, macros=None, command_line_args=None):
hide_status_bar=self.hide_status_bar)
main_window.open_file(ui_file, macros, command_line_args)
main_window.show()
self.windows[main_window] = os.path.dirname(ui_file)
self.windows[main_window] = path_info(ui_file)[0]
# If we are launching a new window, we don't want it to sit right on top of an existing window.
if len(self.windows) > 1:
main_window.move(main_window.x() + 10, main_window.y() + 10)
Expand Down Expand Up @@ -276,7 +276,7 @@ def load_ui_file(self, uifile, macros=None):
-------
QWidget
"""
if macros is not None:
if macros is not None and len(macros) > 0:
f = macro.substitute_in_file(uifile, macros)
else:
f = uifile
Expand Down Expand Up @@ -375,11 +375,11 @@ def open_file(self, ui_file, macros=None, command_line_args=None):
"""
# First split the ui_file string into a filepath and arguments
args = command_line_args if command_line_args is not None else []
split = shlex.split(ui_file)
filepath = split[0]
args.extend(split[1:])
self.directory_stack.append(os.path.dirname(filepath))
(filename, extension) = os.path.splitext(filepath)
dir_name, file_name, extra_args = path_info(ui_file)
args.extend(extra_args)
filepath = os.path.join(dir_name, file_name)
self.directory_stack.append(dir_name)
(filename, extension) = os.path.splitext(file_name)
if macros is None:
macros = {}
merged_macros = self.macro_stack[-1].copy()
Expand Down Expand Up @@ -485,7 +485,6 @@ def remove_connection(self, channel):
if plugin:
plugin.remove_connection(channel)


def eventFilter(self, obj, event):
# Override the eventFilter to capture all middle mouse button events,
# and show a tooltip if needed.
Expand Down
25 changes: 25 additions & 0 deletions pydm/utilities/__init__.py
Expand Up @@ -6,6 +6,9 @@

import os
import sys
import ntpath
import shlex


def is_pydm_app():
from ..application import PyDMApplication
Expand All @@ -16,6 +19,27 @@ def is_pydm_app():
else:
return False


def path_info(path_str):
"""
Returns
-------
tuple: base dir, file name, list of args
"""
if "win" in sys.platform:
os_path_mod = ntpath
else:
os_path_mod = os.path

dir_name, other_parts = os_path_mod.split(path_str)
split = shlex.split(other_parts)
file_name = split.pop(0)
args = split

return dir_name, file_name, args


try: # Forced testing
from shutil import which
except ImportError: # Forced testing
Expand All @@ -30,6 +54,7 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
path.
Note: This function was backported from the Python 3 source code.
"""

# Check that a given file can be accessed with the correct mode.
# Additionally check that `file` is not a directory, as on Windows
# directories pass the os.access check.
Expand Down
3 changes: 3 additions & 0 deletions pydm_launcher/__init__.py
@@ -0,0 +1,3 @@
__all__ = ['main']

from pydm_launcher import *
8 changes: 6 additions & 2 deletions scripts/pydm → pydm_launcher/main.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python
import sys
import argparse
from pydm import PyDMApplication
import json

if __name__ == "__main__":

def 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.')
Expand All @@ -22,3 +22,7 @@
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, hide_nav_bar=pydm_args.hide_nav_bar, hide_menu_bar=pydm_args.hide_menu_bar, hide_status_bar=pydm_args.hide_status_bar, macros=macros)
sys.exit(app.exec_())


if __name__ == "__main__":
main()
16 changes: 10 additions & 6 deletions setup.py
Expand Up @@ -20,16 +20,14 @@
'PySide': ['PySide'],
'pyepics': ['pyepics'],
'perf': ['psutil'],
'testing-ioc': ['pcaspy'],
'test': ['codecov', 'pytest', 'pytest-cov', 'coverage', 'coveralls', 'pcaspy']
'test': ['codecov', 'pytest', 'pytest-cov', 'coverage', 'coveralls']
}


if "CONDA_PREFIX" not in environ:
extras_require['PyQt5'] = ['PyQt5']
else:
print("******************************************************************")
print("* WARNING *")
print("* WARNING *")
print("******************************************************************")
print("Installing at an Anaconda Environment, to avoid naming conflicts ")
print("make sure you do:")
Expand All @@ -51,10 +49,16 @@
author='SLAC National Accelerator Laboratory',

packages=find_packages(),
package_dir={'pydm':'pydm', 'pydm_launcher':'pydm_launcher'},
description='Python Display Manager',
url='https://github.com/slaclab/pydm',
scripts=['scripts/pydm', 'scripts/pydm-testing-ioc'],
package_data={'pydm': ['data/access_rules.as']},
# scripts=['scripts/pydm', 'scripts/pydm-testing-ioc'],
# package_data={'pydm': ['data/access_rules.as']},
entry_points={
'gui_scripts': [
'pydm=pydm_launcher.main:main'
]
},
license='BSD',

install_requires=requirements,
Expand Down

0 comments on commit a038fbe

Please sign in to comment.