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.
Kinoppy (Kinokuniya bookstore app) is a very good app and I recommend it.
It has a bookshelf and a PDF viewer function.
AnacondaNavigator VSCode Python3.7 Kivy1.11
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
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)
Here are two excerpts from the Kivy source code below.
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 = ''
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.
I didn't have a good bookshelf image, so I made one. This is the image.
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.
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