Eclipse RCP Center Dialog on Active Monitor - eclipse

I am trying to center a dialog in my Eclipse RCP application, and I tried different methods to center the dialog.
Is there an easy/accepted way to center the dialog respecting the current location of the primary shell (the workbench app If I am not mistaken)? I can center the dialog on the primary monitor, but I am unable to center the dialog respecting the main app window.
This is a problem on multi-monitor setups. I start the app and it is displayed on the primary monitor. If I move the app to the second screen, I am failing to center the dialog not on the primary monitor but on the second screen where the app is.
---- Update 1 ----
At the moment every dialog is created with a new Shell:
Shell shell = new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
PortOverviewDialog portOverviewDialog = new PortOverviewDialog(shell);
portOverviewDialog.show();
I think this is the main problem. How can I avoid this by getting the primary Shell?
---- Update 2 ----
For me the code Shell shell = HandlerUtil.getActiveShell(event); gets the parent Shell. And I am setting the Dialog to "parent center" with the help of the following code:
Rectangle parentSize = getParent().getBounds();
Rectangle shellSize = shell.getBounds();
int locationX = (parentSize.width - shellSize.width)/2+parentSize.x;
int locationY = (parentSize.height - shellSize.height)/2+parentSize.y;
shell.setLocation(new Point(locationX, locationY));

Related

Powershell Selenium: Unable to Locate Element on Amazon

I'm trying to create a Selenium script in Powershell that automatically buys something that I tell it to. I've gotten it past finding the item, and clicking the Buy Now button, but then this window pops up and I've tried what seems like 3000 different ways of failing to click the Place your order button. Web code to the right. Appears to be the "turbo-checkout-pyo-button", but finding it by ID, XPath, CSSselector, etc have all failed for me. It's not a wait issue. I've even thrown in an explicit (and overly long) 5 second delay to be sure this field is present and "should" be clickable. Any ideas?
I've tried all of these. They're all followed by $placeYourOrderBtn.click() (and have all failed):
$placeYourOrderBtn = $ChromeDriver.FindElementByXpath("//*[#id='turbo-checkout-pyo-button']")
$placeYourOrderBtn = $ChromeDriver.FindElementByXPath("//*[#id='turbo-checkout-place-order-button']")
$placeYourOrderBtn = $ChromeDriver.FindElementByXPath("//span[text() = Place your order]")
$placeYourOrderBtn = $ChromeDriver.FindElementById("turbo-checkout-place-order-button-announce")
$placeYourOrderBtn = $ChromeDriver.FindElementById("turbo-checkout-pyo-button")
$placeYourOrderBtn = $ChromeDriver.FindElementByCssSelector("#turbo-checkout-pyo-button")
I did this for a windows that sends email. You have to click the button to open the new window, then use "SwitchTo()" to change to the new window.
[void]$Webdriver.SwitchTo().Window($WebDriver.WindowHandles[1])
You may have to read the window handles attribute and query each one to determine which one you need to open.

wxPython window randomly freezes on RPi and acts weird afterwards

