I am trying to create a windows based application using eel. I want it to start in any available browser in the system of the user. How can I do it ? ( consider that user have not installed chrome in his system )
You can pass in mode='default' to the eel.start function, and it will try to open the system's default browser. Something like this:
eel.start('index.html', mode='default')
In this case, behind-the-scenes Eel will be proxying the open request to Python's webbrowser.open function, so it's best to check there if you want to know the logic being used. Or you can look at the Python source file for webbrowser.py on your machine... on Windows it would be located somewhere like: C:\Python39\Lib\webbrowser.py.
Maybe it's too late for you, I had the same problem. So to resolve it you have open your folder with code source of eel and open init.py and change browser option.
Related
I need to create a desktop app that access a webpage and also need to be able to control it's caching location (such as images of this webpage) for offline usage.
Just like any browser already does?
Yes, but I cannot use any browser like Firefox, Chrome, Chromium... Unless it's in the form of a DLL or something similar (the browser itself cannot be installed)
I already found how to delete cache and how to disable caching, just need to alter the caching directory.
take this code as example:
import webview
webview.create_window('Hello world', 'https://pywebview.flowrl.com/hello')
webview.start()
Let's suppose it downloads a image and stores it in cache.
I need to be able to open multiple instances of the application, each with it's separate caching directory.
Anyone knows how to change the caching directory? something like:
webview.cache.setDir("c://User/user-2")
I'm alright with the usage of other libs such ad flask or bottle (or any other really)
Also, the solution needs to work for both Widows and Ubuntu
Thanks in advance.
As you mentioned, There are third-party libraries you can use. Flask for instance works very well with pywebview. the webview.create_window method accepts an HTTP server(In this case flask). With flask you can then use the flask cache module to specify a directory to store the files
You can check the docs on flask caching to see other possibilities
https://flask-caching.readthedocs.io/en/latest/
I wrote a little download manager in python, and now i want to "catch" downloads from Chrome Firefox and Explorer so they will download with it, instead of each built-in download manager of the browser itself.
I want to know when each of the browsers are starting a file download, so i can prevent the default behavior and use my own manager. All i need to start a download myself is the file url of course.
I know that in the past there were popular download managers such as "Get Right" that did exactly this. I want to do something similar.
Any ideas how would i go about doing this?
What is an easy(simple/clean) way to add few steps to interact with windows based elements within python selenium script?
eg:
Click a download button via selenium driver, change the file name and location and click save button on windows dialog.
Note:
Downloads button is just an example. I pretty much want to know a common way to handle any kind of items.
I do not want a way where they recommend a way to configure browser such that downloads happen automatically at a specific location on our system.
Way to execute my scenario:
Keep this setting turned ON in chrome.
Ask where to save each file before downloading.
Website to try - https://www.seleniumhq.org/download/.
Try downloading anything.
There is a project called Winium, remote driver implementation of Selenium for automating desktop applications. This could help you with this job.
You can spy ui using Inspect.
Find the samples at https://github.com/2gis/Winium.Desktop/wiki/Magic-Samples
Try to use AUTO It, it will be useful in Interacting with windows based applications in selenium.
Check out here - https://www.guru99.com/use-autoit-selenium.html
Hope This Helps You.
I'm building some simple editors with Backbone.js, and I'm hoping to be able to distribute them as apps for users to edit content in a mostly client-side way (i.e., I don't want users to have to futz with setting up stuff like MySQL or Apache).
So I was imagining a scenario like:
User downloads a .zip file
In the resulting opened folder, the user clicks index.html
That opens in a browser
Backbone app starts, stores data in localStorage
The user can then export to CSV.
Believe it or not, that would solve my problem: I want to help users edit data in a browser and then get it back out in a familiar format (CSV can be loaded into Excel, for instance).
And I’d like to do this without forcing them to configure a server. It seems like this is almost possible in the HTML5 stack. However, in at least one browser (Chrome), this doesn't work, because I get errors like this one:
XMLHttpRequest cannot load file:///users/me/project/data/Appdata.json. Origin null is not allowed by Access-Control-Allow-Origin.
(Oddly enough, I don't get that error in Firefox, and the .js or .json files load fine.)
So at this point it seems to me that there's no way around having these users use something kind of local server to serve up the Backbone interface.
So, I'm trying to figure out how to build a distributable, cross-platform executable that will allow my users to start a Flask server. (I hope to build a REST backend to a Backbone.js app.)
Is this wishful thinking? I'm assuming I can get the people in question to install Python.
Is this doable? There seem to be many ways to package up Python programs, (pyinstaller? py2exe? ...) So I thought I would ask here in case someone might know of a solution for the stack I have in mind.
TIA!
You can use Anthony Gordon McMillan’s Pyinstaller or Tuininga’s cx_Freeze
Quoting the PyInstaller website:
Features
Packaging of Python programs into standard executables, that work on
computers without Python installed.
Multiplatform: works under
Windows (32-bit and 64-bit),
Linux (32-bit and 64-bit),
Mac OS X (32-bit only, 64-bit in git, see Features/MacOsCompatibility) and
experimentally Solaris and AIX (in git).
Multiversion: works under any version of Python from 2.2 up to 2.7.
My suggestion would be to create a thin service wrapper around your code. This will allow the server to run independently of your main codebase - also allowing the user to shut down the server directly (simply right clicking the service icon and selecting "Exit").
This SO answer should help you get started.
After reading your updated question, I think something like mongoose might be more suited to your task. It is an embeddable web server that is FLOSS and has python bindings. Flask might be overkill.
Not easily. On Windows, you'd have to include Python itself. Mac and Linux usually have Python installed, but you can't be sure of what version so it's often easier to bundle your specific Python for them as well. Then you'd have to include all the dependencies that you want to run with in your package or be able to install them with pip, easy_install, etc.
You can use py2app and py2exe. This won't be cross-platform as you'll still need to make a different version for each target OS. The only way to make it cross-platform is to bundle all versions and have some cross-platform code execute the appropriate version for that platform.
If you need databases like MySQL or even SQLite things get more complicated as you'll have to include those too.
Can I use os.system() or subprocess.call() to execute a Python program on a webserver?
I mean can I write these functions in a .py script and run it from a web browser and expect the program to be executed?
Thanks a lot.
EDIT:
Sorry for all the confusion, I am giving you more background to my problem.
The reason I am trying to do is this.
I have a Python program that accepts an XML file and returns me TTF file.
I run that program in terminal like this:
ttx somefile.xml
After which it does all the work and generates a ttf file.
Now when I deploy this script as a module on web server. I use a to allow user to browse and select the XML file.
Then I read the file data to temporary file and then pass the file to the module script to be executed like this:
ttx.main([temp_filename])
Is this right way to do it? Because at this point, I don't get any error in the log or in browser. I get blank screen.
When this didn't work, I was going to try os.system or subprocess.call
You do not use os.system or subprocess.call to execute something as a cgi process.
Maybe you should read the Python cgi tutorial here:
http://www.cs.virginia.edu/~lab2q/
If you want your cgi process to communicate with another process on your local machine, you might want to look at "REST frameworks" for Python.
So long as your server is configured to run CGI scripts (Apache's documentation for that is here, for example), yes, you can execute a python script from a webserver. Simply make sure the script is in the appropriate cgi-bin/ directory and that the file has executable permission on the server.
With regards to your comments:
You can, if you really want, explicitly allow other folders on the server to run executable code. I don't know what server you're using, but on Apache this is done by setting Option +ExecCGI for the folder you want. Again, see the docs I linked to.
You need to give an absolute path with respect to the server. As an example, a site I develop has the layout: /public_html/cgi-bin/ When I want to access .cgi or .py files, the url for the site is something like http://chess.narnia.homeunix.com/cgi-bin/index.cgi. You can also set up re-directs to certain files if you want.
One way to pass parameters through your browser is to append them to the URL like an HTTP POST method. Here's a good example of doing that.
Is that what you were looking for with your question, or did you want to actually invoke the python script with os.system()?
Yes, I do it all the time. Import as you would do normally, stick your .py in your cgi-bin folder and make sure the server is capable of handling python.
Another option would be to simply create an application on Google's App Engine. That gives you oodles of resources and APIs for Python execution.
http://code.google.com/appengine
I've done it quite a bit in classic ASP on IIS 5 and above. I would have the ASP engine execute python code (instead of, e.g., vbscript (hearkening back to the old days, here)). Behind those asp pages would be python modules written in straight python that could be imported and could execute pretty much arbitrary code. As others have mentioned, the effective user needs to have execute permission on the thing you're trying to execute.