Пост #126295

     
сохранен 21.08.2019 16:34
  • Редактировать пост
  • Печать
  • Скачать
  • Сравнить с постом
    #  
  • Нумерация строк
  • Подсветка синтаксиса  
Текст поста
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#-*- coding: UTF-8 -*-
from browser import window, timer, document, ajax, alert, html
import json
from browser.template import Template  
import browser
import ui
from io import StringIO
parser = window.DOMParser.new()
menu_port = {'home': "Главная",'overlays':"Оверлеи", 'doc': 'Документации', 'portage_settngs':"Настройка portage",'app_st':"Настройка",'status':"Процесс"}
catalog = ["Аудио и Видео", "Графика", "Интернет", "Игры", "Программирование", "Система" ]
overlay_cell = ["Имя", "Описание","Домашняя страничка", "Email", "Исходники"]

version = "web_port - 00.0.025"
#document['v'].bind('click', view_row)
# Temlate Menu
Template(document["link_panel"]).render(menu_port=menu_port)
#Template(document["nav_memu"]).render(catalog=catalog)
# location

#document['btnSclose'].bind('click', view_search)

def view_catalog():
  pass

class App():
  """docstring for App"""
  def __init__(self):
    self.data =""
    self.widget_tables = ["Новости", "Рекомендации", "Документация"]
    self.istall_apps = []
    self.req_istall_pkg()
    self.portList = []
    self.Req_portage_dump()

    #super(App, self).__init__()

  def get_portage_dump(self, req):
    if req.status == 200:
      d_list =[]
      d_list = json.loads(req.responseText)

      self.portList = d_list['dump_portage']
    elif req.status == 404:
      alert('Путь не найден')
    elif req.status == 403:
      alert("Доступ запрещён")

  def Req_portage_dump(self):
    req = ajax.ajax()
    req.open('GET', '/get_dump_list', True)
    req.bind('complete', self.get_portage_dump)
    req.send()

  def p_install_list(self, req):
    if req.status == 200:
      plist = json.loads(req.responseText)['install_pkgs']
      self.install_apps = plist
      #alert(self.install_apps)
    elif req.status == 404:
      alert('Путь не найден')
    elif req.status == 403:
      alert("Доступ запрещён")
      
    return plist

  def req_istall_pkg(self):
    req = ajax.ajax()
    req.open('GET', '/get_inastal_list', True)
    req.bind('complete', self.p_install_list)
    req.send()

  def clear_el(self):
    try:
      document["conteiner"].clear('container')
      print("clear_el")
    except KeyError:
      print("KeyError in clear_el")

  def loading(self):
    if document['splash'].style.display == "none":
      document['splash'].style.display = "block"
    else:
      document['splash'].style.display = 'none'

  def add_evenet(self, element):
    pass
  
  def main_bind(self, ev):
    alert(ev.currentTarget.id)

  def main(self, req):
    #alert(str(req.responseText))
    document["conteiner"] <= ui.v_main(req.responseText, self.widget_tables)

  def m_req(self):
    req = ajax.ajax()
    req.open('GET', "/main", True)
    req.bind('complete', self.main)
    req.send()

  def show_result(self, req):
    if req.status == 200:
      alert("Конфигурация прянята и вступит в силу после перезагрузки приложения")
    elif req.status == 403:
      alert("Доступ запрещен")

  def app_save(self,  event):
    port = document['Sv_port'].value
    req = ajax.ajax()
    req.open("GET", "?st_app=" +'port='+str(port) + ",Lang=" + "ru", True)
    req.bind('complete', self.show_result)
    req.send()

  def app_settings(self, req):
    #location ="/app_st"
    
    document["conteiner"] <= ui.v_app_settings(json.loads(req.responseText))
    document['App_save'].bind('click', self.app_save)

  def get_sett(self):
    req = ajax.ajax()
    req.open("GET", "/get_seiings_app", True)
    req.bind('complete', self.app_settings)
    req.send()

  def view_pkg(self, pkgname):
    document['dashbboard'] <= ui.dashbord_view(pkgname,  self.data, self.install_apps)
    document[str(i["Name"]) + "_btn"].bind('click', self.install_config)

  def info_pkg(self, ev):
    #try:
    #  alert("click on %s" %ev.currentTarget.id)
    #except Exception as e:
    #  alert(str(e))
    pkg = str(ev.currentTarget.id)
    alert(pkg)
    document['dashbboard'].clear('card')
    self.view_pkg(pkg)

  def find_bind(self, p_list):    
    #req):  
    #if req.status == 200 or req.status == 0:
      #alert(req.responseText)
    pl = json.loads(p_list)
    self.data = pl
    widget= html.DIV(id="container", Class="")
    w_H = html.HEADER(Class="toolbar toolbar-header")
    w_H <= html.H1("Поиск", Class="title")
    widget <= w_H
    container = html.DIV(Class="window-content")
    widget <= container

    pkg_list = []
    if pl["Package_result"] == 0:
      pass
    else:
      c = html.OL(id="list_p", Class="list-group")
      c.style.width ='100vw'
      d = html.DIV(id="dashbboard")
      c <= html.STRONG("Найдено совпадений:\t" + str(len(pl["Package_result"])))
      c <= html.HR()
      container <= c
      container <= d
        #dashbboard = html.DIV(id ="dashbboard", Class="window-content dashbboard")
        #container <= dashbboard
        #card =  html.DIV(id="card", Class="card")
        #dashbboard <= card 
      #n = 0
      
      
      for i in pl["Package_result"]: 
        #n = n +1
        item = html.P(i)
        #item =  html.LI(id=i, Class="list-group-item")
        #item <= html.A(i)
        #item = html.LI( id=i["Name"], Class="list-group-item")
        #item <= html.A(i["Name"])    
        c <= item
    
    document["conteiner"] <= widget
    for i in pl['Package_result']: 
      try:
        #document[i["Name"]].bind("click", self.info_pkg)
        #document[i].bind("click", self.info_pkg)
        pass

      except KeyError:
        print("KeyError в доб.поиск")

      self.view_pkg(pl['Package_result'][0])
    self.loading()

  def find_pkg(self, req):
    p = []
    self.loading()
    self.clear_el()
    
    for i in self.portList:
      if document["inS"].value in i and not i in p:
        p.append(str(i))
        #json.dumps({"Package_result": pk})
    self.find_bind(str(json.dumps({"Package_result": p})))
    

    """
    req = ajax.ajax()
    if document["inS"].value !='':
      self.loading()
      pm = document["inS"].value
      req.open('GET', '/?p=' + pm,True)
      location ='/?p=' + pm
      req.bind('complete', self.find_bind)
      req.send()
      
    else:
        alert("Name package is Null")
    """
    #self.clear_el()

  
  def view_st_portage(self):
    
    document["conteiner"] <= ui.st_portage()

  def view_overlays(self, req):
    #alert(req.responseText)
    try:
       overlays = json.loads(req.responseText)
    except SyntaxError:
      alert("Синтаксическая ошибка")

    document['container'] <= ui.overlays(overlays)
    self.loading()
  
  def get_overlays(self):
    self.loading()
    self.clear_el()
    document['conteiner'] <= html.DIV(id="container")

    req = ajax.ajax()
    req.open('GET', "/ovelays", True)
    location = "/ovelays"
    req.bind('complete', self.view_overlays)
    req.send()
  #document['all'].bind('click', all_pkgs)

  #get_overlays()
  def install_config(self, ev):
    alert(str(ev.currentTarget.id))

# End  Class App

location = '/'
def check_location():
  pass
# change  themes
def set_theme(req):
  pass

def get_theme(theme):
  req = ajax.ajax()
  name = theme + '.css'
  req.open('GET', '/static/css/' + name, True)
  req.bind('complete', set_theme)
  red.send()

app = App()

def view_console(event):
  alert(app.portList)

# All BINDS
 
def h():
  app.m_req()

def app_s():
  app.get_sett()

def v_overlays():
  app.get_overlays()

def  v_portge_st():
  app.view_st_portage()

def onKDown(event):
  if event.keyCode == 13:
    document['submit_search'].click()

document["overlays"].bind('click', v_overlays)
document["submit_search"].bind('click', app.find_pkg)
document['inS'].bind("keypress", onKDown)
document["app_st"].bind('click', app_s)
document["portage_settngs"].bind('click',  v_portge_st)
document["home"].bind('click', h)

document["debug"].bind("click", view_console)
if  __name__  ==  '__main__':
  app.m_req()
Добавить комментарий
Автор