0

I am writing simple drawing app in Kivy. It works fine on iPhone and iPad butWindow.screenshot() returns only a black screen. What did I wrong? Also, is there a way so that the screenshot() gets saved directly on dropbox/iCloud/Files-App?


    class DrawInput(Widget):

    def btn_save(self):


        user_data_dir = App.get_running_app().user_data_dir

        name = join(user_data_dir, "filename.png")

        Window.screenshot(name)     

    def on_touch_down(self, touch):
        with self.canvas:
            Color(0, 0, 0)
            touch.ud["line"] = Line(points = (touch.x, touch.y))

    def on_touch_move(self, touch):
        touch.ud["line"].points += (touch.x, touch.y)

    def on_touch_up(self, touch): 
        pass

    presentation = Builder.load_file("app_kivy.kv")

    class drawingapp(App):
    def build(self):
        return presentation

    if __name__=="__main__":
        drawingapp().run()

Kivy:-


    Screen:

      name: "drawing"
      on_pre_enter: drawing.canvas.clear()

      FloatLayout:

         DrawInput:
            id: drawing
         Button:
            text: "finish"
            on_press: drawing.btn_save()

I expect to get a screenshot of the drawing.

steveSarsawa
  • 1,559
  • 2
  • 14
  • 31
  • Did you test it on other platforms (windows, Linux etc?) – me2 beats May 14 '19 at 07:04
  • No, I did not. I have neither windows nor linux. – Dawid Archibald May 14 '19 at 07:40
  • could you prepare a simple and short runnable application that gives you a black screen? There may be many reasons for a black screen, for example, you could accidentally make canvas.clear before taking a screenshot – me2 beats May 14 '19 at 08:16
  • I do it in a minute but... would than the app returns correct screenshot on the computer (before running on Xcode)? The '''window.screenshot()''' works fine in python, the problem appears only after installing on iPhone and iPad. – Dawid Archibald May 14 '19 at 08:25
  • I've added code on GitHub: https://github.com/ksgfan/drawing-app – Dawid Archibald May 14 '19 at 09:23

1 Answers1

0

I can’t check your code for iOS right now, (I will try to do it a little later.) but on Linux (Ubuntu) it works fine: the user can take a screenshot of the entire application area, the image is saved in png format in the source folder (unfortunately, I didn’t quite get along with your output paths , therefore, I replaced the name value with name = 'test.png').

then I wrote a minimal example that also works on my system:

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

KV = '''
Button:
    text: 'Save'
    on_press: app.btn_save()
'''

class ApplePenApp(App):

    def build(self):
        self.root = Builder.load_string(KV)

    def btn_save(self):
        Window.screenshot('test.png')

ApplePenApp().run()

Please check if it works on your system (if it works, then most likely the problem is somewhere in your code).

I found the black screenshot problem only when doing something like this:

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

KV = """
Button
    text: '123456'
"""

class MyApp(App):
    def build(self):
        self.root = Builder.load_string(KV)
        self.make_screenshot()

    def make_screenshot(self):
        Window.screenshot('test.png')

MyApp().run()

However I also saw problems with Window.screenshot with some users, for example: https://github.com/kivy/kivy/issues/4514

Btw, as a more advanced alternative to Window.screenshot, you can try export_to_png. You can use this method for any widget, here is a short example:

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

KV = '''
Button:
    text: 'Save'
    on_press: app.btn_save(self)
'''

class ApplePenApp(App):

    def build(self):
        self.root = Builder.load_string(KV)

    def btn_save(self, inst):
        inst.export_to_png('test.png')

ApplePenApp().run()

You cannot use it for a window, but you can use it for a screen (in your case it can be SecondScreen "drawing"):

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

KV = '''
ScreenManager
    Screen
        id: screen
        Button:
            text: 'Save'
            on_press: app.widget_save(screen)
'''

class ApplePenApp(App):

    def build(self):
        self.root = Builder.load_string(KV)

    def widget_save(self, inst):
        inst.export_to_png('test.png')

ApplePenApp().run()

please check if these examples work for you.

me2 beats
  • 774
  • 1
  • 8
  • 24
  • The minimal example works well. Implementing it to my code sadly does not. I still get black image as a png file. 'export_to_png()' returns buttons and drawings as it should but on a black screen (should be white). Thank you very much, I'll try later change somehow my code. – Dawid Archibald May 15 '19 at 14:20
  • I solved the problem with https://stackoverflow.com/questions/20872598/kivy-change-background-color-to-white – Dawid Archibald May 15 '19 at 18:02