The time now is Mon 23 Apr 2018, 00:08
All times are UTC - 4 |
Page 1 of 2 [16 Posts] |
Goto page: 1, 2 Next |
Author |
Message |
PaulR
Joined: 04 May 2005 Posts: 249 Location: UK
|
Posted: Thu 21 Mar 2013, 11:28 Post subject:
BaCon + HUG execute and 'detach'? |
|
I've written a tiny BaCon/HUG program as a learning exercise. One of the callbacks starts another program but my program window remains 'unavailable' until the executed program terminates.
Is there any way to 'detach' the program I'm calling in the same way that <command> & or (<command> &) works in a terminal? so my program can continue?
I'm guessing that the callback isn't returning control to DISPLAY until the called program completes.
It occurs to me that I might be able to accomplish this by a TIMEOUT if I can read the button state rather than use a callback
Any help appreciated
Paul
|
Back to top
|
|
 |
vovchik

Joined: 23 Oct 2006 Posts: 1447 Location: Ukraine
|
Posted: Thu 21 Mar 2013, 11:40 Post subject:
|
|
Dear PaulR,
I was going to say welcome to the kennels, but I see you have been here longer than I have As for BaCon, I am certain one of us can give you some advice. Not a bad idea to post the source, so what we can see where the problem is.
With kind regards,
vovchik
|
Back to top
|
|
 |
PaulR
Joined: 04 May 2005 Posts: 249 Location: UK
|
Posted: Thu 21 Mar 2013, 12:06 Post subject:
|
|
Hi vovchik
Yes I've been a member for quite sometime but not an active user for ages, however I'm really enjoying using Puppy again!
The program works as expected generally, these are the relevant bits...
Code: |
....
CALLBACK(searchButton, subSearch)
DISPLAY
SUB subSearch
...
commandLine$ = GRAB$(entrySearch)
result$ = EXEC$(commandLine$)
...
END SUB
|
The program being called is another GUI program not just a terminal command.
I've checked the contents of commandLine$ and the called program executes as intended; as I mentioned it just 'freezes' my program window (ie it is not receiving any 'paint' instructions) until execution of the called program terminates. My program continues to work as intended once the called program returns.
I don't think there's any error in my code (it is uber-simple after all), it may be that processes started in this way have to complete before the program can resume.
Many thanks
Paul
|
Back to top
|
|
 |
vovchik

Joined: 23 Oct 2006 Posts: 1447 Location: Ukraine
|
Posted: Thu 21 Mar 2013, 12:29 Post subject:
|
|
Dear PaulR,
This should work for invoking a separate prog in a separate thread:
Code: |
commandLine$ = GRAB$(entrySearch) & " &"
|
or
Code: |
result$ = EXEC$(commandLine$ & " &")
|
I am not certain that your callback will work the way you imagine, but maybe it can. I don't see all the code. In any case, you usually define a CALLBACK for a widget, e.g.:
Code: |
SUB MYQUIT()
PRINT "Quitting prog"
QUIT
END SUB
' make button
but1 = BUTTON("quit", 90, 30)
' fix it to a window
ATTACH(win, but1, 10, 10)
' define action that pressing that button will do
CALLBACK(but, MYQUIT)
DISPLAY
|
If you want arguments passed, use CALLBACKX. You seem to be doing that normally.
With kind regards,
vovchik
|
Back to top
|
|
 |
