main.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.uix.boxlayout import BoxLayout
  4. from kivy.properties import StringProperty
  5. from kivy.uix.button import Button
  6. from kivy.uix.textinput import TextInput
  7. from kivy.clock import mainthread
  8. from kivy.core.clipboard import Clipboard as Cb
  9. import threading
  10. import socket
  11. KV = """
  12. MyBL:
  13. orientation: "vertical"
  14. size_hint: (0.95, 0.95)
  15. pos_hint: {"center_x": 0.5, "center_y":0.5}
  16. Label:
  17. font_size: "15sp"
  18. multiline: True
  19. text_size: self.width*0.98, None
  20. size_hint_x: 1.0
  21. size_hint_y: None
  22. height: self.texture_size[1] + 15
  23. text: root.data_label
  24. markup: True
  25. on_ref_press: root.linki()
  26. TextInput:
  27. id: Inp
  28. multiline: False
  29. padding_y: (5,5)
  30. size_hint: (1, 0.5)
  31. on_text: app.process()
  32. Button:
  33. text: "Поиск по названию"
  34. bold: True
  35. background_color:'#00FFCE'
  36. size_hint: (1,0.5)
  37. on_press: root.callback()
  38. Button:
  39. text: "Поиск по описанию"
  40. bold: True
  41. background_color:'#00FFCE'
  42. size_hint: (1,0.5)
  43. on_press: root.callback2()
  44. Button:
  45. text: "Случайный"
  46. bold: True
  47. background_color:'#00FFCE'
  48. size_hint: (1,0.5)
  49. on_press: root.callback3()
  50. Button:
  51. text: "Отправить"
  52. bold: True
  53. background_color:'#00FFCE'
  54. size_hint: (1,0.5)
  55. on_press: root.callback4()
  56. """
  57. class MyBL(BoxLayout):
  58. data_label = StringProperty("Треугольник!")
  59. def __init__(self, **kwargs):
  60. super().__init__(**kwargs)
  61. SERVER = "10.8.0.6"
  62. PORT = 1488
  63. self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  64. self.client.connect((SERVER, PORT))
  65. self.client.sendall(bytes("979879789",'UTF-8'))
  66. threading.Thread(target=self.get_data).start()
  67. def callback(self):
  68. print("Поиск по названию")
  69. self.client.sendall(bytes("Поиск по названию",'UTF-8'))
  70. def callback2(self):
  71. print("Поиск по описанию")
  72. self.client.sendall(bytes("Поиск по описанию",'UTF-8'))
  73. def callback3(self):
  74. print("Случайный")
  75. self.client.sendall(bytes("Случайный",'UTF-8'))
  76. def callback4(self):
  77. print("Отправить")
  78. self.client.sendall(bytes(self.ids.Inp.text,'UTF-8'))
  79. def get_data(self):
  80. while App.get_running_app().running:
  81. in_data = self.client.recv(4096)
  82. print("От сервера :" ,in_data.decode())
  83. kkk = in_data.decode()
  84. zzz = str(kkk)
  85. lines = zzz.split('\n')
  86. print(lines)
  87. if '\t\t\t\t\t' in lines:
  88. lines[4] = "==========="
  89. for ggg in lines:
  90. if ggg.startswith("https://"):
  91. self.ttt = ggg
  92. ggg = '[ref=linki][color=#00FFCE]' + ggg + '[/color][/ref]'
  93. self.set_data_label(ggg)
  94. def linki(self):
  95. print("В буффер")
  96. Cb.copy(self.ttt)
  97. @mainthread
  98. def set_data_label(self, data):
  99. self.data_label += str(data) + "\n"
  100. class MyApp(App):
  101. running = True
  102. def process(self):
  103. text = self.root.ids.Inp.text
  104. def build(self):
  105. return Builder.load_string(KV)
  106. def on_stop(self):
  107. self.running = False
  108. MyApp().run()