From 2d5cb73def5e1ad0dd29ebfb69b43aa6f9deb42a Mon Sep 17 00:00:00 2001 From: David Honegger Rogers <dhr@lanl.gov> Date: Thu, 13 Apr 2017 14:48:56 -0600 Subject: [PATCH 1/2] reconciling clean changes from old branch to new one --- Cinema.py | 86 +++++++++++++++++++++++++++++------ MultiViewerMain.py | 1 - create_dmg | 7 +++ create_ui_files | 5 ++ doc/creating_build_machine.md | 17 +++---- makefile | 10 ++++ version | 1 + widgets/ControllersWidget.py | 2 +- 8 files changed, 106 insertions(+), 23 deletions(-) create mode 100755 create_dmg create mode 100755 create_ui_files create mode 100644 makefile create mode 100644 version diff --git a/Cinema.py b/Cinema.py index 624effb..975949b 100755 --- a/Cinema.py +++ b/Cinema.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # @description Cinema viewer application. Supports loading multiple databases # simultaneously. Either single or a multi-database directories can be loaded @@ -33,25 +33,85 @@ # particular database. import os -if os.path.exists("./widgets/uiFiles"): - # compile ui files as long as the dir exists - import pysideuic as uic - uic.compileUiDir("./widgets/uiFiles") +import argparse +import textwrap + +# --------------------------------------------------------------------- +# +# adjust path, depending upon use case. This fixes a bug for python +# applications that makes it crash, due to access permission for +# file open/close +# +# --------------------------------------------------------------------- +curpath = os.getcwd() +if not curpath.startswith( '/Users' ): + os.chdir( os.environ['HOME'] ) + +import sys +from PySide.QtGui import QApplication +from MultiViewerMain import ViewerMain +from common import DatabaseLoader + +# --------------------------------------------------------------------- +# +# application global variables +# +# --------------------------------------------------------------------- +APP_VERSION = "1.0" +APP_NOTDEFINED = "NOTDEFINED" + + +# --------------------------------------------------------------------- +# +# parse command line args +# +# --------------------------------------------------------------------- +conf_parser = argparse.ArgumentParser( + # Turn off help, so we print all options in response to -h + add_help=False + ) +args, remaining_argv = conf_parser.parse_known_args() + +# --------------------------------------------------------------------------- +# +# command line options +# +# --------------------------------------------------------------------------- +# Don't surpress add_help here so it will handle -h +parser = argparse.ArgumentParser( + # Don't mess with format of description + formatter_class=argparse.RawDescriptionHelpFormatter, + # Inherit options from config_parser + parents=[conf_parser], + # print script description with -h/--help + epilog=textwrap.dedent('''\ + examples: + + python Cinema.py (no args) + open the application and allow the user to open a file + through dialogue boxes. + ''') +) +parser.add_argument( "-v", "--verbose", action="store_true", default=False, + help="report verbosely") +parser.add_argument( "--version", action="version", version=APP_VERSION) +parser.add_argument( "--database", default=APP_NOTDEFINED, + help="open this file when application starts") +args = parser.parse_args(remaining_argv) -import sys # noqa: E402 -from PySide.QtGui import QApplication # noqa: E402 -from MultiViewerMain import ViewerMain # noqa: E402 -from common import DatabaseLoader # noqa: E402 # --------------------------------------------------------------------- # create the qt app a = QApplication(sys.argv) v = ViewerMain() -# parse arguments if any -argv = sys.argv -if len(argv) > 1: - databases, links = DatabaseLoader.loadAll(sys.argv[1]) +# --------------------------------------------------------------------- +# +# handle args +# +# --------------------------------------------------------------------- +if not ( args.database == APP_NOTDEFINED ): + databases, links = DatabaseLoader.loadAll( args.database ) v.setStores(databases, links) # ------------------- start profiling ------------------------------- diff --git a/MultiViewerMain.py b/MultiViewerMain.py index 4e5c4bb..c43dbe3 100644 --- a/MultiViewerMain.py +++ b/MultiViewerMain.py @@ -34,7 +34,6 @@ class ViewerMain(QMainWindow): self.__colorPicker = QColorDialog(self) self.__fileDialog = QFileDialog(self, "Open a Cinema Database", "~", "Cinema Databases (*.cdb)") - self.__fileDialog.setFileMode(QFileDialog.Directory) # Setup ui self.__ui.setupUi(self) diff --git a/create_dmg b/create_dmg new file mode 100755 index 0000000..15ee4ec --- /dev/null +++ b/create_dmg @@ -0,0 +1,7 @@ +#!/bin/bash + +CHID=$(git rev-parse HEAD) +VER=$(cat version) +OSX=$(sw_vers -productVersion) + +hdiutil create -volname cinema -srcfolder dist/Cinema.app -ov -format UDZO cinema_${VER}_OSX${OSX}_${CHID}.dmg diff --git a/create_ui_files b/create_ui_files new file mode 100755 index 0000000..885868a --- /dev/null +++ b/create_ui_files @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +import pysideuic as uic + +uic.compileUiDir("./widgets/uiFiles") diff --git a/doc/creating_build_machine.md b/doc/creating_build_machine.md index b512d7e..bda3594 100644 --- a/doc/creating_build_machine.md +++ b/doc/creating_build_machine.md @@ -23,17 +23,18 @@ These instructions assume that the OS is newly installed, and only minimal chang brew install pyside brew install pyside-tools pip install numpy - cd ~ + cd + mkdir LANL mkdir LANL/git cd LANL/git git clone https://gitlab.kitware.com/cinema/qt-viewer.git git clone https://gitlab.kitware.com/cinema/cinema_python.git - export PYTHONPATH=~/git/cinema_python + export PYTHONPATH=~/LANL/git/cinema_python -## create app +## test the viewer + cd qt-viewer + python Cinema.py - python setup.py py2app - -## create dmg - - hdiutil create -volname cinema -srcfolder dist/Cinema.app -ov -format UDZO cinema.dmg +## create app and dmg + cd qt-viewer + make diff --git a/makefile b/makefile new file mode 100644 index 0000000..6e7df68 --- /dev/null +++ b/makefile @@ -0,0 +1,10 @@ +PYTHON = /usr/bin/env python + +mac: + ./create_ui_files + ${PYTHON} setup.py py2app + ./create_dmg + rm -rf build .eggs dist + +clean: + rm -rf build .eggs dist MultiViewerMain.pyc cinema_*.dmg diff --git a/version b/version new file mode 100644 index 0000000..d3827e7 --- /dev/null +++ b/version @@ -0,0 +1 @@ +1.0 diff --git a/widgets/ControllersWidget.py b/widgets/ControllersWidget.py index 6be58ae..f7a223d 100644 --- a/widgets/ControllersWidget.py +++ b/widgets/ControllersWidget.py @@ -217,7 +217,7 @@ class ControllersWidget(QWidget): if ('label' in storeParameters[k]): s.setTitle(storeParameters[k]['label']) else: - s.setTitle(storeParameters[k]) + s.setTitle(k) s.queryChanged.connect(self.__onQueryChanged) self.__ui.wRangeParams.layout().addWidget(s) -- GitLab From 37fbf4e780d2543540d98d02e52d59c6145ae2ae Mon Sep 17 00:00:00 2001 From: David Honegger Rogers <dhr@lanl.gov> Date: Thu, 13 Apr 2017 14:48:56 -0600 Subject: [PATCH 2/2] updated previous commit --- .gitignore | 6 +++ .gitlab-ci.yml | 8 ++++ Cinema.py | 86 +++++++++++++++++++++++++++++------ MultiViewerMain.py | 1 - create_dmg | 7 +++ create_ui_files | 5 ++ doc/creating_build_machine.md | 17 +++---- makefile | 10 ++++ version | 1 + widgets/ControllersWidget.py | 2 +- 10 files changed, 120 insertions(+), 23 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100755 create_dmg create mode 100755 create_ui_files create mode 100644 makefile create mode 100644 version diff --git a/.gitignore b/.gitignore index 52a14cb..b4a9cd5 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,9 @@ ui_*.py # vim files *.swp *.vim + +# build and dist files +.eggs/ +build/ +dist/ +cinema_*.dmg diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..afdae4c --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,8 @@ +test: + tags: + - osx + script: + - echo hostname + - export PYTHONPATH=~/LANL/git/cinema_python + - make mac + - mv cinema_*.dmg ~/Desktop/. diff --git a/Cinema.py b/Cinema.py index 624effb..975949b 100755 --- a/Cinema.py +++ b/Cinema.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # @description Cinema viewer application. Supports loading multiple databases # simultaneously. Either single or a multi-database directories can be loaded @@ -33,25 +33,85 @@ # particular database. import os -if os.path.exists("./widgets/uiFiles"): - # compile ui files as long as the dir exists - import pysideuic as uic - uic.compileUiDir("./widgets/uiFiles") +import argparse +import textwrap + +# --------------------------------------------------------------------- +# +# adjust path, depending upon use case. This fixes a bug for python +# applications that makes it crash, due to access permission for +# file open/close +# +# --------------------------------------------------------------------- +curpath = os.getcwd() +if not curpath.startswith( '/Users' ): + os.chdir( os.environ['HOME'] ) + +import sys +from PySide.QtGui import QApplication +from MultiViewerMain import ViewerMain +from common import DatabaseLoader + +# --------------------------------------------------------------------- +# +# application global variables +# +# --------------------------------------------------------------------- +APP_VERSION = "1.0" +APP_NOTDEFINED = "NOTDEFINED" + + +# --------------------------------------------------------------------- +# +# parse command line args +# +# --------------------------------------------------------------------- +conf_parser = argparse.ArgumentParser( + # Turn off help, so we print all options in response to -h + add_help=False + ) +args, remaining_argv = conf_parser.parse_known_args() + +# --------------------------------------------------------------------------- +# +# command line options +# +# --------------------------------------------------------------------------- +# Don't surpress add_help here so it will handle -h +parser = argparse.ArgumentParser( + # Don't mess with format of description + formatter_class=argparse.RawDescriptionHelpFormatter, + # Inherit options from config_parser + parents=[conf_parser], + # print script description with -h/--help + epilog=textwrap.dedent('''\ + examples: + + python Cinema.py (no args) + open the application and allow the user to open a file + through dialogue boxes. + ''') +) +parser.add_argument( "-v", "--verbose", action="store_true", default=False, + help="report verbosely") +parser.add_argument( "--version", action="version", version=APP_VERSION) +parser.add_argument( "--database", default=APP_NOTDEFINED, + help="open this file when application starts") +args = parser.parse_args(remaining_argv) -import sys # noqa: E402 -from PySide.QtGui import QApplication # noqa: E402 -from MultiViewerMain import ViewerMain # noqa: E402 -from common import DatabaseLoader # noqa: E402 # --------------------------------------------------------------------- # create the qt app a = QApplication(sys.argv) v = ViewerMain() -# parse arguments if any -argv = sys.argv -if len(argv) > 1: - databases, links = DatabaseLoader.loadAll(sys.argv[1]) +# --------------------------------------------------------------------- +# +# handle args +# +# --------------------------------------------------------------------- +if not ( args.database == APP_NOTDEFINED ): + databases, links = DatabaseLoader.loadAll( args.database ) v.setStores(databases, links) # ------------------- start profiling ------------------------------- diff --git a/MultiViewerMain.py b/MultiViewerMain.py index 4e5c4bb..c43dbe3 100644 --- a/MultiViewerMain.py +++ b/MultiViewerMain.py @@ -34,7 +34,6 @@ class ViewerMain(QMainWindow): self.__colorPicker = QColorDialog(self) self.__fileDialog = QFileDialog(self, "Open a Cinema Database", "~", "Cinema Databases (*.cdb)") - self.__fileDialog.setFileMode(QFileDialog.Directory) # Setup ui self.__ui.setupUi(self) diff --git a/create_dmg b/create_dmg new file mode 100755 index 0000000..15ee4ec --- /dev/null +++ b/create_dmg @@ -0,0 +1,7 @@ +#!/bin/bash + +CHID=$(git rev-parse HEAD) +VER=$(cat version) +OSX=$(sw_vers -productVersion) + +hdiutil create -volname cinema -srcfolder dist/Cinema.app -ov -format UDZO cinema_${VER}_OSX${OSX}_${CHID}.dmg diff --git a/create_ui_files b/create_ui_files new file mode 100755 index 0000000..885868a --- /dev/null +++ b/create_ui_files @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +import pysideuic as uic + +uic.compileUiDir("./widgets/uiFiles") diff --git a/doc/creating_build_machine.md b/doc/creating_build_machine.md index b512d7e..bda3594 100644 --- a/doc/creating_build_machine.md +++ b/doc/creating_build_machine.md @@ -23,17 +23,18 @@ These instructions assume that the OS is newly installed, and only minimal chang brew install pyside brew install pyside-tools pip install numpy - cd ~ + cd + mkdir LANL mkdir LANL/git cd LANL/git git clone https://gitlab.kitware.com/cinema/qt-viewer.git git clone https://gitlab.kitware.com/cinema/cinema_python.git - export PYTHONPATH=~/git/cinema_python + export PYTHONPATH=~/LANL/git/cinema_python -## create app +## test the viewer + cd qt-viewer + python Cinema.py - python setup.py py2app - -## create dmg - - hdiutil create -volname cinema -srcfolder dist/Cinema.app -ov -format UDZO cinema.dmg +## create app and dmg + cd qt-viewer + make diff --git a/makefile b/makefile new file mode 100644 index 0000000..6e7df68 --- /dev/null +++ b/makefile @@ -0,0 +1,10 @@ +PYTHON = /usr/bin/env python + +mac: + ./create_ui_files + ${PYTHON} setup.py py2app + ./create_dmg + rm -rf build .eggs dist + +clean: + rm -rf build .eggs dist MultiViewerMain.pyc cinema_*.dmg diff --git a/version b/version new file mode 100644 index 0000000..d3827e7 --- /dev/null +++ b/version @@ -0,0 +1 @@ +1.0 diff --git a/widgets/ControllersWidget.py b/widgets/ControllersWidget.py index 6be58ae..f7a223d 100644 --- a/widgets/ControllersWidget.py +++ b/widgets/ControllersWidget.py @@ -217,7 +217,7 @@ class ControllersWidget(QWidget): if ('label' in storeParameters[k]): s.setTitle(storeParameters[k]['label']) else: - s.setTitle(storeParameters[k]) + s.setTitle(k) s.queryChanged.connect(self.__onQueryChanged) self.__ui.wRangeParams.layout().addWidget(s) -- GitLab