Guest User

Untitled

a guest
Apr 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import curses
  4. import traceback
  5. import time
  6.  
  7. DIGIT_WIDTH = 5
  8. DIGIT_HEIGHT = 5
  9. DIGIT_SPACING = 2
  10. POINT_SPACING = 0
  11. POINT_WIDTH = 5
  12.  
  13. '''
  14. _0_0_._0_0_0_
  15. '''
  16.  
  17. width = 5*DIGIT_SPACING + 5*DIGIT_WIDTH + 2*POINT_SPACING + POINT_WIDTH
  18. height = 2*DIGIT_SPACING + DIGIT_HEIGHT
  19.  
  20.  
  21. # numbers, list of coords in (y,x)
  22.  
  23. digits = [
  24. [
  25. "#####",
  26. "# #",
  27. "# #",
  28. "# #",
  29. "#####"
  30. ],
  31. [
  32. " #",
  33. " ##",
  34. " #",
  35. " #",
  36. " ###",
  37. ],
  38. [
  39. "#####",
  40. " #",
  41. "#####",
  42. "#",
  43. "#####",
  44. ],
  45. [
  46. "#####",
  47. " #",
  48. " ####",
  49. " #",
  50. "#####",
  51. ],
  52. [
  53. "# #",
  54. "# #",
  55. "#####",
  56. " #",
  57. " #",
  58. ],
  59. [
  60. "#####",
  61. "#",
  62. "#####",
  63. " #",
  64. "#####",
  65. ],
  66. [
  67. "#####",
  68. "#",
  69. "#####",
  70. "# #",
  71. "#####",
  72. ],
  73. [
  74. "#####",
  75. " #",
  76. " #",
  77. " #",
  78. " #",
  79. ],
  80. [
  81. "#####",
  82. "# #",
  83. "#####",
  84. "# #",
  85. "#####",
  86. ],
  87. [
  88. "#####",
  89. "# #",
  90. "#####",
  91. " #",
  92. " #",
  93. ],
  94. [
  95. "",
  96. "",
  97. "",
  98. " ###",
  99. " ###",
  100. ],
  101. ]
  102.  
  103. def draw_digit(win, digit, y, x):
  104. sections = digits[digit]
  105. position = 0
  106. for section in sections:
  107. win.addstr(position+y, x, section)
  108. position += 1
  109.  
  110. def draw_time(win, digits):
  111. x_pos = DIGIT_SPACING
  112. y_pos = 1
  113. digits.insert(2, 10) #add in the point
  114. for d in digits:
  115. draw_digit(win, d, y_pos, x_pos)
  116. x_pos += (DIGIT_SPACING + DIGIT_WIDTH)
  117.  
  118. def tick(win):
  119. tm = time.localtime()
  120. t = ks = tm.tm_hour*3600 + tm.tm_min*60 + tm.tm_sec
  121. a = ks/10000; ks -= a*10000
  122. b = ks/1000; ks -= b*1000
  123. c = ks/100; ks -= c*100
  124. d = ks/10; ks -= d*10
  125. e = ks
  126. draw_time(win, [a,b,c,d,e])
  127. return t
  128.  
  129. def main(screen):
  130. draw_time(screen, [0,1,2,1,2])
  131. t = None
  132. screen.hline(0,0,curses.ACS_BULLET, width)
  133. while True:
  134. screen.clear()
  135. newtime = tick(screen)
  136. if t != newtime:
  137. screen.refresh()
  138. t = newtime
  139. time.sleep(0.5)
  140.  
  141. if __name__ == '__main__':
  142. curses.wrapper(main)
Add Comment
Please, Sign In to add comment