Python interface how to detect file is not open?

09 Feb 2019 06:26 #126037 by bladekel
Hello to all...

I'm trying to create a custom ui with python and I need to detect if an ngc file couldnt opened succesfully.

For this problem I'm using interpreter_errcode like;

self.s = self.emc.stat()


but there is no return with this code..

Can anyone help me?
09 Feb 2019 11:03 #126043 by BigJohnT
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import linuxcnc
    s = linuxcnc.stat() # create a connection to the status channel
    s.poll() # get current values
except linuxcnc.error, detail:
    print "error", detail
s.file # returns the current loaded file
The following user(s) said Thank You: bladekel
09 Feb 2019 11:59 #126052 by cmorley
I might add that you should check the file name (using linuxcnc status) before you load the program, then check it after. If they are the same then the program probably loaded file.

eg gladevcp doe it like this (the code wont work for you but the idea is good):

def _load_file(self, filename):
if filename:
old = self.gstat.stat.file
if old == filename:
self.gstat.emit('file-loaded', filename)
The following user(s) said Thank You: bladekel
11 Feb 2019 08:47 #126192 by bladekel
Thanks bro. Thats the way....
Time to create page: 0.069 seconds
Powered by Kunena Forum