I tried to imitate Python x Kivy de Kinoppy (Kinokuniya bookstore app)

This article is the 14th day of Personal Development Advent Calendar 2019. And this is Qiita's first post. Beginning.

I am creating a Windows application using a framework called Python x Kivy.

background

  1. I cooked a paper book and made it into a PDF. Refreshing! --Now, let's read on the iPad --The iPad was taken by a child ... --I bought a Surface! Now, let's read on Surface --Unlike the iPad, there is no good app for Windows --Kinoppy (Kinokuniya bookstore app) Good! ――I wonder if you can make this with Kivy, which you are studying now.

Kinoppy (Kinokuniya bookstore app) is a very good app and I recommend it.

App overview

It has a bookshelf and a PDF viewer function. pdfapp2-min.gif

Development environment

AnacondaNavigator VSCode Python3.7 Kivy1.11

Library used, etc.

There are many that rely too much on others, but the ones I mainly use are as follows. PDF Rendering: pdf2image Configuration file: ruamel.yaml Icon fonts: iconfonts

Site that was very helpful

Kinoppy Kivy stackoverflow Arakawa Ray Blog Main Building And Qiita:Kivy

Todo It's quite deep and mid-minded, but I'm aiming for the following. far. ..

-[x] PDF reading (local PC) -[] PDF reading (DropBox) -[x] Bookshelf management (bookshelf addition & deletion) -[x] Move books by D & D (in the bookshelf) -[] Move books by D & D (another bookshelf) -[x] Viewer function (1 or 2 page display, right or left open specification) -[] Viewer function (automatic table of contents creation) -[] Viewer function (search)

Source code etc.

Here are two excerpts from the Kivy source code below.

  1. Scatter drag and drop thumbnails --Realization of Sleider's right → left -(Bonus) How to make a bookshelf

1.Scatter drag and drop thumbnails

Grab the thumbnail (the image displayed on the bookshelf) for a few seconds and then drag and drop it to add color to the image frame. If you release it before entering drag and drop, it will be regarded as a normal click and transition to the viewer.

Library.kv



<DraggableThumbnail@Scatter>:
    image_name: ''
    image_path: ''
    image: image_id
    shelf_row: None
    shelf_col: None

    do_rotation: False
    do_scale: False
    auto_bring_to_front: True
    do_collide_after_children: True

    background_color: 0,0,0,0
    background_normal: ''

    Image:
        id: image_id
        source: root.image_path
        allow_stretch:True
        keep_ratio: True
        canvas:
            Color:
                rgb: (1, 1, 1)
            Rectangle:
                texture: self.texture
                pos: self.pos
                size: self.size

Library.py



class DraggableThumbnail(Scatter):
    image_name = StringProperty(None)
    image_path = StringProperty(None)
    shelf_row = NumericProperty(None)
    shelf_col = NumericProperty(None)

    state = OptionProperty('released',options=['grabed','released'])
    img_touched = StringProperty(None)
    t = NumericProperty(0)

    def __init__(self,**kwargs):
        super(DraggableThumbnail,self).__init__(**kwargs)
        #Clock here.schedule_You can't resize without once
        Clock.schedule_once(self.drag_after_init)

    def drag_after_init(self, dt):
        self.size_hint = None,None
        self.size = self.image.size
        #Make only the image frame for drag and drop here
        with self.canvas:
            self.color = Color(rgba = (1,1,1,0))
            self.frame = Line(rectangle=(0,0,self.image.width,self.image.height))

    def on_state(self,*args):
        #When you grab it, make the image frame gray.
        if self.state == 'grabed':
            self.color.rgba = (0.5,0.5,0.5,1)
        #When you release it, put it back.
        elif self.state == 'released':
            self.color.rgba =  (1,1,1,0)

    def time_count(self,*args):
        self.t += 0.1

    def on_t(self,*args):
        if self.t >=0.5:
            Clock.unschedule(self.time_count)
            self.t = 0
            self.state = 'grabed'
            self.img_touched = ''

    def on_touch_down(self, touch):
        self.on_state(touch)
        if self.collide_point(*touch.pos):
            Clock.schedule_interval(self.time_count, 0.1)
            self.img_touched = self.image_name

            touch.grab(self)
            return True

    def on_touch_up(self, touch):
        Clock.unschedule(self.time_count)
        self.t = 0

        if touch.grab_current is self:
            if self.img_touched == self.image_name:
                self.img_touched = ''
                if self.state == 'released':
                    #Transition to viewer
                    app= App.get_running_app()
                    app.root.chgdisp_viewer(self.image_name)
            else:
                #Thumbnail alignment because it was dropped
                app= App.get_running_app()
                app.root.Library.lineup_thumbnail(self,touch)
            touch.ungrab(self)

        self.state = 'released'
        return True

    def on_touch_move(self, touch):
        Clock.unschedule(self.time_count)
        self.t = 0
        if self.state == 'grabed':
            self.pos = touch.x - self.image.width / 2, touch.y - self.image.height / 2
            return True
        else:
            self.img_touched = ''


