Пример #1
0
    def onExportIcalendarEvent(self, event):
        # triggered from "File | Import/Export" Menu

        wildcard = "iCalendar files|*.ics|All files (*.*)|*.*"
        dlg = wx.FileDialog(wx.GetApp().mainFrame, "Choose filename to export to",
                              "", "export.ics", wildcard,
                              wx.SAVE | wx.OVERWRITE_PROMPT)
        if dlg.ShowModal() == wx.ID_OK:
            (dir, filename) = os.path.split(dlg.GetPath())
            dlg.Destroy()
        else:
            dlg.Destroy()
            self.setStatusMessage("Export aborted")
            return

        self.setStatusMessage ("Exporting to %s" % filename)
        try:
            share = Sharing.OneTimeFileSystemShare(dir, filename,
                            ICalendar.ICalendarFormat, view=self.itsView)
            collection = ItemCollection(view=self.itsView)
            for event in Calendar.CalendarEvent.iterItems(self.itsView):
                collection.add(event)
            share.contents = collection
            share.put()
            self.setStatusMessage("Export completed")
        except:
            trace = "".join(traceback.format_exception (*sys.exc_info()))
            logger.info("Failed exportFile:\n%s" % trace)
            self.setStatusMessage("Export failed")
Пример #2
0
 def onImportIcalendarEvent(self, event):
     # triggered from "File | Import/Export" menu
     wildcard = "iCalendar files|*.ics|All files (*.*)|*.*"
     dlg = wx.FileDialog(wx.GetApp().mainFrame, "Choose a file to import",
                           "", "import.ics", wildcard,
                           wx.OPEN | wx.HIDE_READONLY)
     if dlg.ShowModal() == wx.ID_OK:
         (dir, filename) = os.path.split(dlg.GetPath())
         dlg.Destroy()
     else:
         dlg.Destroy()
         self.setStatusMessage("Import aborted")
         return
         
     self.setStatusMessage ("Importing from %s" % filename)
     try:
         share = Sharing.OneTimeFileSystemShare(dir, filename,
                         ICalendar.ICalendarFormat, view=self.itsView)
         collection = share.get()
         self.postEventByName ("AddToSidebarWithoutCopyingAndSelectFirst", {'items':[collection]})
         self.setStatusMessage ("Import completed")
     except:
         trace = "".join(traceback.format_exception (*sys.exc_info()))
         logger.info("Failed importFile:\n%s" % trace)
         self.setStatusMessage("Import failed")