Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDCodeBlock implementation #1769

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Novfensec
Copy link

Description

This a MDCodeBlock implementation. Its subject to further changes. Solves the below issue.

  • MDCodeInput like Kivy's CodeInput #1766

  • Pratially Documented.

  • Added an example on the basis of current implementation in examples directory.

  • The Widget has an additional copy button with clipboard functionality to copy the code.

  • Registered the widget to factory_registers.

Usage

from kivy.core.window import Window
from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen


appkv = """
MDScreen:
    MDStackLayout:
        size_hint: 1, 1
        
        MDBoxLayout:
            orientation: "vertical"
            adaptive_height: True
            padding: [dp(20), dp(20), dp(20), dp(20)]
            
            MDCodeBlock:
                size_hint: 1, None
                adaptive_height: True
                text: "import os"
                style_name: "monokai"
                icon_color: "white"
"""


class MyApp(MDApp):

    def __init__(self, **kwargs):
        super(MyApp, self).__init__(**kwargs)
        Window.clearcolor = self.theme_cls.surfaceColor

    def build(self) -> MDScreen:
        screen = Builder.load_string(appkv)
        return screen

if __name__=="__main__":
    MyApp().run()
  • Adds to some extra widgets that KivyMD provides.

For now this is just a template for the widget. If approved I will continue enhancements based on the requested changes.

@HeaTTheatR
Hope you like this!!!

@T-Dynamos
Copy link
Collaborator

T-Dynamos commented Apr 1, 2025

Thanks for your contribution! However, this component isn't listed in the official Material 3 guidelines (link), so I’d prefer to stick to the documented components to maintain consistency.

@Novfensec
Copy link
Author

Thanks for your contribution! However, this component isn't listed in the official Material 3 guidelines (link), so I’d prefer to stick to the documented components to maintain consistency.

I saw that but I thought that if kivymd provides some kivymd.extras like the android toast. Although the PR remains as is till any further discussion.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants