LinkLabel Proposal
See original GitHub issueFirst of all I know that toga is not aimed to support widget primitives.
But there is already Label
widget that serves for quite low level purposes:
- form inputs short description (like label in html)
- putting any text here or there (like paragraph in html (however there is need for MultiLineLabel https://github.com/beeware/toga/issues/766))
So I think it may be useful as useful is html tag.
Label
-inherited POC for Winforms:
from toga_winforms.libs import WinForms
from toga_winforms.widgets.label import Label as WinFormsLabel
class WinformsLinkLabel(WinFormsLabel):
def create(self):
self.native = WinForms.LinkLabel()
self.native.LinkClicked += WinForms.LinkLabelLinkClickedEventHandler(
self.interface._link_clicked
)
class LinkLabel(toga.Label):
def __init__(self, text, link=None, id=None, style=None, factory=None):
toga.Widget.__init__(self, id=id, style=style, factory=factory)
self._impl = WinformsLinkLabel(interface=self)
# self._impl = self.factory.Label(interface=self)
self.link = link
self.text = text
@property
def link(self):
if self._link is None:
return self.text
return self._link
@link.setter
def link(self, link):
self._link = link
def _link_clicked(self, el, _):
webbrowser.open(self.link)
My usecase: a dead simple GUI - with link to my repository. I wanted to avoid strange Button
with URL inside (alternatively clickable github icon would be OK but not supported currently #774 outside of native commands palette), or create Group
named “About” inside which will be “See on github” action, as it would be the only one command and on Windows it feels strange.
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (18 by maintainers)
Top Results From Across the Web
LinkLabel Class (System.Windows.Forms) | Microsoft Learn
Represents a Windows label control that can display hyperlinks. In this article. Definition; Examples; Remarks; Constructors; Properties; Methods; Events ...
Read more >Press enter to click a LinkLabel - Stack Overflow
If I have a linklabel on a .net winform, is there anyway I can, when the link label is focused, get a press...
Read more >LinkLabel Bluetooth Enabled Label Printer
LinkLabel Bluetooth Enabled Label Printer. Item#: LS3000-PRINTER. $4,334.40 $3,684.24. LinkLabel Bluetooth Enabled Label Printer quantity. Add to cart.
Read more >Link Label Prediction in Signed Social Networks
We propose a matrix factorization based technique MF-LiSP that exhibits strong generalization guarantees. We also investigate the applicability of logistic ...
Read more >A Robust Algorithm Based on Link Label Propagation for ...
Various methods have been proposed to identify the functional modules in PPI networks, but most of these methods do not consider the noisy...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fair point. Also, there is yet another option: have a single
text
attribute and atext_format
attribute which can be for instance “plain”, “html” or another markup language such as “markdown” if this should be supported in the future. This works around having two different properties that hold the displayed text while still preventing ambiguity.I’ll look into stripping certain html tags. Python’s XML parser may have trouble with self-closing html tags.
That’s what I was afraid of - if we can’t get the size of the underlying text, then we can’t use the size of the text in layout calculations.
The HTMLLabel widget looks interesting. If I’m reading that right, it’s going back to basics - literally drawing all the component text. That seems slighly overkill under the circumstances, though.
In which case, having the Windows implementation be “concatenation of Winforms.Label” (and Winforms.LinkLabel, as needed) might be the easiest path forward.
As an aside/simplification, you should find that you can assign attributes directly, rather than invoking
set_
methods -self.native.set_ReadOnly(True)
should be equivalent toself.native.ReadOnly = True
.