Example #1
0
 def cmd_show(self):
     if self.window:
         self.cmd_hide()
     self._current_items = self.items()
     show_lines = min(len(self._current_items) + 1, self.max_lines)
     h = self.theme.menu.line_height
     self.height = h*self.max_lines
     bounds = self.commander['screen'].bounds._replace(height=h)
     self._img = self.xcore.pixbuf(bounds.width, h)
     wid = self.xcore.create_toplevel(bounds,
         klass=self.xcore.WindowClass.InputOutput,
         params={
             self.xcore.CW.BackPixel: self.theme.menu.background,
             self.xcore.CW.OverrideRedirect: True,
             self.xcore.CW.EventMask:
                 self.xcore.EventMask.FocusChange
                 | self.xcore.EventMask.EnterWindow
                 | self.xcore.EventMask.LeaveWindow
                 | self.xcore.EventMask.KeymapState
                 | self.xcore.EventMask.KeyPress,
         })
     self.window = di(self).inject(DisplayWindow(wid, self.draw,
         focus_out=self._close))
     self.dispatcher.all_windows[wid] = self.window
     self.dispatcher.frames[wid] = self.window  # dirty hack
     self.window.show()
     self.window.focus()
     self.text_field = di(self).inject(TextField(self.theme.menu, events={
         'draw': self.redraw,
         'submit': self.submit_ev,
         'complete': self.complete,
         'close': self.close,
         }))
     self.dispatcher.active_field = self.text_field
     self._redraw()
Example #2
0
 def hello(self, conn: web.WebsockCall, sid: str):
     uid = self.redis.execute("GET", 'z:session:' + sid)
     if uid:
         uid = int(uid)
         self.output.set_cookie(conn, 'user:{}'.format(uid))
         user = User(uid)
         di(self).inject(user)
         user.load()
         return {'uid': uid, 'name': user.name}
Example #3
0
 def form_processor(self, resolver, meth, *args, **kw):
     form = form_class(resolver.request.legacy_arguments)
     di(self).inject(form)
     if kw and form.validate():
         try:
             return meth(**form.data)
         except FormError as e:
             getattr(form, e.field).errors.append(e.text)
             return dict(form=form)
     else:
         return dict(form=form)
Example #4
0
 def create_window(self):
     EM = self.xcore.EventMask
     CW = self.xcore.CW
     self.window = DisplayWindow(self.xcore.create_toplevel(self.bounds,
         klass=self.xcore.WindowClass.InputOutput,
         params={
             CW.EventMask: EM.Exposure | EM.SubstructureNotify,
             CW.OverrideRedirect: True,
         }), self.expose)
     self.window.want.size = self.bounds
     di(self).inject(self.window)
     self.dispatcher.register_window(self.window)
     self.window.show()
Example #5
0
 def __zorro_di_done__(self):
     # TODO(tailhook) implement several screens
     for g in self.groups:
         di(self).inject(g)
     self.current_groups = {}
     for i, s in enumerate(self.screenman.screens):
         gr = self.groups[i]
         self.current_groups[s] = gr
         gr.screen = s
         gr.show()
         if i == 0:
             self.commander['group'] = gr
             self.commander['screen'] = s
             self.commander['layout'] = g.current_layout
Example #6
0
 def __zorro_di_done__(self):
     # TODO(tailhook) implement several screens
     for g in self.groups:
         di(self).inject(g)
     self.current_groups = {}
     for i, s in enumerate(self.screenman.screens):
         gr = self.groups[i]
         self.current_groups[s] = gr
         gr.screen = s
         gr.show()
         if i == 0:
             self.commander['group'] = gr
             self.commander['screen'] = s
             self.commander['layout'] = g.current_layout
Example #7
0
 def create_window(self):
     EM = self.xcore.EventMask
     CW = self.xcore.CW
     self.window = DisplayWindow(
         self.xcore.create_toplevel(
             self.bounds,
             klass=self.xcore.WindowClass.InputOutput,
             params={
                 CW.EventMask: EM.Exposure | EM.SubstructureNotify,
                 CW.OverrideRedirect: True,
             }), self.expose)
     self.window.want.size = self.bounds
     di(self).inject(self.window)
     self.dispatcher.register_window(self.window)
     self.window.show()
