Choose a file from folder using "file chooser button" or other widget
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1201
- Thank you received: 103
05 Sep 2018 17:26 #117125
by bkt
Choose a file from folder using "file chooser button" or other widget was created 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
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 or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
Less
More
- Posts: 7760
- Thank you received: 2055
06 Sep 2018 03:37 #117138
by cmorley
Replied by cmorley on topic Choose a file from folder using "file chooser button" or other widget
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
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
The following user(s) said Thank You: bkt
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1201
- Thank you received: 103
06 Sep 2018 07:11 - 06 Sep 2018 07:13 #117139
by bkt
Replied by bkt on topic Choose a file from folder using "file chooser button" or other widget
sorry but with python no love ...
these is correct (hitcounter.py file)
these is correct (hitcounter.py file)
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*/
Last edit: 06 Sep 2018 07:13 by bkt. Reason: inser code note
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1201
- Thank you received: 103
06 Sep 2018 12:41 - 06 Sep 2018 12:45 #117150
by bkt
Replied by bkt on topic Choose a file from folder using "file chooser button" or other widget
I receive these error when try to connect destroy signal to my h_scale
and i use these code for try to save the slider/hscale value:
"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
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:
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
Last edit: 06 Sep 2018 12:45 by bkt.
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1201
- Thank you received: 103
06 Sep 2018 18:06 #117160
by bkt
Replied by bkt on topic Choose a file from folder using "file chooser button" or other widget
@ 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
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 or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
Less
More
- Posts: 7760
- Thank you received: 2055
07 Sep 2018 04:56 #117172
by cmorley
Replied by cmorley on topic Choose a file from folder using "file chooser button" or other widget
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
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
The following user(s) said Thank You: bkt
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1201
- Thank you received: 103
07 Sep 2018 08:51 - 08 Sep 2018 07:40 #117176
by bkt
These my hitcounte.py file ..... so in my ini file I write:
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 ....
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 *******************/
Replied by bkt on topic Choose a file from folder using "file chooser button" or other widget
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:
[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 ....
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 *******************/
Last edit: 08 Sep 2018 07:40 by bkt. Reason: delete code note
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1201
- Thank you received: 103
07 Sep 2018 12:49 #117181
by bkt
Replied by bkt on topic Choose a file from folder using "file chooser button" or other widget
No find the way to save the value of my widget HScale using the function describe to the tutorial.
regards
Giorgio
regards
Giorgio
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
Less
More
- Posts: 7760
- Thank you received: 2055
07 Sep 2018 17:42 - 07 Sep 2018 17:43 #117200
by cmorley
Replied by cmorley on topic Choose a file from folder using "file chooser button" or other widget
One problem at a time.
your error is specified in the error messgage:
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
your error is specified in the error messgage:
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
Last edit: 07 Sep 2018 17:43 by cmorley.
The following user(s) said Thank You: bkt
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1201
- Thank you received: 103
08 Sep 2018 07:30 - 08 Sep 2018 07:56 #117211
by bkt
Replied by bkt on topic Choose a file from folder using "file chooser button" or other widget
/***************** 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 ....
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)
similat to the gladevcp tutorial explain ...
regards
giorgio
/***************** 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 ....
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)
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
Last edit: 08 Sep 2018 07:56 by bkt.
Please Log in or Create an account to join the conversation.
Moderators: HansU
Time to create page: 0.076 seconds