PDA

View Full Version : Development with Quickly



Mr_Electric
July 17th, 2011, 12:54 AM
Hi Everyone,

I need help with creating an application in Ubuntu 11.04 Natty Narwhal. I am new to Ubuntu development and I'm trying to develop a GUI application that sends commands through terminal when a button is pressed. I did some research and found out that it can be accomplished through quickly but I need help on how it should be done. Can someone please direct me to a tutorial on how I can develop this app.



Thanks in advance,
Mr_E

ubudog
July 17th, 2011, 03:03 AM
Hmm... for beginners I would recommend C++ (QT). To install QT, run the following commands in a terminal:

sudo apt-get install qtcreator libqt4-core

It has an easy to use drag and drop interface for creating the UI, and a very easy to learn syntax.

Please let me know if you have any questions. :)

Mr_Electric
July 17th, 2011, 10:59 PM
Thank You! I'll be sure to check it out and contact you if I have any other questions

ubudog
July 17th, 2011, 11:12 PM
Thank You! I'll be sure to check it out and contact you if I have any other questions

No problem! :-)

Mr_Electric
July 18th, 2011, 10:45 PM
I downloaded QT and was messing around with it. I have successfully created a GUI but I think I need help connecting it with the main() c++ code (that I haven't written yet) and interfacing that to type commands into terminal.


Thanks Once Again,
Mr_E

Simian Man
July 18th, 2011, 11:01 PM
C++ and QT is a horrible suggestion for what you want to do. It is way too complicated. It'd be like suggesting you use an industrial blowtorch to make some toast :).

A simpler way would be to use zenity which is a command that allows you to use simple GUIs from bash scripts. If you only need something with a few GUI controls, zenity would suffice. If you need something more, then you will need a full programming language, but even then I would recommend Python and Tkinter over C++/QT as the best option.

ubudog
July 19th, 2011, 12:11 AM
C++ and QT is a horrible suggestion for what you want to do. It is way too complicated. It'd be like suggesting you use an industrial blowtorch to make some toast :).

A simpler way would be to use zenity which is a command that allows you to use simple GUIs from bash scripts. If you only need something with a few GUI controls, zenity would suffice. If you need something more, then you will need a full programming language, but even then I would recommend Python and Tkinter over C++/QT as the best option.

LOL, I suppose you are correct, it is a bit overkill for a small project. I do second Python/TK, that's the first thing I learned. Here is one of my projects you can download for some examples in Python/TK.

http://guessie.sourceforge.net
(make sure to get 1.0)

For Python/TK, you will need to install the python-tk package:

sudo apt-get install python-tk

TwoEars
July 19th, 2011, 12:21 AM
C++ and QT is a horrible suggestion for what you want to do. It is way too complicated. It'd be like suggesting you use an industrial blowtorch to make some toast :).

A simpler way would be to use zenity which is a command that allows you to use simple GUIs from bash scripts. If you only need something with a few GUI controls, zenity would suffice. If you need something more, then you will need a full programming language, but even then I would recommend Python and Tkinter over C++/QT as the best option.

+1

@OP
Have you had any prior programming language experience?

Mr_Electric
July 19th, 2011, 12:29 AM
Okay. Sounds Good, but I know a little C++. The only thing is,if I install the Python program. Then I'm going to need help writing python (I never really got it). I'm looking for somthing similar to Mac OS X's Automator where you can setup an "Ask for Conformation" and then link it to "Run Shell Script".

Thank you So Much,
Mr_E

TwoEars
July 19th, 2011, 12:33 AM
Okay. Sounds Good, but I know a little C++. The only thing is,if I install the Python program. Then I'm going to need help writing python (I never really got it). I'm looking for somthing similar to Mac OS X's Automator where you can setup an "Ask for Conformation" and then link it to "Run Shell Script".

Thank you So Much,
Mr_E

Basically, you want a script with a GUI start up? If it needs root powers, you could always use gksu/beesu. Otherwise, Zenity + Bash will be more than enough for your needs.

Mr_Electric
July 19th, 2011, 12:39 AM
I'll be sure to check it out! :)

Mr_Electric
July 19th, 2011, 12:40 AM
Thanks I'll be sure to check it out! :D

Mr_Electric
July 21st, 2011, 03:00 AM
I did some research about Zenity and it seems helpful, but I need to write an application that types commands into terminal when a button is pressed. I need it to send it commands to my Arduino (programmable microcontroller http://arduino.cc/) through the screen terminal command to control some servos. I want to develop a clean GUI interface.

Thanks Again
MR_E :o

ubudog
July 21st, 2011, 01:17 PM
Here is something in Python (with TK) I made this morning, as an example. It does what you want; it has a button, and when you click on it, it executes the command you put in the code. So, to make it work for you, modify the main.py file, and change the "your command here" to whatever command you want to use. Then, do:

python main.py

Hope this helps you learn a bit. Enjoy, and let us know if you have any questions. :-)

Mr_Electric
July 22nd, 2011, 05:54 AM
Thank You So Much. I am going to check it out now. Could you please tell me how to add more buttons (I need about 6).


Thank You Soo Much

Mr_E

:)

