Discussion:
Window default position...
SH Development
2016-12-11 06:28:43 UTC
Permalink
I’ve been going around and around with this for a while now this evening.

I have a very simple program that writes to a prefs file with the main window’s placement, top, left. This happens both when the window is closed AND when it is moved. Prefs are saved on either event.

The prefs file correctly shows the position I have dragged the window to on any of the screens. However, when I relaunch the application, it always resets the left to a value of 10 and changes it in the prefs file.

In trying different settings for the window in the IDE, I have found that changing the placement behavior affects the problem. When set to “Default”, it always reverts to a left value of 10. When set to "Main Screen", it always jumps back to a left value of 1422, basically centered on my gi-normous 34” Dell monitor.

Is there a way to NOT use any kind of default behavior and simply position the window where I set it? Code follows:


Sub Open()
// Initialize the preferences handler and check for an existing prefs file. PreferencesModule.Initialize(“Test Program")
If Not Preferences.Load then
Preferences.wTop=10 // Main window top coordinate.
Preferences.wLeft=50 // Main window left coordinate.
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
// This will create the folder ~/Library/Application Support/Test Program if it doesn't already exist.
// Creates the default preferences.
End if
mainwindow.Show
End Sub

Sub Close()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub

Sub Moved()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub

Sub Open()
self.top=Preferences.wTop
self.left=Preferences.wLeft
End Sub


I am using the preferences module from Paul Lefebvre as posted on the Xojo developer site. Thoughts?

Jeff J.
_______________________________________________

Xojo forum:

https://forum.xojo.co
Jim Wagner
2016-12-11 06:53:06 UTC
Permalink
I think that you have to apply the position AFTER the .show. Its not totally clear to me when, in the opening process, that you apply the position.

Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by SH Development
I’ve been going around and around with this for a while now this evening.
I have a very simple program that writes to a prefs file with the main window’s placement, top, left. This happens both when the window is closed AND when it is moved. Prefs are saved on either event.
The prefs file correctly shows the position I have dragged the window to on any of the screens. However, when I relaunch the application, it always resets the left to a value of 10 and changes it in the prefs file.
In trying different settings for the window in the IDE, I have found that changing the placement behavior affects the problem. When set to “Default”, it always reverts to a left value of 10. When set to "Main Screen", it always jumps back to a left value of 1422, basically centered on my gi-normous 34” Dell monitor.
Sub Open()
// Initialize the preferences handler and check for an existing prefs file. PreferencesModule.Initialize(“Test Program")
If Not Preferences.Load then
Preferences.wTop=10 // Main window top coordinate.
Preferences.wLeft=50 // Main window left coordinate.
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
// This will create the folder ~/Library/Application Support/Test Program if it doesn't already exist.
// Creates the default preferences.
End if
mainwindow.Show
End Sub
Sub Close()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Moved()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Open()
self.top=Preferences.wTop
self.left=Preferences.wLeft
End Sub
I am using the preferences module from Paul Lefebvre as posted on the Xojo developer site. Thoughts?
Jeff J.
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:
Jim Wagner
2016-12-11 07:48:00 UTC
Permalink
To further clarify, I’ll bet that the position is automatically determined as part of the show process, without regard to what it might have been set, previously. If this is so, then you need to show the window, THEN apply the new position. Yes, it may make for a window that scoots across the screen, but you may not have much choice.

Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Jim Wagner
I think that you have to apply the position AFTER the .show. Its not totally clear to me when, in the opening process, that you apply the position.
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by SH Development
I’ve been going around and around with this for a while now this evening.
I have a very simple program that writes to a prefs file with the main window’s placement, top, left. This happens both when the window is closed AND when it is moved. Prefs are saved on either event.
The prefs file correctly shows the position I have dragged the window to on any of the screens. However, when I relaunch the application, it always resets the left to a value of 10 and changes it in the prefs file.
In trying different settings for the window in the IDE, I have found that changing the placement behavior affects the problem. When set to “Default”, it always reverts to a left value of 10. When set to "Main Screen", it always jumps back to a left value of 1422, basically centered on my gi-normous 34” Dell monitor.
Sub Open()
// Initialize the preferences handler and check for an existing prefs file. PreferencesModule.Initialize(“Test Program")
If Not Preferences.Load then
Preferences.wTop=10 // Main window top coordinate.
Preferences.wLeft=50 // Main window left coordinate.
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
// This will create the folder ~/Library/Application Support/Test Program if it doesn't already exist.
// Creates the default preferences.
End if
mainwindow.Show
End Sub
Sub Close()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Moved()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Open()
self.top=Preferences.wTop
self.left=Preferences.wLeft
End Sub
I am using the preferences module from Paul Lefebvre as posted on the Xojo developer site. Thoughts?
Jeff J.
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
SH Development
2016-12-11 08:02:06 UTC
Permalink
Have tried it both ways. Putting:

