Refactored chat widget to be more manageable for screen readers. Needs improvements
This commit is contained in:
parent
8c1d9c3fe2
commit
331636b9f4
@ -613,19 +613,25 @@ class empty(object):
|
|||||||
|
|
||||||
class chatBuffer(baseBuffer):
|
class chatBuffer(baseBuffer):
|
||||||
|
|
||||||
|
def insert(self, item, reversed=False):
|
||||||
|
""" Add a new item to the list. Uses session.composefunc for parsing the dictionary and create a valid result for putting it in the list."""
|
||||||
|
item_ = getattr(session, self.compose_function)(item, self.session)
|
||||||
|
self.tab.add_message(item_[0])
|
||||||
|
|
||||||
def onFocus(self, *args, **kwargs):
|
def onFocus(self, *args, **kwargs):
|
||||||
msg = self.session.db[self.name]["items"][-1]
|
pass # Fix it later
|
||||||
if msg.has_key("read_state") and msg["read_state"] == 0 and msg["id"] not in self.reads:
|
# msg = self.session.db[self.name]["items"][-1]
|
||||||
self.reads.append(msg["id"])
|
# if msg.has_key("read_state") and msg["read_state"] == 0 and msg["id"] not in self.reads:
|
||||||
self.session.db[self.name]["items"][-1]["read_state"] = 1
|
# self.reads.append(msg["id"])
|
||||||
msg = self.get_post()
|
# self.session.db[self.name]["items"][-1]["read_state"] = 1
|
||||||
if msg.has_key("attachments") and len(msg["attachments"]) > 0:
|
# msg = self.get_post()
|
||||||
self.tab.attachments.list.Enable(True)
|
# if msg.has_key("attachments") and len(msg["attachments"]) > 0:
|
||||||
self.attachments = list()
|
# self.tab.attachments.list.Enable(True)
|
||||||
self.parse_attachments(msg)
|
# self.attachments = list()
|
||||||
else:
|
# self.parse_attachments(msg)
|
||||||
self.tab.attachments.list.Enable(False)
|
# else:
|
||||||
self.tab.attachments.clear()
|
# self.tab.attachments.list.Enable(False)
|
||||||
|
# self.tab.attachments.clear()
|
||||||
|
|
||||||
def create_tab(self, parent):
|
def create_tab(self, parent):
|
||||||
self.tab = home.chatTab(parent)
|
self.tab = home.chatTab(parent)
|
||||||
@ -634,7 +640,7 @@ class chatBuffer(baseBuffer):
|
|||||||
def connect_events(self):
|
def connect_events(self):
|
||||||
widgetUtils.connect_event(self.tab.send, widgetUtils.BUTTON_PRESSED, self.send_chat_to_user)
|
widgetUtils.connect_event(self.tab.send, widgetUtils.BUTTON_PRESSED, self.send_chat_to_user)
|
||||||
widgetUtils.connect_event(self.tab.attachment, widgetUtils.BUTTON_PRESSED, self.add_attachment)
|
widgetUtils.connect_event(self.tab.attachment, widgetUtils.BUTTON_PRESSED, self.add_attachment)
|
||||||
self.tab.set_focus_function(self.onFocus)
|
# self.tab.set_focus_function(self.onFocus)
|
||||||
|
|
||||||
def get_items(self, show_nextpage=False):
|
def get_items(self, show_nextpage=False):
|
||||||
if self.can_get_items == False: return
|
if self.can_get_items == False: return
|
||||||
@ -646,7 +652,7 @@ class chatBuffer(baseBuffer):
|
|||||||
retrieved = err.code
|
retrieved = err.code
|
||||||
return retrieved
|
return retrieved
|
||||||
if show_nextpage == False:
|
if show_nextpage == False:
|
||||||
if self.tab.list.get_count() > 0 and num > 0:
|
if self.tab.history.GetValue() > 0 and num > 0:
|
||||||
v = [i for i in self.session.db[self.name]["items"][:num]]
|
v = [i for i in self.session.db[self.name]["items"][:num]]
|
||||||
v.reverse()
|
v.reverse()
|
||||||
[self.insert(i, False) for i in v]
|
[self.insert(i, False) for i in v]
|
||||||
|
@ -152,12 +152,10 @@ class chatTab(wx.Panel):
|
|||||||
|
|
||||||
def create_controls(self):
|
def create_controls(self):
|
||||||
lbl1 = wx.StaticText(self, wx.NewId(), _(u"History"))
|
lbl1 = wx.StaticText(self, wx.NewId(), _(u"History"))
|
||||||
self.list = widgetUtils.list(self, *[_(u"post")], style=wx.LC_REPORT)
|
self.history = wx.TextCtrl(self, wx.NewId(), style=wx.TE_READONLY|wx.TE_MULTILINE, size=(500, 300))
|
||||||
self.list.set_windows_size(0, 190)
|
|
||||||
# self.list.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnKeyDown)
|
|
||||||
box = wx.BoxSizer(wx.HORIZONTAL)
|
box = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
box.Add(lbl1, 0, wx.ALL, 5)
|
box.Add(lbl1, 0, wx.ALL, 5)
|
||||||
box.Add(self.list.list, 0, wx.ALL, 5)
|
box.Add(self.history, 0, wx.ALL, 5)
|
||||||
return box
|
return box
|
||||||
|
|
||||||
def create_attachments(self):
|
def create_attachments(self):
|
||||||
@ -178,7 +176,15 @@ class chatTab(wx.Panel):
|
|||||||
return box
|
return box
|
||||||
|
|
||||||
def set_focus_function(self, focus_function):
|
def set_focus_function(self, focus_function):
|
||||||
self.list.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, focus_function)
|
pass#self.history.Bind(wx.EVT_LIST_ITEM_FOCUSED, focus_function)
|
||||||
|
|
||||||
|
def add_message(self, message, reverse=False):
|
||||||
|
point = self.history.GetInsertionPoint()
|
||||||
|
if reversed:
|
||||||
|
self.history.SetValue(message+"\n"+self.history.GetValue())
|
||||||
|
else:
|
||||||
|
self.history.AppendText(message+"\n")
|
||||||
|
self.history.SetInsertionPoint(point)
|
||||||
|
|
||||||
class peopleTab(homeTab):
|
class peopleTab(homeTab):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user