Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # This file needs to be rewritten!
  4.  
  5. from os import system
  6. import curses
  7. import re
  8.  
  9.  
  10. def chatWindows(screen,users,emails,window,user_input):
  11. screen.clear()
  12. screen.box()
  13. offset = 0
  14. offset2 = 0
  15. if window[0]:
  16. offset = 16
  17. if window[1]:
  18. offset2 = 32-offset
  19.  
  20. user_size = screen.getmaxyx()
  21. window_size_y,window_size_x = screen.getmaxyx()
  22.  
  23. if window_size_x>38+offset+offset2 and window_size_y>7:
  24. # If window is toggled
  25. if window[0]:
  26. win1 = screen.subwin(window_size_y, 17, 0, 0)
  27. win1.box()
  28. i = 1;
  29. longestOffset = len(str(len(users)))
  30. for user in users:
  31. if window_size_y-1>i:
  32. numberOffset = longestOffset-len(str(i))
  33. win1.addstr(i,1,"%s %s" % (numberOffset*" "+str(i),user[0:14-longestOffset]))
  34. i += 1
  35. win1.refresh()
  36.  
  37. # If window is toggled
  38. if window[1]:
  39. win2 = screen.subwin(window_size_y,33-offset,0,window_size_x-33+offset)
  40. win2.box()
  41. i = 1
  42. for email in emails:
  43. if window_size_y-1>i:
  44. win2.addstr(i,1,"%s" % email[0:31-offset])
  45. i += 1
  46.  
  47. win2.refresh()
  48.  
  49. # Using offsets to create the new sub window.
  50. space_left = window_size_x-offset2-offset
  51. winMessages = screen.subwin(window_size_y,space_left,0,offset)
  52. i = window_size_y-2
  53. for data in reversed(user_input):
  54. if 1<i:
  55. # length of timestap and nick; +4 = 3 spaces and one ":"
  56. startMessageAt = len(data[1])+len(data[0])+4
  57. # tricky part is to get message dynamic with window!
  58. text_space = space_left-startMessageAt-1
  59. text = []
  60. string = ""
  61. for word in data[2].split(" "):
  62. if len(word)>text_space:
  63. while(len(word)>text_space):
  64. text.append(word[0:text_space+1])
  65. word = word[text_space:]
  66. if len(string+word)>text_space:
  67. text.append(string)
  68. string = ""
  69. string = string+word+" "
  70.  
  71. text.append(string)
  72. x = len(text)
  73. if 0<i-x+1:
  74. winMessages.addstr(i-x+1,1,data[0])
  75. winMessages.addstr(i-x+1,len(data[0])+2,data[1]+":")
  76. for line in text:
  77. winMessages.addstr(i-x+1,startMessageAt,line[0:-1])
  78. x -= 1
  79.  
  80. i -= len(text)
  81. # end of tricky part
  82.  
  83.  
  84. elif window_size_x>14 and window_size_y>3:
  85. screen.addstr(0,0,"Screen to small")
  86. screens = ""
  87. if window[0]:
  88. screens += " 1"
  89. if window[1]:
  90. screens += " 2"
  91. screen.addstr(1,0,"Enabled screens:%s" % screens)
Add Comment
Please, Sign In to add comment