Skip to content

Commit

Permalink
add dayOfWk and fix Text(
Browse files Browse the repository at this point in the history
  • Loading branch information
TabulateJarl8 committed May 18, 2021
1 parent 940571c commit 35cbda7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ti842py/__version__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__title__ = "ti842py"
__description__ = "TI-BASIC to Python 3 Transpiler"
__url__ = "https://github.com/TabulateJarl8/ti842py"
__version__ = "0.4.5"
__version__ = "0.4.6"
__author__ = "Tabulate"
__author_email__ = "[email protected]"
__license__ = "GPLv3"
Expand Down
2 changes: 2 additions & 0 deletions ti842py/tiParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ def convertLine(self, index, line):
statement = re.sub(r'(?!\B"[^"]*)rand(?!\(|I|o)+(?![^"]*"\B)', "random.random()", statement)
statement = re.sub(r'(?!\B"[^"]*)rand\(([0-9])\)(?![^"]*"\B)', r'[random.random() for _ in range(\1)]', statement)
self.UTILS['random']['enabled'] = True
if 'dayOfWk(' in statement:
self.UTILS['getDateTime']['enabled'] = True

if 'randInt(' in statement:
# Replace randInt with random.randint
Expand Down
26 changes: 24 additions & 2 deletions ti842py/utils/draw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from graphics import *
import time
import tkinter.font as tkfont


class Draw:
Expand All @@ -8,6 +9,7 @@ def __init__(self):
self.winOpen = False
self.pixels = {}
self.points = {}
self.texts = {}
self.colors = {'BLUE': 'blue', 'RED': 'red', 'BLACK': 'black', 'MAGENTA': 'magenta', 'GREEN': 'green', 'ORANGE': 'orange', 'BROWN': 'brown', 'NAVY': 'navy', 'LTBLUE': 'light sky blue', 'YELLOW': 'yellow', 'WHITE': 'white', 'LTGRAY': 'light gray', 'MEDGRAY': 'dark gray', 'GRAY': 'gray', 'DARKGRAY': 'dark slate gray'}
self.colorNumbers = {'10': 'blue', '11': 'red', '12': 'black', '13': 'magenta', '14': 'green', '15': 'orange', '16': 'brown', '17': 'navy', '18': 'light sky blue', '19': 'yellow', '20': 'white', '0': 'white', '21': 'light gray', '22': 'dark gray', '23': 'gray', '24': 'dark slate gray'}
for _ in range(1, 10):
Expand Down Expand Up @@ -88,11 +90,31 @@ def textColor(self, color):

@_slow
def text(self, row, column, *args):
# TODO: Set font size and use row/column instead of x and y
text = ''.join(args)
# column = x, row = y
text = ''.join([str(arg) for arg in args])
fontsize = 7

# Calculate correct center value based on text width
font = tkfont.Font(family='helvetica', size=fontsize, weight='normal')
text_width = font.measure(text) // 2
text_height = font.metrics('linespace') // 2
column += text_width
row += text_height

# Undraw previous text
# TODO: draw background behind it instead, maybe
if str(column) in self.texts:
if str(row) in self.texts[str(column)]:
self.texts[str(column)][str(row)].undraw()
del self.texts[str(column)][str(row)]

message = Text(Point(column, row), text.upper())
message.setTextColor(self.currentTextColor)
message.setSize(fontsize)
message.draw(self.win)
if str(row) not in self.texts:
self.texts[str(column)] = {}
self.texts[str(column)][str(row)] = message

@_slow
def pxlOn(self, row, column, color='blue'):
Expand Down
5 changes: 5 additions & 0 deletions ti842py/utils/getDateTime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ def getTime():
def getDate():
now = datetime.now()
return [now.year, now.month, now.day]


def dayOfWk(year, month, day):
dt = datetime.strptime('{year}-{month:02d}-{day:02d}'.format(year=year, month=month, day=day), '%Y-%m-%d')
return int(dt.strftime('%w')) + 1 # sunday would be zero, so shift everything up by 1 so that sunday is 1

0 comments on commit 35cbda7

Please sign in to comment.