Hi I'm studying Python and I've started my first little project.
The first thing that I want to do is to add an item to the right click menu of Firefox. So, when I right-click a link that item will be available and when I click it some Python code will be called in order to "do something" with that URL.
Do I have to create a Firefox extension to do this? Can I specify in that extension the Python code that should be called?
Yes, you will need to write a Firefox extension. This is a getting-started tutorial. To call your external Python code you will use nsIProcess.
Why have you chosen to do this in Python? Since Firefox extensions do their thinking in JavaScript anyway, if you use that then you don't have to call external processes. In particular, you won't need to install Python for your extension to work!
I think it is not possible. Normal FF extensions are afaik written in XUL and Javascript and therefore can not call other (non JS-) code.
Related
Background:
Programming in Python (vscode)
on Mac
Story:
I am using selenium to automate a process and at some point throughout that process I have to upload a picture. I can click on the "from Computer" button that pops up but this opens the finder with all my files/documents. I do not know how I could tell python here to navigate to a given folder and klick "submit" (or upload).
Question:
Does anyone know a way to "control" the finder similarly to what selenium does for the web browser?
Thank you!
I have tried:
Selenium but it can not handle this (to my knowledge) since I am no longer in the browser.
I have also tried the package pyautogui but because I would like to be able to run the same program from several computers (the path will be the same) but they display the finder differently so I dont think that will do the trick.
I installed pywin from this site. I used version pywin32-220.win-amd64-py3.6.exe, and it installed without any error.
I am trying to automate use of a software. To do this, I am following a tutorial that says I need to select something from the Tools Menu in pywin. So I expected to find a program with a GUI that I could open from the Windows Start Menu.
However, although I see pywin in Control Panel's Add or Remove Programs, it is not in the start menu, and I don't know where to find it or how to open.
If my description is too vague to suggest a solution, a useful answer to my query would be diagnostic questions I should be asking.
Thank you.
Additional information:
- I am using windows 10.
PythonWin is what I want, yes. It is not in the start menu. (I understand now that pywin32 would not show in the start menu.)
There is a pywin folder on my desktop. One of the subfolders is called Pythonwin. Inside that folder, there is no .exe file. There is a file called start_pythonwin.pyw, but clicking it does not open anything. Based on this webpage, PythonWin needs to be installed separately. Perhaps that is my situation. But there is no .exe file in this folder. I do not know how to install a program from a folder of files--if that is what I need to do, please provide a reference.
Before I can automate use of the softare, the tutorial mentioned above provides the following instructions (sorry, it's on the software site and you have to login, so I can't link). I need to open the GUI to do step 1, but I can't open it.
Instructions:
Open PythonWin and start the COM Makepy utility from the Tools menu. Locate DesktopController Library in the list of COM interfaces and click OK. This produces the following result.
">>> Generating to C:\Python25\lib\site-packages\win32com\gen_py\62401B69-06B2-4C4F-992E-B7A57EFBF059x0x1x0.py
Building definitions from type library...
Generating...
Importing module
Press return and then import the COM support module by typing...(at this point, the tutorial explains how to write code to automate the software...)
I need to select something from the Tools Menu in pywin
I think you mean PythonWin (it comes with pywin32 installer). PythonWin comes with a few tools to use with Pywin32 (it's a GUI program, a Python editor actually and it has a Tools menu). Check your tutorial again and make sure what it is that you're looking for. I could have checked it out, but you didn't provide a link or a quote so it's hard to help you.
Anyway, if it is PythonWin what you are looking for (and I think it is), it should be located along side Python in your start menu.
Hope this helps.
Ok, now that you have updated your question I can help a bit more.
I don't understand how the installer didn't install PythonWin on your Python Start Menu but ok. Since what you want to do is execute makepy, there is another way to do it besides the PythonWin program.
Go to your site-packages folder, then win32com and then into the client directory. So the path will be something like C:\Python36\Lib\site-packages\win32com\client\. There you will find a file called makepy.py and another called makepy.pyc. Either one of those can be used to launch the makepy tool.
Once you have used the makepy tool to create the wrapper to your COM object you can find it in the gen_py directory.
You can comment to this answer if you have any questions.
I have a server on which I want to build a script to login to page which is using javascript. I want to use python selenium to achieve the same.
We have a shared drive which contains all the installed binaries and the same has to be included. So when running a python program I won't be using my #!/usr/bin/python instead efs/path../python, similarly all the packages are to be included in this ways. sys.path.append("/efs/path.../selenium-egg-info"). This works good, but as selenium would need firefox included, I could see mozilla in the path, but where are it's binary, exactly which folder to include inside mozilla.
You can think Selenium as launching 'firefox' behind the scenes. You won't see it but it's there and then accordingly opening up the webpage and manipulating things.
How do you think it does all that cool stuff without writing explicit url header etc. So for that you need to have a firefox installed with a physical display(monitor) installed.
You can fake a pyhsical terminal it's just input/output but you AFAIK you need to have a firefox installed. Sad news but that's the way it is.
You don't need firefox executable since it comes with the Selenium
Firefox driver is included in the selenium-server-stanalone.jar available in the downloads. The driver comes in the form of an xpi (firefox extension) which is added to the firefox profile when you start a new instance of FirefoxDriver.
See my another answer here
I have written a python script with a Tkinter GUI. I would like to create a desktop icon that will execute this script so that the end-user (not myself) will be able to double-click the icon and have the GUI load, rather than 'run' the script from the terminal or python shell and then have to F5 from there.
Is there a way to do this? I have googled many arrangements of my question but most answers seem to be normal python scripts, not ones which are Tkinter based.
I am using a Raspberry Pi with Wheezy and Python 2.7
Thanks in advance.
I create executables(icons that I click to start the programs I write) using 'py2exe'. I use windows 7 and I am not sure if it would work for you with Raspberry Pi, but a google search may clear that up for you. I will provide the link below. Basically you end up with a folder with the executable(icon) and also some files, without which the executable won't work. It's unfortunate that you get this extra 'baggage', but it's still handy and the best solution I have come across. I don't think there is a much better way, but I am not 100% on that. Interestingly, I found that you could delete most of these baggage files and the executable would still work, it was trial and error, but it didn't take long. If I want to send the folder to someone, I zip it first.
py2exe is here
If you need a 64 bit binary you can get it here, along with, actually, pretty much every other version. get py2exe here also
Besides creating executable file other option is create simple .bat file:
Open notepad
Enter "C:\ProgramData\Anaconda3\python.exe" "C:\Users\Your ID\script.py"
First part is path to python.exe, second to your python script
save file as .bat file, ex. "open_program.bat"
Now simply double click on saved .bat file icon should open your script.
I like using cx-freeze to convert python scripts to exe.
There is very easy to follow documentation to do this. In short, you create a setup.py script that specifies what libraries and packages you want to include or exclude in your application.
You can then run the build in the console and it will create a build folder, in which will be an Application File. You can create a Desktop short cut using send to and selecting desktop.
Documentation link
You can save the script as a .pyw file so the user can click on the file and the GUi would open
Having made and tested my .msi installer using cx_freeze, it all works except for one vital part from the point of view of the end user: no start menu or desktop shortcut can be created by ticking a checkbox during the installer and neither of these actions seem to be happening by default.
However, having trawled mail archives and suchlike, I've found it should in fact create a start menu shortcut by default.
Does anyone know if there's something I can add to my setup.py or whatever to make this work? I'm not sure if this is happening just on my PC, so it would help if you could test if the installer makes a shortcut for you. You can test the installer here.
In your setup script, add "shortcutDir" keyword with required parameter. The parameter could be DesktopFolder or StartupFolder. "shortcutName" keyword could also be used to provide the name to the shortcut.
The following links could also be used as references to further help you to resolve your problem:
Use cx-freeze to create an msi that adds a shortcut to the desktop
https://github.com/anthony-tuininga/cx_Freeze/issues/48
Reposting as an answer:
I don't know of a way to do it with cx_Freeze alone, but if you prepare the build folder with cx_Freeze, you can use a separate program like Inno setup to create a more advanced installer.