Kivy reStructuredText 渲染器弹出窗口?

Posted

技术标签:

【中文标题】Kivy reStructuredText 渲染器弹出窗口?【英文标题】:Kivy reStructuredText renderer popup? 【发布时间】:2018-07-02 02:33:18 【问题描述】:

我想要 kivy reStructuredText 渲染器中引用的弹出效果,默认情况下,当我们按下任何引用时,它会滚动到引用,这里我想用弹出替换滚动,我已经搜索了很长时间但徒劳无功,今天我在 kivy 文档中找到了goto(ref, *largs),是否可以使用它来调用参考弹出窗口?是否可以在另一个类中重新定义 RstDocument 函数并使用它?我是初学者。

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

Builder.load_string("""
<RSTGUI>:
    RstDocument:
        text: root.doc
        goto: # Any Popup aur bubble with reference
""")

class RSTGUI(BoxLayout):
    doc="""
.. _top:

Hello world
===========

This is an **emphased text**, some ``interpreted text``.
And this is a reference to top_::

    $ print("Hello world")


"""
class RST(App):
    def build(self):
        return RSTGUI()


if __name__=='__main__':
    RST().run()

【问题讨论】:

【参考方案1】:

经过一番研究,我已经弄清楚了,Alhumdolillah。

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.rst import RstDocument
from kivy.uix.popup import Popup

Builder.load_string("""

<RSTGUI>:
    MyRST:
        text: root.doc




<about_us_popup>:
    size_hint: 0.8,0.6
    title: "About Us"
    BoxLayout:
        orientation:'vertical'
        RstDocument:
            text: "MyText"
        Button:
            text:"OK"
            size_hint: 1,0.1
            on_press:root.dismiss()



""")



class RSTGUI(BoxLayout):

    doc="""
.. _top:

Hello world
===========

This is an **emphased text**, some ``interpreted text``.
And this is a reference to top_::

    $ print("Hello world")

"""

class MyRST(RstDocument):

    def __init__(self, **kwargs):
        super(MyRST, self).__init__(**kwargs)
        self.about_us_popup = about_us_popup()

    def goto(self, ref, *largs):
        self.about_us_popup.open()


class RST(App):
    def build(self):
        return RSTGUI()


class about_us_popup(Popup):
    pass

if __name__=='__main__':
    RST().run()

【讨论】:

以上是关于Kivy reStructuredText 渲染器弹出窗口?的主要内容,如果未能解决你的问题,请参考以下文章

将文本渲染到 kivy 画布

pypi开源项目文档终极秘诀应对rst解析错误:The description failed to render in the default format of reStructuredText(代

pypi开源项目文档终极秘诀应对rst解析错误:The description failed to render in the default format of reStructuredText(代

Kivy 日期选择器小部件

Kivy - 屏幕管理器 - 访问其他类中的属性

获取 kivy 微调器选择的索引