def do_send_message(message, retry=0):
            ''' this method replace the Conversation one when encode is enabled '''

            remoteMail = conversation.switchboard.firstUser
            remoteStatus = conversation.controller.contacts.get_status(
                remoteMail)

            encrypt = conversation.controller.pluginManager.getPlugin(
                "EncryptedMessage")
            if conversation.controller.pluginManager.isEnabled(
                    "EncryptedMessage") and conversation.enabledEncrypt:
                messageEncode = encrypt.encode(conversation, message)
                messageChunks = Conversation.splitMessage(messageEncode)
                message = message + _(' (send encoded) ')
            else:
                messageChunks = Conversation.splitMessage(message)

            def do_send_offline(response, mail='', message=''):
                '''callback for the confirm dialog asking to send offline
                message'''
                conversation.sendOffline = True
                conversation.switchboard.msn.msnOIM.send(mail, message)
                conversation.appendOutputText(self.user, message, 'outgoing')

            if conversation.switchboard.status == 'error' and remoteStatus == 'FLN':
                do_send_offline(stock.YES, remoteMail, message)
                return

            if conversation.switchboard.status == 'closed':
                conversation.reconnect()

            alreadyShow = False

            for chunk in messageChunks:
                try:
                    # why is conversation sending custom emoticons manually?
                    conversation.switchboard.sendCustomEmoticons(chunk)
                    conversation.switchboard.sendMessage(
                        chunk, conversation.getStyle(chunk))
                    if alreadyShow is False:
                        conversation.appendOutputText(conversation.user,
                                                      message, 'outgoing')
                        alreadySend = True

                except Exception, e:
                    raise
                    print str(e)
                    conversation.reconnect()
                    if retry < 3:
                        conversation.do_send_message(
                            ''.join(messageChunks[messageChunks.index(chunk):]), \
                            retry + 1)
                    else:
                        conversation.appendOutputText(None, _('Can\'t send message'), \
                            'information')
                    return
     def do_send_message(message, retry=0):
         ''' this method replace the Conversation one when encode is enabled '''
         
         remoteMail = conversation.switchboard.firstUser
         remoteStatus = conversation.controller.contacts.get_status(remoteMail)
         
         encrypt = conversation.controller.pluginManager.getPlugin("EncryptedMessage")
         if conversation.controller.pluginManager.isEnabled("EncryptedMessage") and conversation.enabledEncrypt:
             messageEncode = encrypt.encode(conversation, message)
             messageChunks = Conversation.splitMessage(messageEncode)
             message = message + _(' (send encoded) ')
         else:
             messageChunks = Conversation.splitMessage(message)
         
         
         def do_send_offline(response, mail='', message=''):
             '''callback for the confirm dialog asking to send offline
             message'''
             conversation.sendOffline = True
             conversation.switchboard.msn.msnOIM.send(mail, message)
             conversation.appendOutputText(self.user, message, 'outgoing')
 
         if conversation.switchboard.status == 'error' and remoteStatus == 'FLN':
             do_send_offline(stock.YES, remoteMail, message)
             return
 
         if conversation.switchboard.status == 'closed':
             conversation.reconnect()
 
         alreadyShow = False
         
         for chunk in messageChunks:
             try:
                 # why is conversation sending custom emoticons manually?
                 conversation.switchboard.sendCustomEmoticons(chunk)
                 conversation.switchboard.sendMessage(chunk, conversation.getStyle(chunk))
                 if alreadyShow is False:
                     conversation.appendOutputText(conversation.user, message, 'outgoing')
                     alreadySend = True
                     
             except Exception, e:
                 raise
                 print str(e)
                 conversation.reconnect()
                 if retry < 3:
                     conversation.do_send_message(
                         ''.join(messageChunks[messageChunks.index(chunk):]), \
                         retry + 1)
                 else:
                     conversation.appendOutputText(None, _('Can\'t send message'), \
                         'information')
                 return        
    def openConversation(self, msnp, mail, weStarted, switchboard=None):
        '''opens a new conversation and a new window or tab'''

        # create new switchboard if needed
        if switchboard is None:
            switchboard = msnp.newSwitchboard()
            switchboard.invite(mail)

        conversation = Conversation.Conversation(self.controller, switchboard)

        # add a tab if we use tabs and if there is a window open already
        useTabs = not self.config.user['windows']
        if useTabs and len(self.conversations) > 0:
            # open a new tab
            window = self.conversations[0][0]
            window.openTab(conversation)
            if weStarted:
                window.present()
        else:
            # open a new window
            window = ConversationWindow.ConversationWindow(
                self.controller, conversation)
            window.show()
            if self.config.user['hideNewWindow'] and not weStarted:
                window.iconify()

        conversation.setWindow(window)
        window.set_icon(conversation.getWindowIcon())
        self.conversations.append((window, conversation))
        self.emit('new-conversation-ui', conversation, window)

        return window, conversation