PaulR
Joined: 04 May 2005 Posts: 249 Location: UK
|
Posted: Thu 21 Mar 2013, 16:30 Post subject:
|
|
Hi vovchik
Thanks for the assistance - I'm sure I tried appending an ampersand (as per my earlier post re the terminal) but I must have done something wrong.
Anyway, I used the syntax you suggested and it worked fine ie the program was launching in it's own thread and not tying up my program.
However, since I added some more code (the part dealing with postfix$ in the callback) it has reverted to the original problem.
Anyway, the program is designed to speed up searching on the net for Puppy related stuff - enter search terms, choose the search target and hit search. I just got tired of typing 'puppy linux' for every search!
I've attached the full source, perhaps you could cast an eye over it?
Many thanks
Paul
PS Is there a way to make the search button the default event when someone hits enter?
PPS I know there's a warning I need to sort out regarding a label/caption
EDIT: I've fixed the warning and edited the code below - the xalign property requires a value of '0.0' rather than '0' ... quirky! (personally I would have used -1/0/1 to indicate aligment, or better yet have LEFT, RIGHT, CENTER #defined - I'm going to do that now!).
Code: |
' Simple utility to google (with firefox) for Puppy Linux terms
' (hard-coded for Firefox/Google but easy to change for other browser/search engine)
' By Paul Robinson 2013
'include the BaCon GUI library
INCLUDE "/usr/share/BaCon/hug_imports.bac"
'this is required when using library above
INIT
versionNo$ = "1.0"
'create the window and widgets
'set window title once name has been supplied?
appWindow = WINDOW(CONCAT$("Psearch ", versionNo$), 220, 180)
'label and text box for user's search terms
markSearchLabel=MARK("Search for", 100, 15)
PROPERTY(markSearchLabel, "xalign", 0.0)
ATTACH(appWindow, markSearchLabel, 10, 10)
entrySearchTerms=ENTRY("", 130, 15)
ATTACH(appWindow, entrySearchTerms, 80, 10)
'radio buttons for search target choice
'put in a frame
rbFrame = FRAME(200, 100)
TEXT(rbFrame, "Target: ")
ATTACH(appWindow, rbFrame, 8, 35)
radioG = RADIO("Google", 200, 15, radioG)
ATTACH(appWindow, radioG, 10, 55)
radioP = RADIO("Puppylinux.org", 200, 15, radioG)
ATTACH(appWindow, radioP, 10, 80)
radioF = RADIO("Puppy Linux Forum", 200, 15, radioG)
ATTACH(appWindow, radioF, 10, 105)
'set default target to google
SET(radioG, TRUE)
'button to run search
searchButton=BUTTON("Search", 50, 30)
ATTACH(appWindow, searchButton, 160, 140)
'button to quit
quitButton=BUTTON("Exit", 50, 30)
ATTACH(appWindow, quitButton, 10, 140)
'define callbacks
'ie functions for widget events
CALLBACK(quitButton, QUIT)
CALLBACK(searchButton, subSearch)
'show the window
DISPLAY
'search button callback
SUB subSearch
'specify new tab in case Firefox is already open
searchURL$ = "firefox -new-tab http://www.google.com/search?q="
IF GET(radioG) THEN
postfix$ = ""
ELIF GET(radioP) THEN
postfix$ = "+site:puppylinux.org"
ELSE
postfix$ = "+site:murga-linux.com/puppy"
END IF
'get user input, replacing any spaces with '+' signs
searchTerms$ = REPLACE$(GRAB$(entrySearchTerms), " ", "+")
'TODO add code to remove or escape single/double quotes
'concat the user's search terms to hard-wired "puppy linux"
searchTerms$ = CONCAT$("puppy+linux+", searchTerms$)
'add any site specific search requirement
searchTerms$ = CONCAT$(searchTerms$, postfix$)
'add that to the basic url string
commandLine$ = CONCAT$(searchURL$, searchTerms$)
'start firefox in it's own thread
result$ = EXEC$(commandLine$ & " &")
END SUB
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 3431 Location: www.eussenheim.de/
|
Posted: Fri 22 Mar 2013, 08:30 Post subject:
psearch Subject description: using STOCK and defaulthtviewer |
|
Very nice.
At the moment I have running your prog in puppy precise.
Just changed
firefox
to
defaulthtmlviewer
and
Code: | 'button to run search
searchButton=BUTTON("Search", 50, 30)
ATTACH(appWindow, searchButton, 160, 140)
'button to quit
quitButton=BUTTON("Exit", 50, 30)
ATTACH(appWindow, quitButton, 10, 140)
|
to Code: | 'button to run search
searchButton = STOCK("gtk-find", 90, 30)
ATTACH(appWindow, searchButton, 116, 140)
'button to quit
quitButton = STOCK("gtk-quit", 100, 30)
ATTACH(appWindow, quitButton, 8, 140) |
Description |
|
Filesize |
3.45 KB |
Viewed |
284 Time(s) |

