Clicking on element in terminal - python

I've noticed that hyperlinks printed in my Debian/Linux terminal are clickable and open the browser when clicked.
I was wondering if this could be used for other things or if this was just hard-coded in the terminal for hyperlinks only.
Is it possible to print out a line in Python that when clicked will launch another process, for example?

URL support is hard coded in the individual terminal emulator.
The terminal may support arbitrary URIs as registered in whichever environment it calls home, so that you can e.g. write a Gnome extension for myapp://something and have it work in gnome-terminal, but this is entirely terminal specific.
It's also possible for a terminal program in any terminal to receive mouse events and it can then do whatever it wants with them (like how elinks lets you click non-URL links to browse). However, this requires the program to be running in the foreground and controlling everything that appears on that terminal.

Related

How can I run selenium (with python) on an open firefox window? (if not, on a Chrome window)

I have this python program made with selenium that automates a search on a firefox page, with a login and everything.
The thing is, after the search is done, the program stops executing (the page is still open. I want it that way) but I want to somehow implement a function that when -given certain argument- it searchs for something different on that open firefox page.
I don't know if I explained myself, but this is very important to me.
If you know how to do this but with Chrome I don't mind. I only need it to work regardless of the browser.
I'm not that pro at this, so please be patient with me. I'm very grateful for all the help you could provide me.
Thanks!!
https://en.wikibooks.org/wiki/Python_Programming/Interactive_mode:
Python has two basic modes: script and interactive. The normal mode is
the mode where the scripted and finished . py files are run in the
Python interpreter. Interactive mode is a command line shell which
gives immediate feedback for each statement, while running previously
fed statements in active memory.
So basically you need to run your code in interactive mode. It depends on your IDE: If you use PyCharm Right-click on the page that you're writing your code and find Run File in Python Console and continue coding in the new window opened by PyCharm. You can also use Jupyter which is a great tool for interactive mode. For other IDEs, try to find any menu that is related to interactive mode or window.

How-to Launch Android Python Script via Shortcut on Homescreen

I've scoured the interwebs and couldn't find anything with python, android, and "shortcut" or "home-screen" to appear on the same page. I have pydroid3 installed, working great. I'd like to have a shortcut (ideally on the home-screen) that I can tap once and have it run without opening the IDE for editing.
Making a shortcut to the file, or opening a source file in the file manager will at best just open it in the pydroid3 IDE, at worst state "this file type is not supported."
At the beginning of the script, I have tried putting "#!/user/data/../pydroid_dir/python", but alas the OS doesn't realize I mean to run it directly in the python interpreter. Any solutions or alternative lines of thinking are appreciated!
EDIT
I'm running an unrooted android 9 PIE. I wanted to provide some more details but not quite a solution for any readers. Check out related question: How to create a homescreen shortcut to launch a shell script?. Closest I got was trying SManager which allows you to create a homescreen shortcut to a shell script. Your shell script could be hardcoded to call python on your script:
/path/to/python /path/to/python/script
Unfortunately, if you're phone is not rooted, you may not have permission to execute whatever version of python you're calling outside of the context of the app it was installed for. Also, you have to ensure that your shell and python scripts reside in an appropriate place for execution. If your phone is rooted, SManager seems to have options to let you run the script as root.
pydroid3 allows me to run scripts residing on my internal storage as well as lets them read and write files at that location. That's why I was hoping that there was a pydroid way to create a shortcut (or an alternative python app that does this) since it has appropriate privileges.
QPython OL lets you create home screen shortcuts to python scripts on Android. First tap on the 'Q' icon at the top of the main screen (it took me a while to realise this was a button), then long-press on the script you want. This should give you a prompt to create a shortcut, as in the screenshots below.
QPython 3L also claims to have similar functionality when you long-press a script in its 'Programs' section. At time of writing (Jun 20) this seems to be broken.
I've not tried Pydroid myself, but haven't come across anything claiming it could create script shortcuts either.
You can use Termux:Widget as a command line to execute a python script. In Termux you can not create GUI with tkinter. You have to launch X-Server with VNC Mobile client. The widget is like a small shell prompt.

Can PyCharm follow file URIs from terminal?

I'm using PyCharm 2018.3.3 and I would like to follow hyperlinks from terminal. Everything works well for hyperlinks that start with http:// or https://. Whereas hyperlinks that start with file:// are correctly highlighted but nothing happens when I click on them.
If I use the default terminal of my environment (i.e. GNOME terminal) then everything works as expected. I am able to follow all the hyperlinks with Ctrl + Left click.
How to make hyperlinks (file URIs) work in PyCharm terminal?
EDIT: Please read the comment below, this is probably not the main issue. PyCharm allows you to change the shell, but not the terminal emulator.
The problem isn't with PyCharm itself, it's with the underlying terminal emulator that PyCharm uses. This is configurable in the settings.
Following the instructions in the link above, you could switch PyCharm to always use GNOME terminal. This would resolve your issue.
Otherwise, try googling this question for the specific terminal emulator that is configured in PyCharm.

Run python program in PyCharm with command line in console

I have a python file named "python_file.py" and I want to run it with a command line such as "python python_file.py" by typing it in the terminal, and not in the python console. I succeed one time, but when I change my working directory, it no longer works.
When I tried, it displays something like "python isn't known as a intern program, a runnable program or a command file".
And I'm using Python 3.7.
Can someone help me ?
You need to create a run/debug configuration, as explained in the official help:
Click on the button left of the green arrow symbol (the green arrow might be greyed out, but that's fine):
Click on Edit Configurations.
Click on the + symbol
Click on Python.
On the right side, enter/activate the following:
Name (a string that describes your according project)
Single instance only (this is less complicated for you)
Click on the Configuration tab.
Select a type of target from the Script path/Module name
Enter the path to your Python script in the according box.
Select the Python interpreter (Python 3.x will be fine).
In the Execution section, select either Emulate terminal in output console or Run with Python console.
Apply the changes and close the dialog.
Click on the button left of the green arrow symbol to run your program from the internal command line.

Why is Python's console split in debug perspective in Eclipse with PyDev?

When I launch my Python program with the debugger in Eclipse with PyDev (Python plug-in for Eclipse), the console is always split into two windows. One where I can actually enter code and the other displays my code entries and their output. See the following snippet.
There is also a "dedicated" debug console which I can start whenever my program is paused, but this requires a manual click (PyDev > Debug Console). This console doesn't have the slip view. See snippet.
Why are there two ways to interact with Python while my program is paused? Why is the default console (from the first screenshot) split into two windows? How can I make my default console be more like the second console without the split view?
The second bottom console keeps a history of user commands that are injected into the current context. It provides a cleaner input mechanism with the ability to navigate through a history of commands. In addition some programs running loops may print to the original console frequently making it difficult to print commands into the top console.
It may have been added for future features as well, like changing the context of the input to a different spot in the code.
That is just my guess. There is a "hide console prompt" terminal button if you do not want to see it. Both consoles can have commands entered in if you are debugging and paused.

Categories