def file_structure(path): """Checks for existing folder structure and sets up if missing""" os.makedirs(path, exist_ok=True) os.makedirs(path + "/tests", exist_ok=True) if not os.path.exists(path + "/config.json"): shutil.copy(func.find_path("assets/default_config.json"), path + "/config.json") open(path + "/batch.txt", "a") if not os.path.exists(path + "/scripts"): os.makedirs(path + "/scripts") shutil.copy(func.find_path("assets/example-script"), path + "/scripts/example")
def __init__(self, config): """Create tray applet and self.controls""" # TODO: Make icon visible on all backgrounds super(Icon, self).__init__(QIcon(func.find_path("assets/bolt.png"))) self.config = config self.menu = QMenu() self.controls = [] self.windows = [] actions = [ { "text": "Cyckei {}".format(config["version"]), "disabled": True }, { "separator": True }, { "text": "Launch Client", "connect": self.launch }, { "text": "Quit Cyckei", "connect": self.stop }, ] for action in actions: self.controls.append(func.action(**action)) self.menu.addAction(self.controls[-1]) # Add the self.menu to the tray self.setContextMenu(self.menu)
def __init__(self, config): super(MainWindow, self).__init__() # Set basic window properties self.setWindowTitle("Cyckei Client") self.config = config self.resize(1100, 600) self.setStyleSheet( open(func.find_path("assets/style.css"), "r").read()) resource = {} # Setup ThreadPool resource["threadpool"] = QThreadPool() self.threadpool = resource["threadpool"] logging.info("Multithreading set with maximum {} threads".format( resource["threadpool"].maxThreadCount() )) # Load scripts resource["scripts"] = ScriptList(config) # Create menu and status bar self.create_menu() self.status_bar = self.statusBar() # Create Tabs resource["tabs"] = QTabWidget(self) self.setCentralWidget(resource["tabs"]) resource["tabs"].addTab(ChannelTab(config, resource), "Channels") resource["tabs"].addTab(ScriptEditor(config, resource), "Scripts") resource["tabs"].addTab(LogViewer(config, resource), "Logs") self.threadpool = resource["threadpool"] self.channels = resource["tabs"].widget(0).channels
def prepare_json(self, protocol): """create json to send to server""" packet = json.load(open(func.find_path("assets/default_packet.json"))) packet["function"] = "test" packet["kwargs"]["protocol"] = protocol return packet
def main(): dirt = get_dirt() path = find_path(dirt) env = Environment(dirt) for pos in path: if is_present(pos, dirt[0]): dirt.remove(dirt[0]) env.update(pos.x, pos.y, flag=True) else: env.update(pos.x, pos.y)
class Keithley2602(object): """Represents a single keithley Interface""" # TODO something in the startup script screws up CC discharge. # It does constant V discharge instead script_startup = open(func.find_path("assets/startup.lua")).read() current_ranges = [ 100 * 1e-9, 1e-6, 10e-6, 100e-6, 1e-3, 0.01, 0.1, 1.0, 3.0 ] def __init__(self, gpib_addr, load_scripts=True): resource_manager = visa.ResourceManager() self.gpib_addr = gpib_addr self.source_meter = resource_manager.open_resource( "GPIB0::{}::INSTR".format(gpib_addr)) # TODO do not reset? Do something else, clear buffers I think self.source_meter.write("reset()") if load_scripts: self.source_meter.write(self.script_startup) def get_source(self, kch, channel=None): """Get source object of Keithley""" return Source(self.source_meter, kch, channel=channel)
def prepare_json(channel, function, protocol, temp): """Sets the channel's json script to current values""" with open(func.find_path("assets/default_packet.json")) as file: packet = json.load(file) packet["function"] = function for key, value in channel.attributes.items(): packet["kwargs"]["meta"][key] = value packet["kwargs"]["channel"] = channel.attributes["channel"] packet["kwargs"]["protocol"] = protocol packet["kwargs"]["meta"]["protocol"] = protocol if temp: dir = tempfile.mkdtemp() else: dir = os.path.join(channel.attributes["record_folder"], str(date.today())) os.makedirs(dir, exist_ok=True) packet["kwargs"]["meta"]["path"] \ = os.path.join(dir, channel.attributes["path"]) return packet
def main(record_dir="Cyckei"): """ Begins execution of Cyckei. Args: record_dir: Optional path to recording directory. Returns: Result of app.exec_(), Qt's main event loop. """ try: # Ensure Recording Directory is Setup record_dir = os.path.join(os.path.expanduser("~"), record_dir) file_structure(record_dir) # Setup Configuration with open(record_dir + "/config.json") as file: config = json.load(file) with open(func.find_path("assets/variables.json")) as file: var = json.load(file) config["version"] = var["version"] config["record_dir"] = record_dir # Setup Logging logging.basicConfig(filename="{}/cyckei.log".format(record_dir), level=config["verbosity"], format="%(asctime)s \t %(message)s") sys.excepthook = handler except Exception as e: print("An error occured before logging began.") print(e) logging.info("cyckei.main: Initializing Cyckei version {}".format( config["version"])) logging.debug("cyckei.main: Logging at debug level") # Create QApplication logging.debug("cyckei.main: Creating QApplication") app = QApplication(sys.argv) app.setStyle("fusion") app.setQuitOnLastWindowClosed(False) app.setWindowIcon(QIcon(func.find_path("assets/cyckei.png"))) # Create Server's ZMQ Socket logging.debug("cyckei.server.server.main: Binding socket") try: context = zmq.Context(1) socket = context.socket(zmq.REP) socket.bind("{}:{}".format(config["zmq"]["server-address"], config["zmq"]["port"])) except zmq.error.ZMQError as error: logging.critical( "It appears the server is already running: ".format(error)) msg = [ "Cyckei Instance Already Running!", "To show client, open taskbar widget and click \"Launch Client\"", func.Critical, "Failed to initialize socket. " "This indicates an existing server insance. " "Error: {}".format(error) ] func.message(*msg) return logging.debug("cyckei.server.server.main: Socket bound successfully") # Start Server logging.debug("cyckei.main: Starting Server") server_thread = threading.Thread(target=server.main, args=( config, socket, ), daemon=True) server_thread.start() # Create Applet logging.debug("cyckei.main: Creating Applet") applet_object = applet.Icon(config) applet_object.show() # Create Client logging.debug("cyckei.main: Creating Initial Client") main_window = client.MainWindow(config) main_window.show() return app.exec_()
def __init__(self, channel, config, resource): super(ChannelWidget, self).__init__() # Default Values self.attributes = { "channel": channel, "record_folder": config["record_dir"] + "/tests", "cellid": 0, "comment": "No Comment", "package": "Pouch", "celltype": "Full", "path": "default.pyb", "mass": 1, "requester": "Unspecified", "protocol_name": None, } self.config = config self.threadpool = resource["threadpool"] self.scripts = resource["scripts"] self.setMinimumSize(1050, 110) # General UI sides = QHBoxLayout(self) left = QVBoxLayout() sides.addLayout(left) middle = QVBoxLayout() sides.addLayout(middle) right = QVBoxLayout() sides.addLayout(right) # Divider self.divider = QWidget(self) self.divider.setMinimumWidth(2) self.divider.setMaximumWidth(2) middle.addWidget(self.divider) # Settings settings = QHBoxLayout() left.addLayout(settings) self.settings = self.get_settings() for element in self.settings: settings.addWidget(element) # Status args = ["Loading Status...", "Current Cell Status"] self.status = func.label(*args) left.addWidget(self.status) # Controls controls = QHBoxLayout() right.addLayout(controls) for element in self.get_controls(): controls.addWidget(element) # Feedback args = ["", "Server Response"] self.feedback = func.label(*args) self.feedback.setAlignment(Qt.AlignCenter) right.addWidget(self.feedback) # Load default JSON self.json = json.load( open(func.find_path("assets/default_packet.json")))