Choose a file from folder using "file chooser button" or other widget

More
8 years 1 month ago #117125 by bkt
He at all ... not see anything about ... my python language is very poor and never use gladevcp only pyvcp .... but i create a nice right gladevcp panel on axis as test.

My problem I need 2 button for choose some file from 2 different folder .... Actually i use file chooser button widget that show my anytime linux mint file chooser dialog with title "recentely used" ... (is real recentely used file dialog) .... not understand how can change that dialog for show mypc/myfolder1 with a button .... and mypc/myfolder2 with second button ....

is possible?

regards
Giorgio

Please Log in to join the conversation.

More
8 years 1 month ago #117138 by cmorley
iconview has a 'jump to directory' button similar to what you want.
The idea would be set the 'start directory' to one option and the 'jump to directory' to another.
linuxcnc.org/docs/2.7/html/gui/gladevcp.html#gladevcp:iconview

If you use a VCP filechooser button -looks like you could specify (in your handler file) the default folder with:
<button_name>. set_current_folder(path-to-folder)

I haven't ever tired either of these ideas.

Chris M

Please Log in to join the conversation.

More
8 years 1 month ago #117139 by bkt
sorry but with python no love ...

these is correct (hitcounter.py file)
Code:
import hal import glib import time class HandlerClass: ''' class with gladevcp callback handlers ''' def on_button_press(self,widget,data=None): self.vcp_filechooserbutton2.set_current_folder('/home/sr/folder1/new') self.vcp_filechooserbutton1.set_current_folder('/home/sr/folder2/old') ''' a callback method parameters are: the generating object instance, likte a GtkButton instance user data passed if any - this is currently unused but the convention should be retained just in case ''' print "on_button_press called" self.nhits += 1 self.builder.get_object('hits').set_label("Hits: %d" % (self.nhits)) def __init__(self, halcomp,builder,useropts): /* these code is more longer ... is from gladepvc example and I modify only those 2 button*/

Please Log in to join the conversation.

More
8 years 1 month ago #117150 by bkt
I receive these error when try to connect destroy signal to my h_scale
Code:
linuxcnc-dev/bin/gladevcp:214: RuntimeWarning: missing handler 'hal_hscale_delay_destroy' builder.connect_signals(handlers)

and i use these code for try to save the slider/hscale value:
Code:
def on_par_destroy(self,obj,data=None): self.ini.save_state(self)

"par" ia a frame inside a tab (notebook1) that is inside a window1 .... I try with notebook1 widget signal and windows1 signal too ... te same result nothing to save.

Problem with file chooser button and 2 different folder is still active.

regards
giorgio

Please Log in to join the conversation.

More
8 years 1 month ago #117160 by bkt
@ cmorley -> sorry I did not understand ... you advised me to use icon wiew widget instead of filechooserbutton .... ok now I understand .... only problem is that I should make them appear on a popup window ... one by one folder and one for the second .... I do not know how to do ... never used python in this way.

in fact icon view widget works ... but if I put it in the side panel inside my notebook1 if axis is in emergency iconview you see it .... just turn it on disappears .... I have to put a setp ??

regards
Giorgio

Please Log in to join the conversation.

More
8 years 1 month ago #117172 by cmorley
I meant that you could use either solution, depending on which you liked better.

Here is a proof of concept test code of vcp_FileChooserButtons - made to be run from gladevcp.
use the command:
loadusr gladevcp -u button_test_handler.py button_test.glade

Check that the hard coded paths I used are available on your system.
if you press the buttons it should pop a dialog that is preselected based on the hard coded path.

Chris M

Please Log in to join the conversation.