Beispiel #4
0
 def parse_data_to_case_class(input):
     conversations = []
     with open(input["data_path"] + ".json", encoding="utf8") as data:
         print("Successfully opened " + input["data_path"] + ".json...")
         for conversation in ijson.items(data,
                                         'conversations.conversation.item'):
             id = conversation["@id"]
             messages = []
             for message in conversation["message"]:
                 messages.append(
                     Message.Message(message["author"], message["time"],
                                     str(message["text"])))
             conversations.append(Conversation.Conversation(id, messages))
     return conversations
Beispiel #5
0
    def _on_conversation_request(self, message):
        '''handle a conversation request, example
        RNG 1581441881 64.4.37.33:1863 CKI 252199185.167235214
        [email protected] tuza U messenger.msn.com'''
        session_id = message.tid
        (chost, auth_type, auth_id, user, username, unk, server, unk2) = \
        message.params

        (host, port) = chost.split(':')

        cid = time.time()
        con = Conversation.Conversation(self.session, cid, host, int(port),
                                        user, session_id, self.p2p, auth_id)
        self.conversations[cid] = con
        con.answer()
        con.start()
Beispiel #6
0
    def __init__(self, fromConversationQueue, myEndpoint, shouldRun=True):

        self.fromConversationQueue = fromConversationQueue  # Messages for app
        self.toSocketQueue = Queue.Queue()  # Messages to be sent by socket
        self.fromSocketQueue = Queue.Queue()  # Messages received by socket

        self.udpSocket = UdpConnection.UdpConnection(self.toSocketQueue,
                                                     self.fromSocketQueue,
                                                     myEndpoint)

        self.conversationFactory = Conversation.ConversationFactory()

        # Conversation Id: Conversation
        self.conversations = {}

        # Thread management
        self.shouldRun = shouldRun
        thread.start_new_thread(self.__run, ())
Beispiel #7
0
def generate_conversations(maze, screen, prompt, C1, C2, R1, R2,
                           conversationCurrent):
    """generates and asssociates locations of convos as a dictionary. 
    keys are tuples of the location
    returns said dictionary
    all conversation writing should be done here!!"""

    #generating random non-wall locations as tuples
    random.shuffle(maze)
    convoLocations = []

    # adding each convo object paired with its location as a key
    conversationDic = {}

    for x in range(15):
        convoLocation = maze[x]
        convoLocations.append(tuple(convoLocation))
        conversationDic[convoLocations[x]] = Conversation.Base_conversation(
            prompt[conversationCurrent], C1[conversationCurrent],
            C2[conversationCurrent], "correctAns", R1[conversationCurrent],
            R2[conversationCurrent], screen)

    return conversationDic
Beispiel #8
0
    def _on_conversation_transfer(self, message):
        '''handle a message that inform us that we must start a new switchboard
        with a server'''
        # XFR 10
        # SB 207.46.27.178:1863 CKI 212949295.5321588.019445 U
        # messenger.msn.com 1

        if len(message.params) == 6:
            (sb_, chost, cki, session_id, unk, server) = message.params
        else:
            (sb_, chost, cki, session_id, unk, server, one) = message.params

        (host, port) = chost.split(':')
        account, cid = self.pending_conversations[int(message.tid)]
        messages = self.pending_messages[cid]

        del self.pending_conversations[int(message.tid)]
        del self.pending_messages[cid]

        if cid in self.pending_cids:
            self.pending_cids.remove(cid)

        if cid not in self.conversations:
            con = Conversation.Conversation(self.session, cid, host, int(port),
                                            account, session_id, self.p2p,
                                            self.proxy)
            self.conversations[cid] = con
            con.send_presentation()
            con.invite(account)
            con.start()
        else:
            con = self.conversations[cid]
            con.reconnect(host, int(port), session_id)

        # send all the pending messages
        for message in messages:
            con.send_message(message)
 def __init__(self, parent,editor, convo=None, convoName=""):
     base.le.ui.bindKeyEvents(False)
     # TODO: onclose, unbind?
     
     self.parent = parent
     self.editor = editor
     self.convoName = convoName
     #print "Type:::", type(editor)
     # Will determine the UI (colors) and 'speaker' data of lines created
     # True: Makes a conversation between two characters, each alternating.  Two speaker types: 'player' and 'npc'
     self.isCharacterConversation = True
     self.changesSinceLastSave = False
     
     if convo == None:
         self.conversation = Conversation() # make an new, empty conversation to edit
         #firstLine = ConversationLine(1, SpeakerType.NPC)
         #self.conversation.addLine(firstLine)
         #self.convoName = ""
     else:
         self.conversation = convo
         #self.convoName = "existing_conversation"
     self.lastUsedLineID = self.conversation.getRootLine().getID()
     
     self.__setup_frame()
