Beispiel #1
0
    def get_files(self, file_descriptors):
        """download given list of file

        file_descriptor is a list: [ [split path], size ]"""
        if self.peer.server.current_state == self.peer.server.new_state:
            SecurityAlert(self.peer.peer_id, "Can't get files: peer's server not known yet")
        else:
            # display downlaod dialog if necessary
            if get_prefs("display_dl") and "wx" in sys.modules:
                from solipsis.util.uiproxy import UIProxy
                from solipsis.services.profile.gui.DownloadDialog import DownloadDialog

                self.download_dlg = UIProxy(DownloadDialog(get_prefs("display_dl"), None, -1))
                self.download_dlg.init()
                self.download_dlg.Show()
            # launch first download
            self.files = file_descriptors
            if self.files:
                split_path, size = self.files.pop()
                self.update_file(split_path[-1], size)
                self._connect(MESSAGE_FILES, format_data_file(split_path, size))
                # create deferred to be called when all files downloaded
                deferred = defer.Deferred()
                self.files_deferred = deferred
                return self.files_deferred
            else:
                display_warning(_("Empty List"), _("No file selected to download"))
def log(*args):
    if get_prefs("log"):
        formatted = []
        for arg in args:
            if isinstance(arg, unicode):
                formatted.append(arg.encode(get_prefs("encoding")))
            else:
                formatted.append(str(arg))
        # log
        print ' '.join(formatted)
 def on_about(self, event): # wxGlade: FilterFrame.<event_handler>
     """display about"""
     # not modal because would freeze the wx thread while twisted
     # one goes on and initialize profile
     about_dlg = AboutDialog(get_prefs("disclaimer"), self, -1)
     about_dlg.Show()
     event.Skip()
    def __set_properties(self):
        # begin wxGlade: FilterFrame.__set_properties
        self.SetTitle(_("Profile Filters"))
        self.SetSize((709, 632))
        self.statusbar.SetStatusWidths([-1])
        # statusbar fields
        statusbar_fields = [_("status")]
        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)
        # end wxGlade

        # properties not generated by wxglade
        width = get_prefs("filter_width")
        height = get_prefs("filter_height")
        self.SetSize((width, height))
        self.do_modified(False)
        self.activate_item.Check()
 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 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_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 __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 __set_properties(self):
     """generated by SetTitle"""
     # begin wxGlade: EditorFrame.__set_properties
     self.SetTitle(_("Profile Editor"))
     self.SetMinSize((460, 600))
     self.statusbar.SetStatusWidths([-1])
     # statusbar fields
     statusbar_fields = [_("status")]
     for i in range(len(statusbar_fields)):
         self.statusbar.SetStatusText(statusbar_fields[i], i)
     # end wxGlade
     # set previous size
     width = get_prefs("profile_width")
     height = get_prefs("profile_height")
     self.SetSize((width, height))
     self.do_modified(False)
     self.activate_item.Check()
     # should be passed through constructor but wxglade does not allow it
     self.personal_tab.do_modified = self.do_modified
     self.blog_tab.do_modified = self.do_modified
     self.file_tab.do_modified = self.do_modified
    def __init__(self, frame, *args, **kwds):
        self.frame = frame
        # begin wxGlade: EditProfilePanel.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.all_label = wx.StaticText(self, -1, _("Search :"))
        self.all_value = wx.TextCtrl(self, -1, "")
        self.title_label = wx.StaticText(self, -1, _("Title :"))
        self.title_value = wx.ComboBox(self, -1, choices=["", _("Mr"), _("Mrs"), _("Ms")], style=wx.CB_DROPDOWN|wx.CB_SIMPLE|wx.CB_READONLY)
        self.firstname_label = wx.StaticText(self, -1, _("First name :"))
        self.firstname_value = wx.TextCtrl(self, -1, "")
        self.lastname_label = wx.StaticText(self, -1, _("Last name :"))
        self.lastname_value = wx.TextCtrl(self, -1, "")
        self.pseudo_label = wx.StaticText(self, -1, _("Pseudo :"))
        self.pseudo_value = wx.TextCtrl(self, -1, "")
        self.email_label = wx.StaticText(self, -1, _("Email :"))
        self.email_value = wx.TextCtrl(self, -1, "")
        self.customs_label = wx.StaticText(self, -1, _("Customs :"))
        self.customs_list = MyListCtrl(self, -1, style=wx.LC_REPORT|wx.LC_EDIT_LABELS|wx.LC_SORT_ASCENDING|wx.SUNKEN_BORDER)
        self.logic_checkbox = wx.CheckBox(self, -1, _("AND search (default: OR)"))
        self.spacer_label = wx.StaticText(self, -1, "")
        self.mode_button = wx.Button(self, -1, _("Advanced mode"))
        self.clear_button = wx.Button(self, -1, _("Clear"))
        self.apply_button = wx.Button(self, -1, _("Apply"))

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.on_right_click, self.customs_list)
        self.Bind(wx.EVT_LIST_COL_RIGHT_CLICK, self.on_right_click, self.customs_list)
        self.Bind(wx.EVT_BUTTON, self.on_switch_mode, self.mode_button)
        self.Bind(wx.EVT_BUTTON, self.on_clear, self.clear_button)
        self.Bind(wx.EVT_BUTTON, self.on_apply, self.apply_button)
        # end wxGlade

        # custom list
        self.customs_list.InsertColumn(0, "Name")
        self.customs_list.InsertColumn(1, "Value")
        self.customs_list.SetColumnWidth(0, wx.LIST_AUTOSIZE_USEHEADER)
        self.customs_list.SetColumnWidth(1, wx.LIST_AUTOSIZE_USEHEADER)

        # popup menu
        self.popup_menu = wx.Menu()
        self.new_item = wx.MenuItem(self.popup_menu, wx.NewId(), _("New"))
        self.delete_item = wx.MenuItem(self.popup_menu, wx.NewId(), _("Delete selected(s)"))
        self.popup_menu.AppendItem(self.new_item)
        self.popup_menu.AppendItem(self.delete_item)
        self.Bind(wx.EVT_MENU, self.on_new_custom, self.new_item)
        self.Bind(wx.EVT_MENU, self.on_delete_custom, self.delete_item)

        if not get_prefs("simple_mode"):
            self.on_switch_mode(None)
 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()