This Problem occurs on the RPi (3B+, Raspbian Buster) only. I run the program on my Mac without any problems.
Short description of my program:
After entering the mainloop, the program enters a second thread with another loop (call it requestloop) when the designated button is pressed. The requestloop can be left by pressing the button again. This requestloop requests a xml table via url every 10 seconds which is then parsed with ElementTree, sorted and displayed in a wx.grid.Grid. I use grid.ForceRefresh to make sure the grid is updated.
I hope the following snippet helps to understand the above:
def on_btnrun(self, event):
global run
if self.btnrun.Label == "Start":
run = True
thrupt = threading.Thread(target=self.thrupdate)
thrupt.start()
self.btnrun.SetLabel("Ende")
elif self.btnrun.Label == "Ende":
run = False
self.btnrun.SetLabel("Start")
def thrupdate(self):
while run is True:
reset()
self.grid.ClearGrid()
update(self.grid)
self.grid.ForceRefresh()
time.sleep(10)
Problem:
Now as mentioned in the title the whole wx Window freezes after passing the requestloop between roughly 5 and 20 times. This happens completely randomly, I could not find any regularities. The program keeps running though, for it still prints the output in the terminal every cycle (I added this function for testing).
When I now open another window (eg. menu dropwdown) which lays over the wx Window it will be copied onto the wx Window and stay there after I closed it.
Here are some Images to better understand what I mean (ignore all other widgets that I didn't mention, they are just nonfunctional placeholders).
Image of the wx Window before it freezes
Image of the wx Window after it freezes
Image of the wx Window after opening and closing the dropdown menu
Extra-Info: while building wxPython on the RPi I got some warnings and everytime I run the program I get the following one (it says the actual time instead of time):
(program.py:1666): Gtk-Critical **: time: gtk_distribute_natural_allocation: assertion ‚extra_space >= 0‘ failed
Question:
I have no idea why any of this happens. Is wxPython not stable on Raspbian? Or did the build partly fail? Or is the RPi not having enough rendering capacity?
Solved it by using wx.CallAfter in the details of the update() method.

VsCode appears to keep running wxPython app when it should have stopped

In my VsCode wxPython application under Windows, I bind the close event to my function as follows:
import wx
class MyFrame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title = title, pos = (150, 0))
self.Bind(wx.EVT_CLOSE, self.OnClose)
# Other stuff ...
def OnClose(self, event):
print("closing")
self.Destroy()
app = wx.App()
top = MyFrame("My App")
top.Show()
app.MainLoop()
print("done")
Now I can see it's being called when I close the top level window (a wxFrame) as the closing and done messages appear. The window itself also disappears.
However VsCode thinks the application is still running since it has the debug controls still available:
and the console that ran it (Python debug console) does not come back with a prompt. It's not until I click on the stop button does the command prompt reappear in that console.
Interestingly, if I run the application outside of VsCode, it exits correctly, returning to the command prompt.
Try wx.Exit() in case you have something still open/running without realising it.
wx.Exit()
Exits application after calling wx.App.OnExit .
Should only be used in an emergency: normally the top-level frame should be deleted (after deleting all other frames) to terminate the application. See wx.CloseEvent and wx.App.

How do I get the bounds of the display for the Mac OS X application with keyboard/mouse focus?

I am using the following script to 'maximize' the current application window on my mac.
It works fine when the frontmost application window is on the main / larger external display, or when my laptop is not connected to an external display.
However, when I am connected to an external display, and the window I am trying to maximize is on my laptop display (not the external, primary display), this script ends up enlarging the window to the dimensions of the larger display.
try
tell application "Finder" to set b to bounds of window of desktop
try
tell application (path to frontmost application as text)
set bounds of window 1 to {item 1 of b, 22, item 3 of b, item 4 of b}
end tell
on error
tell application "System Events" to tell window 1 of (process 1 where it is frontmost)
try
set position to {0, 22}
set size to {item 3 of b, (item 4 of b) - 22}
on error
click (button 1 of window 1 where subrole is "AXZoomButton")
end try
end tell
end try
end try
I believe the issue is the way I am getting the desired bounds, b:
bounds of window of desktop
This seems to always return the bounds of the primary display.
What I need is a way to detect the bounds of the display for the current running application that has keyboard and mouse in focus.
NB: I am totally cool if the solution to this is in Swift and not Apple Script.
Have you considered this:
tell application (path to frontmost application as text)
set zoomed of window 1 to true
end tell

Drtsn32.exe only catching exception once per reboot

I'm trying to setup Drwtsn32.exe as the crash handler on a windows xp embedded system. I have run drwtsn32.exe -i from the prompt to install it as the default handler. Then I added a couple different fragments that would cause exceptions into our application as a test:
int y = 0;
int j = 0;
j /= y;
int* p = 0;
(*p) = 0;
When I run our application for the first time, I get a Drwtsn32.exe popup correctly, the application closes, and drwtsn32.log is written and shows my crash. When I run the same application again, I get no popup, and no log is written. This repeats until I reboot, when the popup and log are both generated a single time, then the problem persists.
On a different system, I see different functionality - drwtsn32.exe does not generate an error (although I do see the MS Send Report popup) and the log is generated every single time, without requiring a reboot.
Does anyone know if I am missing a configuration option, or if a component is missing in our Windows XP Embedded Image?
Thanks