Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# from timeit import Timer
import time
# import os
# from datetime import timedelta
from threading import Thread
import random
from six.moves import range
from six.moves import input
# import struct
class Client(HasTraits):
command = Property(String('GetData', enter_set=True, auto_set=False),
depends_on='_command')
_command = Str
resend = Button
receive_data_stream = Button
response = String
port = Int(1069)
# port = Int(8080)
# host = Str('192.168.0.65')
# host = Str('129.138.12.145')
host = 'localhost'
path = None
kind = Enum('IPC', 'UDP', 'TCP')
period = Float(100)
periodic = Event
periodic_label = Property(depends_on='_alive')
# The currently selected SVG file.
current_file = Str()
abs_current_file = Property(depends_on=['current_file'])
# The current XML ElementTree root Element and its XMLTree view model.
current_xml = Any()
current_xml_view = Any()
# The profilers.
profile_this = Instance(ProfileThis, args=())
#### GUI traits ############################################################
# The text showing the current mouse coordinates over any of the components.
mouse_coords = Property(Str, depends_on=['ch_controller.svg_coords'])
# Move forward and backward through the list of SVG files.
move_forward = Button('>>')
move_backward = Button('<<')
# The description of the test.
description = HTML()
document = Instance(document.SVGDocument)
# The components to view.
kiva_component = ComponentTrait(klass=SVGComponent)
ref_component = ComponentTrait(klass=ImageComponent, args=())
ch_controller = Instance(MultiController)
# The profiler views.
#: Flag, if "True" (not default), the transfer function is
#: cached in h5 files and does not have to be recomputed during subsequent
#: program runs.
#: Be aware that setting this to "True" may result in high memory usage.
cached = Bool(False,
desc="cache flag for transfer function")
# Sound travel distances from microphone array center to grid
# points or reference position (readonly). Feature may change.
r0 = Property(desc="array center to grid distances")
# Sound travel distances from array microphones to grid
# points (readonly). Feature may change.
rm = Property(desc="all array mics to grid distances")
_ref = Any(array([0.,0.,0.]),
desc="reference position or distance")
#: Reference position or distance at which to evaluate the sound pressure
#: of a grid point. Defaults to [0.,0.,0.].
ref = Property(desc="reference position or distance")
def _set_ref (self, ref):
if isscalar(ref):
try:
self._ref = absolute(float(ref))
except:
raise TraitError(args=self,
name='ref',
info='Float or CArray(3,)',
# ============= local library imports ==========================
class MassSpecExportSpec(Loggable):
runid = CStr
labnumber = CStr
aliquot = Either(CInt, Str)
step = Str
irradpos = CStr
isotopes = Dict
mass_spectrometer = Str
extract_device = Str
tray = Str
position = Property(depends_on='_position')
_position = Any
timestamp = Float
power_requested = Float(0)
power_achieved = Float(0)
extract_value = Float(0)
duration = Float(0)
cleanup = Float(0)
duration_at_request = Float(0)
first_stage_delay = CInt(0)
runscript_name = Str
runscript_text = Str
comment = Str
# data_path = Str
if percent == 0.0:
db = float('-inf')
else:
db = 20 * math.log10(percent / 100.0)
return db
def db_to_percent(db):
percent = math.pow(10, db / 20.0 + 2)
return percent
class VUMeter(Component):
# Value expressed in dB
db = Property(Float)
# Value expressed as a percent.
percent = Range(low=0.0)
# The maximum value to be display in the VU Meter, expressed as a percent.
max_percent = Float(150.0)
# Angle (in degrees) from a horizontal line through the hinge of the
# needle to the edge of the meter axis.
angle = Float(45.0)
# Values of the percentage-based ticks; these are drawn and labeled along
# the bottom of the curve axis.
percent_ticks = List(list(sm.range(0, 101, 20)))
# Text to write in the middle of the VU Meter.
c = item.color
if hasattr(c, '__iter__'):
c = [x * 255 for x in c]
return c
def get_text_color(self, obj, trait, row, column=0):
item = getattr(obj, trait)[row]
color = 'black'
if hasattr(item.color, '__iter__'):
if sum(item.color[:3]) < 1.5:
color = 'white'
return color
class BaseLoadPane(TraitsDockPane):
display_load_name = Property(depends_on='model.load_name')
# display_tray_name = Property(depends_on='model.tray')
def _get_display_load_name(self):
if self.model.load_instance:
ret = '<font color="blue" size="12"><b>{} ({}) {}</b></font>'.format(self.model.load_instance.name,
self.model.tray,
self.model.load_instance.create_date)
else:
ret = ''
return ret
class PositionTableConfigurer(TableConfigurer):
id = 'position_table'
class StatsGroup(Loggable):
experiment_queues = List
active_queue = Any
nruns = Int
etf = String
start_at = String
end_at = String
nruns_finished = Int
run_duration = String
current_run_duration = String
_timer = Any
elapsed = Property(depends_on='_elapsed')
_elapsed = Float
run_elapsed = Property(depends_on='_run_elapsed')
_run_elapsed = Float
total_time = Property(depends_on='_total_time')
_total_time = Float
remaining = Property(depends_on='_elapsed, _total_time')
_post = None
_run_start = 0
# not used
def continue_run(self):
pass
editable_traits = [trait for trait in self.editable_traits()
if trait in whitelist]
if 'value' in editable_traits:
i = editable_traits.index('value')
v = editable_traits.pop(i)
editable_traits.insert(i, Item(
v, editor=RangeEditor(low_name='bmin', high_name='bmax')))
view = View(editable_traits, buttons=['OK', 'Cancel'])
return view
@add_gui_method(toolkey="hyperspy.Component")
class Component(t.HasTraits):
__axes_manager = None
active = t.Property(t.CBool(True))
name = t.Property(t.Str(''))
def __init__(self, parameter_name_list):
self.events = Events()
self.events.active_changed = Event("""
Event that triggers when the `Component.active` changes.
The event triggers after the internal state of the `Component` has
been updated.
Arguments
---------
obj : Component
The `Component` that the event belongs to
active : bool
The new active state
"""
class ScriptedComponent(Component):
""" An Enable component that draws its mainlayer from a script """
#: kiva drawing code for mainlayer
draw_script = Code(default_script)
#: any errors which occur
error = Str
#: how long did the last draw take
last_draw_time = Float(0.0)
fps_display = Property(Str, depends_on='last_draw_time')
#: compiled code
_draw_code = Any
def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
""" Try running the compiled code with the graphics context as `gc` """
with gc:
try:
self.error = ''
start_time = time.time()
exec(self._draw_code, {}, {'gc': gc})
self.last_draw_time = time.time() - start_time
except Exception as exc:
self.error = str(exc)
def _compile_script(self):
)
# Help
instructions = help_str
# Console
console_log = String("PyBERT Console Log\n\n")
# Dependent variables
# - Handled by the Traits/UI machinery. (Should only contain "low overhead" variables, which don't freeze the GUI noticeably.)
#
# - Note: Don't make properties, which have a high calculation overhead, dependencies of other properties!
# This will slow the GUI down noticeably.
jitter_info = Property(HTML, depends_on=["jitter_perf"])
perf_info = Property(HTML, depends_on=["total_perf"])
status_str = Property(String, depends_on=["status"])
sweep_info = Property(HTML, depends_on=["sweep_results"])
tx_h_tune = Property(Array, depends_on=["tx_tap_tuners.value", "nspui"])
ctle_h_tune = Property(
Array,
depends_on=[
"peak_freq_tune",
"peak_mag_tune",
"rx_bw_tune",
"w",
"len_h",
"ctle_mode_tune",
"ctle_offset_tune",
"use_dfe_tune",
"n_taps_tune",
],
)