Please allow OpenWindow inside threads

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
kandl
User
User
Posts: 11
Joined: Sat Apr 11, 2009 6:54 am

Please allow OpenWindow inside threads

Post by kandl »

HI

I have multiple projects that uses OpenWindow inside a thread. They function as background processes and have their independent message processing loop. One example is an OpenGL application that spawns a drawing thread separate from the main window, it opens another window in its own thread to probe the extension list. I also have property windows that are non-modal and they require separate event processing as well. All of this functions perfectly in 4.50. I suggest that purebasic change the ERROR to a WARNING because it severely limits the way applications are developed.

Thanks!
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Please allow OpenWindow inside threads

Post by luis »

"Have you tried turning it off and on again ?"
A little PureBasic review
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Please allow OpenWindow inside threads

Post by rsts »

+1

Who's going to rewrite all the useful code snippets that use openWindow in a thread?
:)
infratec
Always Here
Always Here
Posts: 7575
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Please allow OpenWindow inside threads

Post by infratec »

At least there should be a 'MessageRequester()' which is not modal
and can be closed by second call or a 'CloseMessageRequester()'.

Like this:

Code: Select all

MessageRequester("Info", "Please wait ...", #PB_Window_NotModal)
DoSomething()
CloseMessageRequester()
If I have to do such a thing via PostEvent() and ...
it is a lot of overhead and a lot of work :cry:

Or I have to use always

Code: Select all

DisableDebugger
Win = OpenWindow()
EnableDebugger
TextGadget()
DoSomething()
CloseWindow(Win)
:cry:

Bernd
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Please allow OpenWindow inside threads

Post by rsts »

Not necessarily just messageRequester. Several "requester type" snippets rely on threaded behavior to accommodate input.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Please allow OpenWindow inside threads

Post by jassing »

+1 -- it should be a warning..
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Please allow OpenWindow inside threads

Post by netmaestro »

Fred wrote:The problem is it won't work on other OS.
If it works without problems on Windows but causes issues on the other platforms, I think PureBasic for Windows should allow it without any warnings at all and do something different for the other OS's. It's all well and good to be crossplatform but if targeting multiple platforms means crippling the Windows version to accommodate the other operating systems then we're not doing it right. Just my opinion, worth the standard two cents.
BERESHEIT
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Please allow OpenWindow inside threads

Post by skywalk »

I agree. Better approach is to maximize OS support and let documentation do the rest. :wink:
Elements of this are already in play with Callbacks, OnError Lines, etc.
http://www.purebasic.com/documentation/ ... cific.html
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Please allow OpenWindow inside threads

Post by Fred »

Then you will get some angry comments when someone have a 100% working PB program on Windows and want to do a Linux or OS X version as it won't work at all. We enforce it, but if you really want, you can put some disabledebugger around the calls.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Please allow OpenWindow inside threads

Post by PMV »

Fred wrote:Then you will get some angry comments when someone have a 100% working PB program on Windows and want to do a Linux or OS X version as it won't work at all. We enforce it, but if you really want, you can put some disabledebugger around the calls.
Do you remember any commend about that?
I just remember threads where people are confused, why it is not working ...
and they just want to know what they have done wrong ... after you
have explained it, it was ok again, just angry about that they have
used time for programing something wrong ... so it could
be improved in that way to tell them that it will not work on linux/ mac.
A warning on windows instead of an error is the better choice.
On linux and mac it should be still an error.

There are always people who complain about something, if you can
stand this every-month-topic, still your choice :wink:
But for me, there is no reason behind this "error".

MFG PMV
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Please allow OpenWindow inside threads

Post by luis »

I admit didn't even try it, but if the problem is only reported by the debugger, and if you can use the enable/disable debugger as Fred explained to suppress the error on Windows I don't think this is a problem at all.
It's a remainder that on another os could not work at all and you should find another way if you want port your program on another os.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Please allow OpenWindow inside threads

Post by netmaestro »

if you can use the enable/disable debugger as Fred explained to suppress the error on Windows I don't think this is a problem at all.
Sure, fair enough. I like to send messages to the main thread myself and the new PostEvent() will suit me fine.
BERESHEIT
kandl
User
User
Posts: 11
Joined: Sat Apr 11, 2009 6:54 am

Re: Please allow OpenWindow inside threads

Post by kandl »

Thanks Bernd!

The debugger also disallows WaitWindowEvent() and WindowEvent() from executing from inside a thread.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Please allow OpenWindow inside threads

Post by c4s »

kandl wrote:The debugger also disallows WaitWindowEvent() and WindowEvent() from executing from inside a thread.
Yes. Because of that I'm using something like:

Code: Select all

Procedure _OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags=0, ParentID=0)
	Protected Result = 0

	DisableDebugger
	Result = OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags, ParentID)
	EnableDebugger

	ProcedureReturn Result
EndProcedure

Procedure _WaitWindowEvent(Timeout=#PB_Default)
	Protected Result = 0

	DisableDebugger
	Result = WaitWindowEvent(Timeout)
	EnableDebugger

	ProcedureReturn Result
EndProcedure
Just replace all "OpenWindow(" with "_OpenWindow(" etc. and PureBasic should work as before.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
CalamityJames
User
User
Posts: 81
Joined: Sat Mar 13, 2010 4:50 pm

Re: Please allow OpenWindow inside threads

Post by CalamityJames »

I would like to add my voice to those calling for a less heavy-handed approach to opening a window in its own thread. Clearly, not being able to do it in Linux or the Mac OS is an important limitation which those writing cross-platform programs need to be aware of. However there are other important limitations in some PureBasic commands. They are dealt with in the documentation and that is the proper place.
My own PureBasic is set up with only the compiler for Windows active. I frequently use direct calls to the Windows API which obviously means my programs can run only in Windows. Despite this, I am instructed that I cannot open a window in its own thread! I can turn off the compiler as mentioned, but I am not fond of this inelegant solution. I don’t think it should be necessary.
Post Reply