Code Monkey home page Code Monkey logo

comet's People

Contributors

arnobaer avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

arnobaer

comet's Issues

Migrate to qutie

Migrate comet.ui, comet.application and comet.process to qutie.

Note: this will introduce breaking changes.

Driver property assignment issue

In Driver.__setattr__ every property is accessed for a type check, resulting in unwanted queries. Driver attributes can be found in Driver.__dict__ (but properties not).

Improved process callbacks

An optimized approach for custom process/thread callback registration and calls.

class Process(comet.Process):
    def run(self):
        while self.running:
            self.push("temp", 22.5)
            self.push("humid", 50.0)
            self.push("status", 42)

process = Process(
    fail=ctrl.handle_error, # built in callback
    temp=ctrl.handle_temp,
    humid=ctrl.handle_humid
)
process.callbacks["status"] = ctrl.handle_status
...

Optional move built in callbacks begin, finish and fail also to property callbacks to avoid accidental assignment in process run().

Issue with step in linear range function

Linear range class functions.LinearRange does return an empty sequence if step exceeds the absolute ramp distance.

>>> list(LinearRange(0, 1, 5))
[]

It should return

>>> list(LinearRange(0, 1, 5))
[0.0, 1.0]

Resolve pyvisa future warning

FutureWarning: The visa module provided by PyVISA is being deprecated. You can replace import visa by import pyvisa as visa to achieve the same effect.

The reason for the deprecation is the possible conflict with the visa package provided by the https://github.com/visa-sdk/visa-python which can result in hard to debug situations.

Venus1 fixes

Corvus Venus-1 driver fixes after hardware testing.

Using process with functions

Provide an convenient way of using class comet.Process with functions (like class threading.Thread). Attribute target is called if no custom implementaion of run() is provided.

>>> def run(p):
...     while p.running:
...         pass
...
>>> p = comet.Process(id="proc", target=run)
>>> p.start()

Add Corvus TT/eco driver

Add driver for Corvus TT/eco instruments (Venus-1 language)

from comet.driver.corvus import Venus1

Add tree UI widget

Add a simple to use tree widget.

tree = comet.Tree(header=["Key", "Value"])
spam = tree.append(["spam", 1000])
spam.append(["ham", 2000])
spam.append(["eggs", 3000])
for item in tree:
    item[0].checked = True # set checkd state
    for child in item.children:
        child[0].checked = False
        child[1].color = "green"

tree

Add UI scroll area

Add scroll area providing auto scroll bars.

comet.ScrollArea(layout=comet.Column(
    *[comet.CheckBox(text=f"Option {i+1}") for i in range(32)]
))

scrollarea

Generic instrument emulation socket

Create a generic instrument emulation socket server for testing and development.

from comet.emulator import RequestHandler, TCPServer

class K2700Handler(RequestHandler):
    read_terminaton = "\r"
    write_terminaton = "\r"

    @message(r'\*IDN\?')
    def idn(self, message):
        return "Keithley Model 2700 Emulator"

server = TCPServer(K2700Handler)
server.run("localhost", 10001)

Issue with drivers as class attributes

It turned out to be quite tedious/impractical to forward attributes using property classes, implementing Driver sub modules. Possible solution: stick back to classic attribute instances, prevent attribute assignments for Driver instances.

class Axis(Driver):
    def __init__(self, resource, index):
        super().__init__(resource)
        self._index = index

class Venus1(Driver):
    def __init__(self, resource):
        super().__init__(resource)
        self.x = Axis(resource, 1)
        self.y = Axis(resource, 2)
        self.z = Axis(resource, 3)

# Prevent accidental assignments
>>> device = Venus1(...)
>>> device.x = 4
...
AttributeError: can't set attribute

Driver actions and properties

Add method decorator classes for actions and properties like Lantz or Slave do provide for convenient value mapping and list like item access.

class MyDriver(Driver):
    @Action()
    def init(self): ...
    @Property(values={False: 0, True: 1})
    def output(self):
        ...
    @output.setter
    def output(self, value: int):
        ...
    @Property(keys=(0, 1, 2, 3), minimum=-1000.0, maximum=1000.0)
    def channel(self, key):
        ...
    @channel.setter
    def channel(self, key, value):
        ...
>>> with MyDriver(...) as device:
...     device.output = True
...     device.channel[0] = 10.0

Load device/resource settings

An easy approach to load/overwrite settings for registered devices using method load_settings().

