Refactored chat widget to be more manageable for screen readers. Needs improvements

This commit is contained in:
Manuel Cortez 2018-12-04 16:58:40 -06:00
parent 8c1d9c3fe2
commit 331636b9f4
2 changed files with 31 additions and 19 deletions

View File

@ -613,19 +613,25 @@ class empty(object):
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):
msg = self.session.db[self.name]["items"][-1]
if msg.has_key("read_state") and msg["read_state"] == 0 and msg["id"] not in self.reads:
self.reads.append(msg["id"])
self.session.db[self.name]["items"][-1]["read_state"] = 1
msg = self.get_post()
if msg.has_key("attachments") and len(msg["attachments"]) > 0:
self.tab.attachments.list.Enable(True)
self.attachments = list()
self.parse_attachments(msg)
else:
self.tab.attachments.list.Enable(False)
self.tab.attachments.clear()
pass # Fix it later
# msg = self.session.db[self.name]["items"][-1]
# if msg.has_key("read_state") and msg["read_state"] == 0 and msg["id"] not in self.reads:
# self.reads.append(msg["id"])
# self.session.db[self.name]["items"][-1]["read_state"] = 1
# msg = self.get_post()
# if msg.has_key("attachments") and len(msg["attachments"]) > 0:
# self.tab.attachments.list.Enable(True)
# self.attachments = list()
# self.parse_attachments(msg)
# else:
# self.tab.attachments.list.Enable(False)
# self.tab.attachments.clear()
def create_tab(self, parent):
self.tab = home.chatTab(parent)
@ -634,7 +640,7 @@ class chatBuffer(baseBuffer):
def connect_events(self):
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)
self.tab.set_focus_function(self.onFocus)
# self.tab.set_focus_function(self.onFocus)
def get_items(self, show_nextpage=False):
if self.can_get_items == False: return
@ -646,7 +652,7 @@ class chatBuffer(baseBuffer):
retrieved = err.code
return retrieved
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.reverse()
[self.insert(i, False) for i in v]

View File

@ -152,12 +152,10 @@ class chatTab(wx.Panel):
def create_controls(self):
lbl1 = wx.StaticText(self, wx.NewId(), _(u"History"))
self.list = widgetUtils.list(self, *[_(u"post")], style=wx.LC_REPORT)
self.list.set_windows_size(0, 190)
# self.list.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnKeyDown)
self.history = wx.TextCtrl(self, wx.NewId(), style=wx.TE_READONLY|wx.TE_MULTILINE, size=(500, 300))
box = wx.BoxSizer(wx.HORIZONTAL)
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
def create_attachments(self):
@ -178,7 +176,15 @@ class chatTab(wx.Panel):
return box
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):