|
|
Back to top
|
|
 |
Mobeus

Joined: 26 Aug 2010 Posts: 94
|
Posted: Fri 22 Mar 2013, 08:39 Post subject:
|
|
Hello Paul
SYSTEM may work better for you in this case.
Code: | SYSTEM "firefox &"
' r$= EXEC$("firefox &")
FOR i = 1 TO 100
PRINT i
NEXT
END
|
Regards,
Mobeus
_________________ /root for the home team
|
Back to top
|
|
 |
PaulR
Joined: 04 May 2005 Posts: 249 Location: UK
|
Posted: Fri 22 Mar 2013, 09:15 Post subject:
|
|
L18L, glad you think it's useful, I can think of a few features to add...
- Use checkboxes to allow search of multiple sites (just found this is possible by passing site:somesite.com OR site:anothersite.com )
- Add a box to specify browser (and save that setting) but with hindsight your defaulthtmlviewer is probably better/easier. EDIT: not sure how all browsers would cope with the new-tab switch though?
- Allow user-defined sites to search (ie allow editing of the three existing sites)
I'm not keen on all these magic numbers for widget layout either.. now there's a project for someone - a BaCon HUG layout tool!
Mobeus, I haven't tried your idea but the BaCon docs about SYSTEM says;
"It causes the BaCon program to hold until the command has been completed."
...and that is the problem I have. Strange that it worked ok for a time but doesn't now. Echoing commandLine$ doesn't help much either...thinking!
Paul
|
Back to top
|
|
 |
PaulR
Joined: 04 May 2005 Posts: 249 Location: UK
|
Posted: Fri 22 Mar 2013, 09:31 Post subject:
|
|
Well this is strange - I just modified the source to add the STOCK buttons and repositioned some of the widgets, re-compiled and now the program works properly i.e it seems to run in its own thread allowing re-use without closing the browser!
Paul
Here's the updated code - for anyone experimenting (like me!) you need to compile with the -j option to take account of the #define, for example:
# bacon -j psearch.bac
Code: |
' Simple utility to google (with firefox) for Puppy Linux terms
' (hard-coded for Firefox/Google but easy to change for other browser/search engine)
' By Paul Robinson 2013
#define ALIGNLEFT 0.0
'include the BaCon GUI library
INCLUDE "/usr/share/BaCon/hug_imports.bac"
'this is required when using library above
INIT
versionNo$ = "1.0"
'create the window and widgets
'set window title once name has been supplied?
appWindow = WINDOW(CONCAT$("Psearch ", versionNo$), 216, 176)
'label and text box for user's search terms
markSearchLabel=MARK("Search for", 100, 15)
PROPERTY(markSearchLabel, "xalign", ALIGNLEFT)
ATTACH(appWindow, markSearchLabel, 10, 10)
entrySearchTerms=ENTRY("", 130, 15)
ATTACH(appWindow, entrySearchTerms, 78, 10)
'radio buttons for search target choice
'put in a frame
rbFrame = FRAME(200, 100)
TEXT(rbFrame, "Target: ")
ATTACH(appWindow, rbFrame, 8, 35)
radioG = RADIO("Google", 200, 15, radioG)
ATTACH(appWindow, radioG, 10, 55)
radioP = RADIO("Puppylinux.org", 200, 15, radioG)
ATTACH(appWindow, radioP, 10, 80)
radioF = RADIO("Puppy Linux Forum", 200, 15, radioG)
ATTACH(appWindow, radioF, 10, 105)
'set default target to google
SET(radioG, TRUE)
'button to run search
searchButton=STOCK("gtk-find", 90, 30)
ATTACH(appWindow, searchButton, 118, 142)
'button to quit
quitButton=STOCK("gtk-quit", 100, 30)
ATTACH(appWindow, quitButton, 8, 142)
'define callbacks
'ie functions for widget events
CALLBACK(quitButton, QUIT)
CALLBACK(searchButton, subSearch)
'show the window
DISPLAY
'search button callback
SUB subSearch
'specify new tab in case Firefox is already open
searchURL$ = "firefox -new-tab http://www.google.com/search?q="
IF GET(radioG) THEN
postfix$ = ""
ELIF GET(radioP) THEN
postfix$ = "+site:puppylinux.org"
ELSE
postfix$ = "+site:murga-linux.com/puppy"
END IF
'get user input, replacing any spaces with '+' signs
searchTerms$ = REPLACE$(GRAB$(entrySearchTerms), " ", "+")
'TODO add code to remove or escape single/double quotes
'concat the user's search terms to hard-wired "puppy linux"
searchTerms$ = CONCAT$("puppy+linux+", searchTerms$)
'add any site specific search requirement
searchTerms$ = CONCAT$(searchTerms$, postfix$)
'add that to the basic url string
commandLine$ = CONCAT$(searchURL$, searchTerms$)
'start firefox in it's own thread
result$ = EXEC$(commandLine$ & " &")
END SUB
| [/code]
Last edited by PaulR on Fri 22 Mar 2013, 09:37; edited 1 time in total
|
Back to top
|
|
 |