Example #8
0
 def create_window(self):
     self.window = di(self).inject(ClientMessageWindow(
         self.xcore.create_toplevel(
             Rectangle(0, 0, 1, 1),
             klass=self.xcore.WindowClass.InputOnly,
             params={}),
         self.systray_message))
     self.window.show()
     self.dispatcher.register_window(self.window)
     self.xcore.raw.SetSelectionOwner(
         owner=self.window.wid,
         selection=self.xcore.atom._NET_SYSTEM_TRAY_S0,
         time=0,
         )
     self.xcore.send_event('ClientMessage',
         self.xcore.EventMask.StructureNotify,
         self.xcore.root_window,
         window=self.xcore.root_window,
         type=self.xcore.atom.MANAGER,
         format=32,
         data=struct.pack('<LLL',
             0,
             self.xcore.atom._NET_SYSTEM_TRAY_S0,
             self.window.wid,
             ))
Example #9
0
 def __zorro_di_done__(self):
     self.window = Window(self.xcore.create_toplevel(
         Rectangle(0, 0, 1, 1),
         klass=self.xcore.WindowClass.InputOnly,
         params={}))
     di(self).inject(self.window)
     self.xcore.raw.ChangeProperty(
         window=self.xcore.root_window,
         mode=self.xcore.PropMode.Replace,
         property=self.xcore.atom._NET_SUPPORTING_WM_CHECK,
         type=self.xcore.atom.WINDOW,
         format=32,
         data_len=1,
         data=struct.pack('<L', self.window))
     self.window.set_property('_NET_SUPPORTING_WM_CHECK', self.window)
     self.window.set_property('_NET_WM_NAME', 'tilenol')
Example #10
0
 def __zorro_di_done__(self):
     for s in self.screens.screens:
         bar = di(self).inject(
             LeftBar(s, self.width, self.groups, self.states))
         self.bars[s] = bar
         if s.group.name in self.groups:
             s.slice_left(bar)
Example #11
0
 def _redraw(self):
     if not self.visible:
         return
     gr = self.screen.group
     st = self.states.get(gr)
     if st is None:
         st = self.states[gr] = di(self).inject(State(gr))
     if not st.update() and self._img and self._drawn_group == gr:
         return
     if self._img is None:
         self._img = self.xcore.pixbuf(self.width, self.bounds.height)
         self._cairo = self._img.context()
     theme = self.theme.tabs
     ctx = self._cairo
     ctx.set_source(theme.background_pat)
     ctx.rectangle(0, 0, self._img.width, self._img.height)
     ctx.fill()
     theme.font.apply(ctx)
     y = theme.margin.top
     for sec in st.sections:
         for win in sec:
             if isinstance(win, str):
                 if len(st.sections) > 1:
                     y = self._draw_section(win, y)
             else:
                 y = self._draw_win(win, y)
     self._drawn_group = gr
     self.repaint.emit()
Example #12
0
 def _redraw(self):
     if not self.visible:
         return
     gr = self.screen.group
     st = self.states.get(gr)
     if st is None:
         st = self.states[gr] = di(self).inject(State(gr))
     if not st.update() and self._img and self._drawn_group == gr:
         return
     if self._img is None:
         self._img = self.xcore.pixbuf(self.width, self.bounds.height)
         self._cairo = self._img.context()
     theme = self.theme.tabs
     ctx = self._cairo
     ctx.set_source(theme.background_pat)
     ctx.rectangle(0, 0, self._img.width, self._img.height)
     ctx.fill()
     theme.font.apply(ctx)
     y = theme.margin.top
     for sec in st.sections:
         for win in sec:
             if isinstance(win, str):
                 if len(st.sections) > 1:
                     y = self._draw_section(win, y)
             else:
                 y = self._draw_win(win, y)
     self._drawn_group = gr
     self.repaint.emit()
