def on_blacklist(self, evt):
     """end application"""
     pseudo = self.other_tab.get_peer_selected()
     if pseudo:
         get_facade().blacklist_peer(pseudo)
     else:
         print "no peer selected"
 def on_anonymous(self, evt):
     """end application"""
     pseudo = self.other_tab.get_peer_selected()
     if pseudo:
         get_facade().unmark_peer(pseudo)
     else:
         print "no peer selected"
 def on_close(self, evt):
     """hide  application"""
     get_facade().save()
     if self.options["standalone"]:
         self._close()
     else:
         self.Hide()
 def on_make_friend(self, evt):
     """end application"""
     pseudo = self.other_tab.get_peer_selected()
     if pseudo:
         get_facade().make_friend(pseudo)
     else:
         print "no peer selected"
Example #5
0
 def Disable(self):
     """It is called when the user chooses to disable the service."""
     # ask for saving (ca not simply call Close() on editor frame
     # method because of multithreading and the frame is destroyed
     # before the user actually answer to the popup
     if self.editor_frame and self.editor_frame.modified:
         import wx
         self.editor_frame.do_modified(False)
         dlg = wx.MessageDialog(
             self.editor_frame,
             'Your profile has been modified. Do you want to save it?',
             'Saving Profile',
             wx.YES_NO | wx.ICON_INFORMATION)
         if dlg.ShowModal() == wx.ID_YES:
             get_facade()._desc.save()
     if self.filter_frame and self.filter_frame.modified:
         import wx
         self.filter_frame.do_modified(False)
         dlg = wx.MessageDialog(
             self.filter_frame,
             'Your filters have been modified. Do you want to save them?',
             'Saving Filters',
             wx.YES_NO | wx.ICON_INFORMATION)
         if dlg.ShowModal() == wx.ID_YES:
             get_filter_facade().save()
     self.activate(False)
 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 on_tag(self, evt):
     """tag selected files or directory"""
     dir_name = self.owner.tree_list.GetItemText(self.owner.tree_list.GetSelection(), FULL_PATH_COL)
     file_names = [self.owner.dir_list.GetItemText(item)
                   for item in self.owner._get_selected_listitems()]
     get_facade().tag_files((dir_name, file_names, self.owner.tag_value.GetValue()))
     self.owner.do_modified(True)
 def on_refresh(self, evt):
     """put into cache new information when dir expanded in tree"""
     self.current_state = self.tree_state
     file_name = self.tree_list.GetItemText(self.tree_list.GetSelection(), FULL_PATH_COL)
     if self.tree_list.GetSelection() != self.root:
         get_facade().recursive_expand(abspath(file_name))
     evt.Skip()
 def remove_blog(self):
     assert get_facade(), "Facade not initialiazed"
     selected = self.GetSelection()
     if selected != wx.NOT_FOUND:
         get_facade().remove_blog(selected)
     else:
         print "none selected"
Example #10
0
 def _on_new_profile(self, document, peer_id):
     """store and display file object corresponding to profile"""
     print "downloaded profile", peer_id
     get_facade().fill_data((peer_id, document))
     if self.viewer_frame:
         self.viewer_frame.profile_dlg.activate()
         self.viewer_frame.profile_dlg.Show()
 def on_del(self, evt):
     """a custom attribute has been modified"""
     # update data
     if self.custom_list.DeleteItem(self.custom_list.FindItem(0, self.key_value.GetValue())):
         # update cache
         get_facade().del_custom_attributes(self.key_value.GetValue())
         self.do_modified(True)
