Skip to content

Commit

Permalink
Refactor (#1)
Browse files Browse the repository at this point in the history
* new files

* new files

Co-authored-by: msk <54884351+minsangkim89@users.noreply.github.com>
  • Loading branch information
kinetic-flow and kinetic-flow authored Mar 8, 2020
1 parent 9e92ac0 commit b4ccd5b
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 290 deletions.
54 changes: 54 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

import argparse

def parse_args():
parser = argparse.ArgumentParser(description="IIDXSEG")
parser.add_argument("host", type=str)
parser.add_argument("port", type=int)
parser.add_argument("password", type=str)
parser.add_argument(
"--width",
type=int,
help="Width of the window")
parser.add_argument(
"--height",
type=int,
help="Height of the window")
parser.add_argument(
"--borderless",
action="store_true",
help="Remove window border and title bar")
parser.add_argument(
"--x",
type=int,
help="Desired x-coordinate for the window position")
parser.add_argument(
"--y",
type=int,
help="Desired y-coordinate for the window position")
parser.add_argument(
"--font_size",
type=int,
default=0,
help="Preferred font size for the ticker. When omitted, the ticker will fill the window")
parser.add_argument(
"--offset",
type=int,
default=0,
help="Desired y-offset in pixels to shift the ticker up (negative) or down (positive)")
parser.add_argument(
"--clock",
action="store_true",
help="Show the wall clock")
parser.add_argument(
"--timer",
action="store_true",
help="Show the stop watch")
parser.add_argument(
"--time_font_size",
type=int,
default=24,
help="Desired font size for the wall clock and the stop watch")
args = parser.parse_args()
return args
35 changes: 35 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

import os
import sys

DEBUG = False

DEFAULT_WIDTH = 520
DEFAULT_ASPECT_RATIO = (52 / 10)

if getattr(sys, 'frozen', False):
CurrentPath = sys._MEIPASS
else:
CurrentPath = os.path.dirname(__file__)
DEFAULT_FONT = os.path.join(CurrentPath, 'DSEG14Classic-Italic.ttf')

CONNECTING_TEXT = "CONNECT.!.!."

# colors

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

# default colors

COLOR_TEXT_ON = RED
COLOR_TEXT_OFF = GRAY
COLOR_BACKGROUND = BLACK

# '!' is all-off character in DSEG14 font
ALL_OFF_CHAR = "!"

# '~' is all-on character in DSEG14 font
ALL_ON_CHAR = "~"
88 changes: 88 additions & 0 deletions spiceclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env python3

import spiceapi
import time
import pygame
from constants import *

def spice_client(q, host, port, password):
con = None
reconnect = False
failed_connection_attempt = 0
clock = pygame.time.Clock()
while True:
ticker_text = CONNECTING_TEXT
if (con is None and
(time.time() - failed_connection_attempt) > 10):

try:
print("connecting ...")
con = spiceapi.Connection(
host=host,
port=port,
password=password)

except:
con = None

if con is None:
failed_connection_attempt = time.time()

if con is not None:
try:
ticker_text = get_ticker(con)
except:
reconnect = True

if reconnect:
try:
reconnect = False
con.reconnect()
except:
pass

try:
q.put(ticker_text)
except:
pass

clock.tick(8)
pass

def get_ticker(con):
text = spiceapi.iidx_ticker_get(con)
return convert_ticker_text(text[0])

def convert_ticker_text(original_text):
text = original_text

if DEBUG:
print_text_in_hex(original_text)

# HT (horizontal tab) is sent after !
text = text.replace(chr(9), " ")
text = text.replace("!", "./")

# lower case m = period
text = text.replace("m", "." + ALL_OFF_CHAR)
text = text.replace("q", "'")
text = text.replace("u", ",")

# Make S look more like IIDX
text = text.replace("S", "5")
# [ ] are not supported
text = text.replace("[", "(")
text = text.replace("]", ")")
text = text.replace("~", "-")

# Lastly, blank space must be replaced by all-off character to keep
# monospace
text = text.replace(" ", ALL_OFF_CHAR)
return text

def print_text_in_hex(text):
print(text)
for c in text:
print(ord(c), end=" ")

print("")
Loading

0 comments on commit b4ccd5b

Please sign in to comment.