# HG changeset patch # User Goffi # Date 1302873518 -7200 # Node ID c725b702e9273b4ad859e795961a02cce34ae9e5 # Parent 099c05a0dcabe955286942275db4b24d88c8142d register.py and contact.py moved to new directory browser_side diff -r 099c05a0dcab -r c725b702e927 browser_side/__init__.py diff -r 099c05a0dcab -r c725b702e927 browser_side/contact.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/browser_side/contact.py Fri Apr 15 15:18:38 2011 +0200 @@ -0,0 +1,181 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +Libervia: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +""" + +import pyjd # this is dummy in pyjs +from pyjamas.ui.SimplePanel import SimplePanel +from pyjamas.ui.VerticalPanel import VerticalPanel +from pyjamas.ui.HorizontalPanel import HorizontalPanel +from pyjamas.ui.Label import Label +from pyjamas import Window +from pyjamas import DOM + +from pyjamas.dnd import makeDraggable +from pyjamas.ui.DragWidget import DragWidget, DragContainer +from tools.jid import JID + +class DragLabel(DragWidget): + + def __init__(self, text, type): + DragWidget.__init__(self) + self._text = text + self._type = type + + def onDragStart(self, event): + print "onDragStart" + dt = event.dataTransfer + #self.addMessage('types is %s' % dt.getTypes()) + dt.setData('Text', self._text) + dt.setData('type', self._type) + #self.addMessage('after setting, len is %s' % len(dt.dataStore.items)) + #self.addMessage('types is %s' % dt.getTypes()) + dt.setDragImage(self.getElement(), 15, 15) + #dt.effectAllowed = 'copy' + #self.addMessage('mode is %s' % dt.dataStore.items.mode) + + def onDragEnd(self, event): + print "onDragEnd" + #self.addMessage('Drag ended') + #self.addMessage('mode is %s' % dt._data.mode) + + def addMessage(self, message): + print "addMessage" + #parent = self.getParent() + #while not hasattr(parent, 'addMessage'): + # parent = parent.getParent() + #parent.addMessage(message) + +class GroupLabel(DragLabel, Label): + def __init__(self, group): + self.group = group + Label.__init__(self, group) #, Element=DOM.createElement('div') + self.setStyleName('group') + DragLabel.__init__(self, group, "GROUP") + + +class ContactLabel(Label): + def __init__(self, jid, name=None): + if not name: + name=jid + Label.__init__(self, name) + self.jid=jid + self.setStyleName('contact') + +class GroupList(VerticalPanel): + + def __init__(self, parent): + VerticalPanel.__init__(self) + self._parent = parent + + def add(self, group): + _item = GroupLabel(group) + _item.addMouseListener(self._parent) + DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") + VerticalPanel.add(self, _item) + +class ContactList(VerticalPanel): + + def __init__(self): + VerticalPanel.__init__(self) + self.contacts=[] + + def __iter__(self): + return self.contacts.__iter__() + + def add(self, jid, name=None): + _item = ContactLabel(jid, name) + DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") + VerticalPanel.add(self, _item) + self.contacts.append(_item) + +class ContactTitleLabel(DragLabel, Label): + def __init__(self, text): + Label.__init__(self, text) #, Element=DOM.createElement('div') + self.setStyleName('contactTitle') + DragLabel.__init__(self, text, "CONTACT") + +class ContactPanel(SimplePanel): + """Manage the contacts and groups""" + + def __init__(self, host): + SimplePanel.__init__(self) + self.host = host + self.groups={} + + self.vPanel = VerticalPanel() + _title = ContactTitleLabel('Contacts') + DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") + + self._contactList = ContactList() + self._contactList.setStyleName('contactList') + self._groupList = GroupList(self) + self._groupList.setStyleName('groupList') + + self.vPanel.add(_title) + self.vPanel.add(self._groupList) + self.vPanel.add(self._contactList) + self.add(self.vPanel) + self.setStyleName('contactBox') + + def addContact(self, jid, attributes, groups): + """Add a contact to the panel + @param jid: jid + @attributes: cf SàT Bridge API's newContact + @param groups: list of groups""" + for group in groups: + if not self.groups.has_key(group): + self.groups[group] = set() + self._groupList.add(group) + self.host.uniBox.addKey("@%s: " % group) + self.groups[group].add(jid) + self._contactList.add(jid) + + def isContactInGroup(self, group, contact_jid): + """Test if the contact_jid is in the group + @param group: string of single group, or list of string + @param contact_jid: jid to test + @return: True if contact_jid is in on of the groups""" + print "isContactInGroup: %s, %s" % (group, contact_jid) + print JID(contact_jid) + print self.groups[group] + if self.groups.has_key(group) and contact_jid in self.groups[group]: + return True + return False + + def onMouseMove(self, sender, x, y): + pass + + def onMouseDown(self, sender, x, y): + pass + + def onMouseUp(self, sender, x, y): + pass + + def onMouseEnter(self, sender): + if isinstance(sender, GroupLabel): + for contact in self._contactList: + if contact.jid in self.groups[sender.group]: + contact.addStyleName("selected") + + def onMouseLeave(self, sender): + if isinstance(sender, GroupLabel): + for contact in self._contactList: + if contact.jid in self.groups[sender.group]: + contact.removeStyleName("selected") diff -r 099c05a0dcab -r c725b702e927 browser_side/register.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/browser_side/register.py Fri Apr 15 15:18:38 2011 +0200 @@ -0,0 +1,86 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +Libervia: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +""" + +#This page manage subscription and new account creation +import pyjd # this is dummy in pyjs + +from pyjamas.ui.VerticalPanel import VerticalPanel +from pyjamas.ui.Grid import Grid +from pyjamas.ui.PasswordTextBox import PasswordTextBox +from pyjamas.ui.TextBox import TextBox +from pyjamas.ui.FormPanel import FormPanel +from pyjamas.ui.Button import Button +from pyjamas.ui.DialogBox import DialogBox +from pyjamas import Window +from pyjamas.ui import HasAlignment + + + + +class RegisterPanel(FormPanel): + + def __init__(self, callback): + """ + @param callback: method to call if login successful + """ + FormPanel.__init__(self) + self.callback = callback + self.setMethod(FormPanel.METHOD_POST) + vPanel = VerticalPanel() + vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER) + self.loginBox = TextBox() + self.loginBox.setName("login") + self.passBox = PasswordTextBox() + self.passBox.setName("password") + grid = Grid(2, 2) + grid.setText(0,0,"Login:") + grid.setWidget(0,1, self.loginBox) + grid.setText(1,0, "Password:") + grid.setWidget(1,1, self.passBox) + vPanel.add(grid) + login_but = Button("Login", getattr(self, "onLogin")) + vPanel.add(login_but) + self.add(vPanel) + self.addFormHandler(self) + self.setAction('register_api/login') + + def onLogin(self): + self.submit() + + def onSubmit(self, event): + pass + + def onSubmitComplete(self, event): + result = event.getResults() + if result == "AUTH ERROR": + Window.alert('You login and/or password is incorrect. Please try again') + elif result == "LOGGED": + self.callback() + else: + Window.alert('Submit error: %s' % result) + +class RegisterBox(DialogBox): + + def __init__(self, callback, *args,**kwargs): + DialogBox.__init__(self,*args,**kwargs) + _form = RegisterPanel(callback) + self.setHTML('You are not identified, please log in') + self.setWidget(_form) diff -r 099c05a0dcab -r c725b702e927 contact.py --- a/contact.py Fri Apr 15 02:01:34 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,181 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -""" -Libervia: a Salut à Toi frontend -Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -""" - -import pyjd # this is dummy in pyjs -from pyjamas.ui.SimplePanel import SimplePanel -from pyjamas.ui.VerticalPanel import VerticalPanel -from pyjamas.ui.HorizontalPanel import HorizontalPanel -from pyjamas.ui.Label import Label -from pyjamas import Window -from pyjamas import DOM - -from pyjamas.dnd import makeDraggable -from pyjamas.ui.DragWidget import DragWidget, DragContainer -from tools.jid import JID - -class DragLabel(DragWidget): - - def __init__(self, text, type): - DragWidget.__init__(self) - self._text = text - self._type = type - - def onDragStart(self, event): - print "onDragStart" - dt = event.dataTransfer - #self.addMessage('types is %s' % dt.getTypes()) - dt.setData('Text', self._text) - dt.setData('type', self._type) - #self.addMessage('after setting, len is %s' % len(dt.dataStore.items)) - #self.addMessage('types is %s' % dt.getTypes()) - dt.setDragImage(self.getElement(), 15, 15) - #dt.effectAllowed = 'copy' - #self.addMessage('mode is %s' % dt.dataStore.items.mode) - - def onDragEnd(self, event): - print "onDragEnd" - #self.addMessage('Drag ended') - #self.addMessage('mode is %s' % dt._data.mode) - - def addMessage(self, message): - print "addMessage" - #parent = self.getParent() - #while not hasattr(parent, 'addMessage'): - # parent = parent.getParent() - #parent.addMessage(message) - -class GroupLabel(DragLabel, Label): - def __init__(self, group): - self.group = group - Label.__init__(self, group) #, Element=DOM.createElement('div') - self.setStyleName('group') - DragLabel.__init__(self, group, "GROUP") - - -class ContactLabel(Label): - def __init__(self, jid, name=None): - if not name: - name=jid - Label.__init__(self, name) - self.jid=jid - self.setStyleName('contact') - -class GroupList(VerticalPanel): - - def __init__(self, parent): - VerticalPanel.__init__(self) - self._parent = parent - - def add(self, group): - _item = GroupLabel(group) - _item.addMouseListener(self._parent) - DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") - VerticalPanel.add(self, _item) - -class ContactList(VerticalPanel): - - def __init__(self): - VerticalPanel.__init__(self) - self.contacts=[] - - def __iter__(self): - return self.contacts.__iter__() - - def add(self, jid, name=None): - _item = ContactLabel(jid, name) - DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") - VerticalPanel.add(self, _item) - self.contacts.append(_item) - -class ContactTitleLabel(DragLabel, Label): - def __init__(self, text): - Label.__init__(self, text) #, Element=DOM.createElement('div') - self.setStyleName('contactTitle') - DragLabel.__init__(self, text, "CONTACT") - -class ContactPanel(SimplePanel): - """Manage the contacts and groups""" - - def __init__(self, host): - SimplePanel.__init__(self) - self.host = host - self.groups={} - - self.vPanel = VerticalPanel() - _title = ContactTitleLabel('Contacts') - DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") - - self._contactList = ContactList() - self._contactList.setStyleName('contactList') - self._groupList = GroupList(self) - self._groupList.setStyleName('groupList') - - self.vPanel.add(_title) - self.vPanel.add(self._groupList) - self.vPanel.add(self._contactList) - self.add(self.vPanel) - self.setStyleName('contactBox') - - def addContact(self, jid, attributes, groups): - """Add a contact to the panel - @param jid: jid - @attributes: cf SàT Bridge API's newContact - @param groups: list of groups""" - for group in groups: - if not self.groups.has_key(group): - self.groups[group] = set() - self._groupList.add(group) - self.host.uniBox.addKey("@%s: " % group) - self.groups[group].add(jid) - self._contactList.add(jid) - - def isContactInGroup(self, group, contact_jid): - """Test if the contact_jid is in the group - @param group: string of single group, or list of string - @param contact_jid: jid to test - @return: True if contact_jid is in on of the groups""" - print "isContactInGroup: %s, %s" % (group, contact_jid) - print JID(contact_jid) - print self.groups[group] - if self.groups.has_key(group) and contact_jid in self.groups[group]: - return True - return False - - def onMouseMove(self, sender, x, y): - pass - - def onMouseDown(self, sender, x, y): - pass - - def onMouseUp(self, sender, x, y): - pass - - def onMouseEnter(self, sender): - if isinstance(sender, GroupLabel): - for contact in self._contactList: - if contact.jid in self.groups[sender.group]: - contact.addStyleName("selected") - - def onMouseLeave(self, sender): - if isinstance(sender, GroupLabel): - for contact in self._contactList: - if contact.jid in self.groups[sender.group]: - contact.removeStyleName("selected") diff -r 099c05a0dcab -r c725b702e927 libervia.py --- a/libervia.py Fri Apr 15 02:01:34 2011 +0200 +++ b/libervia.py Fri Apr 15 15:18:38 2011 +0200 @@ -36,9 +36,9 @@ from pyjamas import Window from pyjamas.JSONService import JSONProxy from pyjamas.ui.KeyboardListener import KEY_ENTER -from register import RegisterPanel, RegisterBox +from browser_side.register import RegisterPanel, RegisterBox from pyjamas import DOM -from contact import ContactPanel +from browser_side.contact import ContactPanel from datetime import datetime diff -r 099c05a0dcab -r c725b702e927 register.py --- a/register.py Fri Apr 15 02:01:34 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -""" -Libervia: a Salut à Toi frontend -Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -""" - -#This page manage subscription and new account creation -import pyjd # this is dummy in pyjs - -from pyjamas.ui.VerticalPanel import VerticalPanel -from pyjamas.ui.Grid import Grid -from pyjamas.ui.PasswordTextBox import PasswordTextBox -from pyjamas.ui.TextBox import TextBox -from pyjamas.ui.FormPanel import FormPanel -from pyjamas.ui.Button import Button -from pyjamas.ui.DialogBox import DialogBox -from pyjamas import Window -from pyjamas.ui import HasAlignment - - - - -class RegisterPanel(FormPanel): - - def __init__(self, callback): - """ - @param callback: method to call if login successful - """ - FormPanel.__init__(self) - self.callback = callback - self.setMethod(FormPanel.METHOD_POST) - vPanel = VerticalPanel() - vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER) - self.loginBox = TextBox() - self.loginBox.setName("login") - self.passBox = PasswordTextBox() - self.passBox.setName("password") - grid = Grid(2, 2) - grid.setText(0,0,"Login:") - grid.setWidget(0,1, self.loginBox) - grid.setText(1,0, "Password:") - grid.setWidget(1,1, self.passBox) - vPanel.add(grid) - login_but = Button("Login", getattr(self, "onLogin")) - vPanel.add(login_but) - self.add(vPanel) - self.addFormHandler(self) - self.setAction('register_api/login') - - def onLogin(self): - self.submit() - - def onSubmit(self, event): - pass - - def onSubmitComplete(self, event): - result = event.getResults() - if result == "AUTH ERROR": - Window.alert('You login and/or password is incorrect. Please try again') - elif result == "LOGGED": - self.callback() - else: - Window.alert('Submit error: %s' % result) - -class RegisterBox(DialogBox): - - def __init__(self, callback, *args,**kwargs): - DialogBox.__init__(self,*args,**kwargs) - _form = RegisterPanel(callback) - self.setHTML('You are not identified, please log in') - self.setWidget(_form)