Example #13
0
 def __zorro_di_done__(self):
     self.window = Window(
         self.xcore.create_toplevel(Rectangle(0, 0, 1, 1),
                                    klass=self.xcore.WindowClass.InputOnly,
                                    params={}))
     di(self).inject(self.window)
     self.xcore.raw.ChangeProperty(
         window=self.xcore.root_window,
         mode=self.xcore.PropMode.Replace,
         property=self.xcore.atom._NET_SUPPORTING_WM_CHECK,
         type=self.xcore.atom.WINDOW,
         format=32,
         data_len=1,
         data=struct.pack('<L', self.window))
     self.window.set_property('_NET_SUPPORTING_WM_CHECK', self.window)
     self.window.set_property('_NET_WM_NAME', 'tilenol')
Example #14
0
 def create_frame(self):
     s = self.want.size
     if self.lprops.floating:
         border_width = self.theme.window.border_width
         s.x = s.x - border_width
         s.y = s.y - border_width
     self.frame = di(self).inject(
         Frame(
             self.xcore.create_toplevel(
                 s,
                 klass=self.xcore.WindowClass.InputOutput,
                 params={
                     self.xcore.CW.BackPixel:
                     self.theme.window.background,
                     self.xcore.CW.BorderPixel:
                     self.theme.window.inactive_border,
                     self.xcore.CW.EventMask:
                     self.xcore.EventMask.SubstructureRedirect
                     | self.xcore.EventMask.SubstructureNotify
                     | self.xcore.EventMask.EnterWindow
                     | self.xcore.EventMask.LeaveWindow
                     | self.xcore.EventMask.FocusChange
                 }), self))
     self.frame.want.size = s
     self.frame.done.size = s
     self.frame.set_border(self.frame.border_width)
     return self.frame
Example #15
0
 def __zorro_di_done__(self):
     for s in self.screens.screens:
         bar = di(self).inject(LeftBar(s, self.width,
                                       self.groups, self.states))
         self.bars[s] = bar
         if s.group.name in self.groups:
             s.slice_left(bar)
Example #16
0
 def create_window(self):
     self.window = di(self).inject(
         ClientMessageWindow(
             self.xcore.create_toplevel(
                 Rectangle(0, 0, 1, 1),
                 klass=self.xcore.WindowClass.InputOnly,
                 params={}), self.systray_message))
     self.window.show()
     self.dispatcher.register_window(self.window)
     self.xcore.raw.SetSelectionOwner(
         owner=self.window.wid,
         selection=self.xcore.atom._NET_SYSTEM_TRAY_S0,
         time=0,
     )
     self.xcore.send_event('ClientMessage',
                           self.xcore.EventMask.StructureNotify,
                           self.xcore.root_window,
                           window=self.xcore.root_window,
                           type=self.xcore.atom.MANAGER,
                           format=32,
                           data=struct.pack(
                               '<LLL',
                               0,
                               self.xcore.atom._NET_SYSTEM_TRAY_S0,
                               self.window.wid,
                           ))
Example #17
0
 def i(self, num: int):
     data = self.redis.execute('GET', 'issue:{:d}'.format(num))
     issue = Issue.load_blob(data)
     user = User.get(di(self), issue.uid)
     return {
         'issue': issue,
         'user': user,
         }
Example #18
0
 def remove_record(self, npname, id):
     note = di(self).inject(Notepad.from_id(npname))
     self.redis.pipeline((
         (b'LREM', note.records_key, b'0', id),
         (b'DEL', 'record:{}'.format(id)),
     ))
     self.output.publish(note.topic, ['notepad.remove_record', npname, id])
     return 'ok'
Example #19
0
 def remove_record(self, npname, id):
     note = di(self).inject(Notepad.from_id(npname))
     self.redis.pipeline((
         (b'LREM', note.records_key, b'0', id),
         (b'DEL', 'record:{}'.format(id)),
         ))
     self.output.publish(note.topic,
         ['notepad.remove_record', npname, id])
     return 'ok'
Example #20
0
 def __zorro_di_done__(self):
     bar = self.theme.bar
     self.height = bar.height
     self.background = bar.background_pat
     inj = di(self).clone()
     inj['bar'] = self
     for w in self.widgets:
         w.height = self.height
         inj.inject(w)
Example #21
0
 def append_record(self, npname, text):
     note = di(self).inject(Notepad.from_id(npname))
     rec = note.new_record(text)
     self.redis.pipeline((
         (b"SET", 'record:{}'.format(rec['id']), json.dumps(rec)),
         (b"RPUSH", note.records_key, rec['id']),
     ))
     self.output.publish(note.topic, ['notepad.append_record', npname, rec])
     return rec
Example #22
0
 def __zorro_di_done__(self):
     bar = self.theme.bar
     self.height = bar.height
     self.background = bar.background_pat
     inj = di(self).clone()
     inj['bar'] = self
     for w in self.widgets:
         w.height = self.height
         inj.inject(w)
Example #23
0
 def insert_after(self, npname, hint, text):
     note = di(self).inject(Notepad.from_id(npname))
     rec = note.new_record(text)
     self.redis.pipeline((
         (b"SET", 'record:{}'.format(rec['id']), json.dumps(rec)),
         (b"LINSERT", note.records_key, "AFTER", hint, rec['id']),
     ))
     self.output.publish(note.topic,
                         ['notepad.insert_after', npname, hint, rec])
     return rec
Example #24
0
 def insert_after(self, npname, hint,  text):
     note = di(self).inject(Notepad.from_id(npname))
     rec = note.new_record(text)
     self.redis.pipeline((
         (b"SET", 'record:{}'.format(rec['id']), json.dumps(rec)),
         (b"LINSERT", note.records_key, "AFTER", hint, rec['id']),
         ))
     self.output.publish(note.topic,
         ['notepad.insert_after', npname, hint, rec])
     return rec
Example #25
0
 def prepend_record(self, npname, text):
     note = di(self).inject(Notepad.from_id(npname))
     rec = note.new_record(text)
     self.redis.pipeline((
         (b"SET", 'record:{}'.format(rec['id']), json.dumps(rec)),
         (b"LPUSH", note.records_key, rec['id']),
         ))
     self.output.publish(note.topic,
         ['notepad.prepend_record', npname, rec])
     return rec
Example #26
0
 def cmd_set_layout(self, name):
     if self.screen:
         self.hide()
     lay = self.config.all_layouts()[name]
     self.current_layout = di(self).inject(lay())
     self.current_layout.group = self
     for win in self.all_windows:
         if not win.lprops.floating:
             self.current_layout.add(win)
     if self.screen:
         self.set_bounds(self.screen.inner_bounds)
         self.show()
Example #27
0
 def cmd_set_layout(self, name):
     if self.screen:
         self.hide()
     lay = self.config.all_layouts()[name]
     self.current_layout = di(self).inject(lay())
     self.current_layout.group = self
     for win in self.all_windows:
         if not win.lprops.floating:
             self.current_layout.add(win)
     if self.screen:
         self.set_bounds(self.screen.inner_bounds)
         self.show()
Example #28
0
 def cmd_show(self):
     if self.window:
         self.cmd_hide()
     self._current_items = self.items()
     show_lines = min(len(self._current_items) + 1, self.max_lines)
     h = self.theme.menu.line_height
     self.height = h * self.max_lines
     bounds = self.commander['screen'].bounds._replace(height=h)
     self._img = self.xcore.pixbuf(bounds.width, h)
     wid = self.xcore.create_toplevel(
         bounds,
         klass=self.xcore.WindowClass.InputOutput,
         params={
             self.xcore.CW.BackPixel:
             self.theme.menu.background,
             self.xcore.CW.OverrideRedirect:
             True,
             self.xcore.CW.EventMask:
             self.xcore.EventMask.FocusChange
             | self.xcore.EventMask.EnterWindow
             | self.xcore.EventMask.LeaveWindow
             | self.xcore.EventMask.KeymapState
             | self.xcore.EventMask.KeyPress,
         })
     self.window = di(self).inject(
         DisplayWindow(wid, self.draw, focus_out=self._close))
     self.dispatcher.all_windows[wid] = self.window
     self.dispatcher.frames[wid] = self.window  # dirty hack
     self.window.show()
     self.window.focus()
     self.text_field = di(self).inject(
         TextField(self.theme.menu,
                   events={
                       'draw': self.redraw,
                       'submit': self.submit_ev,
                       'complete': self.complete,
                       'close': self.close,
                   }))
     self.dispatcher.active_field = self.text_field
     self._redraw()
Example #29
0
 def set_record_title(self, npname, id, text):
     note = di(self).inject(Notepad.from_id(npname))
     rec = self.redis.execute("GET", 'record:{}'.format(id))
     if rec:
         rec = json.loads(rec.decode('utf-8'))
         rec['title'] = text
         self.redis.execute(b"SET", 'record:{}'.format(rec['id']),
                            json.dumps(rec))
         self.output.publish(note.topic,
             ['notepad.update_record', npname, rec])
         return rec
     else:
         return 'not_found'
Example #30
0
 def set_record_title(self, npname, id, text):
     note = di(self).inject(Notepad.from_id(npname))
     rec = self.redis.execute("GET", 'record:{}'.format(id))
     if rec:
         rec = json.loads(rec.decode('utf-8'))
         rec['title'] = text
         self.redis.execute(b"SET", 'record:{}'.format(rec['id']),
                            json.dumps(rec))
         self.output.publish(note.topic,
                             ['notepad.update_record', npname, rec])
         return rec
     else:
         return 'not_found'
Example #31
0
 def __zorro_di_done__(self):
     self.state = di(self).inject(State())
     bar = self.theme.bar
     self.font = bar.font
     self.inactive_color = bar.dim_color_pat
     self.urgent_color = bar.bright_color_pat
     self.active_color = bar.text_color_pat
     self.selected_color = bar.active_border_pat
     self.subactive_color = bar.subactive_border_pat
     self.padding = bar.text_padding
     self.border_width = bar.border_width
     self.state.gman.group_changed.listen(self.bar.redraw.emit)
     Window.any_window_changed.listen(self.check_state)
Example #32
0
 def __zorro_di_done__(self):
     self.state = di(self).inject(State())
     bar = self.theme.bar
     self.font = bar.font
     self.inactive_color = bar.dim_color_pat
     self.urgent_color = bar.bright_color_pat
     self.active_color = bar.text_color_pat
     self.selected_color = bar.active_border_pat
     self.subactive_color = bar.subactive_border_pat
     self.padding = bar.text_padding
     self.border_width = bar.border_width
     self.state.gman.group_changed.listen(self.bar.redraw.emit)
     Window.any_window_changed.listen(self.check_state)
Example #33
0
 def __zorro_di_done__(self):
     wid = self.xcore.create_toplevel(Rectangle(0, 0, 1, 1),
         klass=self.xcore.WindowClass.InputOutput,
         params={
             self.xcore.CW.BackPixel: self.theme.menu.background,
             self.xcore.CW.OverrideRedirect: True,
             self.xcore.CW.EventMask: self.xcore.EventMask.Exposure,
         })
     self.window = di(self).inject(DisplayWindow(wid, self.paint))
     self.dispatcher.all_windows[wid] = self.window
     self.window.show()
     if self.screen.group:
         self._group_hook()
     self.commander.events['window'].listen(self._check_redraw)
     Window.any_window_changed.listen(self._check_redraw)
Example #34
0
 def __zorro_di_done__(self):
     wid = self.xcore.create_toplevel(
         Rectangle(0, 0, 1, 1),
         klass=self.xcore.WindowClass.InputOutput,
         params={
             self.xcore.CW.BackPixel: self.theme.menu.background,
             self.xcore.CW.OverrideRedirect: True,
             self.xcore.CW.EventMask: self.xcore.EventMask.Exposure,
         })
     self.window = di(self).inject(DisplayWindow(wid, self.paint))
     self.dispatcher.all_windows[wid] = self.window
     self.window.show()
     if self.screen.group:
         self._group_hook()
     self.commander.events['window'].listen(self._check_redraw)
     Window.any_window_changed.listen(self._check_redraw)
