I'm working on a console application. My application uses urwid lib. In some cases, I need to show very long hyperlinks as short text inside table columns. I want to open links in the browser when I click on the text inside the column.
So, my question is:
It is possible to print text as a hyperlink to the console?
Can you provide a small example of how to print text as a hyperlink using python?
A bit late, but there totally is a way to do that now, without curses or anything, just pure text and collaboration from your terminal emulator.
def link(uri, label=None):
if label is None:
label = uri
parameters = ''
# OSC 8 ; params ; URI ST <name> OSC 8 ;; ST
escape_mask = '\033]8;{};{}\033\\{}\033]8;;\033\\'
return escape_mask.format(parameters, uri, label)
Call that function with link('https://example.com/') to get a simple, clickable link, or link('https://example.com/', 'example') for a custom label.
Note that links are faintly underlined in your terminal, and not all of them support the feature.
Yes, using some tools, like gNewt or Curses, you could create a button and 'on click' do an action (like open a browser to a given url).
gNewt : http://gnewt.sourceforge.net/
nCurses : https://docs.python.org/3.7/library/curses.html
Otherwise, it's the terminal application that will manage the text you give it, and if it doesn't implement uri's recognition your program won't work as you'd like.
No, some consoles do recognize urls and convert them to a clickable hyperlink. All you can do is make it easy to recognize for console applications by putting a http:// in your url.
Also see
How does bash recognize a link?
Related
So I would like to create a simple word counter program with Python and add it to the Windows 10 context menu which opens when you right-click something. My goal is to then be able to highlight some text somewhere (a webpage, Microsoft Word, etc.) and pass that highlighted text to the Python program as input. Is this possible...?
I have already figured out how to add a program to the context menu, as explained by this link: https://www.howtogeek.com/107965/how-to-add-any-application-shortcut-to-windows-explorers-context-menu/
I am stuck on figuring out how to pass the highlighted text as input to the program though. I would post things I have tried, but I have no idea where to start..
Im sorry if this question sounds a bit vague, but I dont know the term for what I am looking for.
If you place your mouse cursor over an item in Windows and leave it there for a second, a box pops up with some text. For example, if you have your cursor on the 'e' icon, a box will show up with the text "Microsoft Edge".
Is there a method, using Python, to read what that text is? So for the example given, I would like to write or call a function that returns a string containing "Microsoft Edge".
Thank you for any help you can offer.
You are referring to tooltips. It's possible to use python with BeautifulSoup to scrape these off the web.
I am looking to get tooltip text from an icon displaying in the system tray. There are functions in class pywinauto.controls.common_controls.ToolTipsWrapper(hwnd) in pywinauto module of python. For example GetTipText(tip_index)Return the text of the tooltip. You can try if these functions provide any help to you. But I was getting error like 'no windows found' when using control of the icon by classname as window handle. For e.g
app = Application(backend="uia").connect(path="explorer")
sys_tray = app.window(class_name="Shell_TrayWnd")
hnd = sys_tray.childWindow(class_name= "ToolbarWindow32")``
texts= pywinauto.controls.common_controls.ToolTipsWrapper(hnd).texts()
print(texts)
Documentation of pywinauto: https://media.readthedocs.org/pdf/pywinauto-docs/docs-rework/pywinauto-docs.pdf
I'm trying to get myself a decent RSS reader in python. It's supposed to be a pure console application.
My question is-as mentioned in the title-how to open a link within this console. So e.g theres a recent feed entry and i want to click on it and it should open the linked website in a browser.
Is this possible and if yes I would be glad if you could help me
Since you're using Windows, you can use Windows console functions to detect clicks on the console, translate the click positions (which will already be character positions) to links via hit-testing, and hook them up to e.g. webbrowser.open to open a link.
Input handling for console applications is described here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682079%28v=vs.85%29.aspx.
I wanted to add clickable links to python output. I am outputting the file path & it's contents. Can someone please tell me how to make them clickable, so that when user clicks on them to navigate there directly.
I found this one, but it's for Django web part of Python. I am looking for desktop links
How to add clickable links to a field in Django admin?
Thanks in advance,
Phani
Are you talking about straight forward Python, no frameworks? Why not just print what you want?
print('example text')
I have the same issue, but only for win os.
As talking above you need to generate a link like this 'file:///C:/your/path/'
def show_firm_url(self, obj):
return '%s' % (obj.firm_url, obj.firm_url)
show_firm_url.allow_tags = True
By the security reason there is no way to open your local folder via win explorer, so you need some toher software. I've use Local explorer addin for chrome.
But you can see an error when click on link if your path contains special symbols or non-english characters when generating url link because html convert this characters like '%0H' and this strings will not match with your local path. For this I have not answer.
I'd like to make a small desktop editor to take notes, that uses markdowns to format text quickly. The application should transcribe markdowns instantaneously or after clicking on a button.
For this I'd like to use Qt4 and Python.
What, in your opinion, is the most efficient way to proceed?
In the case the rich text is rendered after pressing a button, I suppose I could use QTextEdit widget for the edit-mode, but what to use to display the rich text? I want this to look good. Should I render the text in HTML? Or something else?
Please advise.
You can look at how ReText has done it. Maybe even ReText is the app you want to code :-)
I came here because I'm looking for a solution for the same task.
Here is what I would (or hopefully will) try:
Subclass QTextEdit, which can display both plain and rich text.
supply two string properties, one containing Markdown source, the other generated HTML.
For entering "edit mode" (however your UI will handle this)
self.setText(self.markdown)
self.setReadOnly(False)
For leaving "edit mode":
self.markdown = self.toPlainText()
self.toHtml() # convert self.markdown to self.html
# don't know yet how to achieve that
self.setHtml(self.html)
self.setReadOnly(True)
For displaying the HTML one can use a CSS stylesheet.
As UI interface I could imagine: clicking on the readonly display mode switches to edit mode, [Ctrl]-[Enter] triggers HTML generation.