Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

how to load python code in rst document

90 views
Skip to first unread message

Degenerate Tech

unread,
Jul 21, 2024, 1:41:24 PM7/21/24
to Kivy users support
i have an app which loads some texts and i want to show python script which is in a file , how to load it properly
?
introduction.rst
Screenshot from 2024-07-21 23-08-26.png

Degenerate Tech

unread,
Jul 21, 2024, 1:43:22 PM7/21/24
to Kivy users support
what is sphinx ? and kivy rst widget support it ?

ElliotG

unread,
Jul 21, 2024, 5:51:52 PM7/21/24
to Kivy users support
Sphinx is a documentation tool. See: https://www.sphinx-doc.org/en/master/

ElliotG

unread,
Jul 21, 2024, 5:58:21 PM7/21/24
to Kivy users support
I assume you have an rst document, and you want to embed python code in the rst document.  

You could use the kivy CodeInput widget to display python code.  This would provide syntax highlighting.

The rst widget in kivy also responds to the kivy label markup, so you can also use that to change fonts or colors.

Degenerate Tech

unread,
Jul 22, 2024, 7:30:34 AM7/22/24
to Kivy users support
I want to load from file .

Degenerate Tech

unread,
Jul 22, 2024, 7:31:06 AM7/22/24
to Kivy users support
I want to load code from file on rst document 

On Monday, July 22, 2024 at 3:28:21 AM UTC+5:30 ElliotG wrote:

ElliotG

unread,
Jul 22, 2024, 9:57:16 AM7/22/24
to Kivy users support
You may find these reference documents helpful:
https://docutils.sourceforge.io/docs/user/rst/quickstart.html#preformatting-code-samples

To insert code in rst the preceding paragraph needs to end with two colons "::".  The code (the literal block) must be indented.  The indentation is what specifies the literal block.  In the example below I used the textwrap module from the standard library to add a leading tab to the code to create the literal block.

from kivy.app import App
from kivy.lang import Builder

import textwrap

kv= """
BoxLayout:
    orientation: 'vertical'
    Label:
        text: 'RST Code Example'
        size_hint_y: None
        height: dp(30)
    RstDocument:
        id: rst_document
"""

rst_text = """

Code in ReStructuredText
========================

This is **Bold text**, some ``interpreted text``.  This is regular text. This is *italics*.


We put code in a "literal box". We start a literal box by putting "::" in the preceding paragraph.
The literal is indicated by being indented at a level greater than the preceding text.  
When the level of indent is restored, the literal box ends.  

The ReStructuredText documentation provides these directions:
To just include a chunk of preformatted, never-to-be-fiddled-with text, finish the prior paragraph with "::".
The preformatted block is finished when the text falls back to the same indentation level as a paragraph prior
to the preformatted block.

"""

class RstApp(App):
    def build(self):
        return Builder.load_string(kv)

    def on_start(self):
        with open('rst_text.py') as f:
            code = f.read()
        indented_code = textwrap.indent(code, prefix='\t')
        self.root.ids.rst_document.text = f"{rst_text}::\n\n{indented_code}\n\nBack to text"


RstApp().run()

rst_text.py

Degenerate Tech

unread,
Jul 23, 2024, 8:24:22 AM7/23/24
to Kivy users support
thanks any idea how to add copy button to copy python code or any text ?

Degenerate Tech

