Exemplo n.º 1
0
	def _on_menu_file_save(self, _evt):
		appconfig = self._appconfig
		dlg = wx.FileDialog(self.wnd,
				_("Please select target sync file."),
				defaultDir=appconfig.get('files', 'last_dir', ''),
				defaultFile=appconfig.get('files', 'last_file', 'GTD_SYNC.zip'),
				style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
		if dlg.ShowModal() == wx.ID_OK:
			filename = dlg.GetPath()
			dlgp = DlgSyncProggress(self.wnd)
			dlgp.run()
			try:
				exporter.save_to_file(filename, dlgp.update)
			except Exception as err:  # pylint: disable=W0703
				_LOG.exception('FrameMain._on_menu_file_save error')
				msgdlg = wx.lib.dialogs.ScrolledMessageDialog(self.wnd,
						str(err), _("Synchronisation error"))
				msgdlg.ShowModal()
				msgdlg.Destroy()
				dlgp.update(100, _("Error: ") + str(err))
			dlgp.mark_finished(2)
			publisher.sendMessage('task.update')
			appconfig.set('files', 'last_dir', os.path.dirname(filename))
			appconfig.set('files', 'last_file', os.path.basename(filename))
		dlg.Destroy()
Exemplo n.º 2
0
	def _on_menu_file_load(self, _evt):
		appconfig = self._appconfig
		dlg = wx.FileDialog(self.wnd,
				_("Please select sync file."),
				defaultDir=appconfig.get('files', 'last_dir', ''),
				defaultFile=appconfig.get('files', 'last_file', 'GTD_SYNC.zip'),
				style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
		if dlg.ShowModal() == wx.ID_OK:
			filename = dlg.GetPath()
			dlgp = DlgSyncProggress(self.wnd)
			dlgp.run()
			try:
				loader.load_from_file(filename, dlgp.update, force=True)
			except Exception as err:  # pylint: disable=W0703
				_LOG.exception("FrameMain._on_menu_file_load error")
				msgdlg = wx.lib.dialogs.ScrolledMessageDialog(self.wnd,
						str(err), _("Synchronisation error"))
				msgdlg.ShowModal()
				msgdlg.Destroy()
				dlgp.update(100, _("Error: ") + str(err))
			dlgp.mark_finished(2)
			appconfig.set('files', 'last_dir', os.path.dirname(filename))
			appconfig.set('files', 'last_file', os.path.basename(filename))
			publisher.sendMessage('task.update')
		dlg.Destroy()
Exemplo n.º 3
0
	def _synchronize(self, on_load=True, autoclose=False):
		""" Synchronize data.

		Attr:
			on_load: if true only read data.
			autoclose: close progress dialog after sync (if no errors)
		"""
		use_dropbox = (self._appconfig.get('sync', 'use_dropbox') and
				dbsync.is_available())
		if not use_dropbox:
			last_sync_file = self._appconfig.get('files', 'last_sync_file')
			if not last_sync_file:
				dlg = wx.FileDialog(self.wnd,
						_("Please select sync file."),
						defaultDir=self._appconfig.get('files', 'last_dir', ''),
						defaultFile=self._appconfig.get('files', 'last_file',
								'GTD_SYNC.zip'),
						style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
				if dlg.ShowModal() == wx.ID_OK:
					last_sync_file = dlg.GetPath()
				dlg.Destroy()
				if last_sync_file:
					self._appconfig.set('files', 'last_sync_file', last_sync_file)
			if not last_sync_file:
				return
		dlg = DlgSyncProggress(self.wnd)
		dlg.run()
		try:
			if use_dropbox:
				dbsync.sync(load_only=on_load)
			else:
				sync.sync(last_sync_file, load_only=on_load)
		except sync.SyncLockedError:
			msgbox = wx.MessageDialog(dlg.wnd, _("Sync file is locked."),
					_("wxGTD"), wx.OK | wx.ICON_HAND)
			msgbox.ShowModal()
			msgbox.Destroy()
			dlg.update(100, _("Sync file is locked."))
			autoclose = False
		except sync.OtherSyncError as err:
			_LOG.exception('FrameMain._on_menu_file_sync error: %r',
					str(err))
			msgdlg = wx.lib.dialogs.ScrolledMessageDialog(self.wnd,
					str(err), _("Synchronisation error"))
			msgdlg.ShowModal()
			msgdlg.Destroy()
			dlg.update(100, _("Error: ") + str(err))
			autoclose = False
		dlg.mark_finished(2 if autoclose else -1)