Example #12
0
 def _on_new_profile(self, document, peer_id):
     """store and display file object corresponding to profile"""
     if self.viewer_frame:
         self.viewer_frame.profile_dlg.activate()
         self.viewer_frame.profile_dlg.Show()
     get_facade().fill_data((peer_id, document))
     return str(document)
 def on_unshare(self, evt):
     """cancel sharing of selected files"""
     dir_name = self.owner.tree_list.GetItemText(self.owner.tree_list.GetSelection(), FULL_PATH_COL)
     file_names = [self.owner.dir_list.GetItemText(item)
                   for item in self.owner._get_selected_listitems()]
     get_facade().share_files(dir_name, file_names, False)
     self.owner.do_modified(True)
 def remove_blog(self):
     assert get_facade(), "Facade not initialiazed"
     selected = self.GetSelection()
     if selected != wx.NOT_FOUND:
         get_facade().remove_blog(selected)
     else:
         display_warning(_("none selected"))
 def refresh(self, files=None):
     """overrides Show, files is {repos: [FileDescriptors], }"""
     if files is None:
         if get_facade() is None:
             return
         files = get_facade().get_document().get_shared_files()
     self.peerfiles_list.DeleteAllItems()
     if len(files) > 0:
         # reformat data
         file_data = []
         for file_descs in files.values():
             for file_desc in file_descs:
                 file_data.append([file_desc.get_path(),
                                   file_desc.name,
                                   file_desc._tag])
         # clear previous data
         for key in self.data.keys():
             del self.data[key]
         # fill list
         for path, name, tag in file_data:
             index = self.peerfiles_list.InsertStringItem(sys.maxint, name)
             self.peerfiles_list.SetStringItem(index, 1, tag)
             self.data[index] = path.split(os.sep)
     # show result
     self.peerfiles_list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
     self.peerfiles_list.SetColumnWidth(1, wx.LIST_AUTOSIZE)
 def refresh(self, files=None):
     """overrides Show, files is {repos: [FileDescriptors], }"""
     if files is None:
         if get_facade() is None:
             return
         files = get_facade().get_document().get_shared_files()
     self.peerfiles_list.DeleteAllItems()
     if len(files) > 0:
         # reformat data
         file_data = []
         for file_descs in files.values():
             for file_desc in file_descs:
                 file_data.append([file_desc.get_path(), file_desc.name, file_desc._tag, file_desc.size])
         # clear previous data
         for key in self.data.keys():
             del self.data[key]
         # fill list
         for path, name, tag, size in file_data:
             index = self.peerfiles_list.InsertStringItem(sys.maxint, unicode(name, ENCODING))
             self.peerfiles_list.SetStringItem(index, TAG_COL, tag)
             self.peerfiles_list.SetStringItem(
                 index, SIZE_COL, formatbytes(size, kiloname="Ko", meganame="Mo", bytename="o")
             )
             self.data[index] = (path.split(os.sep), size)
     # show result
     self.peerfiles_list.SetColumnWidth(TAG_COL, wx.LIST_AUTOSIZE)
 def add_comment(self, text):
     """store blog in cache as wx.HtmlListBox is virtual"""
     assert get_facade(), "Facade not initialiazed"
     selected = self.GetSelection()
     if selected != wx.NOT_FOUND:
         get_facade().add_comment(selected, text, get_facade()._desc.document.get_pseudo())
     else:
         display_warning(_("none selected"))
 def add_comment(self, text):
     """store blog in cache as wx.HtmlListBox is virtual"""
     assert get_facade(), "Facade not initialiazed"
     selected = self.GetSelection()
     if selected != wx.NOT_FOUND:
         get_facade().add_comment((selected, text, get_facade().get_pseudo()))
     else:
         print "none selected"
 def OnGetItem(self, n):
     """callback to display item"""
     assert get_facade(), "Facade not initialiazed"
     try:
         return get_facade()._desc.blog.get_blog(n).html()
     except IndexError, err:
         display_error(_('Could not get blog.'), error=err)
         return "<p>Corrupted Blog</p>"
 def on_expand(self, evt):
     """put into cache new information when dir expanded in tree"""
     self.current_state = self.tree_state
     file_name = self.tree_list.GetItemText(evt.GetItem(), FULL_PATH_COL)
     if evt.GetItem() != self.root:
         get_facade()._desc.document.expand_dir(abspath(file_name).encode(ENCODING))
         get_facade().expand_children(abspath(file_name))
     evt.Skip()
 def on_tag(self, evt):
     """tag selected files or directory"""
     selections = self.get_selection()
     if not selections:
         display_message(_("Your must select a directory or a file to tag"),
                         title="No item selected")
     for selection in selections:
         get_facade().tag_file(selection, self.owner.tag_value.GetValue())
     self.owner.do_modified(True)
 def on_unshare(self, evt):
     """share all files in directory"""
     selections = self.get_selection()
     if not selections:
         display_message(_("Your must select a directory or a file to unshare"),
                         title="No item selected")
     for selection in selections:
         get_facade().recursive_share(selection, False)
     self.owner.do_modified(True)
 def on_tag(self, evt):
     """tag selected files or directory"""
     dir_name = self.owner.tree_list.GetItemText(self.owner.tree_list.GetSelection(), FULL_PATH_COL)
     file_names = [os.path.join(dir_name, self.owner.dir_list.GetItemText(item))
                   for item in self.owner._get_selected_listitems()]
     tag_value = self.owner.tag_value.GetValue()
     for file_name in file_names:
         get_facade().tag_file(file_name, tag_value)
     self.owner.do_modified(True)
