Altair and Panel: Save as button not showing - panel

I am using the Python library Altair to plot and let the user save as SVG file. To import data and interactive configuration I wanted to use the Panel library. They integrate well but the button to save is missing when I put the Altair plot inside a Panel element. Other interactivity works fine.
This seems to be a general problem as I can find no images of Altair plots inside a Panel element having the save button. However, I cannot find anybody addressing this specific issue, so the question is there any way to resurrect the button so the user can save?
(I know about altair_saver for programmatically saving, but unfortunately we cannot allow the dependencies on our system)
Here is a simple example of Altair with and without Panel.
And here is the code:
import pandas as pd
import altair as alt
alt.__version__
import panel as pn
pn.extension('vega')
pn.__version__
dictdata = {'variable': ['A', 'B', 'C', 'D'], 'value': [1, 3, 2, 4] }
df = pd.DataFrame.from_dict(dictdata)
chart = alt.Chart(df).mark_bar().encode(
y = alt.Y('variable:N'),
x = alt.X('value:Q'),
)
chart
pn.Row(chart)

This "save button" is known as the actions menu, and is configurable in vega-embed with the actions option.
Panel's vega chart embedding explicitly removes the actions by setting {actions: false}, as seen here: panel/models/vega.ts#L71.
Unfortunately, it does not appear that the package offers any way to configure this. You might try submitting a feature request to the Panel library.

Related

Image as cell note in Google Sheets, to be displayed at mouseover/hover