Beispiel #12
0
 def _on_complete_file(self, donwload_msg):
     """callback when finished downloading file"""
     log("_on_complete_file: ", self.peer.peer_id)
     # write downloaded file
     split_path = extract_data_file(donwload_msg.message.data)[0]
     download_path = os.path.join(get_prefs("download_repo"), split_path[-1])
     download_file = open(download_path, "wb")
     download_file.write(donwload_msg.file.read())
     download_file.close()
     # download next
     if self.files:
         split_path, size = self.files.pop()
         self.update_file(split_path[-1], size)
         self._connect(MESSAGE_FILES, format_data_file(split_path, size))
     else:
         self.complete_all_files()
 def on_import(self, event):
     """match current filter with given profile"""
     dlg = wx.FileDialog(
         self, message="Match profile ...",
         defaultDir=get_prefs("profile_dir"),
         defaultFile="",
         wildcard="Solipsis file (*.prf)|*.prf",
         style=wx.OPEN)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()[:-4]
         loader = FileDocument()
         loader.load(path + PROFILE_EXT)
         get_facade().fill_data(loader.get_pseudo(), loader)
         get_filter_facade().match(PeerDescriptor(loader.get_pseudo(),
                                                  document = loader))
     event.Skip()
 def on_add(self, evt):
     dlg = wx.FileDialog(
         self, message="Add profile ...",
         defaultDir=get_prefs("profile_dir"),
         defaultFile="",
         wildcard="Solipsis file (*.prf)|*.prf",
         style=wx.OPEN)
     if dlg.ShowModal() == wx.ID_OK:
         directory, file_name = os.path.split(dlg.GetPath()[:-4])
         peer_desc = PeerDescriptor(file_name, document=FileDocument())
         peer_desc.load(directory=directory)
         blogs = peer_desc.blog
         loader = peer_desc.document
         get_facade().fill_data(peer_desc.node_id, loader)
         get_facade().fill_blog(peer_desc.node_id, blogs)
         get_facade().fill_shared_files(peer_desc.node_id, loader.get_shared_files())
         self.display_profile(peer_desc)
         self.display_blog(peer_desc)
         self.display_files(peer_desc)
def _display(msg, msg_type, title="Solipsis Profile", error=None):
    from solipsis.services.profile.plugin import Plugin
    service_api = Plugin.service_api
    if service_api != None:
        if msg_type == "ERR":
            from traceback import extract_stack
            service_api.display_error(msg, title,
                                      error=error,
                                      trace=extract_stack()[:-2])
        elif msg_type == "WARN":
            service_api.display_warning(msg, title)
        elif msg_type == "MSG":
            service_api.display_message(msg, title)
        elif msg_type == "STATE":
            service_api.display_status(msg)
        else:
            print "message type %s not valid"
    if get_prefs("log"):
        print "MSG: " + msg
        if not error is None:
            print "ERR: ", error
            import traceback
            traceback.print_exc()
 def on_about(self, evt):
     """display about"""
     # not modal because would freeze the wx thread while twisted
     # one goes on and initialize profile
     about_dlg = AboutDialog(get_prefs("disclaimer"), self, -1)
     about_dlg.Show()
