window management

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

window management

Post by adventuresofgreg » Wed Mar 20, 2013 11:53 pm

Hello. I am looking for a way to manage a number in instances of a LiveCode standalone running in windows. Ideally, I want to make a standalone with a scrolling list of all LC apps currently running, and clicking on a line will bring that running SA app to the front. I assume this would have to be done using a shell and a windows command line. But, as far as I can tell, there is no command for making a window 'active'.

If I was running these SA instances on a Mac, I could simply "launch" the SA, and if it is already running, it would become active. But this doesnt work on WIndows because re-launching an app, launches a new instance of the app.

Thanks
Greg

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: window management

Post by Simon » Wed Mar 20, 2013 11:58 pm

Check out topStack in the dictionary

Simon
EDIT: or
go stack "myStack"
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: window management

Post by adventuresofgreg » Thu Mar 21, 2013 12:25 am

Thanks Simon, but from what I can tell, topstack returns the name of a stack in front, but doesn't set a standalone app (stack) to the front. Also, it appears that mainstacks function will return a list of all stacks running, but I doubt it would return a list of all instances of a standalone running, as WIndows see's each instance of a standalone as it's own unique exe.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: window management

Post by bn » Thu Mar 21, 2013 12:34 am

Hi Greg,

have a look at "relaunch" in the dictionary. That message should take care of multiple instances on Windows. I don't have a Windows computer to test it.

Kind regards
Bernd

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: window management

Post by adventuresofgreg » Thu Mar 21, 2013 12:54 am

Thanks Bernd. I just tried relaunch, and it will stop the standalone from launching multiple instances of itself (like OSX), however, upon a relaunch attempt, the result is NOT to bring the already launched standalone to the front (as it would - from what I recall - in OSX).

I remember a way back in the HyperCard days, I had written a 'launcher' stack that would build a list of my apps, and launch the one I selected. You could also use it to switch between currently running apps as well, because in OSX, once an app is running, it won't run another instance of it, and instead, will make the already running app to the front. (I think...)

This is basically what I need to do - but in Windows - with multiple instances of the same LC stack (as standalones)

Thanks

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: window management

Post by Simon » Thu Mar 21, 2013 1:29 am

How about using vbs?

Code: Select all

put "set WshShell = WScript.CreateObject("WScript.Shell")" & cr & "WSHShell.AppActivate "LiveCode 5.5.3" into tVbs
do tVbs as VBscript
Replace that LiveCode stuff with your app name.
Probably should check the platform first.

Simon
EDIT I messed up... let me figure this out
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: window management

Post by bn » Thu Mar 21, 2013 2:33 am

Hi Simon,

maybe there is a VB command to bring an application to the front. That could be triggered by the relaunch message Gregg's app gets on launch.
As far as I see that is the only problem that remains. But I just have no idea how this would work on Windows.
Kind regards
Bernd

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: window management

Post by Simon » Thu Mar 21, 2013 2:38 am

Ok I got it:

Code: Select all