I'd like to attach images to certain cells of my Google spreadsheet, to appear upon hovering the mouse upon that cell, similar to how the native text-only regular cell notes (Shift+F2) appear.
Natively, Google Sheets supports inserting images in the cell. My image sizes are however too big, and I'd have to make the row/column width/height huge for them to be displayed at 100%. Plus, I'd want the images to only appear upon mouseover, and not always be visible.
(I should add that the functionality I describe is actually very easily achievable in Excel, which allows setting a picture-background for cell comments, something that Google Sheets does not.)
I discovered a Google Sheets addon which seems to extend regular cell notes to include richer content, including images. Inconveniently, it requires each image be uploaded to an image server rather than be loaded from the PC. That would have still been fine, except I couldn't get it to achieve the above stated goal.
Finally, I found this suggested workaround, which for me does not work, in the sense that the image is not loaded as a preview upon mousing over the URL (whether it ends with .jpg or not), only the URL itself is:
Interestingly, the effect I'm after actually exists in Google Docs, when the link isn't even an image but just a page:
Issue:
There is no native way to trigger actions on hover events in Sheets, and there is no way to retrieve images that have been uploaded from the computer and don't have a valid URL. This greatly limits what you can accomplish.
Nevertheless, there are workarounds available that can get you close to the functionality you're asking for.
Workaround (showModelessDialog):
You could, for example create a modeless dialog whose purpose would be to show the image corresponding to the selected cell.
Ideally, onSelectionChange trigger would be used, since this trigger to refresh the modeless dialog with current image when the user changes the selected cell, but since creating a modeless dialog requires authorization, simple triggers cannot run services that require authorization, and onSelectionChange is only available as a simple trigger (cannot be installed), that won't be possible.
So one possible workflow could be the following:
Show a modeless dialog when the spreadsheet is opened by a user.
The user selects the cell with the image that should be shown.
User clicks a button in the modeless dialog (or the previous image) to refresh the modeless dialog with the currently selected image.
How to do this:
To achieve this, you can follow these steps:
Install onOpen trigger that creates modeless dialog when the user opens the spreadsheet (the trigger needs to be installed, since, as I mentioned, simple triggers cannot use services that require authorization). To do that, go to the Apps Script editor (selecting Tools > Script editor), copy this function to your Code.gs file, and install the trigger following these steps:
function onOpenTrigger(e) {
var html = HtmlService.createTemplateFromFile("Page").evaluate()
.setWidth(800) // Change dimensions according to your preferences
//.setHeight(600) // Change dimensions according to your preferences
SpreadsheetApp.getUi()
.showModelessDialog(html, "My image");
}
Create the HTML template corresponding to the modeless dialog. The idea here would be: when the page loads, the currently selected image is shown. If the button (or the image itself) gets clicked, the page will refresh with current image (see retrieveImage and refreshImage). Create an HTML file in the editor via File > New > HTML file, and copy the following code:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body onload="retrieveImage()">
<img id="currentImage" onclick="retrieveImage()" alt="No image is selected" width="600">
<button onclick="retrieveImage()">Click to refresh image!</button>
</body>
<script>
function retrieveImage() {
google.script.run.withSuccessHandler(refreshImage).getSelectedImage();
}
function refreshImage(imageUrl) {
if (imageUrl) document.getElementById("currentImage").src = imageUrl;
}
</script>
</html>
Back in your script file (.gs), create a function to retrieve the image URL from current cell (in case this cell has an image). This function will get called by the modeless dialog when it loads and when its button is clicked. It could be like this (regex is used to retrieve that — see this answer:
function getSelectedImage() {
var formula = SpreadsheetApp.getActiveRange().getFormula();
var regex = /=image\("(.*)"/i;
var matches = formula.match(regex);
return matches ? matches[1] : null;
}
Note:
You can adapt the dimensions of both the selected image (<img width="" height="">) and the modeless dialog (.setWidth, .setHeight) according to your preferences.
Reference:
Dialogs and Sidebars in G Suite Documents
Installable Triggers: Managing triggers manually
getActiveRange()

Selenium webdriver : I want to click on "Like 1.3M" image which is on the bottom of https://www.msn.com/en-in/weather/today

I want to click on "Like 1.3M" image which is on the bottom of https://www.msn.com/en-in/weather/today
i have tried multiple approches for clicking on "facebook like" image like switching to iframe , clicking on image in webdriver.
but none of them are working .
Since you have no specified any language I will use Python to answer your question.
Firstly you need to switch to iframe that contains the like button like:
driver.get("https://www.msn.com/en-in/weather/today")
iframe = WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[#id="fbcount"]/iframe')))
iframe.location_once_scrolled_into_view
driver.switch_to.frame(iframe)
and then click like:
driver.find_element_by_xpath('//*[#id="u_0_0"]/div/button').click()
and then switch to default content
driver.switch_to.default_content()
If you get NoSuchElementException please add some wait time.
Here is the full code
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Chrome("/chromedriver/location")
driver.get("https://www.msn.com/en-in/weather/today")
iframe = WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[#id="fbcount"]/iframe')))
iframe.location_once_scrolled_into_view
driver.switch_to.frame(iframe)
time.sleep(3)
driver.find_element_by_xpath('//*[#id="u_0_0"]/div/button').click()
time.sleep(3)
driver.switch_to.default_content()
driver.close()
driver.quit()
Instead of click(), use the action class click().
WebElement likeFB=driver.findElement(By.xpath("//div[#id='u_0_0']/div/button"));
Actions act = new Actions(driver);
act.moveToElement(likeFB).click().build().perform();

Link directly to a notebook page in a view

I have an view that extends the current project view, where we add multiple tabs (notebook pages) to show information from other parts of a project.
One of these pages is an overview page that summarizes what is under the other tabs, and I'd like to link the headlines for each section directly to each displayed page. I've currently solved this by using the index of each tab and calling bootstrap's .tab('show') method on the link within the tab:
$(".overview-link").click(function (e) {
e.preventDefault();
var sel = '.nav-tabs a:eq(' + $(this).data('tab-index') + ')';
$(sel).tab('show');
});
This works since I've attached a data-tab-index="<int>" to each header link in my widget code, but it's brittle - if someone adds a tab later, the current indices will be broken. Earlier I relied on the anchor on each tab, but that broke as well (and would probably break if a new notebook page were inserted as well).
Triggering a web client redirect / form link directly works, but I want to show a specific page in the view:
this.do_action({
type: 'ir.actions.act_window',
res_model: 'my.model.name',
res_id: 'my.object.id',
view_mode: 'form',
view_type: 'form',
views: [[false, 'form']],
target: 'current'
});
Is there any way to link / redirect the web client directly to a specific notebook page tab through the do_action method or similar on FormWidget?
If I understood well you want to select the tab from the JavaScript (jQuery) FormWidget taking into account that the id could change if anybody install another module that adds another tab
Solution 0
You can add a class to the page in the xml form view. You can use the id of the element selected by this class name in order to call the right anchor and select the right tab item. This should happen when the page is completely loaded:
<page class="nb_page_to_select">
$('a[href=#' + $('.nb_page_to_select').attr('id') + ']').click()
NOTE: As you have said the following paragrah I assume that you know where to run this instruction. The solution I suggest is independent of the index.
This works since I've attached a data-tab-index="<int>" to each
header link in my widget code, but it's brittle - if someone adds a
tab later, the current indices will be broken. Earlier I relied on the
anchor on each tab, but that broke as well (and would probably break
if a new notebook page were inserted as well).
Solution 1
When the page is loaded you can get the tab list DOM object like this:
var tablist = $('ul[role="tablist"]')
And then you can click on the specifict tab, selecing by the text inside the anchor. So you don't depend on the tab index:
tablist.find('a:contains("Other Information")').click()
I think if you have two tabs with the same text does not make any sense, so this should be sufficient.
Solution 2
Even if you want to be more specific you can add a class to the notebook to make sure you are in the correct notebook
<notebook class="nt_to_change">
Now you can use one of this expressions in order to select the tab list
var tablist = $('div.nt_to_change ul.nav-tabs[role="tablist"]')
// or
var tablist = $('div.nt_to_change ul[role="tablist"]')
Solution 3
If the contains selector doesn't convince you because it should be equal you can do this as well to compare and filter
tablist.find('a').filter(function() {
return $.trim($(this).text()) === "Other Information";
}).click();
Where "Other Information" is the string of the notebook page
I didn't tried the solution I'm giving to you, but if it doesn't work at least may be it makes you come up with some idea.
There's a parameter for XML elements named autofocus (for buttons and fields is default_focus and takes 1 or 0 as value). If you add autofocus="autofocus" to a page in XML, this page will be the displayed one when you open the view.
So, you can try to add this through JavaScript, when the user clicks on the respective link -which honestly, I don't know how to achieve that by now-. But you can add a distinctive context parameter to each link in XML, for example context="{'page_to_display': 'page x'}". When you click on the link, I hope these context keys will arrive to your JS method.
If not, you can also modify the fields_view_get method (here I wrote how to do that: Odoo - Hide button for specific user) to check if you get the context you've added to your links and add the autofocus parameter to the respective page.
As you said:
This works since I've attached a data-tab-index="" to each header
link in my widget code, but it's brittle - if someone adds a tab
later, the current indices will be broken.
I assume that your app allow multi-user interaction in realtime, so you have to integrate somewhere in your code, an update part function.
This function will trig if something has changed and cleanout the data to rebuilt the index in order to avoid that the current indices will be broken.

How to create a floating help layout?

I've got a {N} page and conditionally I'd like to create a floating bubble text label pointing to certain features on the page. e.g. "Press START button to blah".
Any help on how this could be done.
Preferably w/o modifying the xml page files.
I released a plugin that can do what you are requesting simply install it tns plugin add nativescript-tooltip then you can use it as follows
TypeScript
import * as frame from "ui/frame";
import {ToolTip} from "nativescript-tooltip";
new ToolTip(frame.topmost().getViewById("someView"),{text:"Some Text"});
JavaScript
const frame = require("ui/frame");
const ToolTip = require("nativescript-tooltip").ToolTip;
new ToolTip(frame.topmost().getViewById("someView"),{text:"Some Text"});
Plugin Repo

How to have only one tab open in wxribbon bar in wxpython?

I am building a GUI and I am using wxribbon for wxpython. I want to have only one tab(ribbon page) in when user starts my app, from where user can dynamically add more pages or can add panels and buttons to a page. I am able to achieve all the dynamic parts of ribbon. The only problem I have is that I am unable to start with only one ribbon page. When I define only one page, I don't see the ribbon bar(tab bar), what I see is only the page. Now, when I define two page in the beginning, then I see the bar. Can someone tell me what I code have to change in wxribbon so that I am able to have a tab bar visible with only one page in it. Any help would be great. Thanks!. The sample code I am using to add a page is as follows :
import wxRibbon as RB
self._ribbon = RB.RibbonBar(self, id = wx.ID_ANY)
page_1 = RB.RibbonPage(self._ribbon, WORKPIECE, "Workpiece", Bitmap("eye.xpm"))
page_2 = RB.RibbonPage(self._ribbon, wx.ID_ANY, "New Tab", Bitmap("empty.xpm"))
You need the flag RIBBON_BAR_ALWAYS_SHOW_TABS
try this:
self._ribbon = RB.RibbonBar(self, wx.ID_ANY, agwStyle = RB.RIBBON_BAR_DEFAULT_STYLE | RB.RIBBON_BAR_ALWAYS_SHOW_TABS)

Resources