Skip to content

Commit 94d731c

Browse files
authored
Merge pull request #113 from dihm/qt_star_removal
Qt star imports removal
2 parents 3ae9136 + 67176a9 commit 94d731c

10 files changed

Lines changed: 74 additions & 49 deletions

blacs/__main__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@
3535
WINDOWS = platform.system() == 'Windows'
3636

3737
# No splash update for Qt - the splash code has already imported it:
38-
import qtutils
39-
from qtutils import *
40-
import qtutils.icons
41-
from qtutils.qt.QtCore import *
42-
from qtutils.qt.QtGui import *
43-
from qtutils.qt.QtWidgets import *
38+
from qtutils import inmain_decorator, inmain_later, inmain, inthread, UiLoader
39+
import qtutils.icons # import has side-effects we rely on
40+
from qtutils.qt.QtCore import PYQT_VERSION_STR, QT_VERSION_STR, QTimer, Qt
41+
from qtutils.qt.QtGui import QIcon
42+
from qtutils.qt.QtWidgets import (
43+
QMainWindow,
44+
QToolButton,
45+
QMessageBox,
46+
QFileDialog,
47+
QApplication
48+
)
4449
from qtutils.qt import QT_ENV
4550

4651

@@ -166,7 +171,7 @@ def on_click(self):
166171
# Ensure they can't run the game twice at once:
167172
self.setEnabled(False)
168173
# Wait for the subprocess in a thread so that we know when it quits:
169-
qtutils.inthread(self.run_measure_ball)
174+
inthread(self.run_measure_ball)
170175

171176
def run_measure_ball(self):
172177
try:

blacs/analysis_submission.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
import sys
1818
import queue
1919

20-
from qtutils.qt.QtCore import *
21-
from qtutils.qt.QtGui import *
22-
from qtutils.qt.QtWidgets import *
20+
from qtutils.qt.QtCore import Qt, QSize
21+
from qtutils.qt.QtGui import QIcon
2322

24-
from qtutils import *
23+
from qtutils import inmain_decorator, UiLoader
2524
from zprocess import TimeoutError, raise_exception_in_thread
2625
from zprocess.security import AuthenticationFailure
2726
from labscript_utils.ls_zprocess import zmq_get

blacs/compile_and_restart.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
import os
1414
import shutil
1515

16-
from qtutils.qt.QtCore import *
17-
from qtutils.qt.QtGui import *
18-
from qtutils.qt.QtWidgets import *
16+
from qtutils.qt.QtCore import Qt, QTimer
17+
from qtutils.qt.QtWidgets import QDialog
1918

20-
from qtutils import *
19+
from qtutils import inmain_decorator, UiLoader
2120
import runmanager
2221
from labscript_utils.qtwidgets.outputbox import OutputBox
2322

blacs/device_base_class.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@
1616
import time
1717
from queue import Queue
1818

19-
from qtutils.qt.QtCore import *
20-
from qtutils.qt.QtGui import *
21-
from qtutils.qt.QtWidgets import *
19+
from qtutils.qt.QtCore import QTimer
20+
from qtutils.qt.QtGui import QIcon
21+
from qtutils.qt.QtWidgets import (
22+
QWidget,
23+
QSpacerItem,
24+
QSizePolicy,
25+
QPushButton,
26+
QHBoxLayout,
27+
QApplication,
28+
QVBoxLayout,
29+
)
2230

2331
import labscript_utils.excepthook
2432
from qtutils import UiLoader
@@ -339,15 +347,15 @@ def auto_place_widgets(self,*args):
339347
for arg in args:
340348
# A default sort algorithm that just returns the object (this is equivalent to not specifying the sort gorithm)
341349
sort_algorithm = lambda x: x
342-
if type(arg) == type(()) and len(arg) > 1 and type(arg[1]) == type({}) and len(arg[1].keys()) > 0:
350+
if isinstance(arg, tuple) and len(arg) > 1 and isinstance(arg[1], dict) and len(arg[1].keys()) > 0:
343351
# we have a name, use it!
344352
name = arg[0]
345353
widget_dict = arg[1]
346354
if len(arg) > 2:
347355
sort_algorithm = arg[2]
348356
else:
349357
# ignore things that are not dictionaries or empty dictionaries
350-
if type(arg) != type({}) or len(arg.keys()) < 1:
358+
if not isinstance(arg, dict) or len(arg.keys()) < 1:
351359
continue
352360
if isinstance(self.get_channel(list(arg.keys())[0]),AO):
353361
name = 'Analog Outputs'
@@ -472,7 +480,7 @@ def check_remote_values(self):
472480

