How do I open a file with IconFileSelect? (partially solved!!!)

More
06 Feb 2019 22:33 #125886 by cmorley
oops saw another typo
def on_file_selected(self,widget,data=None):
    md = gtk.MessageDialog(None,
    gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION,
    gtk.BUTTONS_YES_NO)
    md.run()
    path = self.builder.get_object('file').get_selected()
    print path
    md.destroy()

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

More
06 Feb 2019 23:16 #125888 by pferrick
Here's what I got (I ran linuxcnc from the command line):

Traceback (most recent call last):
File "./file.py", line 20, in on_file_selected
gtk.BUTTONS_YES_NO, path)
UnboundLocalError: local variable 'path' referenced before assignment

So I re-arrranged things slightly, like this:

def on_file_selected(self,widget,data=None):
path = self.builder.get_object('file').get_selected()
print path
md = gtk.MessageDialog(None,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION,
gtk.BUTTONS_YES_NO, path)
md.run()
md.destroy()

and I got this:

Traceback (most recent call last):
File "./file.py", line 18, in on_file_selected
path = self.builder.get_object('file').get_selected()
File "/usr/lib/pymodules/python2.7/gladevcp/iconview.py", line 423, in get_selected
return on_btn_get_selected_clicked(self)
NameError: global name 'on_btn_get_selected_clicked' is not defined

The first one kinda made sense to me, but that last one....????!?!?! There are no other widgets on the glade window (nor are there any named btn anywhere, AFAIK.

Any ideas? I really appreciate your help, Chris. Thank you.

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

More
06 Feb 2019 23:23 #125890 by cmorley
try the last one I posted

Chris

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

More
06 Feb 2019 23:44 #125892 by cmorley
I'm looking at your code and finally realize that your dialog is built on the fly - and does not have the icon view put in it....So maybe I am missing something.

To help you any further I need the GLADE file.

Chris M

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

More
06 Feb 2019 23:52 #125893 by pferrick
I tried it again and got pretty much the same thing:

Traceback (most recent call last):
File "./file.py", line 18, in on_file_selected
path = self.builder.get_object('file').get_selected()
File "/usr/lib/pymodules/python2.7/gladevcp/iconview.py", line 423, in get_selected
return on_btn_get_selected_clicked(self)
NameError: global name 'on_btn_get_selected_clicked' is not defined

I'll attach both the python and the glade files.

PKF

File Attachment:

File Name: file.py
File Size:1 KB

File Attachment:

File Name: file.glade
File Size:1 KB
Attachments:

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

More
07 Feb 2019 00:52 - 07 Feb 2019 00:53 #125900 by pferrick
Chris-

In case it isn't obvious...I'm only attempting to use a messagebox as a diagnostic tool. Y'know, something to clue me in to the value of a variable. I'm expecting the message to be the path, of course.

I've actually done quite a lot of "recreational" coding over the years, mostly with Visual Basic and the like. A little C here and there, and now I'm tackling Python. So not much "real" programming, I guess you could say! I'm now trying to buckle down and learn what classes, constructors, widgets, methods, etc. are all about.
Last edit: 07 Feb 2019 00:53 by pferrick.

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

More
07 Feb 2019 06:52 #125905 by cmorley
Ok here is the python code; I added an vcp_action_open object to the GLADE file.
I add comments that should explain - feel free to ask specific questions.

BUT:
I'm not sue what screen you are using:
I have discovered (not surprisingly) it doesn't work well if you are using AXIS.
AXIS does not notice program changes in the motion controller - so the screen does not update and if you use the reload
button it reloads the last program that AXIS knows about. I'm sure there is a work around - i'd have to look into it.

If you use Gmoccapy or Gscreen it will work fine.

Also i see there really is little documentation on most actions - i don't image you could have figued out how it worked without looking at the source (which is what i did!)
import gtk
import gladevcp
import linuxcnc
import pygtk
import hal
import os

class HandlerClass:
    def __init__(self, halcomp, builder, useropts):
        # make a class reference to builder 
        # (self.ANYTHING is available anywhere in the HandlerClas class)
        self.builder = builder

        # make a class reference to the open vcp_action
        self.open = builder.get_object('open')

        # change a property in the iconchooser so all programs show
        # this shouldn't be required - it's a bug
        builder.get_object('file').set_property("filetypes", '*')

    # This is a callback function from the icon chooser selected in the GLADE signal editor
    # in GTK the first variable is always the widget that owned the signal that called this function
    # any other variables depend on the widget, in this case icon view sends the path
    def on_file_selected(self, widget, path):
        print path
        if path:
            self.open.load_file(path)
 
# boiler code
def get_handlers(halcomp,builder,useropts):
    return [HandlerClass(halcomp,builder,useropts)]

Chris M
Attachments:

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

More
08 Feb 2019 02:08 #125970 by pferrick
Hi Chris-

Thanks for the detective work! I am using AXIS, so I found as you did that while the code you suggested does return a path but isn't so good at opening a file with it.

I'm playing around with some other possibilities which I'll fill you in on soon. I haven't given up yet, since I have quite a high tolerance for feeling like a complete idiot, apparently!

regards,
Patrick

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

More
08 Feb 2019 09:22 #125985 by cmorley
Ok You can use axis-remote to load programs in AXIS.
In this case you can remove the vcp_action_open from the glade file.
import subprocess

class HandlerClass:

    def __init__(self, halcomp, builder, useropts):
        # make a class reference to builder 
        # (self.ANYTHING is available anywhere in the HandlerClas class)
        self.builder = builder

        # make a class reference to the open vcp_action
        self.open = builder.get_object('open')

        # change a property in the iconchooser so all programs show
        # this shouldn't be required - it's a bug
        builder.get_object('file').set_property("filetypes", '*')

    # This is a callback function from the icon chooser selected in the GLADE signal editor
    # in GTK the first variable is always the widget that owned the signal that called this function
    # any other variables depend on the widget, in this case icon view sends the path
    def on_file_selected(self, widget, path):
        if path:
            print path
            subprocess.call('axis-remote %s' % path, shell=True)
 
# boiler code
def get_handlers(halcomp,builder,useropts):
    return [HandlerClass(halcomp,builder,useropts)]

Chris M
Attachments:

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

More
08 Feb 2019 23:04 #126023 by pferrick
Chris-

I'm right in the middle of trying exactly that. Right now I'm trying to iron out a little problem with using .axisrc to switch AXIS tabs via GladeVCP buttons. But I'm pretty sure when that's taken care of the file-opening situation will also work. That means my whole interface will be working, which will make me extremely happy!

thanks,
Patrick

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

Moderators: HansU
Time to create page: 0.237 seconds
Powered by Kunena Forum