Regarding to previous post...I did asked you about running 2 commands with one button is clicked...
About the time sleep, how to do that??
Read .txt file in Glade GUI, python + glade
Read .txt file in Glade GUI, python + glade
|
|
Apr 15 2009, 02:11 PM
|
![]() ![]()
Junior Member
134 posts Joined: Apr 2005 |
Regarding to previous post...I did asked you about running 2 commands with one button is clicked...
About the time sleep, how to do that?? |
|
|
|
|
|
Apr 15 2009, 03:57 PM
|
![]() ![]() ![]() ![]() ![]()
Senior Member
751 posts Joined: Nov 2004 |
Actually this has been shown in my previous example on using temporary file.
CODE def on_button2_clicked(self, widget): textview1 = self.wTree.get_widget("textview1") os.system('ps ax > output') file = open('output') string = file.read() buffer = textview1.get_buffer() buffer.set_text(string) textview1.scroll_mark_onscreen(buffer.get_insert()) file.close() os.system('rm -f output') return True See the first command is to save ps ax output to output file. Then the output is read to textview. Followed by removal of output file. Sleep is like pausing. Give some time for command to finish or what ever. In python you can use: time.sleep(n) *n = int in seconds Bash scripting is not a real programming language and by far similar to C. But it is the mother of all scripting language and the simplest of all. Compulsory if you want to be a system admin. I won't employed anybody without this knowledge to be a system admin. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html This post has been edited by oshiri: Apr 15 2009, 04:06 PM |
|
|
Apr 15 2009, 04:12 PM
|
![]() ![]()
Junior Member
134 posts Joined: Apr 2005 |
Hi Oshiri
QUOTE See the first command is to save ps ax output to output file. Then the output is read to textview. Followed by removal of output file. Yes, i have refer from the example you give me, I want to read the output text only, but i don't want to show the output... So I can ignore texview part right..? QUOTE Sleep is like pausing. Give some time for command to finish or what ever. For this one, i have insert time.sleep(0.5) between each of the commands...In python you can use: time.sleep(n) *n = int in seconds I want to confirm, is the way I did is the proper way in writing this functions? CODE example: command 1 time.sleep(n) command 2 By the way, It can run with no problem... Again thanks much This post has been edited by Law: Apr 16 2009, 04:28 AM |
|
|
Apr 15 2009, 11:32 PM
|
![]() ![]()
Junior Member
134 posts Joined: Apr 2005 |
CODE (version2.py:12312): libglade-WARNING **: Error loading image: Failed to open file './logoedit.png': No such file or directory (version2.py:12312): libglade-WARNING **: could not convert string to type `GdkPixbuf' for property `icon' (version2.py:12312): libglade-WARNING **: Error loading image: Failed to open file './bt_logo.png': No such file or directory (version2.py:12312): libglade-WARNING **: could not convert string to type `GdkPixbuf' for property `logo' I try to put logo on my GUI, but when i run the python file the error msg shown as above... is it bugs? |
|
|
Apr 16 2009, 11:19 AM
|
![]() ![]() ![]() ![]() ![]()
Senior Member
751 posts Joined: Nov 2004 |
QUOTE Yes, i have refer from the example you give me, I want to read the output text only, but i don't want to show the output... So I can ignore texview part right..? yes QUOTE I want to confirm, is the way I did is the proper way in writing this functions? You are right. But most of the time we don't need sleep. QUOTE I try to put logo on my GUI, but when i run the python file the error msg shown as above... is it bugs? Yes it is a bug but not a libglade's bug. It's glade2 bug. What you can do is, edit your glade file manually. Find the line where your image file is. Put full path to where your image will be found. ex: <property name="icon">/usr/share/pixmaps/logedit.png</property> |
|
|
Apr 16 2009, 01:57 PM
|
![]() ![]()
Junior Member
134 posts Joined: Apr 2005 |
QUOTE(oshiri @ Apr 16 2009, 11:19 AM) yes So you mean that i can just put like this:You are right. But most of the time we don't need sleep. command1 command2 command3 because the time.sleep() made slow response to my application... ignore this should be alright, my command to be enter here is only to create a new directory... QUOTE Yes it is a bug but not a libglade's bug. Amazing...it's worked...It's glade2 bug. What you can do is, edit your glade file manually. Find the line where your image file is. Put full path to where your image will be found. ex: <property name="icon">/usr/share/pixmaps/logedit.png</property> But each time when i save my glade file, the image will not show again... I want to make my application run as super user, I saw a solution for this is to create another window then use << xterm -e >>> Do you have any better idea for this?? I almost end to my "small application" ...very happy and glad have your help.... Hope to hear you soon... I'm waiting for you tutorial... This post has been edited by Law: Apr 16 2009, 02:15 PM |
|
|
|
|
|
Apr 16 2009, 09:44 PM
|
![]() ![]() ![]() ![]() ![]()
Senior Member
751 posts Joined: Nov 2004 |
QUOTE Amazing...it's worked... But each time when i save my glade file, the image will not show again... That is exepected. you need to edit everytime you save glade file. CODE I want to make my application run as super user, I saw a solution for this is to create another window then use << xterm -e >>> Do you have any better idea for this?? Try this : CODE if os.geteuid() != 0: print "You must be root." exit(1) ** Be carefull when using this in Debian. By default Debian does not allowed gui to be run from su. You need sux, gksu or kdesu to run gui from su. |
|
|
Apr 16 2009, 11:35 PM
|
![]() ![]()
Junior Member
134 posts Joined: Apr 2005 |
I have googling around...
I found that, run a GUI with root is a very bad idea... Why? |
|
|
Apr 17 2009, 10:06 AM
|
![]() ![]() ![]() ![]() ![]()
Senior Member
751 posts Joined: Nov 2004 |
QUOTE I found that, run a GUI with root is a very bad idea... Why? Probably it has to do with security so you wil not screw your system or open a hole for others to gain access with full previledge to your system. Back to python, you could actually run your gui from root using su-to-root (comes with Debian's menu package) with this code: CODE if os.geteuid() != 0: print "You are not root. Going to su you." os.system('su-to-root -X -c "python your.py" || exit 1') exit(1) Or if you want to use gksu: CODE if os.geteuid() != 0: print "You are not root. Going to su you." os.system('gksu -g -m "Masukkan Password Root Anda" "python your.py" || exit 1') exit(1) *I read somewhere that python has a module called gksu. But I can't find it anyewhere. Or you can create a su-to root bash wrapper for your python. example: CODE #! /bin/bash # su-to-root python wrapper # created by oshiri MYPY="python your.py" function check_su () { GK=FALSE if [ -f /usr/bin/su-to-root ]; then GK=TRUE fi if [ "$GK" = "FALSE" ]; then echo " You don't have su-to-root. Please apt-get install menu." exit 1 fi } function su_wrapper () { if [ "$UID" -ne 0 ]; then exec su-to-root -X -c "$MYPY" || exit 1 fi } check_su su_wrapper exit 0 Or gksu bash wrapper for your python: CODE #! /bin/bash # gksu python wrapper # created by oshiri MYPY="python your.py" function check_su () { GK=FALSE if [ -f /usr/bin/gksu ]; then GK=TRUE fi if [ "$GK" = "FALSE" ]; then echo " You don't have gksu. Please apt-get install gksu." exit 1 fi } function su_wrapper () { if [ "$UID" -ne 0 ]; then exec gksu -g -m "Masukkan Password Root Anda" "$MYPY" || exit 1 fi } check_su su_wrapper exit 0 This thread has become a tutorial place rather then Q&A. What in here will be in my tutorial.... soon. |
|
|
Apr 18 2009, 07:35 PM
|
![]() ![]()
Junior Member
134 posts Joined: Apr 2005 |
Hehe^^...
Really become a tutorial already... Still editing my python code now... |
|
|
Apr 21 2009, 05:28 PM
|
![]() ![]()
Junior Member
134 posts Joined: Apr 2005 |
Hi Oshiri,
When your tutorial will be done? What package is include in your OshiriX... Maybe will try it... |
|
|
Apr 21 2009, 05:56 PM
|
![]() ![]()
Junior Member
134 posts Joined: Apr 2005 |
Oh ya...
Is there any way to let a window shows immediately after a command button is clicked ?? because the window is waiting for the command running...and it will only show up after command complete running... |
|
|
Apr 21 2009, 09:07 PM
|
![]() ![]() ![]() ![]() ![]()
Senior Member
751 posts Joined: Nov 2004 |
Tutorial ...it's done. Check my site.
6 part all together. Will add more later, taking a break right now. Right now, my interest is in php-gtk. Oshirix, it's a hobby. Latest is Oshirix2009 , DVD. Multi desktop. There is no way you can download it now. The download "window" only open in short period of time. There is another version, cd, my experiment with netbook interfaces. Mainly for troubleshooting purposes. Not for public. QUOTE Is there any way to let a window shows immediately after a command button is clicked ?? because the window is waiting for the command running...and it will only show up after command complete running... Try send you command to background using & This post has been edited by oshiri: Apr 21 2009, 09:09 PM |
|
|
Apr 23 2009, 12:46 PM
|
![]() ![]()
Junior Member
134 posts Joined: Apr 2005 |
I have read through all your tutorials already...
great job dude... very good for anyone who want to learn python + glade + tepache... Very powerful !!! |
| Change to: | 0.0213sec
0.79
6 queries
GZIP Disabled
Time is now: 16th December 2025 - 02:16 AM |