473481
# If no results were returned, raise an exception so that we don't keep calling this function over and over again,
474482
# filling up the text box with the same error, eventually consuming all CPU/memory of the PC
475-
if not self._last_remote_values or type(self._last_remote_values) != type({}):
483+
if not self._last_remote_values or not isinstance(self._last_programmed_values, dict):
476484
raise Exception('Failed to get remote values from device. Is it still connected?')
477485

478486
# A variable to indicate if any of the channels have a changed value

blacs/experiment_queue.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@
2222
from tempfile import gettempdir
2323
from binascii import hexlify
2424

25-
from qtutils.qt.QtCore import *
26-
from qtutils.qt.QtGui import *
27-
from qtutils.qt.QtWidgets import *
25+
from qtutils.qt.QtCore import Qt, QItemSelectionModel
26+
from qtutils.qt.QtGui import QIcon, QAction, QStandardItemModel, QStandardItem
27+
from qtutils.qt.QtWidgets import (
28+
QTreeView,
29+
QMenu,
30+
QFileDialog,
31+
)
2832

2933
import zprocess
3034
from labscript_utils.ls_zprocess import ProcessTree
3135
process_tree = ProcessTree.instance()
3236
import labscript_utils.h5_lock, h5py
3337

34-
from qtutils import *
38+
from qtutils import inmain_decorator, inmain
3539

3640
from labscript_utils.qtwidgets.elide_label import elide_label
3741
from labscript_utils.connections import ConnectionTable
@@ -988,7 +992,7 @@ def restart_function(device_name):
988992
message = self.process_request(path)
989993
except Exception:
990994
# TODO: make this error popup for the user
991-
self._logger.exception('Failed to copy h5_file (%s) for repeat run'%s)
995+
self._logger.exception('Failed to copy h5_file (%s) for repeat run' % path)
992996
logger.info(message)
993997

994998
self.set_status("Idle")

blacs/front_panel_settings.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
import os
1414
import logging
1515

16-
from qtutils.qt.QtCore import *
17-
from qtutils.qt.QtGui import *
18-
from qtutils.qt.QtWidgets import *
16+
from qtutils.qt.QtWidgets import QMessageBox
1917

2018
import labscript_utils.excepthook
2119
import numpy
2220
import labscript_utils.h5_lock, h5py
23-
from qtutils import *
21+
from qtutils import inmain_decorator
2422

2523
from labscript_utils.connections import ConnectionTable
2624

@@ -137,7 +135,7 @@ def handle_return_code(self,row,result,settings,question,error):
137135
# This is because we have the original channel, and the moved channel in the same place
138136
#-1: Device no longer in the connection table, throw error
139137
#-2: Device parameters not compatible, throw error
140-
if type(result) == tuple:
138+
if isinstance(result, tuple):
141139
connection = result[1]
142140
result = result[0]
143141

