Advertisement
barrowman

web11.py

Oct 5th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from Tkinter import *
  4. import string
  5. import getpass
  6. from functools import partial
  7. import time
  8. import os
  9. import urllib2
  10.  
  11. root = Tk()
  12.  
  13. #Set up variables
  14. t = time.localtime()
  15. theday = t.tm_wday
  16.  
  17. col1='#ccffff'
  18. col2='#ffffff'
  19. col3='#ffffcc'
  20.  
  21. sn = 0
  22. s = 0
  23.  
  24. dow = '0'
  25. callit = ['1','2','a.delete(0, END)', 'a.insert(0, 0)', 'b.delete(0, END)', 'b.insert(0, 0)','c.delete(0, END)', 'c.insert(0, 0)', 'u=int(a.get]', 'u=int(b.get)', 'u=int(c.get)']
  26. playit = ['a', 'q = a.get()', 'q = b.get()', 'q = c.get()']
  27. A = StringVar()
  28. B = StringVar()
  29. C = StringVar()
  30.  
  31. cmda = lambda : play_songs(1)
  32. cmdb = lambda : play_songs(2)
  33. cmdc = lambda : play_songs(3)
  34.  
  35. songlist = []
  36. song_count = 0
  37. maxsong = 0
  38. ######v="No Song\n chosen"
  39.  
  40. msg2 = ' '
  41. msg3 = 'Click here to update songs if needed'
  42. msg4 = 'Broadcasting\n and jw.org'
  43.  
  44. msg7 = '___________________________'
  45. myname = getpass.getuser()
  46. myname = "/home/" + myname
  47. mysongs = myname + "/songbook/"
  48. mystart = myname + "/my-startups"
  49. addin="0"
  50. tot=str(t.tm_year)
  51. if(t.tm_mon < 10):
  52. tot=tot + addin
  53. tot=tot + str(t.tm_mon)
  54. mydays = t.tm_mday - t.tm_wday
  55. if(mydays < 10):
  56. tot=tot + addin
  57. tot = tot + str(mydays)
  58. # ++ str(t.tm_mday - t.tm_wday) # + 4)
  59. saved = str(tot)
  60.  
  61. fileget = "http://www.nelliott.co.uk/linux/" + saved
  62.  
  63. os.chdir(mystart)
  64. myday = urllib2.urlopen(fileget)
  65. output = open(tot,'wb')
  66. output.write(myday.read())
  67. output.close()
  68. with open (saved, "r") as myfile:
  69. data=myfile.readline()
  70. myfile.close()
  71.  
  72. #Launching Firefox to display TV.JW.ORG and JW.ORG websites
  73. def showtv():
  74. label6.configure(text = ' ')
  75. label6.update_idletasks()
  76. fire="/usr/bin/firefox -P kingdom-hall"
  77. # Try the one below if using external monitor
  78. # fire="Display=:0.1 /usr/bin/firefox -P kingdom-hall"
  79. retvalue = os.system(fire)
  80. # time.sleep(5)
  81. # offon="/usr/bin/xrandr --output HDMI1 --auto"
  82.  
  83. #This needs re-writing to do it within python so is currently disabled
  84. def get_songs():
  85. label6.configure(text = 'Please wait\nupdating songbook')
  86. label6.update_idletasks()
  87. os.system('/home/norman/my-startups/grabsongs')
  88. label6.configure(text = 'Okay done')
  89.  
  90.  
  91. #Closes program
  92. def cmd1():
  93. root.quit()
  94.  
  95. def cmd2():
  96. label6.configure(text = ' ')
  97. global sn
  98. global s
  99. global v
  100. s = s*10
  101. label2.configure(text = '\n' + str(s), bg=col3) #'\n' + str(s) + '\n', bg=col3)
  102.  
  103. def play_songs(z):
  104. song = "0"
  105. me = int(z)*2
  106. you = me/2
  107. exec playit[you]
  108. u = int(q)
  109. if(u > 0):
  110. if(u <= maxsong):
  111. song ="vlc " + mysongs + songlist[u - 1] + " vlc://quit"
  112. print song
  113. exec callit[me]
  114. exec callit[me + 1]
  115.  
  116. # if ( z == 2):
  117. # b.delete(0, END)
  118. # b.insert(0, 0)
  119. # if ( z == 3):
  120. # c.delete(0, END)
  121. # c.insert(0, 0)
  122. retvalue = os.system(song)
  123.  
  124.  
  125.  
  126. #Open songs.txt which contains the list of song numbers
  127. myfile = myname + "/songbook/songs.txt"
  128. with open(myfile) as the_songs:
  129. for line in the_songs:
  130. lines=line.strip()
  131. songlist.append(lines)
  132. song_count += 1
  133. maxsong= song_count
  134. msg1=" Highest available song\n number is " + str(song_count)
  135.  
  136.  
  137. Button(root, text= msg4, font=("Helvetica", 14), command=showtv).grid(row=19, column=2, columnspan = 2, pady=10)
  138.  
  139. Button(root, text='Exit', font=("Helvetica", 16), command=root.quit).grid(row = 20, column=2, columnspan = 2, padx=20, pady = 14)
  140.  
  141.  
  142.  
  143. a = Entry(root, width = 4, textvariable=A, font=("Helvetica", 16))
  144. a.grid(row=10, column=2)
  145. a.delete(0, END)
  146. G = Button(root, text="Play", width=4, font=("Helvetica", 16), command=cmda).grid(row=10, column=3)
  147.  
  148. b = Entry(root, width = 4, textvariable=B, font=("Helvetica", 16))
  149. b.grid(row=11, column=2)
  150. b.delete(0, END)
  151. H = Button(root, text="Play", width=4, font=("Helvetica", 16), command=cmdb).grid(row=11, column=3)
  152.  
  153. c = Entry(root, width = 4, textvariable=C, font=("Helvetica", 16))
  154. c.grid(row=12, column=2)
  155. c.delete(0, END)
  156. I = Button(root, text="Play", width=4, font=("Helvetica", 16), command=cmdc).grid(row=12, column=3)
  157.  
  158. #Set up labels with the correct songs
  159. if(theday < 5):
  160. a.insert(0, data[0:3])
  161. b.insert(0, data[3:6])
  162. c.insert(0, data[6:9])
  163. msg5 = "Songs for Thursday"
  164.  
  165. else:
  166. a.insert(0, data[9:12])
  167. b.insert(0,data[12:15])
  168. c.insert(0,data[15:18])
  169. msg5 = " Songs for Sunday"
  170.  
  171. label1 = Label(root, text=' ', width = 10)
  172. label1.grid(row = 8, column = 0)
  173.  
  174. label2 =Label(root, text=msg1, width=20, font=("Helvetica", 14))
  175. label2.grid(row = 17, column = 2, columnspan=2, pady = 10)
  176.  
  177.  
  178. label3 = Label(root, text=msg2, width = 20)
  179. label3.grid(row = 8, column = 5)
  180.  
  181. label4 = Label(root, text=msg5, font=("Helvetica", 12))
  182. label4.grid(row = 9, column = 2, columnspan=2)
  183.  
  184. label5 = Label(root, text=msg7,font=("Helvetica", 12))
  185. label5.grid(row = 18, column = 1, columnspan=4)
  186.  
  187. label6 = Label(root, text=msg2, width = 20)
  188. label6.grid(row = 8, column = 5)
  189.  
  190.  
  191. root.geometry("420x420+100+300") # width, height, x position (from left), y position (from top)
  192. root.title("Kingdom Hall software")
  193. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement