primitivus: basic contact list, connexion now work \o/
This commit is contained in:
parent
1fb4156381
commit
9caff8237a
3 changed files with 79 additions and 0 deletions
65
frontends/primitivus/contact_list.py
Normal file
65
frontends/primitivus/contact_list.py
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Primitivus: a SAT frontend
|
||||||
|
Copyright (C) 2009, 2010 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 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import urwid
|
||||||
|
from quick_frontend.quick_contact_list import QuickContactList
|
||||||
|
from custom_widgets import Password,List,InputDialog,ConfirmDialog,Alert
|
||||||
|
|
||||||
|
|
||||||
|
class ContactList(urwid.WidgetWrap, QuickContactList):
|
||||||
|
|
||||||
|
def __init__(self, host, CM):
|
||||||
|
QuickContactList.__init__(self, CM)
|
||||||
|
self.host = host
|
||||||
|
|
||||||
|
self.list_wid = List([], style=['single'], align='left')
|
||||||
|
|
||||||
|
#we now build the widget
|
||||||
|
body_content = urwid.SimpleListWalker([self.list_wid])
|
||||||
|
frame_body = urwid.ListBox(body_content)
|
||||||
|
frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Contacts"),align='center'),'title'))
|
||||||
|
self.main_widget = urwid.LineBox(frame)
|
||||||
|
urwid.WidgetWrap.__init__(self, self.main_widget)
|
||||||
|
|
||||||
|
def clear_contacts(self):
|
||||||
|
"""clear all the contact list"""
|
||||||
|
self.list_wid.changeValues([])
|
||||||
|
|
||||||
|
def replace(self, jid, groups=None):
|
||||||
|
"""add a contact to the list if doesn't exist, else update it"""
|
||||||
|
contacts = self.list_wid.getValues()
|
||||||
|
if jid.short not in contacts:
|
||||||
|
contacts.append(jid.short)
|
||||||
|
contacts.sort()
|
||||||
|
self.list_wid.changeValues(contacts)
|
||||||
|
|
||||||
|
def disconnect(self, jid):
|
||||||
|
"""mark a contact disconnected"""
|
||||||
|
self.remove(jid)
|
||||||
|
|
||||||
|
def remove(self, jid):
|
||||||
|
"""remove a contact from the list"""
|
||||||
|
self.list_wid.deleteValue(jid.short)
|
||||||
|
|
||||||
|
def add(self, jid, param_groups=None):
|
||||||
|
"""add a contact to the list"""
|
||||||
|
self.replace(jid)
|
||||||
|
|
||||||
|
|
@ -113,6 +113,13 @@ class List(urwid.WidgetWrap):
|
||||||
widget.setState(False, invisible)
|
widget.setState(False, invisible)
|
||||||
widget._invalidate()
|
widget._invalidate()
|
||||||
|
|
||||||
|
def deleteValue(self, value):
|
||||||
|
"""Delete the first value equal to the param given"""
|
||||||
|
try:
|
||||||
|
self.content.remove(value)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
def getValue(self):
|
def getValue(self):
|
||||||
"""Convenience method to get the value selected as a string in single mode, or None"""
|
"""Convenience method to get the value selected as a string in single mode, or None"""
|
||||||
values = self.getValues()
|
values = self.getValues()
|
||||||
|
|
@ -126,6 +133,7 @@ class List(urwid.WidgetWrap):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def changeValues(self, new_values):
|
def changeValues(self, new_values):
|
||||||
|
"""Change all value in one shot"""
|
||||||
widgets = [SelectableText(option, self.align) for option in new_values]
|
widgets = [SelectableText(option, self.align) for option in new_values]
|
||||||
for widget in widgets:
|
for widget in widgets:
|
||||||
urwid.connect_signal(widget, 'change', self.__onStateChange)
|
urwid.connect_signal(widget, 'change', self.__onStateChange)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ from quick_frontend.quick_contact_list import QuickContactList
|
||||||
from quick_frontend.quick_contact_management import QuickContactManagement
|
from quick_frontend.quick_contact_management import QuickContactManagement
|
||||||
import urwid
|
import urwid
|
||||||
from profile_manager import ProfileManager
|
from profile_manager import ProfileManager
|
||||||
|
from contact_list import ContactList
|
||||||
import pdb
|
import pdb
|
||||||
"""from window import Window
|
"""from window import Window
|
||||||
from editbox import EditBox
|
from editbox import EditBox
|
||||||
|
|
@ -61,6 +62,7 @@ const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'),
|
||||||
class PrimitivusApp(QuickApp):
|
class PrimitivusApp(QuickApp):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.CM = QuickContactManagement() #FIXME: not the best place
|
||||||
QuickApp.__init__(self) #XXX: yes it's an unusual place for the constructor of a parent class, but the init order is important
|
QuickApp.__init__(self) #XXX: yes it's an unusual place for the constructor of a parent class, but the init order is important
|
||||||
|
|
||||||
## main loop setup ##
|
## main loop setup ##
|
||||||
|
|
@ -79,6 +81,10 @@ class PrimitivusApp(QuickApp):
|
||||||
main_widget = ProfileManager(self)
|
main_widget = ProfileManager(self)
|
||||||
return main_widget
|
return main_widget
|
||||||
|
|
||||||
|
def plug_profile(self, profile_key='@DEFAULT@'):
|
||||||
|
self.loop.widget = self.contactList = ContactList(self, self.CM)
|
||||||
|
QuickApp.plug_profile(self, profile_key)
|
||||||
|
|
||||||
|
|
||||||
sat = PrimitivusApp()
|
sat = PrimitivusApp()
|
||||||
sat.start()
|
sat.start()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue