【问题标题】:Tooltips function to each option in a drop down list in LibreOffice CalcLibreOffice Calc 下拉列表中每个选项的工具提示功能
【发布时间】:2018-07-04 08:20:49
【问题描述】:

我希望能够在我的 LibreOffice Calc 文档中添加工具提示功能。

我有一个使用 Data -> Validity 完成的下拉列表。使用单元格区域或列表。

如何尽可能简单地在该下拉列表中的每个选项上插入工具提示文本?

我之前没有写过宏(工具 -> 宏),我对 Visual Basic、Pyhton 或 Java 不熟悉。 任何安装、插件和/或代码 sn-p 我可以得到帮助?

例如:

1 (tooltip: this is option one)
2 (tooltip: this is option two)
3 (tooltip: option 3 this is)

我有 Ubuntu 18.04。

【问题讨论】:

  • 什么样的下拉列表:Data -> Validity,或者电子表格表单(View -> Toolsbars -> Form Controls),还是宏对话框(Tools -> Macros -> Organize Dialogs)?无论如何,您可能需要编写一个事件侦听器。对于 LO 编程,Basic 是最常见的,Python 是我最喜欢的,Java 是另一个不错的选择。
  • 我的第一次尝试是数据->有效性。我希望有一个简单的解决方案。但我想我现在必须开始学习 Basic、Python 或 Java。
  • 有关 Python 介绍性文档,请参阅 herehere 并使用 APSO

标签: libreoffice-calc


【解决方案1】:

可以轻松完成的一件事是使用 Insert -> Comment 将 cmets 添加到每个单元格。

然后,例如,如下图所示选择单元格 A5 并转到 数据 -> 有效性。将单元格范围源设置为 A1 到 A3。

另外,使用标签控件的工具提示示例位于https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=57791

通过编写事件侦听器,可以找到更接近您在问题中描述的解决方案。 XListBox 有一个名为 itemStateChanged 的事件。可能不是显示工具提示,而是在此事件发生时在文本框中显示信息。

编辑

这是显示我的想法的示例代码。使用 APSO 运行showdlg()

import uno
import unohelper
from com.sun.star.awt import XItemListener

Items = [
        ("Item 1", "This is the first item"),
        ("Item 2", "This is the second item"),
        ("Item 3", "This is the third item"),
    ]

def showdlg():
    doc = XSCRIPTCONTEXT.getDocument()
    dlg = TooltipDialog(doc)
    dlg.show()

class TooltipDialog(XItemListener, unohelper.Base):
    def __init__(self, doc):
        self.parent = doc.CurrentController.Frame.ContainerWindow
        self.dlg = None
        self.label = None

    def show(self):
        toolkit = self.parent.getToolkit()
        ctx = uno.getComponentContext()
        smgr = ctx.ServiceManager
        model = smgr.createInstanceWithContext(
            "com.sun.star.awt.UnoControlDialogModel", ctx)
        dialog = smgr.createInstanceWithContext(
            "com.sun.star.awt.UnoControlDialog", ctx)
        model.setPropertyValue("PositionX", 100)
        model.setPropertyValue("PositionY", 100)
        model.setPropertyValue("Width", 200)
        model.setPropertyValue("Height", 75)
        model.setPropertyValue("Title", "Tooltip Listbox")

        listbox = model.createInstance(
            "com.sun.star.awt.UnoControlListBoxModel")
        listbox.setPropertyValue("PositionX", 20)
        listbox.setPropertyValue("PositionY", 10)
        listbox.setPropertyValue("Width", 40)
        listbox.setPropertyValue("Height", 20)
        listbox.setPropertyValue("Dropdown", True)
        listbox.setPropertyValue("Name", "ListBox1")
        for pos in range(len(Items)):
            listbox.insertItemText(pos, Items[pos][0])
        model.insertByName("ListBox1", listbox)

        label = model.createInstance(
            "com.sun.star.awt.UnoControlFixedTextModel")
        label.setPropertyValue("PositionX", 70)
        label.setPropertyValue("PositionY", 10)
        label.setPropertyValue("Width", 100)
        label.setPropertyValue("Height", 20)
        label.setPropertyValue("Name", "Label1")
        label.setPropertyValue("Label", "(Please select an item.)")
        model.insertByName("Label1", label)

        dialog.setModel(model)
        control = dialog.getControl("ListBox1")
        control.addItemListener(self)
        self.label = dialog.getControl("Label1")
        dialog.createPeer(toolkit, None)
        self.dlg = dialog
        self.dlg.execute()
        self.dlg.dispose()

    def itemStateChanged(self, itemEvent):
        """XItemListener event handler."""
        pos = itemEvent.Source.SelectedItemPos
        description = Items[pos][1]
        self.label.setText(description)

您可能会注意到,该示例不包含任何特殊格式。例如,将其更改为将标签修改为黄色 3-D 框应该很简单。此外,该示例可以使用threads 显示在短时间内消失的消息。它仍然不是一个真正的工具提示,但如果这对您很重要的话,它可以让它看起来和工作起来很像。

可以使用电子表格lookup 函数实现类似的解决方案,而无需任何宏。文本将出现在一个单元格中,而不是单独的对话框中,并且单元格值将根据数据有效性结果计算。这样就不会在外观方面提供太大的灵活性,但它应该能够毫无问题地显示描述。

【讨论】:

  • 我尝试了添加评论,但是 cmets 没有被继承到实际的下拉列表中。谢谢你的想法。我有一些学习要做,我想我将来会回到这个问题来验证答案。
  • 正确;这并没有真正做到你所要求的。但我提到它是因为它显示了工具提示。如果您在编写事件侦听器时需要帮助,请编辑问题或发布新问题。你也可以试试 ask.libreoffice.org,它允许附件。在这种情况下,请务必发布此问题的链接。
  • 我已经编辑了这个问题,所以我可能会得到一些关于 coden-p 的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多