Primitivus: misc fixes + menubar first draft
- Menu bar: first draft of class - Password widget fixed - change some str to unicode, notably for JID
This commit is contained in:
parent
126d529d46
commit
9fbbd52805
6 changed files with 81 additions and 9 deletions
|
|
@ -150,9 +150,10 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
"""mark a contact disconnected"""
|
||||
self.remove(jid.short)
|
||||
|
||||
def remove(self, jid):
|
||||
def remove(self, param_jid):
|
||||
"""remove a contact from the list"""
|
||||
groups_to_remove = []
|
||||
jid = JID(param_jid)
|
||||
for group in self.groups:
|
||||
contacts = self.groups[group][1]
|
||||
if jid.short in contacts:
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import urwid
|
|||
from urwid.escape import utf8decode
|
||||
|
||||
class Password(urwid.Edit):
|
||||
toto=0
|
||||
"""Edit box which doesn't show what is entered (show '*' or other char instead)"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
@ -41,6 +42,18 @@ class Password(urwid.Edit):
|
|||
def get_edit_text(self):
|
||||
return self.__real_text
|
||||
|
||||
def insert_text(self, text):
|
||||
self._edit_text = self.__real_text
|
||||
super(Password,self).insert_text(text)
|
||||
|
||||
def render(self, size, focus=False):
|
||||
Password.toto+=1
|
||||
if Password.toto==30:
|
||||
import os,pdb
|
||||
os.system('reset')
|
||||
pdb.set_trace()
|
||||
return super(Password, self).render(size, focus)
|
||||
|
||||
class AdvancedEdit(urwid.Edit):
|
||||
"""Edit box with some custom improvments
|
||||
new chars:
|
||||
|
|
@ -327,6 +340,49 @@ class List(urwid.FlowWidget):
|
|||
height = min(list_size,self.max_height) or 1
|
||||
return urwid.BoxAdapter(self.genericList, height)
|
||||
|
||||
## MISC ##
|
||||
|
||||
class Menu(urwid.FlowWidget):
|
||||
|
||||
def __init__(self):
|
||||
super(Menu, self).__init__()
|
||||
self.menu_keys = ['test']
|
||||
self.menu = {'test':[('top',None)]}
|
||||
self.shortcuts = {} #keyboard shortcuts
|
||||
|
||||
def checkShortcuts(self, key):
|
||||
for shortcut in self.shortcuts.keys():
|
||||
if key == shortcut:
|
||||
category, item, callback = self.shortcuts[shortcuts]
|
||||
callback((category, item))
|
||||
return key
|
||||
|
||||
def addMenu(self, category, item, callback, shortcut=None):
|
||||
"""Add a menu item, create the category if new
|
||||
@param category: category of the menu (e.g. File/Edit)
|
||||
@param item: menu item (e.g. new/close/about)
|
||||
@callback: method to call when item is selected"""
|
||||
if not category in self.menu.keys():
|
||||
self.menu_keys.append(category)
|
||||
self.menu[category] = []
|
||||
self.menu[category].append[(item, callback)]
|
||||
if shortcut:
|
||||
assert(shortcut not in self.shortcuts.keys())
|
||||
self.shortcuts[shortcut] = (category, item, callback)
|
||||
|
||||
def rows(self,size,focus=False):
|
||||
return self.display_widget(size, focus).rows(size, focus)
|
||||
|
||||
def render(self, size, focus=False):
|
||||
return self.display_widget(size, focus).render(size, focus)
|
||||
|
||||
def display_widget(self, size, focus):
|
||||
render_txt = []
|
||||
for menu in self.menu_keys:
|
||||
render_txt.append('[ %s ] ' % menu)
|
||||
return urwid.AttrMap(urwid.Text(render_txt), 'menubar')
|
||||
|
||||
|
||||
## DIALOGS ##
|
||||
|
||||
class GenericDialog(urwid.WidgetWrap):
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import urwid
|
|||
from profile_manager import ProfileManager
|
||||
from contact_list import ContactList
|
||||
from chat import Chat
|
||||
from custom_widgets import AdvancedEdit,FocusFrame,InputDialog,Alert
|
||||
import custom_widgets
|
||||
import pdb
|
||||
"""from window import Window
|
||||
from editbox import EditBox
|
||||
|
|
@ -65,6 +65,7 @@ const_PALETTE = [('title', 'black', 'light gray', 'standout,underline'),
|
|||
('date', 'light gray', 'default'),
|
||||
('my_nick', 'dark red,bold', 'default'),
|
||||
('other_nick', 'dark cyan,bold', 'default'),
|
||||
('menubar', 'light gray,bold', 'dark red'),
|
||||
]
|
||||
|
||||
class ChatList(QuickChatList):
|
||||
|
|
@ -118,10 +119,18 @@ class PrimitivusApp(QuickApp):
|
|||
def keyHandler(self, input):
|
||||
if input in ('q', 'Q') or input == 'ctrl x':
|
||||
raise urwid.ExitMainLoop()
|
||||
elif input == 'meta m':
|
||||
try:
|
||||
if self.main_widget.header == None:
|
||||
self.main_widget.header = self.menu
|
||||
else:
|
||||
self.main_widget.header = None
|
||||
except AttributeError:
|
||||
pass
|
||||
elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions
|
||||
self.debug()
|
||||
elif input == 'meta j': #user wants to join a room
|
||||
pop_up_widget = InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'test@conference.necton2.int', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
|
||||
pop_up_widget = custom_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'test@conference.necton2.int', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
|
||||
self.showPopUp(pop_up_widget)
|
||||
elif input == 'f2': #user wants to (un)hide the contact_list
|
||||
try:
|
||||
|
|
@ -136,14 +145,19 @@ class PrimitivusApp(QuickApp):
|
|||
except AttributeError:
|
||||
#The main widget is not built (probably in Profile Manager)
|
||||
pass
|
||||
try:
|
||||
return self.menu.checkShortcuts(input)
|
||||
except AttributeError:
|
||||
return input
|
||||
|
||||
def __buildMainWidget(self):
|
||||
self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw())
|
||||
#self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))])
|
||||
self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))])
|
||||
editBar = AdvancedEdit('> ')
|
||||
editBar = custom_widgets.AdvancedEdit('> ')
|
||||
urwid.connect_signal(editBar,'click',self.onTextEntered)
|
||||
self.main_widget = FocusFrame(self.center_part, footer=editBar, focus_part='footer')
|
||||
self.menu = custom_widgets.Menu()
|
||||
self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu, footer=editBar, focus_part='footer')
|
||||
return self.main_widget
|
||||
|
||||
def plug_profile(self, profile_key='@DEFAULT@'):
|
||||
|
|
@ -192,7 +206,7 @@ class PrimitivusApp(QuickApp):
|
|||
else:
|
||||
message = _("'%s' is an invalid JID !") % room_jid
|
||||
error (message)
|
||||
Alert(_("Error"), message, ok_cb=self.removePopUp)
|
||||
custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)
|
||||
|
||||
sat = PrimitivusApp()
|
||||
sat.start()
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
import urwid
|
||||
from custom_widgets import Password,List,InputDialog,ConfirmDialog,Alert,FocusFrame
|
||||
from tools.jid import JID
|
||||
|
||||
|
||||
class ProfileManager(urwid.WidgetWrap):
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ class DbusObject(dbus.service.Object):
|
|||
@dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||
in_signature='ssss', out_signature='')
|
||||
def setParam(self, name, value, category, profile_key='@DEFAULT@'):
|
||||
self.cb["setParam"](str(name), str(value), str(category), profile_key)
|
||||
self.cb["setParam"](unicode(name), unicode(value), unicode(category), profile_key)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||
in_signature='sss', out_signature='s')
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
|
||||
|
||||
class JID(str):
|
||||
class JID(unicode):
|
||||
"""This class help manage JID (Node@Domaine/Resource)"""
|
||||
|
||||
def __new__(cls, jid):
|
||||
self = str.__new__(cls, jid)
|
||||
self = unicode.__new__(cls, jid)
|
||||
self.__parse()
|
||||
return self
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue