Skip to content

Commit 36c8487

Browse files
committed
imports changed to relative
1 parent a015e5c commit 36c8487

4 files changed

Lines changed: 48 additions & 5 deletions

File tree

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
setup(
33
name = 'sort_visualizer',
44
packages = ['sort_visualizer'],
5-
version = '1.0.2',
5+
version = '1.0.3',
66
license='MIT',
77
description = 'Python package to visualize any sorting algorithm',
88
author = 'dduck',
99
author_email = 'famgui14@gmail.com',
1010
url = 'https://github.com/DirectDuck/sorting_visualizer',
11-
download_url = 'https://github.com/DirectDuck/sorting_visualizer/archive/1.0.2.tar.gz',
11+
download_url = 'https://github.com/DirectDuck/sorting_visualizer/archive/1.0.3.tar.gz',
1212
keywords = ['SORT', 'SORTING', 'VISUALIZATION', 'VISUALIZE'],
1313
install_requires=[
1414
'PySimpleGUI',

sort_visualizer/algs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sort_visualizer.sorter import Sorter
1+
from .sorter import Sorter
22

33

44
class Sort():

sort_visualizer/gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PySimpleGUI as sg
2-
from sort_visualizer.sorter import Sorter
3-
from sort_visualizer import algs
2+
from .sorter import Sorter
3+
from . import algs
44

55

66
class GUI:

test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from sort_visualizer import gui, algs
2+
'''
3+
In order to visualize your own sort you
4+
need to create a class that inherits from
5+
algs.Sort and implement execute(self) method.
6+
7+
To access array use self.array.
8+
9+
Every object in self.array is a Rectangle class
10+
instance. To access associated value use .height attribute.
11+
12+
Visual functions:
13+
When an element changed its value use self.redraw()
14+
When swapping two elements of the array use
15+
self.swap_rects(rect1: Rectangle, rect2: Rectangle)
16+
(Please note that swap_rects function only applies visual
17+
part, you still need to actually swap the values in array)
18+
19+
To see more examples check algs.py
20+
'''
21+
22+
23+
class TestBubbleSort(algs.Sort):
24+
25+
def execute(self):
26+
for i in range(len(self.array) - 1):
27+
for j in range(len(self.array) - i - 1):
28+
if self.array[j].height > self.array[j + 1].height:
29+
self.swap_rects(self.array[j], self.array[j + 1])
30+
self.array[j], self.array[j + 1] = self.array[j + 1], self.array[j]
31+
32+
33+
if __name__ == '__main__':
34+
test_gui = gui.GUI()
35+
36+
test_gui.add_sort('Bubble', algs.BubbleSort)
37+
test_gui.add_sort('Merge', algs.MergeSort)
38+
test_gui.add_sort('Radix', algs.RadixSort)
39+
test_gui.add_sort('Gnome', algs.GnomeSort)
40+
test_gui.add_sort('Quick', algs.QuickSort)
41+
test_gui.add_sort('Test', TestBubbleSort)
42+
43+
test_gui.run()

0 commit comments

Comments
 (0)