Skip to content

Commit 4e964aa

Browse files
author
AlvarBer
committed
Release 0.8.1-β
Minor release with mainly visual improvements. Code * Pins now align themselves automatically. * Blocks are round and transparent. * Connections are bèzier curves instead of straight line. * Added direction indicators. * Connections go behind the blocks. * Backgrounds looks good in all sizes. Documentation * Added image with new visual aspect. * Added directions for use. Package * Added minimum python version.
2 parents e1c8007 + b28567b commit 4e964aa

34 files changed

+301
-250
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ If you have pip (Python 3.5+) you can simply type
1818

1919
`$> pip install persimmon`
2020

21+
To execute use.
22+
23+
`$> python -m persimmon`
24+
2125
For windows self-contained executables can be found on the [releases page].
2226

2327

docs/images/final_aspect.png

-16.9 KB
Loading

docs/src/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ On this chapter Persimmon is introduced, along its main objectives and
55
motivations.
66
It also includes a section about topics that are related but beyond the scope
77
of this project.
8-
Finally, it includes an overviewof the project report structure.
8+
Finally, it includes an overview of the project report structure.
99

1010

1111
Description

docs/template.tex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,10 @@
216216
$endif$
217217

218218
% Make sections great again
219-
\usepackage{titlesec}
220-
221-
\titleformat*{\section}{\sffamily\LARGE\bfseries}
222-
\titleformat*{\subsection}{\sffamily\Large\bfseries}
223-
\titleformat*{\subsubsection}{\sffamily\large\bfseries}
219+
%\usepackage{titlesec}
220+
%\titleformat*{\section}{\sffamily\LARGE\bfseries}
221+
%\titleformat*{\subsection}{\sffamily\Large\bfseries}
222+
%\titleformat*{\subsubsection}{\sffamily\large\bfseries}
224223

