Added first experiment on focus mode for chat history
This commit is contained in:
parent
331636b9f4
commit
04102677f2
@ -616,22 +616,45 @@ class chatBuffer(baseBuffer):
|
|||||||
def insert(self, item, reversed=False):
|
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."""
|
""" 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)
|
item_ = getattr(session, self.compose_function)(item, self.session)
|
||||||
self.tab.add_message(item_[0])
|
values = self.tab.add_message(item_[0])
|
||||||
|
self.chats[values] = item["id"]
|
||||||
|
# print len(self.chats)
|
||||||
|
|
||||||
def onFocus(self, *args, **kwargs):
|
def get_focused_post(self):
|
||||||
pass # Fix it later
|
# print self.tab.history.GetInsertionPoint()
|
||||||
# msg = self.session.db[self.name]["items"][-1]
|
position = self.tab.history.PositionToXY(self.tab.history.GetInsertionPoint())
|
||||||
# if msg.has_key("read_state") and msg["read_state"] == 0 and msg["id"] not in self.reads:
|
print position
|
||||||
# self.reads.append(msg["id"])
|
id_ = None
|
||||||
# self.session.db[self.name]["items"][-1]["read_state"] = 1
|
for i in self.chats.keys():
|
||||||
# msg = self.get_post()
|
# print i
|
||||||
# if msg.has_key("attachments") and len(msg["attachments"]) > 0:
|
if position[2] >= i[0] and position[2] <= i[1]:
|
||||||
# self.tab.attachments.list.Enable(True)
|
id_ = self.chats[i]
|
||||||
# self.attachments = list()
|
if id_ != None:
|
||||||
# self.parse_attachments(msg)
|
for i in self.session.db[self.name]["items"]:
|
||||||
# else:
|
if i["id"] == id_:
|
||||||
# self.tab.attachments.list.Enable(False)
|
print i["id"]
|
||||||
# self.tab.attachments.clear()
|
return i
|
||||||
|
return False
|
||||||
|
|
||||||
|
get_post = get_focused_post
|
||||||
|
|
||||||
|
def onFocus(self, event, *args, **kwargs):
|
||||||
|
# pass # Fix it later
|
||||||
|
if event.GetKeyCode() == wx.WXK_UP or event.GetKeyCode() == wx.WXK_DOWN:
|
||||||
|
msg = self.get_focused_post()
|
||||||
|
#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()
|
||||||
|
event.Skip()
|
||||||
|
|
||||||
def create_tab(self, parent):
|
def create_tab(self, parent):
|
||||||
self.tab = home.chatTab(parent)
|
self.tab = home.chatTab(parent)
|
||||||
@ -640,7 +663,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
|
||||||
@ -690,6 +713,7 @@ class chatBuffer(baseBuffer):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(chatBuffer, self).__init__(*args, **kwargs)
|
super(chatBuffer, self).__init__(*args, **kwargs)
|
||||||
self.reads = []
|
self.reads = []
|
||||||
|
self.chats = dict()
|
||||||
|
|
||||||
def parse_attachments(self, post):
|
def parse_attachments(self, post):
|
||||||
attachments = []
|
attachments = []
|
||||||
|
@ -176,15 +176,18 @@ class chatTab(wx.Panel):
|
|||||||
return box
|
return box
|
||||||
|
|
||||||
def set_focus_function(self, focus_function):
|
def set_focus_function(self, focus_function):
|
||||||
pass#self.history.Bind(wx.EVT_LIST_ITEM_FOCUSED, focus_function)
|
self.history.Bind(wx.EVT_CHAR_HOOK, focus_function)
|
||||||
|
|
||||||
def add_message(self, message, reverse=False):
|
def add_message(self, message, reverse=False):
|
||||||
|
old_line = self.history.GetNumberOfLines()#.count("\n")
|
||||||
point = self.history.GetInsertionPoint()
|
point = self.history.GetInsertionPoint()
|
||||||
if reversed:
|
if reversed:
|
||||||
self.history.SetValue(message+"\n"+self.history.GetValue())
|
self.history.SetValue(message+"\n"+self.history.GetValue())
|
||||||
else:
|
else:
|
||||||
self.history.AppendText(message+"\n")
|
self.history.AppendText(message+"\n")
|
||||||
self.history.SetInsertionPoint(point)
|
self.history.SetInsertionPoint(point)
|
||||||
|
new_line = self.history.GetNumberOfLines()#.count("\n")
|
||||||
|
return (old_line, new_line)
|
||||||
|
|
||||||
class peopleTab(homeTab):
|
class peopleTab(homeTab):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user