class ConversationEditor(wx.Frame):
    def __init__(self, parent,editor, convo=None, convoName=""):
        base.le.ui.bindKeyEvents(False)
        # TODO: onclose, unbind?
        
        self.parent = parent
        self.editor = editor
        self.convoName = convoName
        #print "Type:::", type(editor)
        # Will determine the UI (colors) and 'speaker' data of lines created
        # True: Makes a conversation between two characters, each alternating.  Two speaker types: 'player' and 'npc'
        self.isCharacterConversation = True
        self.changesSinceLastSave = False
        
        if convo == None:
            self.conversation = Conversation() # make an new, empty conversation to edit
            #firstLine = ConversationLine(1, SpeakerType.NPC)
            #self.conversation.addLine(firstLine)
            #self.convoName = ""
        else:
            self.conversation = convo
            #self.convoName = "existing_conversation"
        self.lastUsedLineID = self.conversation.getRootLine().getID()
        
        self.__setup_frame()
        
    def __setup_frame(self):

        self.res = xrc.XmlResource(EDITOR_XRC_FILENAME)
        self.frame = self.res.LoadFrame(self.parent, 'mainFrame')
        
        #print 'res', self.res
        #print 'frame', self.frame
        
        #self.frame.SetTitle(FRAME_TITLE) # will overwrite title in XRC file
        
        self.frame.Bind(wx.EVT_CLOSE, self.onClose)
        
        self.convoTreeCtrl = xrc.XRCCTRL(self.frame, 'convoTreeCtrl')
        self.addChildBtn = xrc.XRCCTRL(self.frame, 'addChildBtn')
        self.delNodeBtn = xrc.XRCCTRL(self.frame, 'delNodeBtn')
        self.moveUpBtn = xrc.XRCCTRL(self.frame, 'moveUpBtn')
        self.moveDownBtn = xrc.XRCCTRL(self.frame, 'moveDownBtn')
        self.expandAllBtn = xrc.XRCCTRL(self.frame, 'expandAllBtn')
        self.collapseAllBtn = xrc.XRCCTRL(self.frame, 'collapseAllBtn')
        self.infoText = xrc.XRCCTRL(self.frame, 'infoText')
        
        self.lineText = xrc.XRCCTRL(self.frame, 'lineText')
        self.linkChoice = xrc.XRCCTRL(self.frame, 'linkChoice')
        self.lineText_rb = xrc.XRCCTRL(self.frame, 'lineText_rb')
        self.linkChoice_rb = xrc.XRCCTRL(self.frame, 'linkChoice_rb')
        
        self.saveBtn = xrc.XRCCTRL(self.frame, 'saveBtn')
        
        self.convoTreeCtrl.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSelectionChange)
        self.addChildBtn.Bind(wx.EVT_BUTTON, self.onAddChild)
        self.delNodeBtn.Bind(wx.EVT_BUTTON, self.onDelNode)
        self.moveUpBtn.Bind(wx.EVT_BUTTON, self.onMoveLineUp)
        self.moveDownBtn.Bind(wx.EVT_BUTTON, self.onMoveLineDown)
        self.expandAllBtn.Bind(wx.EVT_BUTTON, self.onExpandAll)
        self.collapseAllBtn.Bind(wx.EVT_BUTTON, self.onCollapseAll)
        self.saveBtn.Bind(wx.EVT_BUTTON, self.onSave)
        
        self.lineText.Bind(wx.EVT_TEXT, self.onTextChange)
        self.linkChoice.Bind(wx.EVT_CHOICE, self.onChooseLink)
        self.lineText_rb.Bind(wx.EVT_RADIOBUTTON, self.onChooseLineType)
        self.linkChoice_rb.Bind(wx.EVT_RADIOBUTTON, self.onChooseLineType)

        self.lineText_rb.SetValue(True)

        self.processedLineIDs = set()
        self.originalTreeItems = {SpeakerType.PLAYER:[], SpeakerType.NPC:[]} # maps SpeakerType to a list of ConversationLine IDs (as strings) which are active in the conversation
        self.loadConversation()
        # expand the root node to show the first line
        self.convoTreeCtrl.Expand(self.convoTreeCtrl.GetRootItem())
        
        self.notebook = xrc.XRCCTRL(self.frame, 'notebook_1')
        
        self.pageTwo = ConditionPropertyPanel(self.notebook, self.editor, CONDITION_PANEL_XRC_FILENAME)
        self.notebook.AddPage(self.pageTwo, "Conditions")
        
        self.pageThree = ConversationScriptPanel(self.notebook, self.editor, SCRIPT_PANEL_XRC_FILENAME)
        self.notebook.AddPage(self.pageThree, "Scripts")
        
        self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.onNotebookPageChanging)
        

        self.frame.Show()
        self.frame.Layout()
    
    def onExpandAll(self, event=None):
        self.convoTreeCtrl.ExpandAllChildren(self.convoTreeCtrl.GetRootItem())
        
    def onCollapseAll(self, event=None):
        self.convoTreeCtrl.CollapseAllChildren(self.convoTreeCtrl.GetRootItem())
    
    def onMoveLineDown(self, event):
        parentTreeID = self.convoTreeCtrl.GetItemParent(self.selectedTreeItem)
        parentLineID = self.getIDs(parentTreeID)['curID'] # CONSIDER: should this be uniqID?
        parentLine = self.conversation.getLine(parentLineID)
        
        selectedLineID = self.getIDs(self.selectedTreeItem)['curID']
        selectedLine = self.conversation.getLine(selectedLineID)
        
        parentLine.moveSuccessorDown(selectedLineID)
        
        self.refreshTreeUI()
        self.onSelectionChange()
        self.onExpandAll()
        