...
>>> app.devices.add("smu", K2140(Resource("GBIP::1::INSTR")))
>>> app.devices.get("smu").resource.resource_name
'GBIP::1::INSTR'
...
>>> app.devices.load_settings() # overwrite resource values by settings
>>> app.devices.get("smu").resource.resource_name
'ASRL1::INSTR'

Add VISA options to preferences

Add VISA specific instrument options (eg. read_termination, write_termination) to the resources preferences dialog.

It is required to update these options depending on the physical device settings without updating the application code.

Custom UI

Create simple custom UI classes to wrap PyQt5 widgets to provide an easy way to create COMET dashboards.

A bit like a simplified version of Plotly's Dash Python framework.

import comet

app = comet.Application(name='sample')
app.layout = comet.Row(
    comet.Plot(id='plot'),
    comet.Column(
        comet.Button(id='reset', text='Reset'),
        comet.Button(id='clear', text='Clear')
    )
)

@comet.event('refresh', 'clicked')
def refresh(event):
    app.get('plot').reset()
@comet.event('clear', 'clicked')
def clear(event):
    app.get('plot').clear()

app.run()

Add file/directory open/save UI dialogs

Add functions to create file/directory open/save dialogs.

>>> comet.file_open(...)
'/home/user/sample.txt'
>>> comet.files_open(...)
['/home/user/foo.txt', '/home/user/bar.txt']
>>> comet.directory_open(...)
'/home/user'
>>> comet.file_save(...)
'/home/user/sample.txt'
>>> comet.directory_save(...)
'/home/user'

Add table UI widget

Add a simple to use table widget.

table = comet.Table(header=["Key", "Value"])
table.append(["spam", 1000])
table.append(["ham", 2000])
table.append(["eggs", 3000])
for row in table:
    row[0].checked = True # set check state
    row[0].color = "blue"

table

Delay consecutive write commands

Some individual instruments (observed with a Keithley 2700) might occasionally require an additional delay between consecutive write() commands.

  • add device property write_delay
  • add overriding attribute write_delay to device write() method
  • set individual device write_delay using preferences dialog

Linear range issues

Special case

for value in comet.Range(0, 0, 1):
    print(value)

will count up infinite.

Add stacked UI widget

Providing a simple UI widget stack using QStackedWidget.

stack = comet.Stack(id="stack", [
    comet.Label(id="p1", "Page 1"),
    comet.Label(id="p2", "Page 2"),
    comet.Label(id="p3", "Page 3")
])
stack.current = 1 # shows page 1
stack.current = stack.get('p3') # shows page 3

Add message UI dialogs

Add functions to create modal message dialogs.

>>> comet.show_info(title="Hey!", text="This is informative.")
>>> comet.show_warning(title="Ho!", text="Hold your horses.")
>>> comet.show_error(title="An error occurred", text="This is a fatal error.")
>>> comet.show_critical(title="A critical error occurred", text="This is really critical.")
>>> try:
...     no_such_func()
... except NameError as e:
...     comet.show_exception(e)

ShuntBox switch relais issues

In class comet.devices.hephy.ShuntBox methods enable() and enableAll() raise assertion errors for query results. This is due to trailing blank characters in the result (despite the read termination).

Process event handling: revisited

Introducing an event handler for convenient use of callbacks from within processes (threads).

Depending on the thread context an event callback is either called in the same thread the process was created in (usually the main thread) or a PyQt5 signal is emitted from within a worker thread.

Callbacks should be accessible as dictionary and also as attribute for convenience.

def on_reading(data):
    print(data)
def on_finished():
    print("finished.")

def run(p):
    while p.running:
        p.events.reading([42]) # access as attribute
    p.events["finished"]() # access as dict item

app = comet.Application()

p = comet.Process(target=run, events=dict(reading=print)) # initial assign as dict
p.events["reading"] = on_reading # (re-)assign as dict item
p.events.finished = on_finished # assign as attribute
p.start()

app.run() # events require event loop to work!

Thread safe immutable data exchange

Introduce thread save immutable data exchange mechanism (exchanging only deep copies) using methods get(key, default=None) and set(key, value)

>>> def run(p):
...     for i in range(42):
...         value = p.get('count', default=0)
...         value += 1
...         p.set('count', value)
>>> p = comet.Process(target=run)
>>> p.set('count', 0)
>>> p.start()
>>> p.join()
>>> p.get('count')
42

Window resize

Setting application properties width and height result in fixed sized window, should use function resize instead to adjust window size.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.