225224
% Better abstract
226225
\renewenvironment{abstract}{

persimmon/background.png

27.5 KB
Loading

persimmon/border.png

624 Bytes
Loading

persimmon/circuit_board.png

-7.07 KB
Binary file not shown.

persimmon/connections.png

-293 Bytes
Binary file not shown.

persimmon/view/blocks/block.kv

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
<Block>:
2-
# Fixed options
3-
size_hint: None, None
4-
size: '200dp', '75dp'
5-
drag_rectangle: self.x, self.y, self.width, self.height
6-
drag_timeout: 10000000
7-
drag_distance: 0
2+
# Fixed options
3+
size_hint: None, None
4+
width: '200dp'
5+
drag_rectangle: self.x, self.y, self.width, self.height
6+
drag_timeout: 10000000
7+
drag_distance: 0
8+
label: label
89
canvas:
910
Color:
10-
rgb: .2, .2, .2
11-
Rectangle:
11+
rgba: .15, .15, .15, .8
12+
RoundedRectangle:
1213
pos: self.pos
1314
size: self.size
14-
#canvas.before:
15-
#Color:
16-
#rgb: 1, 1, 1
17-
#BorderImage:
18-
#pos: self.x - 5, self.y - 5
19-
#size: self.width + 10, self.height + 10
20-
#source: 'tex2.png'
21-
# Children
22-
Label:
23-
pos: root.x, root.y + root.height - 20
24-
size_hint: None, None
25-
height: '20dp'
15+
# Children
16+
Label:
17+
id: label
18+
pos: root.x, root.y + root.height - 20
19+
size_hint: None, None
20+
height: '20dp'
2621
width: root.width
2722
text: root.title
28-
canvas.before:
29-
Color:
30-
rgb: root.block_color
31-
Rectangle:
32-
pos: self.pos
33-
size: self.size
23+
canvas.before:
24+
Color:
25+
rgba: [*root.block_color, 0.8]
26+
RoundedRectangle:
27+
pos: self.pos
28+
size: self.size
29+
radius: [(10, 10), (10, 10), (0, 0), (0, 0)]

persimmon/view/blocks/block.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
from kivy.uix.behaviors import DragBehavior
66
from kivy.properties import ListProperty, StringProperty, ObjectProperty
77
from kivy.lang import Builder
8-
from kivy.graphics import BorderImage, Color
8+
from kivy.graphics import BorderImage, Color, RoundedRectangle
99
from kivy.uix.image import Image
1010
# Types are fun
1111
from typing import Optional
1212
from abc import abstractmethod
13+
from functools import partial
1314

1415

1516
Builder.load_file('view/blocks/block.kv')
1617

1718
class Block(DragBehavior, FloatLayout, metaclass=AbstractWidget):
1819
block_color = ListProperty([1, 1, 1])
1920
title = StringProperty()
21+
label = ObjectProperty()
2022
inputs = ObjectProperty()
2123
outputs = ObjectProperty()
2224
input_pins = ListProperty()
@@ -26,18 +28,32 @@ class Block(DragBehavior, FloatLayout, metaclass=AbstractWidget):
2628

2729
def __init__(self, **kwargs):
2830
super().__init__(**kwargs)
31+
2932
if self.inputs:
3033
for pin in self.inputs.children:
3134
self.input_pins.append(pin)
3235
pin.block = self
36+
self.gap = pin.width * 2
3337
if self.outputs:
3438
for pin in self.outputs.children:
3539
self.output_pins.append(pin)
3640
pin.block = self
41+
self.gap = pin.width * 2
3742
self.tainted_msg = 'Block {} has unconnected inputs'.format(self.title)
3843
self._tainted = False
3944
self.kindled = None
4045
self.border_texture = Image(source='border.png').texture
46+
# Make block taller if necessary
47+
self.height = (max(len(self.output_pins), len(self.input_pins), 3) *
48+
self.gap + self.label.height)
49+
# Position pins nicely
50+
y_origin = self.y + (self.height - self.label.height)
51+
for i, in_pin in enumerate(list(self.input_pins[::-1]), 1):
52+
self._bind_pin(self, (in_pin.x, in_pin.y), in_pin, i, False)
53+
self.fbind('pos', self._bind_pin, pin=in_pin, i=i, output=False)
54+
for i, out_pin in enumerate(list(self.output_pins[::-1]), 1):
55+
self._bind_pin(self, (out_pin.x, out_pin.y), out_pin, i, True)
56+
self.fbind('pos', self._bind_pin, pin=out_pin, i=i, output=True)
4157

4258
@property
4359
def tainted(self):
@@ -72,14 +88,14 @@ def function(self):
7288
raise NotImplementedError
7389

7490
# Kivy touch events override
75-
def on_touch_down(self, touch):
91+
def on_touch_down(self, touch) -> bool:
7692
pin = self.in_pin(*touch.pos)
7793
if pin: # if touch is on pin let them handle
7894
return pin.on_touch_down(touch)
7995
else: # else default behavior (drag if collide)
8096
return super().on_touch_down(touch)
8197

82-
def on_touch_up(self, touch):
98+
def on_touch_up(self, touch) -> bool:
8399
pin = self.in_pin(*touch.pos)
84100
if pin:
85101
result = pin.on_touch_up(touch)
@@ -91,9 +107,9 @@ def kindle(self):
91107
""" Praise the sun \[T]/ """
92108
with self.canvas.before:
93109
Color(1, 1, 1)
94-
self.kindled = BorderImage(pos=(self.x - 5, self.y - 5),
95-
size=(self.width + 10,
96-
self.height + 10),
110+
self.kindled = BorderImage(pos=(self.x - 2, self.y - 2),
111+
size=(self.width + 4,
112+
self.height + 4),
97113
texture=self.border_texture)
98114
self.fbind('pos', self._bind_border)
99115

@@ -109,4 +125,14 @@ def unkindle(self):
109125
# Auxiliary functions
110126
def _bind_border(self, block, new_pos):
111127
""" Bind border to position. """
112-
self.kindled.pos = new_pos[0] - 5, new_pos[1] - 5
128+
self.kindled.pos = new_pos[0] - 2, new_pos[1] - 2
129+
130+
def _bind_pin(self, block, new_pos, pin, i, output):
131+
""" Keep pins on their respective places. """
132+
pin.y = (block.y + (block.height - block.label.height) - i * self.gap +
133+
pin.height / 2)
134+
if output:
135+
pin.x = block.x + block.width - self.gap
136+
else:
137+
pin.x = block.x + 5
138+

0 commit comments

Comments
 (0)