More
8 years 1 month ago #117176 by bkt
Code:
import hal import glib import time import gtk import gtk.glade import gobject import os class HandlerClass: ''' class with gladevcp callback handlers ''' def on_button_press(widget,data=None): ''' a callback method parameters are: the generating object instance, likte a GtkButton instance user data passed if any - this is currently unused but the convention should be retained just in case ''' print "on_button_press called" self.nhits += 1 self.builder.get_object('hits').set_label("Hits: %d" % (self.nhits)) def on_window1_destroy_event(widget, data=None): gtk.main_quit() def on_notebook1_destroy(self,obj,data=None): self.ini.save_state(self) def __init__(self, halcomp,builder,useropts): ''' Handler classes are instantiated in the following state: - the widget tree is created, but not yet realized (no toplevel window.show() executed yet) - the halcomp HAL component is set up and the widhget tree's HAL pins have already been added to it - it is safe to add more hal pins because halcomp.ready() has not yet been called at this point. after all handlers are instantiated in command line and get_handlers() order, callbacks will be connected with connect_signals()/signal_autoconnect() The builder may be either of libglade or GtkBuilder type depending on the glade file format. ''' self.halcomp = halcomp self.builder = builder self.nhits = 0 builder.get_object('vcp_filechooserbutton1').set_current_folder(os.path.expanduser('~/home/PC/FOLDER1/')) builder.get_object('vcp_filechooserbutton2').set_current_folder(os.path.expanduser('~/home/PC/FOLDER2')) def get_handlers(halcomp,builder,useropts): /* these row have a tab space that is an error .... so my error because retur is out of handlers .... I forgot the space order of python script ... */ ''' this function is called by gladevcp at import time (when this module is passed with '-u <modname>.py') return a list of object instances whose methods should be connected as callback handlers any method whose name does not begin with an underscore ('_') is a callback candidate the 'get_handlers' name is reserved - gladevcp expects it, so do not change ''' return [HandlerClass(halcomp,builder,useropts)]

These my hitcounte.py file ..... so in my ini file I write:
Code:
[DISPLAY] GLADEVCP= -u hitcounter.py my_filechooser_button.test.ui /* <-- with 2 EMC_filechooserbutton inside similar to yours */ DISPLAY = axis CYCLE_TIME = 0.100 HELP_FILE = doc/help.txt

And I have these error at start up ... sorry, but never study python program structure that is similar to arabian language for my ... So I not know the problem in these code ....
Code:
Starting LinuxCNC... Starting LinuxCNC server program: linuxcncsvr Loading Real Time OS, RTAPI, and HAL_LIB modules Starting LinuxCNC IO program: io Starting HAL User Interface program: halui Found file(LIB): /home/PC/linuxcnc-dev/lib/hallib/basic_sim.tcl Starting TASK program: milltask Starting DISPLAY program: axis Embeded tab command "halcmd loadusr -Wn gladevcp gladevcp -c gladevcp -x 90177679 -u hitcounter.py bmeccanica_ultrasonic.ui" exited with error: 1 Shutting down and cleaning up LinuxCNC... Killing task linuxcncsvr, PID=31177 Killing task milltask, PID=31209 task: 660 cycles, min=0.000005, max=0.006313, avg=0.001064, 0 latency excursions (> 10x expected cycle time of 0.001000s) Removing HAL_LIB, RTAPI, and Real Time OS modules Removing NML shared memory segments Debug file information: setup_kins: cmd=loadrt trivkins Note: Using POSIX realtime note: MAXV max: 1.200 units/sec 72.000 units/min note: LJOG max: 1.200 units/sec 72.000 units/min note: LJOG default: 0.250 units/sec 15.000 units/min note: jog_order='XYZ' note: jog_invert=set([]) Traceback (most recent call last): File "/home/PC/linuxcnc-dev/bin/gladevcp", line 312, in <module> main() File "/home/PC/linuxcnc-dev/bin/gladevcp", line 212, in main handlers = load_handlers(opts.usermod,halcomp,builder,opts.useropts) File "/home/PC/linuxcnc-dev/bin/gladevcp", line 113, in load_handlers mod = __import__(basename) File "./hitcounter.py", line 67 ''' IndentationError: expected an indented block <commandline>:0: waitpid failed gladevcp gladevcp <commandline>:0: gladevcp exited without becoming ready 31177 PID TTY STAT TIME COMMAND 31209 PID TTY STAT TIME COMMAND Stopping realtime threads Unloading hal components Note: Using POSIX realtime

Your gui file is .glade (so i undertand Lcnc use libglade-1 .... mine is .ui so in my case Lcnc use gtkbuilder ... pheranps maybe I understand wrong) mine is .ui ... so i think some "import" is not right .... I use glade 3.8.6 on linuxmint 18.3 rip-install ... I think no problem for these pourpuse.

Regards
giorgio


/***************** SOLVE THESE ERROR RIGHT FILE ATTACH*******************/
/***************** thanks cmorley for the help *******************/

Please Log in to join the conversation.

More
8 years 1 month ago #117181 by bkt
No find the way to save the value of my widget HScale using the function describe to the tutorial.

regards
Giorgio

Please Log in to join the conversation.

More
8 years 1 month ago #117200 by cmorley
One problem at a time.

your error is specified in the error messgage:
Code:
Traceback (most recent call last): File "/home/PC/linuxcnc-dev/bin/gladevcp", line 312, in <module> main() File "/home/PC/linuxcnc-dev/bin/gladevcp", line 212, in main handlers = load_handlers(opts.usermod,halcomp,builder,opts.useropts) File "/home/PC/linuxcnc-dev/bin/gladevcp", line 113, in load_handlers mod = __import__(basename) File "./hitcounter.py", line 67 ''' IndentationError: expected an indented block