Example #35
0
 def create(cls, resolver):
     req = resolver.request
     if hasattr(resolver, 'user'):
         return resolver.user
     sid = req.cookies.get('sidb')
     if sid is None:
         sid = req.cookies.get('sida')
     if sid is None:
         raise web.CompletionRedirect('/login')
     inj = di(resolver.resource)
     redis = inj['redis']
     uid = redis.execute("GET", 'sess:' + sid)
     if uid is None:
         raise web.CompletionRedirect('/login')
     uid = int(uid)
     user = cls.get(inj, uid)
     resolver.user = user
     return user
Example #36
0
 def append_left(self, cid, dash, uri):
     data = self.redis.execute('GET', 'dashboard:{}:notepads'.format(dash))
     if data:
         data = json.loads(data.decode('utf-8'))
     else:
         data = []
     data.append(('left', uri))
     self.redis.execute('SET', 'dashboard:{}:notepads'.format(dash),
         json.dumps(data))
     np = di(self).inject(Notepad.from_url(uri))
     self.output.subscribe(cid, np.topic)
     self.output.publish('dashboard:'+dash,
         ['dashboard.append_left', dash, {
             'ident': np.ident,
             'title': uri_to_title(uri),
             'records': np.records,
             }])
     return 'ok'
Example #37
0
 def new(self, user:User, brief, level, tags, reason):
     iid = int(self.redis.execute('INCR', 'issueid'))
     siid = str(iid)
     issue = di(self).inject(Issue(
         id=iid,
         startdate=int(time.time()),
         uid=user.uid,
         brief=brief,
         level=level,
         tags=tags,
         reason=reason,
         ))
     issue.save()
     self.redis.pipeline([
         ('ZADD', 'rt:' + k, 0, siid)
         for k in issue._keys()
         ] + [('ZADD', 'rc:' + k, issue.startdate, issue.id)
         for k in issue._keys()])
     raise web.CompletionRedirect('/i/{:d}'.format(iid))
Example #38
0
 def add_hint(self):
     res = di(self).inject(HintWindow(self.xcore.create_window(
         Rectangle(0, 0, 1, 1),
         klass=self.xcore.WindowClass.InputOutput,
         parent=self,
         params={
             self.xcore.CW.BackPixel: self.theme.hint.background,
             self.xcore.CW.BorderPixel: self.theme.hint.border_color,
             self.xcore.CW.OverrideRedirect: True,
             self.xcore.CW.EventMask:
                 self.xcore.EventMask.SubstructureRedirect
                 | self.xcore.EventMask.SubstructureNotify
                 | self.xcore.EventMask.EnterWindow
                 | self.xcore.EventMask.LeaveWindow
                 | self.xcore.EventMask.FocusChange
         }), self))
     res.set_border(self.theme.hint.border_width)
     res.show()
     return res
Example #39
0
 def append_left(self, cid, dash, uri):
     data = self.redis.execute('GET', 'dashboard:{}:notepads'.format(dash))
     if data:
         data = json.loads(data.decode('utf-8'))
     else:
         data = []
     data.append(('left', uri))
     self.redis.execute('SET', 'dashboard:{}:notepads'.format(dash),
                        json.dumps(data))
     np = di(self).inject(Notepad.from_url(uri))
     self.output.subscribe(cid, np.topic)
     self.output.publish('dashboard:' + dash, [
         'dashboard.append_left', dash, {
             'ident': np.ident,
             'title': uri_to_title(uri),
             'records': np.records,
         }
     ])
     return 'ok'
Example #40
0
 def add_hint(self):
     res = di(self).inject(HintWindow(self.xcore.create_window(
         Rectangle(0, 0, 1, 1),
         klass=self.xcore.WindowClass.InputOutput,
         parent=self,
         params={
             self.xcore.CW.BackPixel: self.theme.hint.background,
             self.xcore.CW.BorderPixel: self.theme.hint.border_color,
             self.xcore.CW.OverrideRedirect: True,
             self.xcore.CW.EventMask:
                 self.xcore.EventMask.SubstructureRedirect
                 | self.xcore.EventMask.SubstructureNotify
                 | self.xcore.EventMask.EnterWindow
                 | self.xcore.EventMask.LeaveWindow
                 | self.xcore.EventMask.FocusChange
         }), self))
     res.set_border(self.theme.hint.border_width)
     res.show()
     return res
