Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port to python3 #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Timeline
A tool for creating SVG timelines from JSON.

### Prerequisites

Install tkinter and required packages using:

```shell
$ sudo apt install python3-tk
$ sudo apt install -r requirements.txt
```

### Example

You will be able to create timelines that look like this:
Expand Down
16 changes: 8 additions & 8 deletions make_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import json
import os.path
import sys
import tkFont
import Tkinter
import tkinter
import tkinter.font as TkFont

class Colors:
black = '#000000'
Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(self, filename):
self.tick_format = self.data.get('tick_format', None)
self.markers = {}
# initialize Tk so that font metrics will work
self.tk_root = Tkinter.Tk()
self.tk_root = tkinter.Tk()
self.fonts = {}
# max_label_height stores the max height of all axis labels
# and is used in the final height computation in build(self)
Expand Down Expand Up @@ -232,24 +232,24 @@ def get_text_metrics(self, family, size, text):
if key in self.fonts:
font = self.fonts[key]
else:
font = tkFont.Font(family=family, size=size)
font = TkFont.Font(family=family, size=size)
self.fonts[key] = font
assert font is not None
w, h = (font.measure(text), font.metrics("linespace"))
return w, h

def usage():
print 'Usage: ./make_timeline.py in.json > out.svg'
print('Usage: ./make_timeline.py in.json > out.svg')
sys.exit(-1)

if __name__ == '__main__':
if len(sys.argv) < 2:
print 'missing input filename'
print('missing input filename')
usage()
filename = sys.argv[1]
if not os.path.isfile(filename):
print 'file %s not found' % filename
print('file %s not found' % filename)
sys.exit(-1)
timeline = Timeline(filename)
timeline.build()
print timeline.to_string().encode('utf-8')
print(timeline.to_string().encode('utf-8'))
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# run `sudo apt install python3-tk` if required
parsedatetime
svgwrite
tk-tools