1

I know how to open a program from python, using the webbrowser module.
My question is this: how do I get it to open full screen?
At the moment I have this code:

import webbrowser  
webbrowser.open("file.txt")

But it still opens Restored Down.
Please help!

pvg
  • 2,673
  • 4
  • 17
  • 31
AskTom
  • 11
  • 1
  • 3
  • 3
    I looked through the [webbrowser documentation](https://docs.python.org/2/library/webbrowser.html) and I didn't see anything about full screen capability. I think you're going to have to find a non-webbrowser approach. – Kevin Apr 19 '17 at 13:50
  • Does this actually open the web browser, or does it open a text editor? – Josh Lee Apr 19 '17 at 14:11
  • I tried it with python interactive at a knome terminal and it opened a xed text editor. –  Apr 19 '17 at 14:29
  • I am guessing that the default webbrowser selects the program from the system defaults for certain known file types (PDF, TXT, etc). –  Apr 19 '17 at 14:31
  • Kevin is probably correct; a solution using something else (maybe subprocess) is a better way. On my system, FYI, this opens the text editor at whatever state (min, max, sized) the windows were last in before closing. –  Apr 19 '17 at 14:33
  • 1
    On my Fedora machine `br = webbrowser.get(); print(br.name)` yields 'xdg-open' which will simply open the file using the suitable application based on MIME-type, file extension or whatever magic it uses. I am guessing this is is true for most desktop Linux systems. – Hannes Ovrén Apr 19 '17 at 14:46
  • @HannesOvrén Yep. –  Apr 19 '17 at 14:49
  • 1
    I think @AskTom need to clarfiy what he is trying to achieve here. Opening any document? Just text documents? In a browser? In a text editor? Because I find it a bit weird to use the `webbrowser` module to open a text file in full screen mode. – Hannes Ovrén Apr 19 '17 at 14:56
  • Agreed, but, based on the question, "program using python", It appears he wants to open a document with the appropriate program... He would not be the first person to do something in a less ideal way just because it is 'easy' for him to do so. At least he _did_ provide a MCVE... :) –  Apr 19 '17 at 15:02

1 Answers1

0

Given the documentation, the webbrowser module does not have this capability at all. This is not very surprising since you don't know what kind of device you are operating on, and it might not even have a graphical display!

What I would try is the following:

  1. Use browser = webbrowser.get(SOME_BROWSER) to query which browsers are available.
  2. Launch the browser using browser-specific command line arguments. You might be able to to do browser.args.append(FULLSCREEN_ARGUMENT) and then call browser.open_new(URL) instead of launching the browser manually using e.g. the subprocess module.
Hannes Ovrén
  • 21,229
  • 9
  • 65
  • 75
  • This answer is not really correct because executing webbrowser.open('somefile') will return False if the session does not have a graphical display (or there is no terminal browser, I assume), solving the problem of whether it has a graphical display... Webbrowser will solve the device/OS problem by calling the default browser (returning True if it finds one). The default browser, in turn, will often select a default program to open said file (if so configured). –  Apr 19 '17 at 14:39
  • However, using the subprocess module would be a good solution. You may consider editing the answer to elaborate a solution using subprocess! –  Apr 19 '17 at 14:41
  • I can't see that the documentation mentions a return value for `webbrowser.open` at all. Since it explicitly talks about text-mode browsers I think my comment about graphical displays is quite correct. – Hannes Ovrén Apr 19 '17 at 14:43
  • My most important point was that `webbrowser` does not give you any portable way to launch the browser full screen, but that you could probably use it to probe for available browsers and apply the right flags given that. – Hannes Ovrén Apr 19 '17 at 14:45
  • I just tried it using gnome-terminal and it returns True (boolean) and opened and xed text editor. I tried it again at a TTY (no GUI avail) and it simply returns False and does nothing... python 2.7.11 and Linux mint "sarah" system. –  Apr 19 '17 at 14:45
  • He is not trying to launch a "browser"; his end-game appears to be opening the appropriate program (text editor in this case). "open a program from python" was what he says.. he is just doing so via webbrowser... –  Apr 19 '17 at 14:46
  • Setting `BROWSER=links2` and printing the return value open links2 (a text browser) and returns `True`. So it does not have to do anything with graphical vs text. Probably `False` signals "There is no browser available". – Hannes Ovrén Apr 19 '17 at 14:49
  • Yes, but it DOES return a value.. and for our purposes the distinction is not important (whether it is because it is not a GUI or that they dont have a text browser..) –  Apr 19 '17 at 14:52
  • The source code for 'open' does indeed return a value based on whether it could successfully open a 'browser'.. of course this means 'opening a browser and raising no errors in the process..' –  Apr 19 '17 at 14:56