Example #41
0
 def handle_CreateNotifyEvent(self, ev):
     win = di(self).inject(Window.from_notify(ev))
     if win.wid in self.windows:
         log.warning("Create notify for already existent window %r",
             win.wid)
         # TODO(tailhook) clean up old window
     if win.wid in self.all_windows:
         return
     win.done.size = win.want.size
     self.xcore.raw.ChangeWindowAttributes(window=win, params={
             self.xcore.CW.EventMask: self.xcore.EventMask.PropertyChange
         })
     self.windows[win.wid] = win
     self.all_windows[win.wid] = win
     try:
         for name in self.xcore.raw.ListProperties(window=win)['atoms']:
             win.update_property(name)
     except XError:
         log.warning("Window destroyed immediately %d", win.wid)
Example #42
0
    def register(self, name, email, password, cpassword):
        uid = self.redis.execute("INCR", 'z:last_uid')
        ok = self.redis.execute("HSETNX", 'z:names', name, uid)
        if not ok:
            raise FormError("name", "Login exists")
        ok = self.redis.execute("HSETNX", 'z:names', email, uid)
        if not ok:
            self.redis.execute("HDEL", 'z:names', name)
            raise FormError("email", "This email is already registered")
        salt = os.urandom(32)
        hash = hashlib.sha256(password.encode('utf-8') + salt).digest()
        pw = b'A' + hash + salt
        self.redis.execute('SET', 'z:user:{}:password'.format(uid), pw)

        user = di(self).inject(User(uid))
        user.name = name
        user.email = email
        user.save()

        return self.login(name, password)
Example #43
0
 def create(cls, resolver):
     req = resolver.request
     inj = di(resolver.resource)
     if isinstance(req, web.Request):
         if 'sid' not in req.cookies:
             raise web.CompletionRedirect('/login')
         redis = inj['redis']
         uid = redis.execute("GET", 'z:session:' + req.cookies['sid'])
         if uid is None:
             raise web.CompletionRedirect('/login')
         uid = int(uid)
     elif isinstance(req, web.WebsockCall):
         marker = getattr(req, 'marker', None)
         if not marker or not marker.startswith(b'user:'******'user:'):])
     else:
         raise AssertionError("Wrong request type {!r}".format(req))
     user = inj.inject(User(uid))
     user.load()
     return user
Example #44
0
 def insert_after(self, cid, dash, hint, uri):
     data = self.redis.execute('GET', 'dashboard:{}:notepads'.format(dash))
     if data:
         data = json.loads(data.decode('utf-8'))
     else:
         data = []
     for idx, (kind, nuri) in enumerate(data):
         if nuri[1:] == hint:
             data.insert(idx+1, (kind, uri))
             break
     self.redis.execute('SET', 'dashboard:{}:notepads'.format(dash),
         json.dumps(data))
     np = di(self).inject(Notepad.from_url(uri))
     self.output.subscribe(cid, np.topic)
     self.output.publish('dashboard:'+dash,
         ['dashboard.insert_after', dash, hint, {
             'ident': np.ident,
             'title': uri_to_title(uri),
             'records': np.records,
             }])
     return 'ok'
Example #45
0
 def create_frame(self):
     s = self.want.size
     if self.lprops.floating:
         border_width = self.theme.window.border_width
         s.x = s.x - border_width
         s.y = s.y - border_width
     self.frame = di(self).inject(Frame(self.xcore.create_toplevel(s,
         klass=self.xcore.WindowClass.InputOutput,
         params={
             self.xcore.CW.BackPixel: self.theme.window.background,
             self.xcore.CW.BorderPixel: self.theme.window.inactive_border,
             self.xcore.CW.EventMask:
                 self.xcore.EventMask.SubstructureRedirect
                 | self.xcore.EventMask.SubstructureNotify
                 | self.xcore.EventMask.EnterWindow
                 | self.xcore.EventMask.LeaveWindow
                 | self.xcore.EventMask.FocusChange
         }), self))
     self.frame.want.size = s
     self.frame.done.size = s
     self.frame.set_border(self.frame.border_width)
     return self.frame