Example #24
0
 def DoPointToPointAction(self, it, peer, deferred=None):
     """Called when a point-to-point action is invoked, if available."""
     if get_facade() and get_facade()._activated:
         # retreive corect method
         actions = self.POINT_ACTIONS.values()
         # call method on peer
         actions[it](peer.id_, deferred)
     # service not activated, do nothing
     else:
         print "service not activated"
 def on_export(self, evt):
     """export .html"""
     dlg = wx.FileDialog(
         self, message="Export HTML file as ...",
         defaultDir=get_prefs("profile_dir"),
         defaultFile="",
         wildcard="HTML File (*.html)|*.html",
         style=wx.SAVE)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()
         get_facade().export_profile(path)
 def on_export(self, evt):
     """export .html"""
     dlg = wx.FileDialog(
         self, message=_("Export HTML file as ..."),
         defaultDir=get_prefs("profile_dir"),
         defaultFile="%s.html"% get_facade()._desc.document.get_pseudo(),
         wildcard=_("HTML File (*.html)|*.html"),
         style=wx.SAVE)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()
         get_facade().export_profile(path)
 def on_set_repo(self, evt):
     """add shared directory to list"""
     # pop up to choose repository
     dlg = wx.DirDialog(self, message=_("Choose location to download files into"),
                        defaultPath = get_facade().get_document().get_download_repo(),
                        style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)
     if dlg.ShowModal() == wx.ID_OK:
         # path chosen
         path = dlg.GetPath()
         get_facade().change_download_repo(path)
     dlg.Destroy()
 def on_export(self, evt):
     """export .html"""
     dlg = wx.FileDialog(
         self, message="Export HTML file as ...",
         defaultDir=PROFILE_DIR,
         defaultFile="%s.html"% get_facade().get_pseudo(),
         wildcard="HTML File (*.html)|*.html",
         style=wx.SAVE)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()
         get_facade().export_profile(path)
Example #29
0
 def ChangedNode(self, node):
     """need to update node_id"""
     # ChangedNode is call more than one time on change. Thus, be
     # careful not to do the job every time
     if get_facade() is None or get_facade().get_pseudo() != node.pseudo:
         facade = create_facade(node.pseudo)
         facade.load_profile()
         if self.editor_frame:
             facade.add_view(EditorView(facade._desc, self.editor_frame))
             self.editor_frame.on_change_facade()
             facade.add_view(ViewerView(facade._desc, self.viewer_frame))
             self.viewer_frame.on_change_facade()
 def on_remove(self, evt):
     """remove shared directory from repository"""
     file_name = self.tree_list.GetItemText(self.tree_list.GetSelection(), FULL_PATH_COL)
     repositories = get_facade()._desc.document.get_repositories()
     if file_name and file_name in repositories:
         self.dir_list.DeleteAllItems()
         self.tree_list.SelectItem(self.root)
         item = get_facade().get_file_container(file_name)
         self.tree_list.DeleteChildren(item.data)
         self.tree_list.Delete(item.data)
         get_facade().del_repository(file_name)
         self.do_modified(True)