unread,
Jul 23, 2024, 9:16:15 AM7/23/24
to Kivy users support
[WARNING] [MTD         ] Unable to open device "/dev/input/event14". Please ensure you have the appropriate permissions.
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute. Remaining events:
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstBlockQuote object at 0x7fe84d1d8c10>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstListItem object at 0x7fe84d1ba730>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstList object at 0x7fe84d1b9230>>>
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute. Remaining events:
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstBlockQuote object at 0x7fe84d1d8c10>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstListItem object at 0x7fe84d1ba730>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstList object at 0x7fe84d1b9230>>>
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute. Remaining events:
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstBlockQuote object at 0x7fe84d1d8c10>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstListItem object at 0x7fe84d1ba730>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstList object at 0x7fe84d1b9230>>>
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute. Remaining events:
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstBlockQuote object at 0x7fe84d1d8c10>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstListItem object at 0x7fe84d1ba730>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstList object at 0x7fe84d1b9230>>>
[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute. Remaining events:
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstBlockQuote object at 0x7fe84d1d8c10>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstListItem object at 0x7fe84d1ba730>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstList object at 0x7fe84d1b9230>>>

when i do resize kivy window.

Degenerate Tech

unread,
Jul 23, 2024, 12:54:59 PM7/23/24
to Kivy users support
how to change ttf file of text in RstDocument
chnage text color ?
i want to see which feature are supported by RstDocument ?

ElliotG

unread,
Jul 23, 2024, 6:52:57 PM7/23/24
to Kivy users support
You can use the Label markup in the RstDocument to change color or font inline.  See: https://kivy.org/doc/stable/api-kivy.uix.label.html#markup-text
The RstDocument has a colors dictionary that controls the color of major components.  You can print it out, printing out the colors dictionary from my previous example shows:
self.root.ids.rst_document.colors={'background': 'e5e6e9ff', 'link': 'ce5c00ff', 'paragraph': '202020ff', 'title': '204a87ff', 'bullet': '000000ff'}
If you change the value in the colors dict the corresponding element will change color. 

I would suggest trying the features in the ReStrucuturedText documentation.  If you have trouble, reach out I'll try to help.
see: 

ElliotG

unread,
Jul 23, 2024, 6:56:11 PM7/23/24
to Kivy users support
This kind of problem is generally created when a recursive loop is accidently created.  If for example you have a widget where the size is dependent on the parent, and the parent size is dependent on the size of the child it creates a recursive loop. Carefully look thorough your kv code.  You could start commenting out elements until the problem resolves, to help find the root cause.

[CRITICAL] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute. Remaining events:
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstBlockQuote object at 0x7fe84d1d8c10>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstListItem object at 0x7fe84d1ba730>>>
<ClockEvent (-1.0) callback=<bound method GridLayout.do_layout of <kivy.uix.rst.RstList object at 0x7fe84d1b9230>>>

ElliotG

unread,
Jul 23, 2024, 7:19:30 PM7/23/24
to Kivy users support
If you need to select and copy arbitrary text, use a TextInput or CodeInput.  Looking at the source code for RstDocument, the elements are made of labels.  You could use the clipboard to select all of the text.
Another possible approach using the RstDocumet would be to use markup to create refernce tags or anchors and use those to copy text to the clipboard.

Siva 14

unread,
Jul 27, 2024, 1:40:55 PM7/27/24
to kivy-...@googlegroups.com
Hi,

Need help to make my app bar's corners rounded, I have searched in internet and gpt couldn't find anything. I need my app bar to look like a google search bar but not a search bar ofc.

Thanks,
Siva.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/daaf23ab-66a1-4e60-8c5e-4bbf38036e83n%40googlegroups.com.

ElliotG

unread,
Jul 28, 2024, 12:41:43 PM7/28/24
to Kivy users support
In the future when asking a new question, create a new conversation. 

You can create your own bar (depending on the features you need), or you will need to modify the source code for the kivymd app bar.  Setting the radius of the MDTopAppBar is not a supported feature. 

Here is a quick example just using a Label and canvas to create a rounded rectangle with text.  You could add the CommonElevationBehavior and a Label if you wanted the elevation effect.

from kivymd.app import MDApp
from kivy.lang import Builder

kv = """
MDScreen:
    md_bg_color: self.theme_cls.secondaryContainerColor
   
    Label:
        text: 'Not a real app Bar'
        color: 'black'
        size_hint: .8, None
        padding: dp(10)
        size: self.texture_size
        pos_hint: {'center_x': 0.5, 'center_y': 0.5}
        canvas.before:
            Color:
                rgba: 1, 1, 1, 1
            RoundedRectangle:
                size: self.size
                pos: self.pos
                radius: 30, 30, 30, 30
"""

class RoundedBarApp(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        return Builder.load_string(kv)

RoundedBarApp().run()




Reply all
Reply to author
Forward
0 new messages