I want to display a hyperlink in a pygtk table:
cr=gtk.CellRendererText()
column=gtk.TreeViewColumn(name)
column.add_attribute(cr, "markup", 0)
my_liststore=['google', ...]
Hyperlink "a" seems not supported by the markup. I get this warning:
GtkWarning: Failed to set text from markup due to error parsing markup: Unknown tag 'a' on line 1
How can I display a hyperlink in a pygtk table? And of course it should open the browser if you click on it ...
Update
Several month after asking this question: Here is my personal advice: don't use gtk. It is a dead horse. I don't know if Qt is better. The way to go is web technology.
Here are the lines which I use now. The cell gets rendered with blue color and underlined. The double click event calls a callback with uses the webbrowser module.
table = gtk.TreeView(list_store)
cr = gtk.CellRendererText()
# allow pango markup
column.add_attribute(cr, "markup", i)
# connect double click handler:
self.timeline.connect('row-activated', self.on_treeview_click)
# content in the data rows:
u'<span foreground="blue" underline="single">%s</span>' % (
glib.markup_escape_text(name))
Callback:
def on_treeview_click(self, treeview, path, view_column):
model=treeview.get_model()
action_id=model[path][0]
url='....' # build your url
import webbrowser
webbrowser.open(url)
Related
Something that drives me nuts in the developper tools of Chrome (106) and Firefox (105) is the fact that whenever some text logged to the console via console.log(text) happens to contain a hyperlink, this link is not only turned clickable (I can live with it even when I usually prefer to have just plain text) but is abbreviated, if it is a long link. So when I want to control what precise link is in some variable, I cannot just write e.g. console.log(img.src), because some of the interesting information of the link is hidden.
You can try yourself with
var href = 'https://stackoverflow.com/search?q=%5Bgoogle-chrome-devtools%5D+%5Bconsole.log%5D+%5Bfirefox-developer-tools%5D+%5Bhyperlink%5D+automatic+detection&someMoreStuffTomakeTheLinkLonger';
console.log(href);
In both, Firefox and Chrome, the output for me contains some '...', e.g. in Firefox I obtain as output:
https://stackoverflow.com/search?q=%5Bgoogle-chrome-devtools…link%5D+automatic+detection&someMoreStuffTomakeTheLinkLonger
thus hiding the part after "-devtools". (Chrome hides a slightly different part). The console is mostly a debugging tool. I log things because I want to see them, not hide them. I always need to either hover with the mouse and wait for the tooltip (doesn't allow me to copy fractions of the link) or to right click copy the link and paste it somewhere where I can see it completely. Or take a substring to remove the "https://" in the front. But note that the variable isn't necessarily a single hyperlink, but can be any text containing several such hyperlinks. I didn't find a way to force console.log to just print plain text all content. Did anybody meet this problem as well and find a workaround?
I made this a community wiki answer, because the main insight is not from myself but from the comments. Feel free to improve.
The console.log() function allows several arguments, which allows also a formatted output similar to printf in some languages. The possibilities of formatting can be found in the documentation of console.log() on MDN. In any case, this formatted output provides a solution at least for Chrome, as #wOxxOm pointed out in the comments:
console.log('%O', href) // works in Chrome
This is rather surprising, because %O is described at MDN as
"Outputs a JavaScript object. Clicking the object name opens more information about it in the inspector".
It seems there is no 'clicking' in Chrome when the object is a string.
There is also %s for string output, but this just gives the standard behavior of replacing links in both browsers. And for Firefox none of the above two formatting options works. There one really has to replace the protocol "https://" by something that is not recognized as link. A space behind ':' seems enough, so "https: //". It turns out, that one can also insert a formatting string "https:%c//", which can even be empty, and thus yield an output which is the complete link and can be copied as well:
console.log(href.replace(/(https?:)/, "$1%c"), ""); // works in Firefox
In particular the FF solution is cumbersome, and there might also be several links within one console-output. So it is useful to define one's own log-function (or if one prefers, redefine console.log, but note the remark at the end)
function isChrome() {...} // use your favorite Chrome detection here
function isFirefox() {...} // use your favorite Firefox detection here
function plainLog() {
const msg = arguments[0];
if (isChrome() && arguments.length == 1 && typeof msg == "string") {
return console.log("%O", msg);
}
if (isFirefox() && arguments.length == 1 && typeof msg == "string") {
const emptyStyle = ""; // serves only as a separator, such that FF doesn't recognize the link anymore
const reg = /(https?:)\/\//g;
const emptyStyles = []; // we need to insert one empty Style for every found link
const matches = msg.matchAll(reg);
for (let match of matches) {
emptyStyles.push(emptyStyle);
}
return console.log(msg.replace(reg, '$1%c//'), ...emptyStyles);
}
return console.log(...arguments);
}
For browser detection isChrome() and isFirefox() see e.g. here on SO.
One can of course extend the redefinition also to the other console functions (console.info, console.warn, etc.)
The downside of the redefinition of console.log is that usually every output of the console shows also the last entry of the call stack as a practical link to the source of the logging. But due to the redefintion, this link is now always to the same place, namely the file and line number where plainLog() is defined and calls console.log(), instead of the place where the new log command plainLog() was called. This new problem is described on SO here, but the solution (see comment) is again a bit involved and also not completely satisfying to serve as a replacement for the built-in console.log . So if links appear only rarely in the logging, it's probably better to switch to the redefined plainLog() only for these links.
I'm trying to write a script that will automatically open a webpage http://www.legislation.gov.uk/new/uksi and then click on all the links in the table "All New Legislation".
So far I've managed to get it to open the page but no luck with clicking.
Here's my script so far:
activate application "Safari"
open location "http://www.legislation.gov.uk/new/uksi"
to clickID()
do JavaScript "document.getElementById(id=per).click();" in document 1
end tell
The following example AppleScript code will open the targetURL in a new Safari window, wait for the page to finish loading, retrieve all URLs on the target page, search them for URLs pointing the various Statutory Instruments published today, and then open each one in a new tab of the same window the targetURL was opened.
set targetURL to "http://www.legislation.gov.uk/new/uksi"
set theseURLs to {}
set grepSearchPattern to ".*\\.uk/uksi/.*\\|.*\\.uk/ssi/.*\\|.*\\.uk/wsi/.*\\|.*\\.uk/nisi/.*"
set jsStatements to "var a = document.links; var x = ''; var i; for (i = 0; i < a.length; i++) { x = x + a[i].href + '|'; };"
tell application "Safari"
make new document with properties {URL:targetURL}
activate
end tell
tell application "System Events"
repeat until exists ¬
(buttons of UI elements of groups of toolbar 1 of window 1 of ¬
process "Safari" whose name = "Reload this page")
delay 1
end repeat
end tell
tell application "Safari"
set allURLs to (do JavaScript jsStatements in document 1)
end tell
try
set theseURLs to paragraphs of (do shell script "tr '|' '\\12' <<< " & ¬
allURLs's quoted form & " | grep " & grepSearchPattern's quoted form)
end try
if (length of theseURLs) is greater than 0 then
tell application "Safari" to tell front window
repeat with thisURL in theseURLs
set current tab to (make new tab with properties {URL:thisURL})
end repeat
set current tab to first tab
end tell
else
display dialog " Nothing published on this date." buttons {"OK"} ¬
default button 1 with title "All New Legislation" with icon note
end if
Hint: Mouse over and horizontal/vertical scroll to see full code.
Notes:
The do JavaScript1 command create a pipe delimited string of all URLs on the page of the targetURL.
The do shell script command takes the pipe delimited string of all URLs and replaces the pipe characters with newline characters, using tr, so grep can return the URLs that match the grepSearchPattern.
The grepSearchPattern variable currently only searches for Statutory Instruments, as I assume that is all that will show under All New Legislation on the page the targetURL opens to, because of /new/uksi in the targetURL, and what I've observed at that URL since you posted the question. If you also want links for other types of legislation, the grepSearchPattern variable can be adjusted to accommodate.
1 Using the do JavaScript command requires Allow JavaScript from Apple Events to be checked on the Safari > Develop menu, which is hidden by default and can be shown by checking [√] Show Develop menu in menu bar in: Safari > Preferences… > AdvancedIf you are not allowed to enable that setting, the URLs can be collected for processing in another manner, however it uses the lynx third party utility.
Opening the links without the use of the do JavaScript command:
The following example AppleScript code will use lynx to retrieve the URLs from the targetURL, search them for URLs pointing the various Statutory Instruments published today, and if some have been published will open the targetURL in a new Safari window, wait for the page to finish loading, and then open each one in a new tab of the same window the targetURL was opened.
set targetURL to "http://www.legislation.gov.uk/new/uksi"
set theseURLs to {}
set lynxCommand to "/usr/local/bin/lynx --dump -listonly -nonumbers -hiddenlinks=ignore"
set grepSearchPattern to ".*\\.uk/uksi/.*\\|.*\\.uk/ssi/.*\\|.*\\.uk/wsi/.*\\|.*\\.uk/nisi/.*"
try
set theseURLs to paragraphs of ¬
(do shell script lynxCommand & space & targetURL's quoted form & ¬
" | grep " & grepSearchPattern's quoted form)
end try
if (length of theseURLs) is greater than 0 then
tell application "Safari"
make new document with properties {URL:targetURL}
activate
end tell
tell application "System Events"
repeat until exists ¬
(buttons of UI elements of groups of toolbar 1 of window 1 of ¬
process "Safari" whose name = "Reload this page")
delay 1
end repeat
end tell
tell application "Safari" to tell front window
repeat with thisURL in theseURLs
set current tab to (make new tab with properties {URL:thisURL})
end repeat
set current tab to first tab
end tell
else
display dialog " Nothing published on this date." buttons {"OK"} ¬
default button 1 with title "All New Legislation" with icon note
end if
Hint: Mouse over and horizontal/vertical scroll to see full code.
Notes:
In the lynxCommand variable, change /usr/local/bin/lynx to the appropriate /path/to/lynx. lynx can be installed using Homebrew
The grepSearchPattern variable currently only searches for Statutory Instruments, as I assume that is all that will show under All New Legislation on the page the targetURL opens to, because of /new/uksi in the targetURL, and what I've observed at that URL since you posted the question. If you also want links for other types of legislation, the grepSearchPattern variable can be adjusted to accommodate.
Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.
I have a jaspersoft report (line chart built in studio), and I want the data series in the chart to be hyperlinks that drilldown to open a dashboard.
Based on this wiki page I was able to create Reference hyperlinks so that clicking on any data series in the chart opens the correct dashboard. But I cannot get the Input Control parameters to pass correctly.
The URL when I load my dashboard directly from the repository (not by clicking hyperlinks in my line chart report) is
http://ddevrpt:8080/jasperserver-pro/dashboard/viewer.html#%2Fpublic%2FP2%2FMidcap%2FFinancial%2FDashboards%2FWell_Profile
The URL generated when i do not include input controls in my hyperlink reference expression is the same:
http://ddevrpt:8080/jasperserver-pro/dashboard/viewer.html#%2Fpublic%2FP2%2FMidcap%2FFinancial%2FDashboards%2FWell_Profile
JRXML:
<itemHyperlink hyperlinkType="Reference">
<hyperlinkReferenceExpression><![CDATA["./dashboard/viewer.html#%2Fpublic%2FP2%2FMidcap%2FFinancial%2FDashboards%2FWell_Profile"]]></hyperlinkReferenceExpression>
</itemHyperlink>
The URL generated when i do include Input Control parameter values is different, but still loads the dashboard empty (without passing the parameter values):
http://ddevrpt:8080/jasperserver-pro/dashboard/viewer.html?hidden_WellConcatenated_0=49005478.1:%20DILTS%2044-15%20TH&hidden_OccurrenceDate_1=2015-09-28%2000:00:00.0&hidden_OccurrenceDate_2=2015-10-05%2000:00:00.0#%2Fpublic%2FP2%2FMidcap%2FFinancial%2FDashboards%2FWell_Profile
JRXML:
<itemHyperlink hyperlinkType="Reference">
<hyperlinkReferenceExpression><![CDATA["./dashboard/viewer.html#%2Fpublic%2FP2%2FMidcap%2FFinancial%2FDashboards%2FWell_Profile"+"&hidden_WellConcatenated_0=" + $V{WellConcatenated_0} + "&hidden_OccurrenceDate_1=" + $P{RecordDate_0_1} + "&hidden_OccurrenceDate_2=" + $P{TimeStampMinusOneWeek}]]></hyperlinkReferenceExpression>
</itemHyperlink>
I know I am naming the input controls correctly because if i change my link type to report execution and link to a simple report using those input controls the proper report opens and the input control values are passed correctly.
I would also appreciate if anyone has other references they can point me to for drilling down TO a dashboard from a report.
I'm working with 6.3 and was able to resolve the issue with a small modification to the HyperlinkReferenceExpression syntax.
Specifically, I removed the "_hidden" before the input control resource IDs:
HyperlinkReferenceExpression:
original syntax:
"./dashboard/viewer.html#%2Fpublic%2FP2%2FMidcap%2FFinancial%2FDashboards%2FWell_Profile"
+"&hidden_WellConcatenated_0=" + $V{WellConcatenated_0}
+"&hidden_OccurrenceDate_1=" + $P{RecordDate_0_1}
+"&hidden_OccurrenceDate_2=" + $P{TimeStampMinusOneWeek}
modified syntax:
"./dashboard/viewer.html#%2Fpublic%2FP2%2FMidcap%2FFinancial%2FDashboards%2FWell_Profile"
+"&WellConcatenated_0=" + $V{WellConcatenated_0}
+"&OccurrenceDate_1=" +$P{RecordDate_0_1}
+"&OccurrenceDate_2=" + $P{TimeStampMinusOneWeek}
I'm assuming you're running 6.4.0. I'm not sure that approach is still valid.
You will likely need to register a custom hyperlink handler in your report in order to drill-down to a Dashboard. See here for more details: http://community.jaspersoft.com/wiki/how-use-custom-hyperlink-handler-dashboard-jasperreports-server
And here: http://www.helicaltech.com/use-custom-hyperlink-handler-with-a-dashboard-in-jasperreports-server/
Let me know if that works for you on 6.4.0!
My solution is a bad solution., but it worked for me.
In my Dataset - query I used the following:
Select p.printer_name, p.display_name, $P{start_date_1} as start_date_param, ....
Then, use the start_date_param as a field in the hyperlink.
I have a .txt file and it has FormFeed character between para1 and para 2.
Para2 needs to be shown in next page on printing hence FormFeed is placed here.
sample txt file layout:
para1
formFeedCharacter
para2
expected layout on printing:
para1 is shown in 1st page and para 2 is shown in 2nd page as formFeed acts as page break.
When opened and printed with MS Word/WordPad:
expected layout is coming in 2 pages as expected.
When opened and printed with NotePad:
1)FormFeed is not acting as Page Break and all content is printed in 1 page only
2)FormFeed is displayed as unreadable Symbol
Final Printed layout when used Notepad:
para1
Unreadable symbol (caused by FormFeed)
para2
Why Notepad is unable to render FormFeed as pageBreak ?
Is it because NotePad is a text Editor While WordPad/MS Word is Word processor ?
Is there any way how we can make this work with NotePad ?
Notepad:
1)It is a text Editor program and cannot interpret Form Feed character as Page Break.
2) Hence there is no way we can make formFeed work as page break and print it by using NotePad.
WordPad/MS Word:
1) Both are Word Processor softwares and can interpret FormFeed correctly as Page Break.
Hence Unreadable symbol is not shown on opening txt file with them
2) We can also see the page Break by Print Preview feature in wordpad/NotePad.
This hyperLink provides additional information on this topic:
Additional Info
Also below hyperlink shows similar topic post asking for a universal solution for pageBreak Feature using txt file.
page Break in txt file Universal Solution
I want open ws2 inside the same libreoffice wb with a hyperlink in a cell on ws1.
My code is:
wb["test"].cell(row = 1, column = 2).hyperlink = '#%s' % "test2"
This works, but openpyxl adds file://... to the link and a new instance of libreoffice starts (and auto close) with every click on my hyperlink.
If i add manually a hyperlink to libreoffice calc no file:// is added and no other instances of libreoffice starts.
What target_modes are supported?
I believe target_mode = "External is hard coded inside the openpyxl cell hyperlink attr. wb.cell()._hyperlink_rel.target_mode = "External
It's fair to say that support for hyperlinks isn't perfect. However, starting with version 2.3 there is at least full support for the type. The relevant code for serialising could easily be adapted to reflect this.