#        swapTreeID = self.convoTreeCtrl.GetNextSibling(self.selectedTreeItem)
#        swapLineID = self.getIDs(swapTreeID)['curID']
#        swapLine = self.conversation.getLine(swapLineID)
#        
#        if swapTreeID.IsOk():
#            swapTreeID_new = self.convoTreeCtrl.InsertItem(parentTreeID, self.selectedTreeItem, swapLine.getText())
#            swapTreeID_new.
#            self.setIDs(swapTreeID_new, {'uniqID':self.getIDs(swapTreeID)['uniqID'], 'curID':self.getIDs(swapTreeID)['curID']}) # all new lines are original (not links) by default
#            
#        self.convoTreeCtrl.SelectItem(self.selectedTreeItem)
    
    def onMoveLineUp(self, event):
        parentTreeID = self.convoTreeCtrl.GetItemParent(self.selectedTreeItem)
        parentLineID = self.getIDs(parentTreeID)['curID'] # CONSIDER: should this be uniqID?
        parentLine = self.conversation.getLine(parentLineID)
        
        selectedLineID = self.getIDs(self.selectedTreeItem)['curID']
        selectedLine = self.conversation.getLine(selectedLineID)
        
        parentLine.moveSuccessorUp(selectedLineID)
        
        self.refreshTreeUI()
        self.onSelectionChange()
        self.onExpandAll()
    
    def onNotebookPageChanging(self, event):
        if self.linkChoice_rb.GetValue():
            event.Veto()
            dlg = wx.MessageDialog(self.frame, "Cannot edit the conditions or scripts of a linked line.  You can either unlink this line and then edit it, or edit the line it links to.", "Cannot Edit", 
                                   style = wx.OK | wx.ICON_HAND)
            dlg.ShowModal()
            dlg.Destroy()
        elif self.getIDs(self.selectedTreeItem)['curID'] == self.conversation.getRootLine().getID(): 
            event.Veto()
            dlg = wx.MessageDialog(self.frame, "Cannot edit the conditions or scripts of the root line, since it never appears in the game.", "Cannot Edit", 
                                   style = wx.OK | wx.ICON_HAND)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            self.changesSinceLastSave = True
    
    def onChooseLink(self, event):
        self.changesSinceLastSave = True
        #print 'change made...onChooseLink'
        index = event.GetSelection()
        self.updateLinkChoice(index)
    
    
    def updateLinkChoice(self, selectionIndex):
        if self.linkChoice_rb.GetValue():
            IDs = self.getIDs(self.selectedTreeItem)
            line = self.conversation.getLine(IDs['curID'])
            
            parentTreeID = self.convoTreeCtrl.GetItemParent(self.selectedTreeItem)
            parentLineID = self.getIDs(parentTreeID)['curID'] # CONSIDER: should this be uniqID?
            parentLine = self.conversation.getLine(parentLineID)
            
            linkLineID = int(self.originalTreeItems[line.getSpeaker()][selectionIndex])
            
            # temp
            #print 'choice selection index = %d' %(selectionIndex)
            
            test1 = parentLine.removeSuccessor(IDs['curID'])
            if not test1: # temp
                print 'ERROR: removal of successor from parent failed!'
            test2 = parentLine.addSuccessor(linkLineID)
            if not test2: # temp
                print 'ERROR: adding successor to parent failed!'
            
            # remove the unique ID of this line from the list of original lines in the tree for link selection
            if str(IDs['uniqID']) in self.originalTreeItems[line.getSpeaker()]: 
                self.originalTreeItems[line.getSpeaker()].remove(str(IDs['uniqID']))
                self.originalTreeItems[line.getSpeaker()].sort()
                self.linkChoice.SetItems(self.originalTreeItems[line.getSpeaker()])
            
            # set the curID to match the link's ID
            IDs['curID'] = linkLineID
            self.setIDs(self.selectedTreeItem, IDs)
            
            # update the UI of the tree item
            self.updateTreeItemUI(self.selectedTreeItem)
    
    def onChooseLineType(self, event):
        self.changesSinceLastSave = True
        #print 'change made...onChooseLineType'
        
        IDs = self.getIDs(self.selectedTreeItem)
        line = self.conversation.getLine(IDs['curID'])
        
        parentTreeID = self.convoTreeCtrl.GetItemParent(self.selectedTreeItem)
        parentLineID = self.getIDs(parentTreeID)['curID'] # CONSIDER: should this be uniqID?
        parentLine = self.conversation.getLine(parentLineID)
        
        if self.lineText_rb.GetValue(): # make this line an original line
            if IDs['uniqID'] == LineIDType.UNASSIGNED:
                # is a link, but has no assigned unique ID and so is not in the conversation
                newID = self.generateUnusedLineID()
                IDs['uniqID'] = newID
                newLine = ConversationLine(newID, line.getSpeaker())
                self.conversation.addLine(newLine)
                
            
            # change the successors of the parent
            test1 = parentLine.removeSuccessor(IDs['curID'])
            if not test1: # temp
                print 'ERROR: removal of successor from parent failed!'
            test2 = parentLine.addSuccessor(IDs['uniqID'])
            if not test2: # temp
                print 'ERROR: adding successor to parent failed!'
            
            # set the curID to match the original uniqID
            IDs['curID'] = IDs['uniqID']
            self.setIDs(self.selectedTreeItem, IDs)
            
            # add the unique ID of this line to the list of original lines in the tree for link selection
            if str(IDs['curID']) not in self.originalTreeItems[line.getSpeaker()]:
                self.originalTreeItems[line.getSpeaker()].append(str(IDs['curID']))
                self.originalTreeItems[line.getSpeaker()].sort()
                self.linkChoice.SetItems(self.originalTreeItems[line.getSpeaker()])
            
            # make text reflect the change
            event = wx.CommandEvent(wx.wxEVT_COMMAND_TEXT_UPDATED)
            event.SetEventObject(self.lineText)
            event.SetId(self.lineText.GetId())
            self.onTextChange(event)
        
        elif self.linkChoice_rb.GetValue():
            self.updateLinkChoice(self.linkChoice.GetSelection())