mainwindow.top=Preferences.wTop
mainwindow.left=Preferences.wLeft

Just before the mainwindow.show

And in the Open event of the window:

self.top=Preferences.wTop
self.left=Preferences.wLeft

No difference either way.

Jeff J.
Post by Jim Wagner
To further clarify, I’ll bet that the position is automatically determined as part of the show process, without regard to what it might have been set, previously. If this is so, then you need to show the window, THEN apply the new position. Yes, it may make for a window that scoots across the screen, but you may not have much choice.
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Jim Wagner
I think that you have to apply the position AFTER the .show. Its not totally clear to me when, in the opening process, that you apply the position.
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by SH Development
I’ve been going around and around with this for a while now this evening.
I have a very simple program that writes to a prefs file with the main window’s placement, top, left. This happens both when the window is closed AND when it is moved. Prefs are saved on either event.
The prefs file correctly shows the position I have dragged the window to on any of the screens. However, when I relaunch the application, it always resets the left to a value of 10 and changes it in the prefs file.
In trying different settings for the window in the IDE, I have found that changing the placement behavior affects the problem. When set to “Default”, it always reverts to a left value of 10. When set to "Main Screen", it always jumps back to a left value of 1422, basically centered on my gi-normous 34” Dell monitor.
Sub Open()
// Initialize the preferences handler and check for an existing prefs file. PreferencesModule.Initialize(“Test Program")
If Not Preferences.Load then
Preferences.wTop=10 // Main window top coordinate.
Preferences.wLeft=50 // Main window left coordinate.
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
// This will create the folder ~/Library/Application Support/Test Program if it doesn't already exist.
// Creates the default preferences.
End if
mainwindow.Show
End Sub
Sub Close()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Moved()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Open()
self.top=Preferences.wTop
self.left=Preferences.wLeft
End Sub
I am using the preferences module from Paul Lefebvre as posted on the Xojo developer site. Thoughts?
Jeff J.
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://forum.xo
François Van Lerberghe
2016-12-11 08:39:25 UTC
Permalink
Try without using the Moved event.
Btw, why do you save the coordinates in the Moved event ? It seems to me that Open and Close are sufficient (and that's what I use successfully).

François Van Lerberghe
Thier Monty, 15 A
4570 Marchin (Belgium)
+32 (0) 85 25 08 25
Post by SH Development
mainwindow.top=Preferences.wTop
mainwindow.left=Preferences.wLeft
Just before the mainwindow.show
self.top=Preferences.wTop
self.left=Preferences.wLeft
No difference either way.
Jeff J.
Post by Jim Wagner
To further clarify, I’ll bet that the position is automatically determined as part of the show process, without regard to what it might have been set, previously. If this is so, then you need to show the window, THEN apply the new position. Yes, it may make for a window that scoots across the screen, but you may not have much choice.
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Jim Wagner
I think that you have to apply the position AFTER the .show. Its not totally clear to me when, in the opening process, that you apply the position.
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by SH Development
I’ve been going around and around with this for a while now this evening.
I have a very simple program that writes to a prefs file with the main window’s placement, top, left. This happens both when the window is closed AND when it is moved. Prefs are saved on either event.
The prefs file correctly shows the position I have dragged the window to on any of the screens. However, when I relaunch the application, it always resets the left to a value of 10 and changes it in the prefs file.
In trying different settings for the window in the IDE, I have found that changing the placement behavior affects the problem. When set to “Default”, it always reverts to a left value of 10. When set to "Main Screen", it always jumps back to a left value of 1422, basically centered on my gi-normous 34” Dell monitor.
Sub Open()
// Initialize the preferences handler and check for an existing prefs file. PreferencesModule.Initialize(“Test Program")
If Not Preferences.Load then
Preferences.wTop=10 // Main window top coordinate.
Preferences.wLeft=50 // Main window left coordinate.
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
// This will create the folder ~/Library/Application Support/Test Program if it doesn't already exist.
// Creates the default preferences.
End if
mainwindow.Show
End Sub
Sub Close()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Moved()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Open()
self.top=Preferences.wTop
self.left=Preferences.wLeft
End Sub
I am using the preferences module from Paul Lefebvre as posted on the Xojo developer site. Thoughts?
Jeff J.
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://forum.xojo.com/
Pascal PLUCHON
2016-12-11 10:03:04 UTC
Permalink
Hi,

Use the bounds property. Works fine for me.

http://docs.xojo.com/index.php/Window.Bounds

Regards,
Pascal PLUCHON
Post by François Van Lerberghe
Try without using the Moved event.
Btw, why do you save the coordinates in the Moved event ? It seems to me that Open and Close are sufficient (and that's what I use successfully).
François Van Lerberghe
Thier Monty, 15 A
4570 Marchin (Belgium)
+32 (0) 85 25 08 25
Post by SH Development
mainwindow.top=Preferences.wTop
mainwindow.left=Preferences.wLeft
Just before the mainwindow.show
self.top=Preferences.wTop
self.left=Preferences.wLeft
No difference either way.
Jeff J.
Post by Jim Wagner
To further clarify, I’ll bet that the position is automatically determined as part of the show process, without regard to what it might have been set, previously. If this is so, then you need to show the window, THEN apply the new position. Yes, it may make for a window that scoots across the screen, but you may not have much choice.
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Jim Wagner
I think that you have to apply the position AFTER the .show. Its not totally clear to me when, in the opening process, that you apply the position.
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by SH Development
I’ve been going around and around with this for a while now this evening.
I have a very simple program that writes to a prefs file with the main window’s placement, top, left. This happens both when the window is closed AND when it is moved. Prefs are saved on either event.
The prefs file correctly shows the position I have dragged the window to on any of the screens. However, when I relaunch the application, it always resets the left to a value of 10 and changes it in the prefs file.
In trying different settings for the window in the IDE, I have found that changing the placement behavior affects the problem. When set to “Default”, it always reverts to a left value of 10. When set to "Main Screen", it always jumps back to a left value of 1422, basically centered on my gi-normous 34” Dell monitor.
Sub Open()
// Initialize the preferences handler and check for an existing prefs file. PreferencesModule.Initialize(“Test Program")
If Not Preferences.Load then
Preferences.wTop=10 // Main window top coordinate.
Preferences.wLeft=50 // Main window left coordinate.
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
// This will create the folder ~/Library/Application Support/Test Program if it doesn't already exist.
// Creates the default preferences.
End if
mainwindow.Show
End Sub
Sub Close()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Moved()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Open()
self.top=Preferences.wTop
self.left=Preferences.wLeft
End Sub
I am using the preferences module from Paul Lefebvre as posted on the Xojo developer site. Thoughts?
Jeff J.
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

h
Marnaud
2016-12-11 10:22:33 UTC
Permalink
Post by Pascal PLUCHON
Use the bounds property. Works fine for me.
http://docs.xojo.com/index.php/Window.Bounds
Hello,
I’m still convinced the original problem is the use of the Moved event for that purpose. I’m almost certain that event is called near the opening of the window; it would mean the Moved event is also called before the window has been restored, saving the wrong position to the file.
_______________________________________________

Xojo forum:

https://forum.xojo.com/
Pascal PLUCHON
2016-12-11 10:27:11 UTC
Permalink
Hello,

I save bounds when quitting the app, and restore the values when opening. No need to save bounds when the window is moved.

The doc says : "Use this property to Get/Set the true bounds of a window (i.e. including frame/title decorations)."

Regards,
Pascal.
Post by Marnaud
Post by Pascal PLUCHON
Use the bounds property. Works fine for me.
http://docs.xojo.com/index.php/Window.Bounds
Hello,
I’m still convinced the original problem is the use of the Moved event for that purpose. I’m almost certain that event is called near the opening of the window; it would mean the Moved event is also called before the window has been restored, saving the wrong position to the file.
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xoj
Marnaud
2016-12-11 10:30:56 UTC
Permalink
Post by Marnaud
Hello,
I save bounds when quitting the app, and restore the values when opening. No need to save bounds when the window is moved.
Hello,
We both agree.
Post by Marnaud
The doc says: "Use this property to Get/Set the true bounds of a window (i.e. including frame/title decorations)."
I didn’t know about this property. I guess it’s relatively new (my licence expired last august).

Regards,
Arnaud
_______________________________________________

Xojo forum:

https://forum.xojo.com/
Claudius Sailer
2016-12-11 10:35:22 UTC
Permalink
Halo,

I didn’t followed the complete thread.


im Move Event of a window I use this

if PrefDic.value("FensterBuchungX")<>self.Left OR PrefDic.value("FensterBuchungY")<>self.Top OR PrefDic.value("FensterBuchungH")<>self.Height OR PrefDic.value("FensterBuchungB")<>self.width then
PrefDic.value("FensterBuchungX")=self.Left
PrefDic.value("FensterBuchungY")=self.Top
PrefDic.value("FensterBuchungH")=self.Height
PrefDic.value("FensterBuchungB")=self.width
PrefSpeicher ‚‘Saving Prefs for next use when App is started new
end if

same code in Event „Resized“


I have a method

WindowPositioning
self.left=PrefDic.value("FensterBuchungX")
self.top=PrefDic.value("FensterBuchungY")
self.Height=PrefDic.value("FensterBuchungH")
self.Width=PrefDic.value("FensterBuchungB")

I call this method by open event of the window.

possibly not best solution but it works more than 10 year without any problem and it is easy!!!!
Post by Marnaud
Post by Pascal PLUCHON
Use the bounds property. Works fine for me.
http://docs.xojo.com/index.php/Window.Bounds
Hello,
I’m still convinced the original problem is the use of the Moved event for that purpose. I’m almost certain that event is called near the opening of the window; it would mean the Moved event is also called before the window has been restored, saving the wrong position to the file.
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://forum.xojo.co
vaughnsc .
2016-12-11 13:03:06 UTC
Permalink
I agree that the 'wpos' should be set only on window.close or app.close but
the issue is in window.open: unless i missed something i only saw wpos set
when preferences failed to be read?

i might also add that you should test handling in Windows (big W) if the
window was maximized (full screen) by user, otherwise you may save
offscreen coordinates like -10000

Vaughn
Post by Claudius Sailer
Halo,
I didn’t followed the complete thread.
im Move Event of a window I use this
if PrefDic.value("FensterBuchungX")<>self.Left OR PrefDic.value("FensterBuchungY")<>self.Top
OR PrefDic.value("FensterBuchungH")<>self.Height OR PrefDic.value("FensterBuchungB")<>self.width
then
PrefDic.value("
FensterBuchungX")=self.Left
PrefDic.value("
FensterBuchungY")=self.Top
PrefDic.value("
FensterBuchungH")=self.Height
PrefDic.value("
FensterBuchungB")=self.width
PrefSpeicher ‚‘Saving
Prefs for next use when App is started new
end if
same code in Event „Resized“
I have a method
WindowPositioning
self.left=PrefDic.value("
FensterBuchungX")
self.top=PrefDic.value("
FensterBuchungY")
self.Height=PrefDic.value("
FensterBuchungH")
self.Width=PrefDic.value("
FensterBuchungB")
I call this method by open event of the window.
possibly not best solution but it works more than 10 year without any
problem and it is easy!!!!
Post by Marnaud
Post by Pascal PLUCHON
Use the bounds property. Works fine for me.
http://docs.xojo.com/index.php/Window.Bounds
Hello,
I’m still convinced the original problem is the use of the Moved event
for that purpose. I’m almost certain that event is called near the opening
of the window; it would mean the Moved event is also called before the
window has been restored, saving the wrong position to the file.
Post by Marnaud
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://forum
Claudius Sailer
2016-12-11 13:16:34 UTC
Permalink
by loading the preferences I use a routine which checks the possible values in the screen and I have a menu for reset the sizes to the defined minimum size of each window....
Post by vaughnsc .
I agree that the 'wpos' should be set only on window.close or app.close but
the issue is in window.open: unless i missed something i only saw wpos set
when preferences failed to be read?
i might also add that you should test handling in Windows (big W) if the
window was maximized (full screen) by user, otherwise you may save
offscreen coordinates like -10000
Vaughn
Post by Claudius Sailer
Halo,
I didn’t followed the complete thread.
im Move Event of a window I use this
if PrefDic.value("FensterBuchungX")<>self.Left OR PrefDic.value("FensterBuchungY")<>self.Top
OR PrefDic.value("FensterBuchungH")<>self.Height OR PrefDic.value("FensterBuchungB")<>self.width
then
PrefDic.value("
FensterBuchungX")=self.Left
PrefDic.value("
FensterBuchungY")=self.Top
PrefDic.value("
FensterBuchungH")=self.Height
PrefDic.value("
FensterBuchungB")=self.width
PrefSpeicher ‚‘Saving
Prefs for next use when App is started new
end if
same code in Event „Resized“
I have a method
WindowPositioning
self.left=PrefDic.value("
FensterBuchungX")
self.top=PrefDic.value("
FensterBuchungY")
self.Height=PrefDic.value("
FensterBuchungH")
self.Width=PrefDic.value("
FensterBuchungB")
I call this method by open event of the window.
possibly not best solution but it works more than 10 year without any
problem and it is easy!!!!
Post by Marnaud
Post by Pascal PLUCHON
Use the bounds property. Works fine for me.
http://docs.xojo.com/index.php/Window.Bounds
Hello,
I’m still convinced the original problem is the use of the Moved event
for that purpose. I’m almost certain that event is called near the opening
of the window; it would mean the Moved event is also called before the
window has been restored, saving the wrong position to the file.
Post by Marnaud
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________
Keith DeLong
2016-12-11 15:34:55 UTC
Permalink
Others are correct, stop using the moved event code. Save on close and set on open.

Event order is undefined. When the window is being build with the default values, the moved event is firing, thus saving the defaults to your prefs and overwriting those saved in your last close.

HTH,
Keith DeLong
Post by SH Development
I’ve been going around and around with this for a while now this evening.
I have a very simple program that writes to a prefs file with the main window’s placement, top, left. This happens both when the window is closed AND when it is moved. Prefs are saved on either event.
The prefs file correctly shows the position I have dragged the window to on any of the screens. However, when I relaunch the application, it always resets the left to a value of 10 and changes it in the prefs file.
In trying different settings for the window in the IDE, I have found that changing the placement behavior affects the problem. When set to “Default”, it always reverts to a left value of 10. When set to "Main Screen", it always jumps back to a left value of 1422, basically centered on my gi-normous 34” Dell monitor.
Sub Open()
// Initialize the preferences handler and check for an existing prefs file. PreferencesModule.Initialize(“Test Program")
If Not Preferences.Load then
Preferences.wTop=10 // Main window top coordinate.
Preferences.wLeft=50 // Main window left coordinate.
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
// This will create the folder ~/Library/Application Support/Test Program if it doesn't already exist.
// Creates the default preferences.
End if
mainwindow.Show
End Sub
Sub Close()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Moved()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Open()
self.top=Preferences.wTop
self.left=Preferences.wLeft
End Sub
I am using the preferences module from Paul Lefebvre as posted on the Xojo developer site. Thoughts?
Jeff J.
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://for
Jim M
2016-12-11 16:05:03 UTC
Permalink
I would think the problem is that "show" positions the window, and thereby triggers the Moved event, resetting your saved values.

Remove the moved event.
Set the window to visible=false in the IDE.
Create an instance of the window, set the position, then set visible=true.

If the window is the default window, moved may fire before open, since it is created on launch.
If implicitInstance=true, then calling mainwindow.left already created, opened and likely fired the moved event in order to have an object to set .left on

Dim w as new mainWindow ///creates a new window whose visible=false in the IDE
w.bounds=savedBounds //set up stuff the user shouldn't see
w.visible=true // show it to the user


Also I think that setting self.left causes resized to fire in your WindowPositioning method.

Set break points in each event/method to see whats really happening.

jim m
Post by Keith DeLong
Others are correct, stop using the moved event code. Save on close and set on open.
Event order is undefined. When the window is being build with the default values, the moved event is firing, thus saving the defaults to your prefs and overwriting those saved in your last close.
HTH,
Keith DeLong
Post by SH Development
I’ve been going around and around with this for a while now this evening.
I have a very simple program that writes to a prefs file with the main window’s placement, top, left. This happens both when the window is closed AND when it is moved. Prefs are saved on either event.
The prefs file correctly shows the position I have dragged the window to on any of the screens. However, when I relaunch the application, it always resets the left to a value of 10 and changes it in the prefs file.
In trying different settings for the window in the IDE, I have found that changing the placement behavior affects the problem. When set to “Default”, it always reverts to a left value of 10. When set to "Main Screen", it always jumps back to a left value of 1422, basically centered on my gi-normous 34” Dell monitor.
Sub Open()
// Initialize the preferences handler and check for an existing prefs file. PreferencesModule.Initialize(“Test Program")
If Not Preferences.Load then
Preferences.wTop=10 // Main window top coordinate.
Preferences.wLeft=50 // Main window left coordinate.
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
// This will create the folder ~/Library/Application Support/Test Program if it doesn't already exist.
// Creates the default preferences.
End if
mainwindow.Show
End Sub
Sub Close()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Moved()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Open()
self.top=Preferences.wTop
self.left=Preferences.wLeft
End Sub
I am using the preferences module from Paul Lefebvre as posted on the Xojo developer site. Thoughts?
Jeff J.
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://fo
SH Development
2016-12-11 16:59:16 UTC
Permalink
Thank you for all the suggestions. I have a workable solution now.

It should be noted that saving prefs on moved event USED to work without any problems, as I pulled the code from a project I did a couple of years ago. The compiled app currently works fine using that technique. At which version of Xojo or RB it changed, I can’t tell you.

Jeff J.
Post by Jim M
I would think the problem is that "show" positions the window, and thereby triggers the Moved event, resetting your saved values.
Remove the moved event.
Set the window to visible=false in the IDE.
Create an instance of the window, set the position, then set visible=true.
If the window is the default window, moved may fire before open, since it is created on launch.
If implicitInstance=true, then calling mainwindow.left already created, opened and likely fired the moved event in order to have an object to set .left on
Dim w as new mainWindow ///creates a new window whose visible=false in the IDE
w.bounds=savedBounds //set up stuff the user shouldn't see
w.visible=true // show it to the user
Also I think that setting self.left causes resized to fire in your WindowPositioning method.
Set break points in each event/method to see whats really happening.
jim m
Post by Keith DeLong
Others are correct, stop using the moved event code. Save on close and set on open.
Event order is undefined. When the window is being build with the default values, the moved event is firing, thus saving the defaults to your prefs and overwriting those saved in your last close.
HTH,
Keith DeLong
Post by SH Development
I’ve been going around and around with this for a while now this evening.
I have a very simple program that writes to a prefs file with the main window’s placement, top, left. This happens both when the window is closed AND when it is moved. Prefs are saved on either event.
The prefs file correctly shows the position I have dragged the window to on any of the screens. However, when I relaunch the application, it always resets the left to a value of 10 and changes it in the prefs file.
In trying different settings for the window in the IDE, I have found that changing the placement behavior affects the problem. When set to “Default”, it always reverts to a left value of 10. When set to "Main Screen", it always jumps back to a left value of 1422, basically centered on my gi-normous 34” Dell monitor.
Sub Open()
// Initialize the preferences handler and check for an existing prefs file. PreferencesModule.Initialize(“Test Program")
If Not Preferences.Load then
Preferences.wTop=10 // Main window top coordinate.
Preferences.wLeft=50 // Main window left coordinate.
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
// This will create the folder ~/Library/Application Support/Test Program if it doesn't already exist.
// Creates the default preferences.
End if
mainwindow.Show
End Sub
Sub Close()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Moved()
Preferences.wTop=self.top
Preferences.wLeft=self.left
If Not Preferences.Save Then
MsgBox("Could not save preferences.”)
End If
End Sub
Sub Open()
self.top=Preferences.wTop
self.left=Preferences.wLeft
End Sub
I am using the preferences module from Paul Lefebvre as posted on the Xojo developer site. Thoughts?
Jeff J.
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

Continue reading on narkive:
Loading...