OSDN Git Service

The 'create portable copy' wizard is now just one dialog, rather like the install...
authorMichael Curran <mick@kulgan.net>
Wed, 28 Mar 2012 04:15:29 +0000 (14:15 +1000)
committerMichael Curran <mick@kulgan.net>
Wed, 28 Mar 2012 04:15:29 +0000 (14:15 +1000)
source/gui/__init__.py
source/gui/installerGui.py
source/installer.py

index 7856967..88865c2 100644 (file)
@@ -229,8 +229,9 @@ class MainFrame(wx.Frame):
                if isInMessageBox:\r
                        return\r
                self.prePopup()\r
-               from gui.installerGui import createPortableCopy\r
-               createPortableCopy()\r
+               import gui.installerGui\r
+               d=gui.installerGui.PortableCreaterDialog(gui.mainFrame)\r
+               d.Show()\r
                self.postPopup()\r
 \r
        def onInstallCommand(self, evt):\r
index 7b0aff6..3fa0506 100644 (file)
@@ -85,20 +85,60 @@ class IndeterminateProgressDialog(wx.ProgressDialog):
                self.timer.Stop()\r
                self.Destroy()\r
 \r
-def createPortableCopy():\r
-               with wx.DirDialog(gui.mainFrame,_("Choose where you wish to place the portable copy of NVDA")) as d:\r
-                       if d.ShowModal()!=wx.ID_OK:\r
-                               return\r
-                       path=d.Path\r
-               copyUserConfig=gui.messageBox(_("Would you like to include your current NVDA settings in the portable copy?"), _("Copy User Configuration"), wx.YES_NO|wx.ICON_QUESTION) == wx.YES\r
-               createAutorun=(ctypes.windll.kernel32.GetDriveTypeW(os.path.splitdrive(path)[0]+u'\\')==2 and gui.messageBox(_("Would you like to create an autorun file for your removable drive to allow NVDA to start automatically?"), _("Removable Drive Detected"), wx.YES_NO|wx.ICON_QUESTION) == wx.YES)\r
-\r
-               d = IndeterminateProgressDialog(gui.mainFrame, _("Creating Portable Copy"), _("Please wait while a portable copy of NVDA is created."))\r
-               try:\r
-                       installer.CreatePortableCopy(path,copyUserConfig=copyUserConfig,createAutorun=createAutorun)\r
-               except OSError:\r
-                       d.done()\r
-                       gui.messageBox(_("Failed to create portable copy"),_("Error"))\r
-                       return\r
+class PortableCreaterDialog(wx.Dialog):\r
+\r
+       def __init__(self, parent):\r
+               super(PortableCreaterDialog, self).__init__(parent, title=_("Create Portable NVDA"))\r
+               mainSizer = self.mainSizer = wx.BoxSizer(wx.VERTICAL)\r
+               dialogCaption=wx.StaticText(self,label=_("To create a portable copy of NVDA, please select the path and other options and then press Continue")) \r
+               mainSizer.Add(dialogCaption)\r
+               optionsSizer = wx.StaticBoxSizer(wx.StaticBox(self, label=_("Portable options")), wx.HORIZONTAL)\r
+               sizer = wx.StaticBoxSizer(wx.StaticBox(self, label=_("Portable directory:")), wx.HORIZONTAL)\r
+               ctrl = self.portableDirectoryEdit = wx.TextCtrl(self, value='e:\\')\r
+               sizer.Add(ctrl)\r
+               ctrl = wx.Button(self, label=_("Browse..."))\r
+               ctrl.Bind(wx.EVT_BUTTON, self.onBrowseForPortableDirectory)\r
+               sizer.Add(ctrl)\r
+               optionsSizer.Add(sizer)\r
+               ctrl = self.createAutorunCheckbox = wx.CheckBox(self, label=_("Create an &Autorun file"))\r
+               ctrl.Value = False\r
+               optionsSizer.Add(ctrl)\r
+               ctrl = self.copyUserConfigCheckbox = wx.CheckBox(self, label=_("Copy current &user configuration"))\r
+               ctrl.Value = False\r
+               optionsSizer.Add(ctrl)\r
+               mainSizer.Add(optionsSizer)\r
+\r
+               sizer = wx.BoxSizer(wx.HORIZONTAL)\r
+               ctrl = wx.Button(self, label=_("C&ontinue"), id=wx.ID_OK)\r
+               ctrl.Bind(wx.EVT_BUTTON, self.onCreatePortable)\r
+               sizer.Add(ctrl)\r
+               sizer.Add(wx.Button(self, id=wx.ID_CANCEL))\r
+               # If we bind this using button.Bind, it fails to trigger when the dialog is closed.\r
+               self.Bind(wx.EVT_BUTTON, self.onCancel, id=wx.ID_CANCEL)\r
+               mainSizer.Add(sizer)\r
+\r
+               self.Sizer = mainSizer\r
+\r
+       def onBrowseForPortableDirectory(self, evt):\r
+               with wx.DirDialog(self, _("Select portable  directory"), defaultPath=self.portableDirectoryEdit.Value) as d:\r
+                       if d.ShowModal() == wx.ID_OK:\r
+                               self.portableDirectoryEdit.Value = d.Path\r
+\r
+       def onCreatePortable(self, evt):\r
+               self.Hide()\r
+               doCreatePortable(self.portableDirectoryEdit.Value,self.createAutorunCheckbox.Value,self.copyUserConfigCheckbox.Value)\r
+\r
+       def onCancel(self, evt):\r
+               self.Destroy()\r
+\r
+def doCreatePortable(portableDirectory,createAutorun=False,copyUserConfig=False):\r
+       d = IndeterminateProgressDialog(gui.mainFrame, _("Creating Portable Copy"), _("Please wait while a portable copy of NVDA is created."))\r
+       try:\r
+               installer.CreatePortableCopy(portableDirectory,copyUserConfig=copyUserConfig,createAutorun=createAutorun)\r
+       except:\r
+               log.error("Failed to create portable copy",exc_info=True)\r
                d.done()\r
-               gui.messageBox(_("Successfully created a portable copy of NVDA at %s")%path,_("Success"))\r
+               gui.messageBox(_("Failed to create portable copy"),_("Error"))\r
+               return\r
+       d.done()\r
+       gui.messageBox(_("Successfully created a portable copy of NVDA at %s")%portableDirectory,_("Success"))\r
index da2b0c7..40ef1d4 100644 (file)
@@ -8,6 +8,7 @@ import os
 import tempfile\r
 import shutil\r
 import shellapi\r
+import globalVars\r
 import languageHandler\r
 import config\r
 import versionInfo\r