def __init__(self, parent): # display variables self.dist_max = 2**127L self.scale = 1.0 self.coeff_zoom = 1 # my node variables self.myNode_pseudo = "" self.myNode_ar = "" self.delta_x = 0 self.delta_y = 0 # displaying options self.isDisplayPseudos = 0 val = configuration.readConfParameterValue("displayPseudos") if val: self.isDisplayPseudos = long(val) self.isDisplayAvatars = 1 val = configuration.readConfParameterValue("displayAvatars") if val: self.isDisplayAvatars = long(val) # default images #self.myNode_avatar = 'Img//avat_gh.png' self.myNode_avatar = "" self.neighbor_avatar = 'Img//avat_gris.png' avatarFile = commun.AVATAR_DIR_NAME + os.sep + "neighbor_default.png" shutil.copyfile(self.neighbor_avatar, avatarFile) # resize the avatar file self.neighbor_avatar = commun.chgSize(avatarFile) # dictionary associating widget item with a neighbor # {[neighbor_id]:[neighbor_posX, neighbor_posY, neighbor_pseudo, # neighbor_chat, neighbor_display2d, neighbor_sharing, neighbor_image]} self.neighbor_item = {} # init controls self._init_ctrls(parent) # navigator #self.navigator = Navigator(self, socket.gethostbyname(socket.gethostname()), "8080") self.navigator = Navigator(self) # refresh timer variables self.TIMER_ID = 1 self.toRefresh = FALSE # start the timer to refresh displaying every second self.timer = wxTimer(self, self.TIMER_ID) EVT_TIMER(self, self.TIMER_ID, self.OnRefreshTimer) self.timer.Start(1000)
def drawMyNode(self, pseudo, ar): debug.debug_info("ihm.drawMyNode") self.myNode_pseudo = pseudo self.myNode_ar = ar # default avatar avatarFile = commun.AVATAR_DIR_NAME + os.sep + pseudo + "_default.png" shutil.copyfile("Img//avat_gh.png", avatarFile) # resize the avatar file self.myNode_avatar = commun.chgSize(avatarFile) # refresh the drawing self.toRefresh = TRUE
def OnChooseButton(self, event): """ send the avatar selected to the neighbors """ # check if an item is selected if (self.imageIndice != -1): # check if the navigator is connected to a node if (self.navigator.getIsConnected() == 1): # display a confirmation message message = 'Are you sure you want to send this avatar to your neighbors : ' + self.imageList[self.imageIndice] + ' ?' dlg = wxMessageDialog(self, message, 'Choose avatar', wxOK|wxCANCEL|wxCENTRE|wxICON_QUESTION) dlg.Center(wxBOTH) if dlg.ShowModal() == wxID_OK: image_name = self.avatarsDir + os.sep + self.imageList[self.imageIndice] + ".png" # copy the avatar in the avatarDir avatarFile = commun.AVATAR_DIR_NAME + os.sep + self.navigator.getNodePseudo() + "_" + self.imageList[self.imageIndice] + ".png" shutil.copyfile(image_name, avatarFile) # resize the avatar file resizeFile = commun.chgSize(avatarFile) # send the file to the navigator self.navigator.sendImage(avatarFile, resizeFile) # close the dialog box self.Close(FALSE) else: commun.displayError(self, 'Sorry you are not connected !')
def watch(self): """ watching if a chunk has been received since a long time, a way to check chunk lost""" #debug.debug_info("display2d.watch()") # get the list of chunks received since a long time silent = self.extractSilent(self.CHECKWAIT) # if a chunk has been received since a long time if silent: self.dictLock.acquire() for i in silent: # get information about this chunk(sender, number of this chunk, name of image) sender = i[0] chunkfilename = i[1] hyphen = chunkfilename.find("-") filename = chunkfilename[:hyphen] if self.list_neighbors.has_key(sender): object_sender = self.list_neighbors[sender] # get the list of chunks of this sender chunklist = self.dictListSender[sender] # create a list in order to sort chunks missing list_number = [] # get the number of the chunkfile (because chunklist == [filename - number)] for chunk in chunklist[1:]: number_chunk = string.splitfields(chunk, "-", 1)[1] chunklist.remove(chunk) list_number.append(number_chunk) # sort listnumber list_number_sorted = self.sortStr(list_number) # reconstitute the list of chunk_missing in the order (because list_number_sorted == 1, 2, 3........) for number in list_number_sorted: chunkfile = filename +"-"+ number chunklist.append(chunkfile) # get total number of chunks that should be received totalChunk = int(chunklist[0]) if len(chunklist) == totalChunk +1: # we have all chunks data = "" for chunk in chunklist[1:]: data += self.chunkdict[(sender, chunk)] del self.chunkdict[(sender,chunk)] # create a file to save image filename = str(commun.AVATAR_DIR_NAME) + os.sep + object_sender.pseudo + "_" + filename imgfile = file(filename, "wb") imgfile.write(data) imgfile.close() # resize the avatar image resizeFile = commun.chgSize(filename) # display image in the 2D View screen #self.navigator.receiveImage(sender, resizeFile) wxPostEvent(self.navigator.ihm, wxMainFrame.receiveImageEvent(sender=sender, image_name=resizeFile)) # we remove the sender from the list "silent" silent.remove((sender, self.beatDict[sender][1])) # we remove sender from all dictionaries del self.dictListSender[sender] del self.beatDict[sender] # send acknowledgement in order to inform we have received all chunks list = ["ACKNOWLEDGEMENT", str(filename)] msg = self.encodeMsg(list) host, port = object_sender.dict_service[self] self.udp_socket.sendto(msg, (host, int(port))) else: # chunks miss # retrieve the chunks missing (number...) missing_list = [] for chunk_number in list_number_sorted: if chunk_number in list_number_sorted[1:-1]: chunk_index = list_number_sorted.index(chunk_number) previous_value = int(list_number_sorted[chunk_index-1]) if int(chunk_number) <> previous_value+1: self.retrieveChunkMiss(missing_list, previous_value, int(chunk_number) - 1, filename) if chunk_number == list_number_sorted[0]: if int(chunk_number) <> 1: self.retrieveChunkMiss(missing_list, int(0), int(chunk_number) - 1, filename) if chunk_number == list_number_sorted[-1]: if int(chunk_number) <> totalChunk: self.retrieveChunkMiss(missing_list, int(chunk_number), int(totalChunk), filename) # send the list of name of chunks missing list = ["MISSINGCHUNK", self.my_node.id, str(missing_list), str(totalChunk)] msg = self.encodeMsg(list) host, port = object_sender.dict_service[self] self.udp_socket.sendto(msg, (host, int(port))) # delete the last chunk received since a long time in order to watch the new chunks received since the missingchunk request del self.beatDict[sender] self.dictLock.release()