Skip to content

Commit

Permalink
Merged in cbillington/blacs/filepath_fix (pull request labscript-suit…
Browse files Browse the repository at this point in the history
…e#32)

Absolute imports, and don't use __file__
  • Loading branch information
chrisjbillington committed Mar 12, 2018
2 parents 0f8ac2c + fec45a3 commit ecf9905
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 33 deletions.
17 changes: 17 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,20 @@
#####################################################################

__version__ = '2.2.0'


import os
from labscript_utils import labscript_suite_install_dir
if labscript_suite_install_dir is not None:
BLACS_DIR = os.path.join(labscript_suite_install_dir, 'blacs')
else:
# No labscript install directory found? Fall back to relying on __file__ and
# hope that it is not a relative path that has been invalidated by a call to
# os.chdir() between interpreter start and now (this can happen if blacs is run
# with python 2 using "python -m blacs" whilst the current directory is the
# parent of the blacs directory):
BLACS_DIR = os.path.dirname(os.path.realpath(__file__))
if not os.path.isdir(BLACS_DIR):
# Don't want to continue if we have not found the directory:
msg = "Cannot locate the directory BLACS is installed in."
raise RuntimeError(msg)
18 changes: 9 additions & 9 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@


# Connection Table Code
from connections import ConnectionTable
from blacs.connections import ConnectionTable
#Draggable Tab Widget Code
from labscript_utils.qtwidgets.dragdroptab import DragDropTabWidget
# Lab config code
Expand All @@ -133,21 +133,21 @@
# And for icons:
import qtutils.icons
# Analysis Submission code
from analysis_submission import AnalysisSubmission
from blacs.analysis_submission import AnalysisSubmission
# Queue Manager Code
from experiment_queue import QueueManager, QueueTreeview
from blacs.experiment_queue import QueueManager, QueueTreeview
# Module containing hardware compatibility:
import labscript_devices
# Save/restore frontpanel code
from front_panel_settings import FrontPanelSettings
from blacs.front_panel_settings import FrontPanelSettings
# Notifications system
from notifications import Notifications
from blacs.notifications import Notifications
# Preferences system
from labscript_utils.settings import Settings
#import settings_pages
import plugins
import blacs.plugins as plugins

os.chdir(os.path.abspath(os.path.dirname(__file__)))
from blacs import BLACS_DIR


def set_win_appusermodel(window_id):
Expand All @@ -156,7 +156,7 @@ def set_win_appusermodel(window_id):
executable = sys.executable.lower()
if not executable.endswith('w.exe'):
executable = executable.replace('.exe', 'w.exe')
relaunch_command = executable + ' ' + os.path.abspath(__file__.replace('.pyc', '.py'))
relaunch_command = executable + ' ' + os.path.join(BLACS_DIR, '__main__.py')
relaunch_display_name = app_descriptions['blacs']
set_appusermodel(window_id, appids['blacs'], icon_path, relaunch_command, relaunch_display_name)

Expand Down Expand Up @@ -222,7 +222,7 @@ def __init__(self,application):
loader = UiLoader()
loader.registerCustomWidget(QueueTreeview)
#loader.registerCustomPromotion('BLACS',BLACSWindow)
self.ui = loader.load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'main.ui'), BLACSWindow())
self.ui = loader.load(os.path.join(BLACS_DIR, 'main.ui'), BLACSWindow())
logger.info('BLACS ui loaded')
self.ui.blacs=self
self.tab_widgets = {}
Expand Down
4 changes: 3 additions & 1 deletion analysis_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
from socket import gaierror
import labscript_utils.shared_drive
from labscript_utils.qtwidgets.elide_label import elide_label
from blacs import BLACS_DIR


class AnalysisSubmission(object):
def __init__(self, BLACS, blacs_ui):
self.inqueue = Queue.Queue()
self.BLACS = BLACS
self.port = int(self.BLACS.exp_config.get('ports', 'lyse'))

self._ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'analysis_submission.ui'))
self._ui = UiLoader().load(os.path.join(BLACS_DIR, 'analysis_submission.ui'))
blacs_ui.analysis.addWidget(self._ui)
self._ui.frame.setMinimumWidth(blacs_ui.queue_controls_frame.sizeHint().width())
elide_label(self._ui.resend_shots_label, self._ui.failed_to_send_frame.layout(), Qt.ElideRight)
Expand Down
5 changes: 4 additions & 1 deletion compile_and_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import runmanager
from qtutils.outputbox import OutputBox

from blacs import BLACS_DIR


class CompileAndRestart(QDialog):
def __init__(self, blacs, globals_files,connection_table_labscript, output_path, close_notification_func=None):
QDialog.__init__(self,blacs['ui'])
Expand All @@ -33,7 +36,7 @@ def __init__(self, blacs, globals_files,connection_table_labscript, output_path,
self.blacs = blacs
self.close_notification_func = close_notification_func

self.ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'compile_and_restart.ui'))
self.ui = UiLoader().load(os.path.join(BLACS_DIR, 'compile_and_restart.ui'))
self.output_box = OutputBox(self.ui.verticalLayout)
self.ui.restart.setEnabled(False)

