1

I'm writing a blender python plugin which has an integrated connection to an online market, when the user buys a product (3d model) a window needs to open up to make the transaction through PayPal. The code I'm using works ok for that:

import webbrowser
webbrowser.open_new("http://www.paypal.com/buyProductURL")

However the window does not open up in the center of the screen and I also cannot find out how to define the size of the browser window that is being opened.

How can I move the browser window to the center and how can I define its size?

Miger
  • 1,175
  • 1
  • 12
  • 33

1 Answers1

2

I think this might be what you want:

import webbrowser

browser = ' '.join([
    "chrome",
    "--chrome-frame",
    "--window-size=800,600",
    "--window-position=240,80",
    "--app=%s &",
])

webbrowser.get(browser).open('http://www.paypal.com/buyProductURL')

The %s parameter is the url used by the module. It's required to call the browser as a command with arguments.

Here are some answers on how to call chrome in the command line.

If you require portability with the same behavior across all browsers it seems to be unattainable to me. I don't think you have an alternative here unless you ship the browser with your code or write more code for browser alternatives like chrome, firefox and opera. I wrote a code where it would work as a popup-like on chrome and chromium and as a tab open on other browsers:

import webbrowser

try_browsers = {
    "chrome": [
        "chrome",
        "--chrome-frame",
        "--window-size=800,600",
        "--window-position=240,80",
        "--app=%s &",
    ],
}
try_browsers['chromium'] = try_browsers['chrome'][:]
try_browsers['chromium'][0] = 'chromium'
URL = 'http://www.paypal.com/buyProductURL'

for browser in try_browsers.values():
    if webbrowser.get(' '.join(browser)).open(URL):
        break
else:
    webbrowser.open(URL)
Maicon Mauricio
  • 2,052
  • 1
  • 13
  • 29