#            # change the successors of the parent
#            linkID = 0
#            if line.getSpeaker() == SpeakerType.NPC:
#                linkID = 1 # temp
#            
#            test1 = parentLine.removeSuccessor(IDs['curID'])
#            if not test1: # temp
#                print 'ERROR: removal of successor from parent failed!'
#            test2 = parentLine.addSuccessor(linkID)
#            if not test2: # temp
#                print 'ERROR: adding successor to parent failed!'
#            
#            # remove the unique ID of this line from the list of original lines in the tree for link selection
#            self.originalTreeItems[line.getSpeaker()].remove(str(IDs['curID']))
#            self.linkChoice.SetItems(self.originalTreeItems[line.getSpeaker()])
#            
#            # set the curID to match the link's ID
#            IDs['curID'] = linkID
#            self.setIDs(self.selectedTreeItem, IDs)


#            event = wx.CommandEvent(wx.wxEVT_COMMAND_CHOICE_SELECTED)
#            event.SetEventObject(self.linkChoice)
#            event.SetId(self.linkChoice.GetId())
#            self.onChooseLink(event)
            
        
        # update the UI of the tree item
        self.updateTreeItemUI(self.selectedTreeItem)

    def updateTreeItemUI(self, treeID):
        lineID = self.getIDs(treeID)['curID']
        line = self.conversation.getLine(lineID)
        self.convoTreeCtrl.SetItemTextColour(treeID, SpeakerType.typeAsColor(line.getSpeaker()))
        if self.isOriginalLine(treeID):
            self.convoTreeCtrl.SetItemBold(treeID, bold=False)
            self.convoTreeCtrl.SetItemText(treeID, self.generateTreeText(line))
            self.infoText.SetLabel('Line ID: %d, Speaker: %s' %(lineID, line.getSpeaker()))
        else:
            self.convoTreeCtrl.SetItemBold(treeID, bold=True)
            self.convoTreeCtrl.SetItemText(treeID, ' <<LINK>> ' + self.generateTreeText(line))
            self.infoText.SetLabel('LINK TO: %d, Speaker: %s' %(lineID, line.getSpeaker()))

    def onAddChild(self, event):
        self.changesSinceLastSave = True
        #print 'change made...onAddChild'
        
        selectedLineID = self.getIDs(self.selectedTreeItem)['curID'] # CONSIDER: should this be uniqID?
        selectedLine = self.conversation.getLine(selectedLineID)
        childSpeaker = SpeakerType.PLAYER
        if self.isCharacterConversation and (selectedLine.getSpeaker() == SpeakerType.PLAYER):
            childSpeaker = SpeakerType.NPC
    
        # Make a new ConversationLine with an unused ID and the correct speaker type
        childLineID = self.generateUnusedLineID()
        childLine = ConversationLine(childLineID, childSpeaker, '')
        
        # Add the line to the Conversation object
        self.conversation.addLine(childLine)
        
        # Add the line to the Tree
        treeID = self.convoTreeCtrl.AppendItem(self.selectedTreeItem, self.generateTreeText(childLine))
        self.setIDs(treeID, {'uniqID':childLineID, 'curID':childLineID}) # all new lines are original (not links) by default
        self.updateTreeItemUI(treeID)
        
        # Add the line to the list of possible links
        self.originalTreeItems[childSpeaker].append(str(childLineID))
        self.linkChoice.SetItems(self.originalTreeItems[childSpeaker])
        
        # Add the line to the successors of its parent (currently selected)
        self.conversation.getLine(selectedLineID).addSuccessor(childLineID)
        
        # Select the new line
        self.convoTreeCtrl.SelectItem(treeID) # CONSIDER: alternatively, expand the parent and don't select the new line
        
        # TODO: after adding a new line, but having it link to an old line after clicking button,
        # MAKE SURE that the new line does not overwrite the old line with the same ID...
    
    def onDelNode(self, event):
        self.changesSinceLastSave = True
        #print 'change made...onDelNode'
        
        parentTreeID = self.convoTreeCtrl.GetItemParent(self.selectedTreeItem)
        parentLineID = self.getIDs(parentTreeID)['curID'] # CONSIDER: should this be uniqID?
        selectedLineID = self.getIDs(self.selectedTreeItem)['curID']
        selectedLine = self.conversation.getLine(selectedLineID)
        
        # Remove the unique ID from the list of possible links, if it is there
        uniqIDString = str(self.getIDs(self.selectedTreeItem)['uniqID'])
        if uniqIDString in self.originalTreeItems[selectedLine.getSpeaker()]:
            #print 'removing uniqID %s from list of possible links (curID = %s)' %(str(self.getIDs(self.selectedTreeItem)['uniqID']), str(self.getIDs(self.selectedTreeItem)['curID']))
            self.originalTreeItems[selectedLine.getSpeaker()].remove(uniqIDString)
            self.linkChoice.SetItems(self.originalTreeItems[selectedLine.getSpeaker()])
        
        # Remove the line from the successors of its parent
        self.conversation.getLine(parentLineID).removeSuccessor(selectedLineID)
        
        # TODO: if it was the last instance of that line in the conversation, delete it from the Conversation self.lines dict
        
        # After done using the ConversationLine data of the line to be removed, remove the line and its children from the Tree
        self.convoTreeCtrl.DeleteChildren(self.selectedTreeItem)
        self.convoTreeCtrl.Delete(self.selectedTreeItem) # will this mess up keeping track of selectedTreeItem, or does it generate an sel changed event?

    def onSelectionChange(self, event=None):
        if event != None:
            self.selectedTreeItem = event.GetItem()
        
        selLineID = self.getIDs(self.selectedTreeItem)['curID']
        selLine = self.conversation.getLine(selLineID)
        #self.infoText.SetLabel('Line ID: %d, Speaker: %s' %(selLineID, selLine.getSpeaker()))
        
        if self.isOriginalLine(self.selectedTreeItem):
            self.lineText_rb.SetValue(True)
        else:
            self.linkChoice_rb.SetValue(True)
        
        self.updateTreeItemUI(self.selectedTreeItem)
        self.lineText.ChangeValue(self.conversation.getLine(selLineID).getText()) # does not send a EVT_TEXT
        self.linkChoice.SetItems(self.originalTreeItems[selLine.getSpeaker()])
        if str(selLineID) in self.originalTreeItems[selLine.getSpeaker()]:
            self.linkChoice.SetSelection(self.originalTreeItems[selLine.getSpeaker()].index(str(selLineID)))
        else:
            pass
        self.pageTwo.updateProps(selLine)
        self.pageTwo.update()
        self.pageThree.updateProps(selLine)
        self.pageThree.update()
        
        if selLineID == self.conversation.getRootLine().getID():
            self.delNodeBtn.Disable()
            self.lineText.Disable()
            self.linkChoice.Disable()
            self.lineText_rb.Disable()
            self.linkChoice_rb.Disable()
            self.moveUpBtn.Disable()
            self.moveDownBtn.Disable()
            self.notebook.ChangeSelection(0)
        else:
            self.delNodeBtn.Enable()
            self.lineText.Enable()
            self.linkChoice.Enable()
            self.lineText_rb.Enable()
            self.linkChoice_rb.Enable()
            self.moveUpBtn.Enable()
            self.moveDownBtn.Enable()

    def onTextChange(self, event):
        self.changesSinceLastSave = True
        #print 'change made...onTextChange'
        
        # CONSIDER: remove for efficiency, only overwrite on selection changes and user save
        if self.isOriginalLine(self.selectedTreeItem):
            changedText = event.GetString()
            
            # Change the text of the ConversationLine data
            selLineID = self.getIDs(self.selectedTreeItem)['curID']
            selLine = self.conversation.getLine(selLineID)
            selLine.setText(changedText)
            
            # Change the text in the TreeCtrl with the updated ConversationLine
            self.convoTreeCtrl.SetItemText(self.selectedTreeItem, self.generateTreeText(selLine))

    def generateTreeText(self, convoLine):
        return '(%d | %s) ' %(convoLine.getID(), convoLine.getSpeaker()) + convoLine.getText()

    def generateUnusedLineID(self):
        while self.conversation.hasLine(self.lastUsedLineID):
            self.lastUsedLineID += 1
        return self.lastUsedLineID

    def getIDs(self, treeID):
        # TODO: do not allow if it is the root; it has no data...
        try:
            dataDict = self.convoTreeCtrl.GetItemData(treeID).GetData()
            return dataDict
        except:
            print 'Undefined error: This tree item has no data associated with it'
    
    def setIDs(self, treeID, dict):
        d = wx.TreeItemData()
        d.SetData(dict)
        self.convoTreeCtrl.SetItemData(treeID, d)

    def isOriginalLine(self, treeID):
        dataDict = self.convoTreeCtrl.GetItemData(treeID).GetData()
        uniqID = dataDict['uniqID']
        curID = dataDict['curID']
        return (uniqID == curID)

    def onSave(self, event=None):