from logilab.common.testlib import main
from solipsis.services.profile.tools.prefs import get_prefs, set_prefs

if __name__ == '__main__':
    import sys, os
    logging = get_prefs("log")
    if not logging:
        print "desactivating log"
    set_prefs("log", False)
    main(os.path.dirname(sys.argv[0]) or '.')
    set_prefs("log", logging)
 def Show(self, show=True):
     wx.Frame.Show(self, show)
     # disclaimer
     if show and get_prefs("disclaimer"):
         self.on_about(None)
    def __init__(self, options, parent, id, title, plugin=None, **kwds):
        self.plugin = plugin
        self.modified = False
        self.options = options
        args = (parent, id, title)
        # begin wxGlade: EditorFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.profile_book = wx.Notebook(self, -1, style=0)
        
        # Menu Bar
        self.profile_menu = wx.MenuBar()
        self.SetMenuBar(self.profile_menu)
        self.profile_item = wx.Menu()
        self.activate_item = wx.MenuItem(self.profile_item, wx.NewId(), _("&Online\tCtrl+O"), _("Allow users seeing profile"), wx.ITEM_CHECK)
        self.profile_item.AppendItem(self.activate_item)
        self.profile_item.AppendSeparator()
        self.export_item = wx.MenuItem(self.profile_item, wx.NewId(), _("&Export HTML ...\tCtrl+E"), _("Write profile as HTML File"), wx.ITEM_NORMAL)
        self.profile_item.AppendItem(self.export_item)
        self.save_item = wx.MenuItem(self.profile_item, wx.NewId(), _("&Save\tCtrl+S"), _("Save profile into file"), wx.ITEM_NORMAL)
        self.profile_item.AppendItem(self.save_item)
        self.quit_item = wx.MenuItem(self.profile_item, wx.NewId(), _("&Close\tCtrl+W"), _("Close profile management"), wx.ITEM_NORMAL)
        self.profile_item.AppendItem(self.quit_item)
        self.profile_menu.Append(self.profile_item, _("Action"))
        self.files_menu = wx.Menu()
        self.add_item = wx.MenuItem(self.files_menu, wx.NewId(), _("&Add directory...\tCtrl+A"), "", wx.ITEM_NORMAL)
        self.files_menu.AppendItem(self.add_item)
        self.del_item = wx.MenuItem(self.files_menu, wx.NewId(), _("&Remove directory...\tCtrl+R"), "", wx.ITEM_NORMAL)
        self.files_menu.AppendItem(self.del_item)
        self.files_menu.AppendSeparator()
        self.share_item = wx.MenuItem(self.files_menu, wx.NewId(), _("Share"), "", wx.ITEM_NORMAL)
        self.files_menu.AppendItem(self.share_item)
        self.unshare_item = wx.MenuItem(self.files_menu, wx.NewId(), _("Unshare"), "", wx.ITEM_NORMAL)
        self.files_menu.AppendItem(self.unshare_item)
        self.profile_menu.Append(self.files_menu, _("Files"))
        self.help_menu = wx.Menu()
        self.preview_item = wx.MenuItem(self.help_menu, wx.NewId(), _("&Profile...\tCtrl+P"), _("Preview your profile"), wx.ITEM_NORMAL)
        self.help_menu.AppendItem(self.preview_item)
        self.shared_item = wx.MenuItem(self.help_menu, wx.NewId(), _("S&hared Files...\tCtrl+H"), _("Preview your shared files"), wx.ITEM_NORMAL)
        self.help_menu.AppendItem(self.shared_item)
        self.help_menu.AppendSeparator()
        self.about_item = wx.MenuItem(self.help_menu, wx.NewId(), _("About...\tCtrl+?"), "", wx.ITEM_NORMAL)
        self.help_menu.AppendItem(self.about_item)
        self.profile_menu.Append(self.help_menu, _("Info"))
        # Menu Bar end
        self.statusbar = self.CreateStatusBar(1, 0)
        self.personal_tab = PersonalPanel(self.profile_book, -1)
        self.blog_tab = BlogPanel(self.profile_book, -1)
        self.file_tab = FilePanel(self.profile_book, -1,
                                  cb_selected=self.cb_selected)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade
        
        if self.options["standalone"]:
            #put here special initialisation for standalone editor
            pass
        self.profile_dlg = ProfileDialog(parent, -1, plugin=self.plugin)
        self.download_dlg = UIProxy(DownloadDialog(get_prefs("display_dl"), parent, -1))
        # events
        self.bind_controls()