def refresh(self, files=None): """overrides Show, files is {repos: [FileDescriptors], }""" if not self.IsShown(): return if files is None: if get_facade() is None: return files = get_facade()._desc.document.get_shared_files() # clear previous data self.peerfiles_list.DeleteAllItems() for key in self.data.keys(): del self.data[key] # fill new data for file_container in files.flatten(): path = file_container.get_path() index = self.peerfiles_list.InsertStringItem( sys.maxint, force_unicode(file_container.name)) self.peerfiles_list.SetStringItem(index, TAG_COL, file_container._tag) self.peerfiles_list.SetStringItem(index, SIZE_COL, formatbytes(file_container.size, kiloname="Ko", meganame="Mo", bytename="o")) self.data[index] = (path.split(os.sep), file_container.size) # show result self.peerfiles_list.SetColumnWidth(TAG_COL, wx.LIST_AUTOSIZE)
def update_file(self, name, size): """reset gaucge and display file name""" self.SetTitle(_("Downloading %s"% name)) self.download_label.SetLabel(force_unicode(name)) self.download_gauge.SetRange(size) self.download_gauge.SetValue(0) self.counter += 1
def _display_dir_content(self, dir_container): """update list view with content of directory""" self.dir_list.DeleteAllItems() for name, container in dir_container.iteritems(): if isinstance(container, DirContainer): index = self.dir_list.InsertImageStringItem(sys.maxint, force_unicode(name), self.dir_fldridx) self.dir_list.SetItemTextColour(index, wx.LIGHT_GREY) else: index = self.dir_list.InsertImageStringItem(sys.maxint, force_unicode(name), self.dir_fileidx) self.dir_list.SetStringItem(index, SIZE_COL, formatbytes(container.size, kiloname="Ko", meganame="Mo", bytename="o")) self.dir_list.SetItemTextColour(index, container._shared and wx.BLUE or wx.BLACK) self.dir_list.SetStringItem(index, SHARED_COL, str(container._shared)) self.dir_list.SetStringItem(index, TAG_COL, container._tag) self.dir_list.SetColumnWidth(TAG_COL, wx.LIST_AUTOSIZE)
def SetTitle(self, title=None): if not title: if self.peer_desc: title = self.peer_desc.document.get_pseudo() + "'s files" else: title = force_unicode("your files going into " + \ get_prefs("download_repo")) wx.Dialog.SetTitle(self, title)
def _add_container_in_tree(self, parent, container, overwrite=False): """format item in tree view""" # create item container_path = container.get_path() name = os.path.basename(container_path) if container.data != None and overwrite == False: child = container.data else: child = self.tree_list.AppendItem(parent, force_unicode(name)) container.data = child self.tree_list.SetItemImage(child, self.tree_fldridx, which = wx.TreeItemIcon_Normal) self.tree_list.SetItemImage(child, self.tree_fldropenidx, which = wx.TreeItemIcon_Expanded) self.tree_list.SetItemText(child, u"%s"% str(container.nb_shared()), NB_SHARED_COL) self.tree_list.SetItemText(child, force_unicode(container_path), FULL_PATH_COL) # create grand children for key, container in container.iteritems(): if isinstance(container, DirContainer): self._add_container_in_tree(child, container, overwrite=overwrite)
def __set_properties(self): # begin wxGlade: FileDialog.__set_properties self.SetTitle(_("Chose Files")) self.SetMinSize((460, 410)) self.repo_button.SetToolTipString(_("Dowload repository")) self.repo_button.SetSize(self.repo_button.GetBestSize()) self.download_button.SetToolTipString(_("Download selected files")) self.download_button.SetSize(self.download_button.GetBestSize()) # end wxGlade self.repo_value.SetValue(force_unicode(get_prefs("download_repo"))) if not self.plugin: self.download_button.Enable(False)
def on_browse_repo(self, evt): """select download directory in DirDialog""" # pop up to choose repository dlg = wx.DirDialog(self, message=_("Choose location to download files into"), defaultPath = force_unicode(get_prefs("download_repo")), style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON) if dlg.ShowModal() == wx.ID_OK: # path chosen path = dlg.GetPath() set_prefs("download_repo", path.encode(ENCODING)) self.repo_value.SetValue(path) self.repo_button.SetToolTipString(path) self.SetTitle() dlg.Destroy()
def get_files(self): """returns {root: Container}""" # lazy initialisation if self.files != {}: return FileSharingMixin.get_files(self) # full init for repo in self.init_repos(): try: self.files[repo] = create_container(repo, checked=False) except AssertionError: print "non valid repo '%s'"% repo # if no valid repo found, does not try any further... if self.files == {}: return self.files for option in self.config.options(SECTION_FILE): # get share & tag try: o_description = self.config.get(SECTION_FILE, option) o_file, o_share, o_size, o_tag = o_description.split(',', 3) o_file = (o_file == 'F') and True or False o_share = (o_share == SHARED_TAG) o_tag = force_unicode(o_tag) o_size = int(o_size) except (ValueError, ConfigParser.NoSectionError, ConfigParser.NoOptionError), err: print >> sys.stderr, "option '%s' not well formated: %s"\ % (o_description, err) o_file, o_share, o_tag, o_size = False, False, DEFAULT_TAG, 0 # add container try: file_container = o_file and self.get_file(option) \ or self.get_container(option) file_container.share(o_share) file_container.tag(o_tag) file_container.size = o_size except KeyError: print "non valid file '%s'"% option
def get_view(self, update=False): """returns HTML String""" if update: self._update_view() return force_unicode(self.view.getvalue())
def test_photo(self): """photo as unicode""" for document in self.documents: document.set_photo(force_unicode(unittest.__file__))
def test_change_photo(self): self.facade.change_photo(force_unicode(unittest.__file__)) self.assertEquals(u"%s"% unittest.__file__, self.facade._desc.document.get_photo())
def test_photo(self): """photo as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_photo) for document in self.documents: self.assertRaises(TypeError, document.set_photo, "./dummy/dummy.jpg") document.set_photo(force_unicode(unittest.__file__))