Gremlin

More
19 Dec 2012 23:39 #27870 by BigJohnT
Replied by BigJohnT on topic Gremlin
Maybe pestering paid off LOL.

In gremlin.py I see
self.show_dtg = True
and
def get_show_distance_to_go(self): return self.show_dtg

Any clues as to how to change that in code?

John

Please Log in or Create an account to join the conversation.

More
20 Dec 2012 00:21 - 20 Dec 2012 00:42 #27872 by ArcEye
Replied by ArcEye on topic Gremlin

Any clues as to how to change that in code?


I imagine you have a gremlin object so you can just use gremlin.show_dtg = False

I don't know how you incorporated it so could be self.gremlin.show_dtg = False or whatever

PS

Just have to make sure that the variable is public to be able to access it.

If it isn't, just write a public method in gremlin to change it, this is a better OOP method anyway
eg
def setShowDTG(bool show):
	show_dtg = show
Last edit: 20 Dec 2012 00:42 by ArcEye.

Please Log in or Create an account to join the conversation.

More
20 Dec 2012 01:59 #27875 by BigJohnT
Replied by BigJohnT on topic Gremlin
The variable must have public access as the following works!

gremlin.show_dtg = False

One more piece of the puzzle solved.

Now to understand what Daniel is telling me to do in the mail room with subclassing.

John

Please Log in or Create an account to join the conversation.

More
20 Dec 2012 15:25 #27887 by ArcEye
Replied by ArcEye on topic Gremlin
Getting there.

Sub-classing is writing a class which inherits all the methods and members of the original class, on top of which you add your own.

It is the big advantage to C++ or any OOP language over linear ones, you don't have to re-invent the wheel or do lots of cutting and pasting.

In C++ you simply declare a class and specify the inheritence

class MyGremlin(QWidget* parent) : public Gremlin(parent)
{
MyGremlin::MyGremlin(QWidget* parent);
...
etc
}

All the existing stuff in gremlin is still available, and you can define your own functions and variables to do extra stuff, or redefine or overload some of the existing ones.

I expect python has a similar but not quite the same syntax.

regards

Please Log in or Create an account to join the conversation.

More
20 Dec 2012 16:23 #27890 by cmorley
Replied by cmorley on topic Gremlin
HAL_gremlin in fact does this.
It inherits gremlin, and then marries goobject, gladevcp and GLADE into it.

In the master version I wrote some code to override the DRO text method in glcannon.py so as to add an offsets display option to the DRO.

If you look at the properties dic in HAL_gremlin - you can call most of them directly.

I'm not sure if you are using master or not...
but it is an example of what you can do by subclassing gremlin (It's a little complicated by the stuff for gobject/glade interfacing)

Chris M

Please Log in or Create an account to join the conversation.

More
20 Dec 2012 21:47 - 20 Dec 2012 21:52 #27901 by BigJohnT
Replied by BigJohnT on topic Gremlin
This is the subclass that Rogge did for me.
class jt_gremlin(gremlin.Gremlin):
    def __init__(self, inifile):
        gremlin.Gremlin.__init__(self, inifile)
        
    def report_gcode_error(self, result, seq, filename):
        import gcode
        error_str = gcode.strerror(result)
        error_str = "\n\nG-Code error in " + os.path.basename(filename) + "\n" + "Near line " + str(seq) + " of\n" + filename + "\n" + error_str + "\n"
        # do something here with the error message in your UI

and this is what I have come up with so far in the init of the main class to do a few things.
    self.gremlin = jt_gremlin(self.ini_file_object)
    self.gremlin.show_dtg = False
    self.gremlin.metric_units = False
    self.gremlin.current_view = 'y'
    self.plot = self.builder.get_object('hbox1')
    self.plot.pack_start(self.gremlin)
    self.plot.reorder_child(self.gremlin, 1)

If I'm understanding the report_gcode_error function correctly when I
load a file I need to call the function and check for an error? Should
the function return the error_str?

Not quite. When g code is loaded, gremlin generates the preview, and in doing so it runs the code through the interpreter. If it finds an error, it will report it via the report_gcode_error function. If you don't subclass it, it just prints the error to stdout (you'd see it in the terminal window). If you want to display the error on a gtk.label on your GUI, you'll need to subclass that function, and throw the error up onto the label. Something like: gui7.error_label.set_text(error_msg).


The part I'm unsure of at this point is do I need to subclass gremlin again or just do something like
self.gremlin.error = jt_gremlin(self.ini_file_object)

Chris, I'm using 2.5.1

John
Last edit: 20 Dec 2012 21:52 by BigJohnT.

Please Log in or Create an account to join the conversation.

More
22 Dec 2012 16:36 - 22 Dec 2012 16:38 #27954 by ArcEye
Replied by ArcEye on topic Gremlin
Don't know if Chris has started his UK travels yet.

The part I'm unsure of at this point is do I need to subclass gremlin again or just do something like
self.gremlin.error = jt_gremlin(self.ini_file_object)


Once you have subclassed, you just use your new class wherever you previously used gremlin

In C++ it would be something like
jt_gremlin *JTGremlin = new jt_gremlin(this, inifile);
thereafter using JTGremlin as the class pointer from which everything within it is addressed

The equivalent from the gremlin launching program would appear to be
from jt_gremlin import jt_gremlin
......
self.vbox = W(self, gtk.VBox)
self.jt_gremlin = W(self.vbox, jt_gremlin, inifile)
self.jt_gremlin.set_size_request(400, 400)
......
Last edit: 22 Dec 2012 16:38 by ArcEye.

Please Log in or Create an account to join the conversation.

More
22 Dec 2012 20:09 - 22 Dec 2012 20:16 #27960 by BigJohnT
Replied by BigJohnT on topic Gremlin
Turns out the report_gcode_error method is only in master.

Turns out Rogge showed my how to load gremlin like so:
class jt_gui(object):
  def __init__(self, inifile):
    <snip>
    self.ini_file_path = os.environ['INI_FILE_NAME']
    self.ini_file_object = linuxcnc.ini(self.ini_file_path)
    self.gremlin = jt_gremlin(self.ini_file_object)
  
class jt_gremlin(gremlin.Gremlin):
  def __init__(self, inifile):
    gremlin.Gremlin.__init__(self, inifile)

A screenshot of what I have so far



I can change all the view options and they work. I can change the view from the menu to X, Y, Z or Perspective. I can open a file and it will display. Working on the error part and I just had a thought on that...

John
Attachments:
Last edit: 22 Dec 2012 20:16 by BigJohnT.

Please Log in or Create an account to join the conversation.

More
25 Dec 2012 07:36 - 25 Dec 2012 07:39 #28024 by BigJohnT
Replied by BigJohnT on topic Gremlin
Ok I got most things working in the gremlin tutorial and have it on my web site. For now I'm running it from a RIP but I just had one of those subclassing moments and now I understand how to incorporate stuff into a method...

John
Last edit: 25 Dec 2012 07:39 by BigJohnT.

Please Log in or Create an account to join the conversation.

More
27 Dec 2012 00:31 #28046 by ArcEye
Replied by ArcEye on topic Gremlin
You are building up quite a body of work there John.

You are probably doing it the right way, writing it all up as you go along and find out how to do it.

If you leave it until you are finished with the project, you normally have lost interest and moved onto something else, and it never gets done B)

Please Log in or Create an account to join the conversation.

Time to create page: 0.246 seconds
Powered by Kunena Forum