Page 1 of 1
How to control Python with Yad?
Posted: Fri Mar 26, 2021 2:35 pm
by Kennel Dweller
Hi. I know this is the wrong place to ask for this sort of help and I hope to be forgiven for that.
I don't belong to many groups and rarely need help but with all the knowledge and talent here I hope to solve my nightmare with this issue.
Basically I have found a python script which I like to use and it works well, rather than messing with it I would like to link to the necessary and not have to alter the code in future.
With that in mind I thought I could use yad and create a box with a launcher, not being well versed in either yad or python I did much reading and got myself well and truly confused.
I cannot for the life of me get the info from yad to go were I want it in the python script having tried all sorts of links, commands, options etc, stdin/out, input, arg, you name it?
I would have thought it should be easy but a big fat NO is all I get.
Can somebody tell me what to do or put me on the right track~? Better still do it for me lol.
I am using python 3.9, the yad works in it's own right and links to the python file ok, the python script works fine when type the filename in the red box, I just need the green box to be the red box if that makes sense.
![Screenshot_2021-03-26_13-44-12.png](./download/file.php?id=3294&sid=e939f120bfd263cde19df847d5d1e155)
- Screenshot_2021-03-26_13-44-12.png (204.81 KiB) Viewed 872 times
Re: Yad to Python HELP !!
Posted: Fri Mar 26, 2021 3:19 pm
by rockedge
Hello!
So you need the variable in the shell (yad) script to equal "sample.dxf"?
could you rename both programs by adding a".gz" to the end and post them here? So I can run them to see what would be best in this case.
Re: Yad to Python HELP !!
Posted: Fri Mar 26, 2021 3:54 pm
by Kennel Dweller
Any help would be much appreciated, many thanks.
Re: Yad to Python HELP !!
Posted: Fri Mar 26, 2021 3:59 pm
by Kennel Dweller
I obviously didn't read your instruction properly.
Thrilled to get a response lol.
Is this better?
dxf2img.py.gz[/attachment
][attachment=1]dxf2png.sh.gz
Re: How to control Python with Yad?
Posted: Fri Mar 26, 2021 4:45 pm
by Kennel Dweller
I have a feeling I might have posted the version I had been messing with.
Here is the original.
Re: How to control Python with Yad?
Posted: Fri Mar 26, 2021 5:32 pm
by rockedge
I don't have the needed python modules loaded at the moment to actually see but this seems to work
Code: Select all
#!/bin/bash
cd /root/Desktop/funpics/in/
dialog=$(yad --title "DXF2PNG" --image="/root/apps/logo2.jpg" --form --field="imgname")
name=$(echo $dialog | awk 'BEGIN {FS="|" } { print $1 }')
python3 /root/app/dxf2img.py $(echo $name)
Re: How to control Python with Yad?
Posted: Fri Mar 26, 2021 6:58 pm
by Kennel Dweller
Thanks for such a swift response but that returns error.
python3.9/dist-packages/ezdxf/lldxf/validator.py", line 229, in is_binary_dxf_file
with open(filename, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'name'
But I have seen that before, I think the error pertains to the type of file entered although the script should read both ascii and binary.
I'll try with another dxf.
Re: How to control Python with Yad?
Posted: Fri Mar 26, 2021 7:03 pm
by Kennel Dweller
That returned same error, I am back to trying to replace the text in red square with a variable from yad, is see that as what I need to do but don't know how to do it.
Re: How to control Python with Yad?
Posted: Fri Mar 26, 2021 7:39 pm
by rockedge
my mistake! I have to install a couple of python modules to check it
Code: Select all
#!/bin/bash
cd /root/Desktop/funpics/in/
dialog=$(yad --title "DXF2PNG" --image="/root/apps/logo2.jpg" --form --field="imgname")
name=$(echo $dialog | awk 'BEGIN {FS="|" } { print $1 }')
python3 /root/app/dxf2img.py $name
this is what I am seeing:
Code: Select all
root-# ./dxf2png.sh
lopqj6x7.dxf
Traceback (most recent call last):
File "/root/Build/Test/dxf2img.py", line 40, in <module>
first.convert_dxf2img(["9.dxf"],img_format='.png')
File "/root/Build/Test/dxf2img.py", line 16, in convert_dxf2img
doc = ezdxf.readfile(name)
File "/opt/ActivePython-3.7/lib/python3.7/site-packages/ezdxf/filemanagement.py", line 138, in readfile
if is_binary_dxf_file(filename):
File "/opt/ActivePython-3.7/lib/python3.7/site-packages/ezdxf/lldxf/validator.py", line 229, in is_binary_dxf_file
with open(filename, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: '9.dxf'
root-# ./dxf2png.sh
/root/Build/Test/lopqj6x7.dxf
Traceback (most recent call last):
File "/root/Build/Test/dxf2img.py", line 40, in <module>
first.convert_dxf2img(["9.dxf"],img_format='.png')
File "/root/Build/Test/dxf2img.py", line 16, in convert_dxf2img
doc = ezdxf.readfile(name)
File "/opt/ActivePython-3.7/lib/python3.7/site-packages/ezdxf/filemanagement.py", line 138, in readfile
if is_binary_dxf_file(filename):
File "/opt/ActivePython-3.7/lib/python3.7/site-packages/ezdxf/lldxf/validator.py", line 229, in is_binary_dxf_file
with open(filename, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: '9.dxf'
Re: How to control Python with Yad?
Posted: Fri Mar 26, 2021 7:49 pm
by rockedge
This looks good. 2 things, one line added and one line modified in the python program
Code: Select all
if __name__ == '__main__':
first = DXF2IMG()
first.convert_dxf2img([(sys.argv[2])],img_format='.png')
And the Bash script like this:
Code: Select all
#!/bin/bash
cd /root/Desktop/funpics/in/
dialog=$(yad --title "DXF2PNG" --image="/root/apps/logo2.jpg" --form --field="imgname")
name=$(echo $dialog | awk 'BEGIN {FS="|" } { print $1 }')
python3 /root/app/dxf2img.py $name
Re: How to control Python with Yad?
Posted: Fri Mar 26, 2021 8:05 pm
by fredx181
Yes, the python script needs modification so it accept arguments, here it is:
- dxf2img.py.gz
- remove fake .gz and make executable
- (1.54 KiB) Downloaded 53 times
The yad script as rockedge provided works with above python script (when giving the name of one .dfx file in the same directory as running the script from)
But you you may want to add to the yad script a file selector so you can browse for (multiple) .dfx files to convert, like this:
Code: Select all
#!/bin/bash
cd /root/Desktop/funpics/in/
dialog=$(yad --title "DXF2PNG" --image="/root/apps/logo2.jpg" --form --field="imgname:mfl")
name=$(echo $dialog | awk 'BEGIN {FS="|" } { print $1 }' | sed 's/!/ /')
python3 /root/apps/dxf2img.py $name
Works only with filenames not containing spaces.
EDIT: Haha, I see now that rockedge beat me with similar python script ![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Fred
Re: How to control Python with Yad?
Posted: Fri Mar 26, 2021 9:16 pm
by Kennel Dweller
You've done it!!! absolutely amazing, thank you so much.
4 days and sleepless nights of head scratching, reading, thinking, trying and you do it in a few minutes.
Maybe I shouldn't be so stubborn and ask for help sooner.
It's now working perfectly many thanks indeed.
Re: How to control Python with Yad?
Posted: Fri Mar 26, 2021 11:12 pm
by Kennel Dweller
Just looked back at previous attempts and I was quite close to solving it but went off on a tangent and missed the point again.
At one time I had imported sys and followed a tutorial to no avail but looking at the changes Rockedge has made I see I wasn't far away.
I am so chuffed to get this working I can't thank you enough, It was nice to get some real genuine help instead of the sarky comments I was expecting.
It saddens me when I see so often unhelpful comments.
"Can anyone help with this issue I only get syntax error?
That's you ain't using correct syntax"
Why bother to make the comment? Is it me?
Re: How to control Python with Yad?
Posted: Sat Mar 27, 2021 1:43 pm
by rockedge
@Kennel Dweller
I find outside of this forum it's usual to be answered by comments that would NEVER be said face to face, but behind the keyboard real "warriors" abound with talent to point out how stupid my question is/was.
What if one day I had a question to a problem I need to be solved? And you just happen to be the guy with that answer? And I sometime before belittled you....Karma can be a bitch.
My brother is a rocket scientist...a real one.....sometimes he asks the most basic question about some computer procedure that any 8 year old kid knows inside and out. I help the best I can to answer that....he is a rocket scientist for Pete's sake (his name is Peter) and I know there will be a time when I'll need a hand and he is full of engineer/scientist ideas and thoughts, and if I acted like a know-it-all-better jerk he would answer my question with that in mind.....if at all.
We here in "the kennels" try our best to be kind and insightful. Who knows? You might be the next guy answering the call for some help when someone is SO close to getting the code to work but just is making some simple syntax error because they are learning and had the guts to try to make a tool on their own.