#        dlg = wx.FileDialog(self.frame, "Choose a location to save the source file", \
#        defaultDir= base.le.currentProj.dir.toOsSpecific(),\
#        defaultFile = 'conversation' + '.xml', wildcard="*.xml", style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
        
        dlg = wx.TextEntryDialog(self.frame, "Choose a name for this conversation", defaultValue=self.convoName)    
        
        if dlg.ShowModal() == wx.ID_OK:
            name = dlg.GetValue()
            if name in base.le.lib.conversations:
                messageDlg = wx.MessageDialog(self.frame, "\"%s\" already exists, do you want to overwrite?" %(name))
                if messageDlg.ShowModal() == wx.ID_OK:
                    #print 'overwrite it'
                    base.le.lib.removeConversation(name)
                else:
                    #print 'do not overwrite it'
                    messageDlg.Destroy()
                    return
            else:
                self.convoName = name
                
            base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
            
            #== Create temporary XML file for the asset
            doc = xml.dom.minidom.Document()
            root = doc.createElement("the_root")
            doc.appendChild(root)
            root.appendChild(self.conversation.encode(doc))
            
            tempFilePath = base.le.lib.projDir.toOsSpecific() + '/' + name + '.xml'
            assetFilename = Filename(tempFilePath)
            #print 'temporary file path for asset: ' + assetFilename.toOsSpecific()
    
            f = open(assetFilename.toOsSpecific(), 'w')
            f.write(doc.toxml())
            f.close()
            
            #== Make an Asset based on the temporary source file and add it to the library
            asset = ConversationAsset(name, assetFilename)
            base.le.lib.addConversation(asset, True)
            base.le.ui.storyObjUI.update()
            
            #== Remove the temporary source file
            tempFilename = Filename(tempFilePath)
            #print 'temporary file path to now delete: ' + tempFilename.toOsSpecific()
            os.remove(tempFilename.toOsSpecific())
            
            self.changesSinceLastSave = False
            
            base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) 
            
            #print 'added to library...'
    
    def onClose(self, event):
        if self.changesSinceLastSave:
            messageDlg = wx.MessageDialog(self.frame, "Save this conversation before closing?", style=wx.YES_NO)
            if messageDlg.ShowModal() == wx.ID_YES:
                #print 'save on exit? : yes'
                self.onSave()
            else:
                #print 'save on exit? : no'
                messageDlg.Destroy()
        #self.frame.Destroy()
        event.Skip() # finish the rest of the closing process

    def refreshTreeUI(self):
        self.convoTreeCtrl.DeleteAllItems()
        self.loadConversation()

    def loadConversation(self):
        self.processedLineIDs.clear()
        self.originalTreeItems.clear()
        self.originalTreeItems = {SpeakerType.PLAYER:[], SpeakerType.NPC:[]} # maps SpeakerType to a list of ConversationLine IDs (as strings) which are active in the conversation
        
        rootLine = self.conversation.getRootLine()
        rootLineID = rootLine.getID()
        self.lastUsedLineID = rootLineID
        rootTreeID = self.convoTreeCtrl.AddRoot(self.generateTreeText(rootLine))
        self.setIDs(rootTreeID, {'uniqID':rootLineID, 'curID':rootLineID})
        
        self.updateTreeItemUI(rootTreeID) # the root is always a player node
        
        self.selectedTreeItem = rootTreeID # CAUTION
        self.processedLineIDs.add(rootLineID)
        for succID in rootLine.getSuccessors():
            self.rec_loadConvoTree(rootTreeID, succID)

    def rec_loadConvoTree(self, parentTreeID, lineID):
        line = self.conversation.getLine(lineID)
        #print 'id %d, %s' %(lineID, line.getSpeaker())
        treeID = self.convoTreeCtrl.AppendItem(parentTreeID, self.generateTreeText(line))
        
        if not lineID in self.processedLineIDs:
            self.processedLineIDs.add(lineID)
            self.originalTreeItems[line.getSpeaker()].append(str(lineID))
            self.setIDs(treeID, {'uniqID':lineID, 'curID':lineID})
            for succID in line.getSuccessors():
                self.rec_loadConvoTree(treeID, succID)
        else:
            self.setIDs(treeID, {'uniqID':LineIDType.UNASSIGNED, 'curID':lineID})
        
        self.updateTreeItemUI(treeID)