Mr_Electric
July 22nd, 2011, 06:31 AM
Can you help me write the same code in C++ so I can attach it to the GUI I created with QT.


Other than that it is exactly what I'm looking for

Mr_Electric

P.S How do you attach the GUI objects (buttons, sliders, ect) to the code?

TwoEars
July 22nd, 2011, 06:34 AM
Can you help me write the same code in C++ so I can attach it to the GUI I created with QT.


Other than that it is exactly what I'm looking for

Mr_Electric

P.S How do you attach the GUI objects (buttons, sliders, ect) to the code?

No need. You can use Python.

Read here- http://www.riverbankcomputing.com/static/Docs/PyQt4/html/

ubudog
July 22nd, 2011, 05:11 PM
Nope, there is no need, you can do everything you want by modifying the main.py file. Let's say you want to add a button. You already have the "gobtn", so it would go something like this. Put this one line below the gobtn code.



secondbtn = Tkinter.Button(frame, text="My Second Button",command=mysecondcommand)
secondbtn.pack(side=BOTTOM)


You may want to modify the code a bit. Also, you will want to create a command up where I put the "def gocommand():". So the command would be like this: (assuming you are still executing command line programs)


def mysecondcommand():
os.system("commandlinecommand")

* replace "commandlinecommand" with the command line command, lol.

Using this, you can create as many buttons as you want. Let me know if you have any questions.

Mr_Electric
July 22nd, 2011, 05:46 PM
Thank You! The second line of code made Much clearer. I am going to try it out in a little bit (due to an unrelated problem, my hard drive failed and I had to reinstall it on a new one).
Mr_E

ubudog
July 22nd, 2011, 06:36 PM
Sucks that your HD died, I know how you feel...

Well, let me know if you have any problems/questions. :-)