Example #46
0
 def insert_after(self, cid, dash, hint, uri):
     data = self.redis.execute('GET', 'dashboard:{}:notepads'.format(dash))
     if data:
         data = json.loads(data.decode('utf-8'))
     else:
         data = []
     for idx, (kind, nuri) in enumerate(data):
         if nuri[1:] == hint:
             data.insert(idx + 1, (kind, uri))
             break
     self.redis.execute('SET', 'dashboard:{}:notepads'.format(dash),
                        json.dumps(data))
     np = di(self).inject(Notepad.from_url(uri))
     self.output.subscribe(cid, np.topic)
     self.output.publish('dashboard:' + dash, [
         'dashboard.insert_after', dash, hint, {
             'ident': np.ident,
             'title': uri_to_title(uri),
             'records': np.records,
         }
     ])
     return 'ok'
Example #47
0
 def default(self, uri):
     ident = uri[2:]
     leftcol = []
     rightcol = []
     data = self.redis.execute('GET', 'dashboard:{}:notepads'.format(ident))
     if data:
         data = json.loads(data.decode('utf-8'))
         inject = di(self).inject
         for kind, uri in data:
             note = inject(Notepad.from_url(uri))
             if kind == 'left':
                 leftcol.append(note)
             elif kind == 'right':
                 rightcol.append(note)
             else:
                 raise NotImplementedError(kind)
     return (b'200 OK', b'Content-Type\0text/html; charset=utf-8\0',
             self.jinja.get_template('dashboard.html').render(
                 title=uri_to_title(ident),
                 left_column=leftcol,
                 right_column=rightcol,
             ))
Example #48
0
 def default(self, uri):
     ident = uri[2:]
     leftcol = []
     rightcol = []
     data = self.redis.execute('GET', 'dashboard:{}:notepads'.format(ident))
     if data:
         data = json.loads(data.decode('utf-8'))
         inject = di(self).inject
         for kind, uri in data:
             note = inject(Notepad.from_url(uri))
             if kind == 'left':
                 leftcol.append(note)
             elif kind == 'right':
                 rightcol.append(note)
             else:
                 raise NotImplementedError(kind)
     return (b'200 OK',
             b'Content-Type\0text/html; charset=utf-8\0',
             self.jinja.get_template('dashboard.html').render(
                 title=uri_to_title(ident),
                 left_column=leftcol,
                 right_column=rightcol,
                 ))
Example #49
0
 def home(self, user:User):
     return di(self).inject(Home(user))
Example #50
0
 def default(self, uri):
     note = di(self).inject(Notepad.from_url(uri))
     return (b'200 OK', b'Content-Type\0text/html; charset=utf-8\0',
             self.jinja.get_template('notepad.html').render(notepad=note))
Example #51
0
 def subscribe(self, cid, npname):
     note = di(self).inject(Notepad.from_id(npname))
     self.output.subscribe(cid, note.topic)
     return 'ok'
Example #52
0
 def __zorro_di_done__(self):
     inj = di(self)
     for i, scr in enumerate(self.screens):
         inj.inject(scr)
         self.commander['screen.{}'.format(i)] = scr
Example #53
0
 def setter(win):
     wid = win.props[prop][0]
     other = di(win)['event-dispatcher'].all_windows[wid]
     win.lprops.group = other.lprops.group
Example #54
0
 def __zorro_di_done__(self):
     di(self).inject(self.current_layout)
Example #55
0
 def setter(win):
     gman = di(win)['group-manager']
     if group in gman.by_name:
         win.lprops.group = gman.groups.index(gman.by_name[group])
Example #56
0
 def register_gadgets(self):
     inj = di(self)
     for name, inst in self.config.gadgets():
         inj.inject(inst)
         self.commander[name] = inst
Example #57
0
 def __zorro_di_done__(self):
     di(self).inject(self.current_layout)