Beispiel #11
0
def generate_conversations(maze, screen):
    """generates and asssociates locations of convos as a dictionary. 
    keys are tuples of the location
    returns said dictionary
    all conversation writing should be done here!!"""

    #generating random non-wall locations as tuples
    random.seed()
    convoLocations = []
    for x in range(5):  # Fix me before end
        while True:
            convoLocation = [random.randint(0, 19), random.randint(0, 19)]
            if maze[convoLocation[0]][convoLocation[1]] == 1:
                convoLocations.append(tuple(convoLocation))
                break

    # adding each convo object paired with its location as a key
    conversationDic = {}
    """ create a new:

            conversationDic[convoLocations[n]] = Conversation.Base_conversation
            ("nPrompt","option1","option2", "correctAns", "nPositiveResponse", "nNegativeResponse",screen)

        for each conversation we want added. ADD ONE TO N EACH TIME, AND MAKE SURE RANGE IN
        LINE 15 IS THE TOTAL NUMBER OF CONVERSATIONS)"""

    #convo 1
    conversationDic[convoLocations[0]] = Conversation.Base_conversation(
        "OH, well hello there. Pretty fine day, huh? Pretty fine maze?",
        "I mean, sure, yeah, it's a pretty fine maze, a bit simple maybe.",
        "THIS MAZE IS TRANCH, MAN.",
        "I mean, sure, yeah, it's a pretty fine maze, a bit simple maybe.",
        "Huh... that's... pretty bold of you, dog, to suggest_that this is a simple space. You know people have to like,_carve this junk out, right? Well, whatever, you should be out in a jiffy,_then. If it's so simple.",
        "... Well you're about to get it right in the_exactly where it's coming to you, friend.",
        screen)

    #convo 2
    conversationDic[convoLocations[1]] = Conversation.Base_conversation(
        "HUH, look at that! It's almost like there's some_contingency plan to donk up fools like you who_think this place is simple. Wild days.",
        "It uh, still looks pretty easy, though.",
        "What the- let me out of here you dillweed!",
        "It uh, still looks pretty easy, though.",
        "Thank goodness it probably only switches_things up on you once then, huh?",
        "IT'S A SIMPLE MAZE, GET YOURSELF OUT, DILLWEED", screen)

    #convo 3
    conversationDic[convoLocations[2]] = Conversation.Base_conversation(
        "Oh boy, you're still stuck in this *super* simple maze,_huh? It's almost like, I don't know, you've been asked to do some_sort of complex task that doesn't just happen in the blink of an eye._Sometimes you've got to spend like, 24 hours on this kind of thing._It's hard business.",
        "I'm only struggling because I've gotten little to no sleep.",
        "You're hard business.",
        "I'm only struggling because I've gotten little to no sleep.",
        "You and everyone else in this Ether, fool.",
        "NO YOU'RE HARD BUSINESS.", screen)

    #convo 4
    conversationDic[convoLocations[3]] = Conversation.Always_wrong_conversation(
        "Still here, loser?", "You're pretty blatantly unkind, you know that?",
        "Shut the fu-", "correctAns",
        "Right back at you my dude. You know what, get out of here,_this is as lame as the day you were born.",
        "Right back at you my dude. You know what, get out of here,_this is as lame as the day you were born.",
        screen)

    #convo 5
    conversationDic[convoLocations[4]] = Conversation.Base_conversation(
        " AHAHAHAHA, I TOTALLY GO YOU, YOU FOOL, YOU WAD.",
        "Please make this hackathon stop. I mean... maze? What the...",
        "Why aren't you a physical entity I can punch? ",
        "Please make this hackathon stop. I mean... maze? What the...",
        "My days, what sort of whacked out_astral plane are you on right now?_Alright dog, get out of here for real time. Get some sleep.",
        "Voice from the Ether: Yeah, they didn't have time for that. Okay, okay, you can actually go now. Even I'm bored.",
        screen)

    return conversationDic
Beispiel #12
0
import speech_recognition as sr
import logging
import Conversation as Cv

if __name__ == '__main__':

    r = sr.Recognizer()
    while True:
        with sr.Microphone() as source:

            r.adjust_for_ambient_noise(source)
            print("have a conversation with the machine: ")
            order = r.listen(source)

            try:

                Order = r.recognize_google(order, language='en-US')
                print("You said: " + Order)
                Cv.conversation(Order)

            except Exception as e:
                logging.exception(e)
                Cv.error_msg()