on mouseUp
put "set WshShell = WScript.CreateObject("&quote&"WScript.Shell"&quote&")" & cr & \
"WSHShell.AppActivate "&quote&"notepad"&quote&""  into url "file:focus.vbs"
launch document "focus.vbs"
wait 1 second with messages
delete file "focus.vbs"
end mouseUp
replace "notepad" up there with your app
Note: you can use just "note" in the example above and it will find "notepad" it looks for the closest match. Might be of some help.
I was only able to get it to work if it was written to a file, not ideal :(

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: window management

Post by Simon » Thu Mar 21, 2013 3:44 am

Sorry I keep updating:

Code: Select all

on mouseUp
   set hideConsoleWindows to true
   get shell("tasklist")
   put it into tTask
   put "notepad" into tProg
   if tProg is in tTask then
      put "set WshShell = WScript.CreateObject("&quote&"WScript.Shell"&quote&")" & cr & \
            "WSHShell.AppActivate "&quote& tProg &quote&""  into url "file:focus.vbs"
      launch document "focus.vbs"
      wait 1 second with messages
      delete file "focus.vbs"
   else
      answer "app not running"
   end if
end mouseUp
I've added the shell to make sure your app is running first otherwise it might just focus the nearest named app.
You probably want to put that shell stuff into the openCard or somewhere so you only have to run it once... or maybe not? (you might start and stop apps randomly).
The name of your standalones should be unique (I found that adding .exe to the end didn't focus on the app).

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: window management

Post by adventuresofgreg » Thu Mar 21, 2013 4:04 pm

Thanks Simon - you are brilliant! It works. Only issue now, is I have to figure out a way to change the name of each standalone instance because if there are duplicate names running at the same time, the script won't work. Is it even possible for a standalone to change it's name?

thinking... Each instance of the standalone opens it's own data file. I could manually change the NAME of the standalone to reflect the data file that it is supposed to open. Then, rather than manually loading in the data file after I launch each instance of the SA, the SA could just automatically open it's own data file depending on it's name. That way, I would have uniquely named SA's to window manage... And easy start up procedure by simply launching all the SA's.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: window management

Post by Simon » Thu Mar 21, 2013 9:10 pm

I'm glad it's working for you :D
As I think about it, since your standalones were made with LC... Shouldn't they be substacks of your "control panel"?
Think about how much more you could do with them:
go stack "myStack" would work, you could open all of them at once or any of them. Bring any of them into focus.
All the substacks could communicate with each other.
Control their size and position via your control panel.
But most of all, be wickedly cool. 8)

It's easy to at least try out, just set the main stack to your control panel.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: window management

Post by sturgis » Thu Mar 21, 2013 9:18 pm

My suspicion is that separate instances are needed so that a pseudo type of multiprocessing can be done. (otherwise yeah i'm with you, just "go stack.." ) For some applications though popping up several instances can drastically decrease the time it takes to accomplish a task since each process can grab a separate core. (I've messed with this method as well as laying jobs off on several web servers running lc server on my network.. Pretty cool stuff!) Think one of the marks (I get confused) also put together a progress bar stack that is its own engine instance so that its easier to have a smoothly updating bar. I forget the details but seem to recall that it was pretty slick.

Of course, now i'm curious to know whats being done that might require the multiple instances!


EDIT: Also just remembered, if running on a mac I think you can still "send to program.." and call handlers directly to other instances.

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: window management

Post by adventuresofgreg » Thu Apr 11, 2013 5:42 pm

Simon: I finally got back to the "Switcher", and it would work PERFECTLY, except for one problem:

When I change the name of a SA (standalone) in windows, the name of the Process (as shown in Task Manager) now shows the new name, however, the name of the "APPLICATION" running (as shown in Task Manager) still shows the native application name (in Properties, this is the "Product name"). When refreshing the list showing currently running apps in Switcher, it will grab the new name, which is good, however, it can't find it because Windows thinks the name is the Product name.

Any ideas?

Thanks!
Greg

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: window management

Post by Simon » Thu Apr 11, 2013 10:08 pm

Hi Greg,
Are you renaming the apps while they are running?
Actually I'm quite confused as to what is you are doing, my testing was just to open up Word, Excel, Notepad and LC and then bring any of them into focus. That was what the vb script was doing for me.

What are you doing differently?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: window management

Post by adventuresofgreg » Thu Apr 11, 2013 10:32 pm

Hi Simon:

I'm sorry, my explanation was probably confusing. The reason it works with Notepad, Excel, and other applications are because they all have UNIQUE names. It doesn't work with duplicate copies of LC standalones, because, even though they have all been re-named with unique names, their 'actual', internal names are all the same (which is the same name that the stack was given before the SA was generated.) Just renaming the copies of the SA's by changing the file name in Windows, does not actually change it's name as it is referenced via Windows system and your tools.

Did that explain it better?

Greg

Post Reply