2. Realization of Sleider right → left

The inconvenience of overseas PDF Viewer is that it does not support vertical writing (right → left). Kivy sliders can be left-to-right (bottom-top), but there is no right-to-left setting. I also wanted the number of pages when sliding, so I made it a part. The source is uploaded to Github. I learned how to customize standard parts in this way. Please see the source if you like.

Example.gif

3. (Bonus) How to make a bookshelf

I didn't have a good bookshelf image, so I made one. This is the image. shelf2.png

How to make [My blog here](https://flat-kids.net/2019/10/06/inkscape0-92-4%e3%81%a7%e6%9c%ac%e6%a3%9a% At e3% 82% 92% e4% bd% 9c% e3% 82% 8b /), it has nothing to do with the program and there seems to be no demand anywhere.

Finally

The first Qiita post and the first Advent Calendar, it's too early from December 1st to my charge! !! Every day, the excitement of "Ah, it's about to turn ..." became a very good motivation. Without this event, it wouldn't have been finished so far. I'm glad I was able to participate. Thank you for reading.

Recommended Posts

I tried to imitate Python x Kivy de Kinoppy (Kinokuniya bookstore app)
I tried to touch Python (installation)
I tried to summarize Python exception handling
I tried to implement PLSA in Python
I tried to implement permutation in Python
Wrangle x Python book I tried it [2]
I tried to implement PLSA in Python 2
Python3 standard input I tried to summarize
I tried to implement ADALINE in Python
I tried to implement PPO in Python
Wrangle x Python book I tried it [1]
[Python] I tried to calculate TF-IDF steadily
I tried to touch Python (basic syntax)
I tried to get CloudWatch data with Python
I tried to output LLVM IR with Python
I tried to implement TOPIC MODEL in Python
I tried to automate sushi making with python
I tried to implement selection sort in python
I tried to multiply bouncing balls (occasionally x100)
I tried to find out how to streamline the work flow with Excel x Python ②
I tried to find out how to streamline the work flow with Excel x Python ④
I tried to find out how to streamline the work flow with Excel x Python ⑤
I tried to find out how to streamline the work flow with Excel x Python ①
I tried to find out how to streamline the work flow with Excel x Python ③
I tried to build an environment for machine learning with Python (Mac OS X)
I tried to graph the packages installed in Python
When I tried to introduce python3 to atom, I got stuck
I tried to summarize how to use matplotlib of python
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
I tried to touch the CSV file with Python
I tried to draw a route map with Python
I tried to solve the soma cube with python
I tried to implement a pseudo pachislot in Python
Continuation ・ I tried to make Slackbot after studying Python3
I tried to get started with blender python script_Part 02
I tried to implement Dragon Quest poker in Python
I tried to implement an artificial perceptron with python
I tried to implement GA (genetic algorithm) in Python
[Python] I tried to graph the top 10 eyeshadow rankings
I tried to automatically generate a password with Python3
I tried to summarize how to use pandas in python
I tried to solve the problem with Python Vol.1
I tried to analyze J League data with Python
[Python] I tried to get Json of squid ring 2
I tried to access Google Spread Sheets using Python
I tried to summarize the string operations of Python
I tried to solve AOJ's number theory with Python
I tried Python> autopep8
I tried to debug.
I tried to paste
I tried Python> decorator
I also tried to imitate the function monad and State monad with a generator in Python
I tried to summarize useful knowledge when developing / operating machine learning services [Python x Azure]
I tried to create API list.csv in Python from swagger.yaml
I tried to make various "dummy data" with Python faker
I tried various methods to send Japanese mail with Python
I tried LeetCode every day 13. Roman to Integer (Python, Go)
I tried mushrooms Pepper x IBM Bluemix Text to Speech
[Markov chain] I tried to read negative emotions into Python.
[Markov chain] I tried to read a quote into Python.