Mr_Electric
July 22nd, 2011, 07:58 PM
Actually It is not so bad. I installed Ubuntu on a spare machine of mine and use it for developing and other fun. I do all my work on my laptop (Windows7/Mac OS 10.6) and my tower (Mac OS 10.4). Anyhow, once I finish developing the program, I am going to export it to a BeagleBoard(http://beagleboard.org/) running Natty with an Arduino(http://arduino.cc/). My aim is to have an easy to use interface (the app on the BeagleBoard) that controls servos, motors, lights, ect remotely (using a wireless card and VNC). The Arduino will be the low level Microcontroller linked by the screen command in Terminal

Thank You SO Much.
I am going to work on the python code and I will get back to you if I need anymore help/

Mr_E :mrgreen:

LemursDontExist
July 22nd, 2011, 08:34 PM
As an aside - have you considered interfacing with the arduino directly from python? I've found that that's easy and clean. Some instructions (http://www.arduino.cc/playground/Interfacing/Python).

ubudog
July 22nd, 2011, 09:56 PM
As an aside - have you considered interfacing with the arduino directly from python? I've found that that's easy and clean. Some instructions (http://www.arduino.cc/playground/Interfacing/Python).

Nice!

Mr_Electric
July 23rd, 2011, 02:07 AM
Hmmm. Not bad, though I still think Arduino and the screen command work well. As for the python code, It is exactly what I was looking for.

I will post some pictures once my project is completed and I will contact you'll if I need anymore assistance.



Mr_E :o

Mr_Electric
July 23rd, 2011, 02:16 AM
Is there a way to trigger the buttons using the Arrow Keys?

Thanks,
MR_E :(

Mr_Electric
July 23rd, 2011, 03:27 AM
I modified the code you gave me to one that has three buttons (you can see in the screenshot) so that it would configure the arduino (screen /dev/ttyACM0). I also added two other buttons for turning an led on and off. When I start up the code, I can click the configure button and it opens a screen session with the Arduino, but the Configure button is still highlighted, preventing me from sending the commands using the other two buttons. Can you please check my code and tell me what I did wrong?

ubudog
July 23rd, 2011, 05:34 PM
Hmm, I believe that's because the screen command is running, and it continues to run and doesn't stop. Of course, you can't kill it, or the other buttons won't work...

I've modified the LED.py code to where I think it will work. Make a backup of your current LED.py, and then download and replace it with this one.

Mr_Electric
July 24th, 2011, 02:29 AM
Well now it clicks but I get a message in terminal that it needs to be connected to a terminal (check the screenshot). I modified the code so that is runs screen in the Root user (I unlocked that) mode but it still says that it needs to be connected to a terminal. I attached my modified LED2.py file.

Thank You SO Much
Mr_E :P

Mr_Electric
July 24th, 2011, 02:33 AM
Here are the attachments. Sorry I forgot to upload them in my previous post ;)

ubudog
July 24th, 2011, 05:49 PM
I modified it a bit, with something I found on Google. Let me know how it goes. :-)

Mr_Electric
July 26th, 2011, 03:50 AM
Still not working. I tried it out but it says that it needs to be connected to a terminal (again) and it needs suid root to be run. Is there a way to just link the code to a terminal without the root?

Thanks for all your help
MR_E

kalaharix
July 27th, 2011, 08:46 AM
Hi

I don't understand why you are involving a terminal as an intermediary in your gui. /dev/ttyACM0 is a raw device and behaves like a file. You should be able to redirect output to the raw device. I must admit that I have not done this with USB but have used the method on both parallel (e.g. /dev/lp0) and serial devices.

My advice (admittedly untested) would be to create a simple text file containing "0011" (without parentheses). You should then be able to cat the file to the device with something like 'cat /home/Fred/Documents/ledOn.txt>/dev/ttyACM0' or whatever.

Once you can successfully test that from the terminal then your can use your os.system(same command) from within the gui.

Mr_Electric
July 27th, 2011, 07:15 PM
Maybe that would work... The device (my arduino UNO) is using a virtual serial port which is named /ttyACM0. Could you please show me an example on how I could use your method?


Thanks,
Mr_E

LemursDontExist
July 29th, 2011, 03:06 PM
Hi
I don't understand why you are involving a terminal as an intermediary in your gui. /dev/ttyACM0 is a raw device and behaves like a file. You should be able to redirect output to the raw device. I must admit that I have not done this with USB but have used the method on both parallel (e.g. /dev/lp0) and serial devices.

This seems like a good time for another plug for just connecting to the device directly in python (http://www.arduino.cc/playground/Interfacing/Python). Getting rid of all the intermediary stages would eliminate all the complexity.

Mr_Electric
July 29th, 2011, 11:52 PM
Okay, so how would I do it?

LemursDontExist
July 30th, 2011, 01:47 AM
If I understand right, you have the arduino connected as a serial device at /dev/ttyACM0, so the instructions (http://www.arduino.cc/playground/Interfacing/Python) I've linked above should apply pretty directly.

I believe pySerial is installed by default in Ubuntu if
import serial works in python, you're good. If not,

sudo apt-get install python-serial should get it for you.

After that

import serial
ser = serial.Serial('/dev/ttyACM0', 9600)

gets you a serial connection, and you can use it like any file object. So


line = ser.readline()
ser.write("0011")

should, in turn, read a line of input from the Arduino and write "0011" to the it.

Withot more detail on exactly what you're doing it's hard to say more, but you can play around with it directly in the python interpreter and see what works.

Mr_Electric
July 31st, 2011, 07:41 AM
The reason why I am trying to interface my arduino with a GUI so I can have an easy to use interface to control LEDs, Servos, ect. I am just a beginner and I have asked around a few places an gotten a lot of responses on how I can do it. I have been told that I can use quickly, QT, or just a python code but whatever method I use I just want to be able to get the job done. Can you please direct me (or tell me how) to get this done.

Thanks,
Mr_E

LemursDontExist
August 1st, 2011, 04:27 PM
Sorry about the slow reply - life's been busy!

I looked at the code you've been working with, and it wasn't very clear to me what the manconfig function was for. But here's a version that should at least let you control the leds directly. (assuming that your arduino is programmed to respond to "0011 " (are those spaces intentional - or a typo?), "0022" by turning on (toggling?) leds 1 and 0 respectively).


#!/usr/bin/python
import Tkinter
from Tkconstants import *
import serial

tk = Tkinter.Tk()
tk.title("LED CONTROL")
ser = serial.Serial('/dev/ttyACM0', 9600)

def led1():
ser.write("0011 ")

def led0():
ser.write("0022")

frame = Tkinter.Frame(tk, relief=RIDGE, borderwidth=5)
frame.pack(fill=X, expand=1)
abtmain = Tkinter.Label(frame, text="Press a button below.")
abtmain.pack(fill=X, expand=1)

led1btn = Tkinter.Button(frame, text="LED ON",command=led1)
led1btn.pack(side=LEFT)

led0btn = Tkinter.Button(frame, text="LED OFF",command=led0)
led0btn.pack(side=RIGHT)

tk.mainloop()

Mr_Electric
August 2nd, 2011, 03:11 AM
Well actually the manual configuration (manconfig) button was to start the screen session with the arduino but now I see that it is not necessary. I originally wanted to put 0 and one but decided on 0011 so it would be four characters.

Thanks,
Mr_E :D

Mr_Electric
August 4th, 2011, 05:07 AM
Thanks to all of you'll, I've finally been able to accomplish my task and get my problem solved.

Thanks again,
Mr_E

ubudog
August 5th, 2011, 03:17 AM
Sounds good!

onizukal
January 12th, 2012, 08:56 PM
Hey all
Sorry actually my question is little far from the main question but i use your good programmers code to my project and i got some problems caused by it . Actually i little bit modified the main.py as my project but the problem when i used it , main.py is just stop working . In my project i should make a gui for launching FFServer and also the same gui should be able to stop it but my problem is FFserver is starting as how i want but when it started main.py program is just becaming deactivating. i cant click on the other button that is gonna make stop the FFserver . But it is just GUI which is not clickable. When i click the command screen , it is working . I can stop the server by pressing CTRL + C . But the GUI is not working . Button just pressed and not released .

http://imageshack.us/photo/my-images/51/screenshotokv.png/

I dont have much idea about python . Sorry for my novice status but if you help me , i can be gratefull . Thank you