@@ -285,7 +283,7 @@ def save_front_panel_to_h5(self,current_file,states,tab_positions,window_data,pl
285283

286284
if save_conn_table or result:
287285
with h5py.File(current_file,'r+') as hdf5_file:
288-
if hdf5_file['/'].get('front_panel') != None:
286+
if hdf5_file['/'].get('front_panel') is not None:
289287
# Create a dialog to ask whether we can overwrite!
290288
overwrite = False
291289
if not silent:

blacs/output_classes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
import math
1515
import sys
1616

17-
from qtutils.qt.QtCore import *
18-
from qtutils.qt.QtGui import *
19-
from qtutils.qt.QtWidgets import *
17+
from qtutils.qt.QtCore import Qt
18+
from qtutils.qt.QtGui import QStandardItemModel, QStandardItem
19+
from qtutils.qt.QtWidgets import (
20+
QApplication,
21+
QWidget,
22+
QVBoxLayout,
23+
QSpacerItem,
24+
QSizePolicy,
25+
)
2026

2127

2228
from labscript_utils.qtwidgets.analogoutput import AnalogOutput

blacs/plugins/connection_table/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
import sys
1717
import ast
1818

19-
from qtutils.qt.QtCore import *
20-
from qtutils.qt.QtGui import *
21-
from qtutils.qt.QtWidgets import *
19+
from qtutils.qt.QtCore import Qt
20+
from qtutils.qt.QtGui import QStandardItemModel, QStandardItem
21+
from qtutils.qt.QtWidgets import QMessageBox, QFileDialog
2222

2323
from blacs.compile_and_restart import CompileAndRestart
2424
from labscript_utils.filewatcher import FileWatcher
25-
from qtutils import *
25+
from qtutils import inmain, UiLoader
2626
from blacs.plugins import PLUGINS_DIR
2727

2828
FILEPATH_COLUMN = 0

blacs/plugins/theme/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import logging
1414
import os
1515

16-
from qtutils import *
16+
from qtutils import UiLoader
1717

1818
from blacs.plugins import PLUGINS_DIR
1919

blacs/tab_base_classes.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
from types import GeneratorType
2525
from bisect import insort
2626

27-
from qtutils.qt.QtCore import *
28-
from qtutils.qt.QtGui import *
29-
from qtutils.qt.QtWidgets import *
27+
from qtutils.qt.QtCore import Qt, QTimer
28+
from qtutils.qt.QtGui import QIcon, QColor
29+
from qtutils.qt.QtWidgets import QLabel, QWidget, QPushButton, QApplication, QVBoxLayout
3030

31-
from qtutils import *
31+
from qtutils import inmain_decorator, inmain, inthread, UiLoader
3232
from labscript_utils.qtwidgets.outputbox import OutputBox
3333
import qtutils.icons
3434

@@ -782,7 +782,7 @@ def mainloop(self):
782782
# run the function in the Qt main thread
783783
generator = inmain(func,self,*args,**kwargs)
784784
# Do any work that was queued up:(we only talk to the worker if work has been queued up through the yield command)
785-
if type(generator) == GeneratorType:
785+
if isinstance(generator, GeneratorType):
786786
# We need to call next recursively, queue up work and send the results back until we get a StopIteration exception
787787
generator_running = True
788788
# get the data from the first yield function
@@ -1087,7 +1087,7 @@ def initUI(self):
10871087
# appearance settings). You should never be calling queue_work
10881088
# or do_after from un undecorated callback.
10891089
@define_state(MODE_MANUAL,True)
1090-
def foo(self):
1090+
def foo(self,button=None):
10911091
self.logger.debug('entered foo')
10921092
#self.toplevel.set_sensitive(False)
10931093
# Here's how you instruct the worker process to do
@@ -1113,7 +1113,7 @@ def fatal(self):
11131113
self.queue_work('My worker','foo', 5,6,7,x='x')
11141114

11151115
@define_state(MODE_MANUAL,True)
1116-
def bar(self):
1116+
def bar(self,button):
11171117
self.logger.debug('entered bar')
11181118
results = yield(self.queue_work('My worker','bar', 5,6,7,x=5))
11191119

@@ -1134,7 +1134,7 @@ def baz(self, button=None):
11341134
# This event shows what happens if you try to send a unpickleable
11351135
# event through a queue to the subprocess:
11361136
@define_state(MODE_MANUAL,True)
1137-
def baz_unpickleable(self):
1137+
def baz_unpickleable(self, button):
11381138
self.logger.debug('entered baz_unpickleable')
11391139
results = yield(self.queue_work('My worker','baz', 5,6,7,x=threading.Lock()))
11401140
self.logger.debug('leaving baz_unpickleable')
@@ -1167,7 +1167,10 @@ def init(self):
11671167
# the former.
11681168
global serial; import serial
11691169
self.logger.info('got x! %d' % self.x)
1170-
raise Exception('bad import!')
1170+
# randomly fail this on init, but only occasionally
1171+
import random
1172+
if random.random() < 0.15:
1173+
raise Exception('bad import!')
11711174

11721175
# Here's a function that will be called when requested by the parent
11731176
# process. There's nothing special about it really. Its return
@@ -1195,6 +1198,8 @@ def baz(self,zzz,*args,**kwargs):
11951198
import sys
11961199
import logging.handlers
11971200
# Setup logging:
1201+
from labscript_utils.setup_logging import setup_logging
1202+
setup_logging('BLACS')
11981203
logger = logging.getLogger('BLACS')
11991204
handler = logging.handlers.RotatingFileHandler(os.path.join(BLACS_DIR, 'BLACS.log'), maxBytes=1024**2, backupCount=0)
12001205
formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s: %(message)s')
@@ -1222,6 +1227,7 @@ def baz(self,zzz,*args,**kwargs):
12221227
class FakeConnection(object):
12231228
def __init__(self):
12241229
self.BLACS_connection = 'None'
1230+
self.properties = {}
12251231
class FakeConnectionTable(object):
12261232
def __init__(self):
12271233
pass

0 commit comments

Comments
 (0)