somewhere around line 67 of hitcounter.py the indentation is wrong.

glade file ending doesn't matter as long as you the launch command and the actual file is the same.
GLADE used to use .glade but now seems to use .ui but it doesn't matter at all.

gladevcp is smart enough to use libglade or builder as required, but in reality builder is always used.
(libglade is very old technology)

Chris M

Please Log in to join the conversation.

More
8 years 1 month ago #117211 by bkt
/***************** SOLVE THESE ERROR RIGHT FILE ATTACH*******************/
/***************** thanks cmorley for the help *******************/

As I wrote in previous ... the file attach run ok without error about folder button .... identation problem is solved, because after some hour of works I remember the third or fourty program that i make in python 2 year ago ... the major problem was identation ... so I see what you see and of course i correct it. For best precision in my life is only the Sixth program make in python by me. Normally I work on c/c++ at a non-professional level (I'm not a good programmer). So never understand identation on python (for me it remains rather absurd). Real sorry ... but need the an help as a beginner.

SO THE filechooserbutton WORKS OK. filechooserbutton1 open folder1 and filechooserbutto2 open folder2 without error.
But I have error on exit and not know the right way to save the value of slider.

these the error about exit ....
Code:
LINUXCNC - 2.8.0~pre1 Machine configuration directory is '/home/PC/linuxcnc-dev/configs/sim/axis/gladevcp' Machine configuration file is 'gladevcp_panel.ini' Starting LinuxCNC... Found file(LIB): /home/PC/linuxcnc-dev/lib/hallib/basic_sim.tcl setup_kins: cmd=loadrt trivkins Note: Using POSIX realtime note: MAXV max: 100.000 units/sec 6000.000 units/min note: LJOG max: 100.000 units/sec 6000.000 units/min note: LJOG default: 50.000 units/sec 3000.000 units/min note: jog_order='XYZ' note: jog_invert=set([]) /home/PC/linuxcnc-dev/bin/gladevcp:298: GtkWarning: gtk_widget_size_allocate(): attempt to allocate widget with width -5 and height 17 gtk.main() task: main loop took 0.010049 seconds /home/PC/linuxcnc-dev/bin/gladevcp:298: GtkWarning: GdkWindow 0x5000003 unexpectedly destroyed gtk.main() **** GLADE VCP ERROR: X Protocol Error: 3 Shutting down and cleaning up LinuxCNC... task: 17359 cycles, min=0.000005, max=0.010049, avg=0.001056, 1 latency excursions (> 10x expected cycle time of 0.001000s) Note: Using POSIX realtime


I use these row for bring exit signal and save the data (really I not know really well what I do .... so for sure is wrong)
Code:
def on_window1_destroy_event(widget, data=None): gtk.main_quit() def on_notebook1_destroy(self,obj,data=None): self.ini.save_state(self)

similat to the gladevcp tutorial explain ...

regards
giorgio

Please Log in to join the conversation.

Time to create page: 0.222 seconds
Powered by Kunena Forum