def loadChat( self, chat=None ): # when the user clicks on Person in listBox3 this function is called and loads the correct chat and sets up everything needed to start the communication if not chat: if self.listBox3.curselection()[0] or self.listBox3.curselection( )[0] == 0: selection = self.listBox3.curselection()[ 0] # this gives an int value: first element = 0 if selection or selection == 0: # if something is selected self.partner[0] = self.person_list[int(selection)][0] self.partner[1] = self.person_list[int(selection)][1] else: if self.partner[0] != chat[0]: self.partner[0] = chat[0] self.partner[1] = chat[1] for i in range(len(self.person_list)): if self.person_list[i][1] == self.partner[1]: self.person_list[i][2] = time.time() chat_type = self.chat_function.get_full_chat( 'chat', self.feed_id, self.partner[1])[0][0].split("#split:#")[ 3] # get the type of the chat (private or group) if chat_type == "private": self.username_label.config( text=TextWrapper.shorten_name(self.partner[0], 34)) else: # chat_type == "group" self.username_label.config( text=TextWrapper.shorten_name(self.partner[0], 27) + " (" + self.partner[1] + ")") self.updateContent(self.partner[1])
def __init__(self, frame_image, font, npc): super().__init__() self.image = copy.copy(frame_image) self.dialogue_box = pygame.Surface((800, 200), pygame.SRCALPHA, 32) self.rect = self.image.get_rect() self.rect.x = 0 self.rect.y = 385 self.dialogue_box_rect = self.dialogue_box.get_rect() TextWrapper.drawText(self.dialogue_box, npc.dialogue, (0, 0, 0), self.dialogue_box_rect, font) self.image.blit(self.dialogue_box, (204, 16)) self.image.blit(npc.close_up, (12, 12))
def addPartners(self): self.listBox3.delete(0, 'end') self.personList.sort(key=lambda x: self.get_time_of_last_message(x[1]), reverse=True) for i in range(len(self.personList)): counter = self.check_for_new_messages(i) if self.partner[1] == self.personList[i][1]: counter = 0 self.listBox3.insert( 'end', TextWrapper.mergeNameCounter(self.personList[i][0], counter, 25)) if counter != 0: self.listBox3.itemconfig(i, bg='#dfd') else: #print("No new messages in chat",i) self.listBox3.itemconfig(i, bg="white") #self.listBox3.insert('end', '') # TODO: hans usegnoh zum teste # Opening the first Chat by default if len(self.personList) != 0: #set the first person as partner: if self.partner[0] == "": self.loadChat(self.personList[0]) else: # personlist empty or variable partner isn't empty self.username_label.config(text="")
def addPartners(self): self.listBox3.delete(0, 'end') self.person_list.sort(key=lambda x: self.chat_function.get_full_chat( 'chat', self.feed_id, x[1])[-1][1], reverse=True) for i in range(len(self.person_list)): counter = self.check_for_new_messages(i) if self.partner[1] == self.person_list[i][1]: counter = 0 self.listBox3.insert( 'end', TextWrapper.mergeNameCounter(self.person_list[i][0], counter)) if counter != 0: self.listBox3.itemconfig(i, bg='#dfd') else: self.listBox3.itemconfig(i, bg="white") # Opening the first Chat by default if len(self.person_list) != 0: # Choose the partner as first person: if self.partner[0] == "": self.loadChat(self.person_list[0]) else: # person_list empty or variable partner isn't empty self.username_label.config(text="")
def editDepend(infile, outfile, extraDependencies=''): file = open(infile, 'r') lines = file.readlines() file.close() # Extract target from first line groups = lines[0].split(":") target = groups[0] lines[0] = groups[1] # Replace target by absolute path # (The gcc -M option yields only the target base name) dirname = os.path.dirname(infile) if (dirname != '.' and dirname != ''): dirname = os.path.abspath(dirname) else: dirname = os.getcwd() target = os.path.normpath(os.path.join(dirname, target)) # Replace dependencies by absolute paths text = TextWrapper('\\\n', 8) for i in range(len(lines)): line = lines[i] if line[-1] == '\n': line = line[:-1] if line[-1] == '\\': line = line[:-1] lines[i] = line if i == 0: text.append(target + ': ') deps = line.split() for dep in deps: path = os.path.abspath(dep) text.append(path) # Process extraDependencies (if any) if extraDependencies: deps = extraDependencies.split() for dep in deps: path = os.path.abspath(dep) text.append(path) file = open(outfile, 'w') file.write(str(text)) file.close()
def editDependLocal(pfile, dfile, blddir, srcroot, extraDependencies): file = open(pfile, 'r') lines = file.readlines() file.close() # Extract target from first line groups = lines[0].split(":") target = groups[0] lines[0] = groups[1] # Replace target by file in build directory base = os.path.basename(target) target = os.path.normpath(os.path.join(blddir, base)) # Replace local dependencies by absolute paths text = TextWrapper('\\\n', 8) for i in range(len(lines)): line = lines[i] if line[-1] == '\n': line = line[:-1] if line[-1] == '\\': line = line[:-1] lines[i] = line if i == 0: text.append(target + ': ') deps = line.split() for dep in deps: pair = [srcroot, dep] if (os.path.commonprefix(pair) == srcroot): path = os.path.abspath(dep) text.append(path) # Process extraDependencies (if any) if extraDependencies: deps = extraDependencies.split() for dep in deps: path = os.path.abspath(dep) text.append(path) file = open(dfile, 'w') file.write(str(text)) file.close()
def addPartners(self): if len(self.person_list) != 0: self.listBox3.delete(0, 'end') self.person_list.sort( key=lambda x: self.chat_function.get_full_chat(x[1])[-1][1], reverse=True) for i in range(len(self.person_list)): counter = self.check_for_new_messages(i) if self.partner[1] == self.person_list[i][1]: counter = 0 self.listBox3.insert( 'end', TextWrapper.mergeNameCounter(self.person_list[i][0], counter)) if counter != 0: self.listBox3.itemconfig(i, bg='#dfd') else: self.listBox3.itemconfig(i, bg="white")
def editDepend(pfile, dfile, blddir, extraDependencies): file = open(pfile, "r") lines = file.readlines() file.close() # Extract target from first line groups = lines[0].split(":") target = groups[0] lines[0] = groups[1] # Replace target by file in build directory base = os.path.basename(target) target = os.path.normpath(os.path.join(blddir, base)) # Replace dependencies by absolute paths text = TextWrapper("\\\n", 8) for i in range(len(lines)): line = lines[i] if line[-1] == "\n": line = line[:-1] if line[-1] == "\\": line = line[:-1] lines[i] = line if i == 0: text.append(target + ": ") deps = line.split() for dep in deps: path = os.path.abspath(dep) text.append(path) # Process extraDependencies (if any) if extraDependencies: deps = extraDependencies.split() for dep in deps: path = os.path.abspath(dep) text.append(path) file = open(dfile, "w") file.write(str(text)) file.close()
def add(self, chatID): self.listBox1.delete(0, 'end') self.listBox2.delete(0, 'end') self.time = datetime.datetime.now() timezone = 7200 # +2h, so we have the european time in the most simplistic way chat = self.chatfunction.get_full_chat('chat', self.feed_id, chatID) chat_type = chat[0][0].split("#split:#")[ 3] #get the type of the chat (private or group) for i in range(1, len(chat)): chatMessage = chat[i][0].split( "#split:#" ) # a chat-message is like: username#split:#message, so we need to split this two username = chatMessage[0] #from who is the message message = chatMessage[1] #the real content / message additional_msg = chatMessage[2] if len(chatMessage) == 4: if chat_type == "private" and self.partner[0] == self.partner[ 1]: for i in range(len(self.personList)): if self.partner[1] == self.personList[i][1]: self.personList[i][ 0] = username #the creator of the group gets the name of his partner for the first time self.partner[0] = username self.username_label.config( text=TextWrapper.shorten_name( self.partner[0], 34)) else: # length of message == 3 #TODO: special clause for BILD and PDF_ if username != self.username: #message from the partner(s) #print the message with white background: if chat_type == "group": self.listBox1.insert('end', username + ":") try: self.listBox1.itemconfig( 'end', bg='white', foreground=HexMex.name_to_color(username)) except: self.listBox1.itemconfig( 'end', bg='white', foreground=HexMex.name_to_color("randomName")) self.listBox2.insert('end', "") if additional_msg[0:3] == "pdf": self.listBox1.insert( 'end', "Click to open pdf. (" + str(i) + ")") elif additional_msg[0:3] == "img": self.listBox1.insert( 'end', "Click to open image. (" + str(i) + ")") else: self.listBox1.insert('end', message) self.listBox1.itemconfig('end', bg='white') self.listBox1.insert( 'end', "{:<16}{:>16}".format( "", time.strftime("%H:%M %d.%m.%Y", time.gmtime(chat[i][1] + timezone)))) self.listBox1.itemconfig('end', bg='white', foreground="lightgrey") for i in range(2): self.listBox2.insert( 'end', "") # add 2 empty lines to balance both sides self.listBox1.yview(END) self.listBox2.yview(END) self.listBox1.insert('end', '') # some space to enhance appeal self.listBox2.insert('end', '') else: #username = self.username: message from the user #print the message with green background: if additional_msg[0:3] == "pdf": self.listBox2.insert( 'end', "Click to open PDF. (" + str(i) + ")") elif additional_msg[0:3] == "img": self.listBox2.insert( 'end', "Click to open image. (" + str(i) + ")") else: # == msg self.listBox2.insert('end', message) self.listBox2.itemconfig('end', bg='#dafac9') self.listBox2.insert( 'end', "{:<16}{:>16}".format( "", time.strftime("%H:%M %d.%m.%Y", time.gmtime(chat[i][1] + timezone)))) self.listBox2.itemconfig('end', bg='#dafac9', foreground="lightgrey") for i in range(2): self.listBox1.insert( 'end', "") # add 2 empty lines to balance both sides self.listBox2.yview(END) self.listBox1.yview(END) self.listBox2.insert('end', '') # some space to enhance appeal self.listBox1.insert('end', '')
def make(self): # Find all the source and header files in this directory self.find() # Recursively descend into subdirectories for dir in self.dirs: dir.make() # --------------------------------------------------------------------- # Open and write sources.mk file file = open_w(self.makePath('sources.mk')) # Include subdirectory sources.mk files if len(self.dirs) > 0: for dir in self.dirs: basename = os.path.basename(dir.path) if basename != 'tests': varpath = basename + os.sep + 'sources.mk' file.write(self.makeInclude(varpath)) file.write('\n') # Construct prefix for aggregate names if self.dirname == 'SRC': prefix = '' else: prefix = self.dirname + '_' wrapper = TextWrapper('\\\n', 4) # Write aggregate definition for SRCS wrapper.clear() wrapper.append(prefix + 'SRCS=') for dir in self.dirs: basename = os.path.basename(dir.path) if basename != 'tests': wrapper.append('$(' + dir.dirname + '_SRCS) ') for base in self.srcs: name = '$(SRC_DIR)' + os.sep + self.makePathFromSrc(base) name += '.' + self.srcSuffix() + ' ' wrapper.append(name) file.write(str(wrapper)) file.write('\n\n') # Write aggregate definition for OBJS file.write(prefix + 'OBJS=$(') file.write(prefix + 'SRCS:.' + self.srcSuffix() + '=.o)') file.write('\n\n') #file.write(prefix + 'DEPS=$(') #file.write(prefix + 'SRCS:.' + self.srcSuffix() + '=.d)') #file.write('\n\n') # Add library target, if any if self.hasLib: file.write(self.libName + ': ' + self.libObjs + '\n') file.write('\t$(AR) rcs ' + self.libName + ' ' + self.libObjs + '\n') file.write('\n') file.close() # -------------------------------------------------------------------- # Write makefile file = open(self.makePath('makefile'), 'w') file.write('SRC_DIR_REL =' + self.pathToSrc + '\n\n') file.write(self.globalInclude) if self.isTest: file.write('include $(SRC_DIR_REL)/test/sources.mk\n') file.write('include sources.mk\n') file.write('\n') if self.dirname == 'SRC': objs = 'OBJS' else: objs = self.dirname + '_OBJS' targets = '$(' + objs + ')' deps = '$(' + objs + ':.o=.d)' if self.isTest: for base in self.srcs: targets += ' ' + base file.write('all: ' + targets) if self.hasLib: file.write(' ' + self.libName) file.write('\n\n') file.write('clean:\n\trm -f ' + targets + ' ' + deps) if self.hasLib: file.write(' ' + self.libName) file.write('\n\n') file.write('clean-deps:\n\trm -f ' + deps) file.write('\n\n') if self.isTest: for base in self.srcs: file.write(base + ': ' + base + '.o ' + self.linkObjs + '\n') file.write('\t$(CXX) $(LDFLAGS) $(INCLUDES) $(DEFINES)') file.write(' -o ' + base + ' ' + base + '.o \\\n') file.write('\t ' + self.linkObjs + '\n\n') #file.write('-include $(' + objs + ':.o=.d)\n\n') file.write('-include ' + deps + '\n\n') file.close()
def add(self, username, content): # self.updateContent(self.partner) # instead of an update button, it checks for new incoming messages when/before when you send a new message: currently results in errors (Aborted (core dumped)): seems like an infinite loop self.time = datetime.datetime.now() # self.lastMessage[chatNumber] = self.time #Update last message sent from this person if username != self.username: # user updated try: wrappedContent = TextWrapper.textWrap(content, 0) print("getting message from " + self.partner + ":") self.listBox1.insert( 'end', '[' + self.time.strftime("%H:%M:%S") + ']') self.listBox1.itemconfig('end', bg='white', foreground="lightgrey") self.listBox1.insert('end', wrappedContent[0]) for i in range(2): self.listBox2.insert( 'end', "") # add 2 empty lines to balance both sides self.listBox1.itemconfig('end', bg='white') self.listBox1.yview(END) self.listBox2.yview(END) self.listBox1.insert('end', '') # some space to enhance appeal self.listBox2.insert('end', '') except: print("no new messages available from " + self.partner) else: # user typed something lastEntry = '' index = 0 ContentArray = pcap.dumpIt(username + '.pcap') while True: # while not at the end of the list (we want to get the last entry) try: lastEntry = ContentArray[index + 1] lastEntry = lastEntry[2:len(ContentArray[index + 1]) - 2] # removing the [""] index += 1 except: print("Arrived at last message: \"" + lastEntry + "\"") if content != '': self.listBox2.insert( 'end', '[' + self.time.strftime("%H:%M:%S") + ']') self.listBox2.itemconfig( 'end', bg='#dafac9', foreground="lightgrey" ) # dafac9 = light green (coloring for sender messaages) self.listBox1.insert( 'end', '' ) # adjust the other listbox for them to by synced on the same height wrappedContent = TextWrapper.textWrap(content, 0) print(".", wrappedContent) for i in range(len(wrappedContent)): self.listBox2.insert('end', wrappedContent[i]) self.listBox2.itemconfig('end', bg='#dafac9') self.listBox1.insert( 'end', '' ) # adjust the other listbox for them to by synced on the same height self.listBox1.yview(END) self.listBox2.yview(END) self.listBox1.yview(END) self.listBox2.yview(END) self.listBox1.insert( 'end', '') # some space to enhance appeal self.listBox2.insert('end', '') self.text_field.delete(0, 'end') self.save(content) break