Mobeus

Joined: 26 Aug 2010 Posts: 94
|
Posted: Fri 22 Mar 2013, 09:32 Post subject:
|
|
Paul,
Yes the docs do say that but that's not quite what happens. Run the code from the terminal with SYSTEM then with EXEC and you will see the difference.
Regards,
Mobeus
_________________ /root for the home team
|
Back to top
|
|
 |
PaulR
Joined: 04 May 2005 Posts: 249 Location: UK
|
Posted: Fri 22 Mar 2013, 09:38 Post subject:
|
|
Hi Mobeus
Haha, I'll try that a little later, many thanks (although see my last post the program is now working as intended!).
EDIT: Tried that, there's no discernible difference, both forms seems to work ok now.
Paul
|
Back to top
|
|
 |
Mobeus

Joined: 26 Aug 2010 Posts: 94
|
Posted: Fri 22 Mar 2013, 11:17 Post subject:
|
|
Paul,
I tested your app, nice & handy too. Thanks!
It would not build as is on my system. It's Lupu 5.10 and has the old hug.so from 2011.
Just FYI, to get it to build (and work without hanging) I used the latest bacon and hug.bac and made these changes.
Code: | USEH
#define ALIGNLEFT 0.0
END USEH
'include the BaCon GUI library
'INCLUDE "/usr/share/BaCon/hug_imports.bac"
'this is required when using library above
INCLUDE "hug.bac" |
and
Code: | commandLine$ = CONCAT$(searchURL$, searchTerms$, " &")
'start firefox in it's own thread
'result$ = EXEC$(commandLine$)
SYSTEM commandLine$
|
Compiled it without the -j option
Regards,
Mobeus
_________________ /root for the home team
|
Back to top
|
|
 |
PaulR
Joined: 04 May 2005 Posts: 249 Location: UK
|
Posted: Fri 22 Mar 2013, 12:55 Post subject:
|
|
Great, I understand.
I've been working on using checkboxes such that a user can search either Google OR one or both sites. Finally got the checkbox logic figured out (after fighting with nested if statements all afternoon!), should have a modified version ready later today or tomorrow.
Thanks for the help
Paul
|
Back to top
|
|
 |
PaulR
Joined: 04 May 2005 Posts: 249 Location: UK
|
Posted: Fri 22 Mar 2013, 14:38 Post subject:
|
|
OK the next version is ready
Just one thing I need to know:
What will be the effect of the -new-tab switch if I change the called program to defaulthtmlviewer and the browser is something other than Firefox?
I'll build and compress the executable and upload it to some webspace with the source for anyone to access.
Paul
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 3431 Location: www.eussenheim.de/
|
Posted: Fri 22 Mar 2013, 15:01 Post subject:
|
|
PaulR wrote: | ...What will be the effect of the -new-tab switch if I change the called program to defaulthtmlviewer and the browser is something other than Firefox? | seamonkey has worked fine with me.
PaulR wrote: | I'll build and compress the executable and upload it to some webspace with the source for anyone to access. | Browsers and Internet in Additional software here on this forum will do it too
|
Back to top
|
|
 |
|
Page 1 of 2 [16 Posts] |
Goto page: 1, 2 Next |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|