Skip to content

Commit

Permalink
color (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: msk <54884351+minsangkim89@users.noreply.github.com>
  • Loading branch information
kinetic-flow and kinetic-flow authored Mar 8, 2020
1 parent b4ccd5b commit 9330aaf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ def parse_args():
type=int,
default=24,
help="Desired font size for the wall clock and the stop watch")
parser.add_argument(
"--color",
type=str,
default="0xff0000",
help="Desired color (e.g., 0x00ff00 for green), or 'rgb'")
args = parser.parse_args()
return args
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# colors

BLACK = (0, 0, 0)
GRAY = (20, 10, 10)
GRAY = (20, 20, 20)
RED = (255, 0, 0)

# default colors
Expand Down
23 changes: 20 additions & 3 deletions ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ def get_width_and_height(arg_width, arg_height):

return (width, height)

def generate_color(option):
if option == "rgb":
rgb = pygame.Color(*RED)
while True:
hue = rgb.hsva[0]
hue = (hue + 2) % 360
rgb.hsva = (hue, *rgb.hsva[1:])
yield rgb
else:
fixed_color = pygame.Color(option)
while True:
yield fixed_color

def main():
args = config.parse_args()

Expand Down Expand Up @@ -62,13 +75,16 @@ def main():
else:
stopwatch = None

# multiprocessing
q = Queue(maxsize=2)
p = Process(
target=spiceclient.spice_client,
args=(q, args.host, args.port, args.password))
p.start()

# ticker stuff
last_ticker_text = CONNECTING_TEXT
color_generator = generate_color(args.color)
while True:
# Check for pygame events
for event in pygame.event.get():
Expand Down Expand Up @@ -103,11 +119,12 @@ def main():

# Render
surface.fill(COLOR_BACKGROUND)
ticker.render(ticker_text)
color = next(color_generator)
ticker.render(ticker_text, color)
if wallclock:
wallclock.render()
wallclock.render(color)
if stopwatch:
stopwatch.render()
stopwatch.render(color)
pygame.display.flip()
clock.tick(8)
pass
Expand Down
12 changes: 6 additions & 6 deletions widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def on_resize(self, new_surface):
self.surface = new_surface
self.__update_font()

def render(self, ticker_text):
def render(self, ticker_text, color):
self.__render_text(ALL_ON_CHAR * self.LENGTH, COLOR_TEXT_OFF)
self.__render_text(ticker_text, COLOR_TEXT_ON)
self.__render_text(ticker_text, color)

def __render_text(self, text, color):
text = self.font.render(text, True, color)
Expand Down Expand Up @@ -64,15 +64,15 @@ def on_resize(self, new_surface):
self.surface = new_surface
self.__update_font()

def render(self):
def render(self, color):
self.__render_text(self.DEFAULT_TEXT, COLOR_TEXT_OFF)
now = datetime.now()
if (now.microsecond < (500000)) == 0:
separator = ":"
else:
separator = " "
ticker_text = now.strftime("%I" + separator + "%M")
self.__render_text(ticker_text, COLOR_TEXT_ON)
self.__render_text(ticker_text, color)

def __render_text(self, text, color):
text = self.font.render(text, True, color)
Expand Down Expand Up @@ -101,15 +101,15 @@ def on_resize(self, new_surface):
self.surface = new_surface
self.__update_font()

def render(self):
def render(self, color):
self.__render_text(self.DEFAULT_TEXT, COLOR_TEXT_OFF)
time_diff = datetime.now() - self.start_time
# time_diff += timedelta(hours=9, minutes=59, seconds=50)
seconds = time_diff.seconds % 60
minutes = (time_diff.seconds // 60) % 60
hours = (time_diff.seconds // 60 // 60) % 10
ticker_text = f"{hours:01}:{minutes:02}:{seconds:02}"
self.__render_text(ticker_text, COLOR_TEXT_ON)
self.__render_text(ticker_text, color)

def __render_text(self, text, color):
text = self.font.render(text, True, color)
Expand Down

0 comments on commit 9330aaf

Please sign in to comment.