Expand Down
15 changes: 8 additions & 7 deletions device_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import labscript_utils.excepthook
from qtutils import UiLoader

from tab_base_classes import Tab, Worker, define_state
from tab_base_classes import MODE_MANUAL, MODE_TRANSITION_TO_BUFFERED, MODE_TRANSITION_TO_MANUAL, MODE_BUFFERED
from output_classes import AO, DO, DDS
from blacs import BLACS_DIR
from blacs.tab_base_classes import Tab, Worker, define_state
from blacs.tab_base_classes import MODE_MANUAL, MODE_TRANSITION_TO_BUFFERED, MODE_TRANSITION_TO_MANUAL, MODE_BUFFERED
from blacs.output_classes import AO, DO, DDS
from labscript_utils.qtwidgets.toolpalette import ToolPaletteGroup


Expand Down Expand Up @@ -445,7 +446,7 @@ def check_remote_values(self):
changed = True

if changed:
ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'tab_value_changed_dds.ui'))
ui = UiLoader().load(os.path.join(BLACS_DIR, 'tab_value_changed_dds.ui'))
ui.channel_label.setText(self._DDS[channel].name)
for sub_chnl in front_value:
ui.__getattribute__('front_%s_value'%sub_chnl).setText(front_values_formatted[sub_chnl])
Expand All @@ -464,7 +465,7 @@ def check_remote_values(self):
remote_value = str(bool(int(remote_value)))
if front_value != remote_value:
changed = True
ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'tab_value_changed.ui'))
ui = UiLoader().load(os.path.join(BLACS_DIR, 'tab_value_changed.ui'))
ui.channel_label.setText(self._DO[channel].name)
ui.front_value.setText(front_value)
ui.remote_value.setText(remote_value)
Expand All @@ -474,7 +475,7 @@ def check_remote_values(self):
remote_value = ("%."+str(self._AO[channel]._decimals)+"f")%remote_value
if front_value != remote_value:
changed = True
ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'tab_value_changed.ui'))
ui = UiLoader().load(os.path.join(BLACS_DIR, 'tab_value_changed.ui'))
ui.channel_label.setText(self._AO[channel].name)
ui.front_value.setText(front_value)
ui.remote_value.setText(remote_value)
Expand Down Expand Up @@ -703,7 +704,7 @@ def transition_to_manual(self):
import logging.handlers
# Setup logging:
logger = logging.getLogger('BLACS')
handler = logging.handlers.RotatingFileHandler('BLACS.log', maxBytes=1024**2, backupCount=0)
handler = logging.handlers.RotatingFileHandler(os.path.join(BLACS_DIR, 'BLACS.log'), maxBytes=1024**2, backupCount=0)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s: %(message)s')
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion experiment_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from labscript_utils.qtwidgets.elide_label import elide_label

# Connection Table Code
from connections import ConnectionTable
from blacs.connections import ConnectionTable
from blacs.tab_base_classes import MODE_MANUAL, MODE_TRANSITION_TO_BUFFERED, MODE_TRANSITION_TO_MANUAL, MODE_BUFFERED

FILEPATH_COLUMN = 0
Expand Down
7 changes: 4 additions & 3 deletions notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os

from qtutils import UiLoader
from blacs import BLACS_DIR

logger = logging.getLogger('BLACS.NotificationManager')

Expand Down Expand Up @@ -50,7 +51,7 @@ def add_notification(self, notification_class):
get_state = lambda: self.get_state(notification_class)

# create layout/widget with appropriate buttons and the widget from the notification class
ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'notification_widget.ui'))
ui = UiLoader().load(os.path.join(BLACS_DIR, 'notification_widget.ui'))
ui.hide_button.setVisible(bool(properties['can_hide']))
ui.hide_button.clicked.connect(lambda: hide_func(True))
ui.close_button.setVisible(bool(properties['can_close']))
Expand All @@ -76,7 +77,7 @@ def add_notification(self, notification_class):


#TODO: Make the minimized widget
ui2 = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'notification_minimized_widget.ui'))
ui2 = UiLoader().load(os.path.join(BLACS_DIR, 'notification_minimized_widget.ui'))
#ui2.hide()
if not hasattr(self._notifications[notification_class], 'name'):
self._notifications[notification_class].name = notification_class.__name__
Expand Down Expand Up @@ -153,4 +154,4 @@ def close_all(self):
notification.close()
except:
pass


7 changes: 4 additions & 3 deletions plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import logging
import importlib
from labscript_utils.labconfig import LabConfig
from blacs import BLACS_DIR
PLUGINS_DIR = os.path.join(BLACS_DIR, 'plugins')

default_plugins = ['connection_table', 'general', 'memory', 'theme']

Expand All @@ -26,9 +28,8 @@
exp_config.add_section('BLACS/plugins')

modules = {}
this_dir = os.path.dirname(os.path.abspath(__file__))
for module_name in os.listdir(this_dir):
if os.path.isdir(os.path.join(this_dir, module_name)):
for module_name in os.listdir(PLUGINS_DIR):
if os.path.isdir(os.path.join(PLUGINS_DIR, module_name)):
# is it a new plugin?
# If so lets add it to the config
if not module_name in [name for name, val in exp_config.items('BLACS/plugins')]:
Expand Down
5 changes: 3 additions & 2 deletions plugins/connection_table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from blacs.compile_and_restart import CompileAndRestart
from labscript_utils.filewatcher import FileWatcher
from qtutils import *
from blacs.plugins import PLUGINS_DIR

FILEPATH_COLUMN = 0
name = "Connection Table"
Expand Down Expand Up @@ -128,7 +129,7 @@ def __init__(self, BLACS):
self.filewatcher = None

# Create the widget
self._ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'notification.ui'))
self._ui = UiLoader().load(os.path.join(PLUGINS_DIR, module, 'notification.ui'))
self._ui.button.clicked.connect(self.on_recompile_connection_table)
#self._ui.hide()

Expand Down Expand Up @@ -198,7 +199,7 @@ def __init__(self,data):

# Create the page, return the page and an icon to use on the label (the class name attribute will be used for the label text)
def create_dialog(self,notebook):
ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'connection_table.ui'))
ui = UiLoader().load(os.path.join(PLUGINS_DIR, module, 'connection_table.ui'))

# Create the models, get the views, and link them!!
self.models = {}
Expand Down
3 changes: 2 additions & 1 deletion plugins/delete_repeated_shots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from labscript_utils.shared_drive import path_to_agnostic
import zprocess.locking
from blacs.plugins import PLUGINS_DIR

name = "Delete repeated shots"
module = "delete_repeated_shots" # should be folder name
Expand Down Expand Up @@ -49,7 +50,7 @@ def plugin_setup_complete(self, BLACS):
self.BLACS = BLACS

# Add our controls to the BLACS UI:
self.ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'controls.ui'))
self.ui = UiLoader().load(os.path.join(PLUGINS_DIR, module, 'controls.ui'))
BLACS['ui'].queue_controls_frame.layout().addWidget(self.ui)

# Restore settings to the GUI controls:
Expand Down
5 changes: 3 additions & 2 deletions plugins/general/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import os

from qtutils import UiLoader

from blacs.plugins import PLUGINS_DIR

class Plugin(object):
def __init__(self, initial_settings):
self.menu = None
Expand Down Expand Up @@ -69,7 +70,7 @@ def __init__(self,data):

# Create the GTK page, return the page and an icon to use on the label (the class name attribute will be used for the label text)
def create_dialog(self,notebook):
ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'general.ui'))
ui = UiLoader().load(os.path.join(PLUGINS_DIR, 'general', 'general.ui'))

# get the widgets!
self.widgets = {}
Expand Down
4 changes: 3 additions & 1 deletion plugins/theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from qtutils import *

from blacs.plugins import PLUGINS_DIR

name = "GUI Theme"
module = "theme" # should be folder name
logger = logging.getLogger('BLACS.plugin.%s'%module)
Expand Down Expand Up @@ -169,7 +171,7 @@ def on_set_green_button_theme(self):

# Create the page, return the page and an icon to use on the label (the class name attribute will be used for the label text)
def create_dialog(self,notebook):
ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'theme.ui'))
ui = UiLoader().load(os.path.join(PLUGINS_DIR, module, 'theme.ui'))

# restore current stylesheet
ui.stylesheet_text.setPlainText(self.data['stylesheet'])
Expand Down
5 changes: 3 additions & 2 deletions tab_base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import qtutils.icons

from labscript_utils.qtwidgets.elide_label import elide_label
from blacs import BLACS_DIR

class Counter(object):
"""A class with a single method that
Expand Down Expand Up @@ -246,7 +247,7 @@ def __init__(self,notebook,settings,restart=False):
self._restart_receiver = []

# Load the UI
self._ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'tab_frame.ui'))
self._ui = UiLoader().load(os.path.join(BLACS_DIR, 'tab_frame.ui'))
self._layout = self._ui.device_layout
self._device_widget = self._ui.device_controls
self._changed_widget = self._ui.changed_widget
Expand Down Expand Up @@ -992,7 +993,7 @@ def baz(self,zzz,*args,**kwargs):
import logging.handlers
# Setup logging:
logger = logging.getLogger('BLACS')
handler = logging.handlers.RotatingFileHandler('BLACS.log', maxBytes=1024**2, backupCount=0)
handler = logging.handlers.RotatingFileHandler(os.path.join(BLACS_DIR, 'BLACS.log'), maxBytes=1024**2, backupCount=0)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s: %(message)s')
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
Expand Down

0 comments on commit ecf9905

Please sign in to comment.