Something wrong with the python code
This commit is contained in:
parent
abfcbe4a4e
commit
b3803637ba
|
@ -24,89 +24,96 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
|
||||||
class InstallerAppDelegate(NSObject):
|
class InstallerAppDelegate(NSObject):
|
||||||
|
|
||||||
window = objc.IBOutlet()
|
window = objc.IBOutlet()
|
||||||
licenseView = objc.IBOutlet()
|
licenseView = objc.IBOutlet()
|
||||||
licenseTextView = objc.IBOutlet()
|
licenseTextView = objc.IBOutlet()
|
||||||
messageLabel = objc.IBOutlet()
|
messageLabel = objc.IBOutlet()
|
||||||
agreeButton = objc.IBOutlet()
|
agreeButton = objc.IBOutlet()
|
||||||
cancelButton = objc.IBOutlet()
|
cancelButton = objc.IBOutlet()
|
||||||
|
|
||||||
def awakeFromNib(self):
|
|
||||||
self.window.setDelegate_(self)
|
|
||||||
self.window.setTitle_(NSLocalizedString("McBopomofo", ""))
|
|
||||||
self.agreeButton.setTitle_(NSLocalizedString("Agree", ""))
|
|
||||||
self.cancelButton.setTitle_(NSLocalizedString("Cancel", ""))
|
|
||||||
self.messageLabel.setStringValue_(NSLocalizedString("Do you agree with the license?", ""))
|
|
||||||
self.licenseTextView.textStorage().mutableString().setString_(MIT_LICENSE)
|
|
||||||
|
|
||||||
def windowWillClose_(self, notification):
|
|
||||||
NSApp.terminate_(self)
|
|
||||||
|
|
||||||
def checkOSVerion(self):
|
def awakeFromNib(self):
|
||||||
mac_version = platform.mac_ver()[0].split(".")
|
self.window.setDelegate_(self)
|
||||||
if int(mac_version[1]) < 6:
|
self.window.setTitle_(NSLocalizedString("McBopomofo", ""))
|
||||||
NSRunAlertPanel(NSLocalizedString("McBopomofo requires on Mac OS X 10.6 or later verion.", ""),
|
self.agreeButton.setTitle_(NSLocalizedString("Agree", ""))
|
||||||
NSLocalizedString("Unable to install McBopomofo on your Mac.",""),
|
self.cancelButton.setTitle_(NSLocalizedString("Cancel", ""))
|
||||||
NSLocalizedString("OK", ""), None, None)
|
self.messageLabel.setStringValue_(NSLocalizedString("Do you agree with the license?", ""))
|
||||||
NSApp.terminate_(self)
|
self.licenseTextView.textStorage().mutableString().setString_(MIT_LICENSE)
|
||||||
|
|
||||||
def showLicenseWindow(self):
|
|
||||||
windowFrame = self.window.frame()
|
|
||||||
windowFrame.size = self.licenseView.frame().size
|
|
||||||
windowFrame.size.height += 20.0
|
|
||||||
self.window.setFrame_display_animate_(windowFrame, True, True)
|
|
||||||
self.window.contentView().addSubview_(self.licenseView)
|
|
||||||
self.window.center()
|
|
||||||
self.window.setDefaultButtonCell_(self.agreeButton.cell())
|
|
||||||
self.window.makeKeyAndOrderFront_(None)
|
|
||||||
|
|
||||||
@objc.IBAction
|
|
||||||
def agreeLicenseAction_(self, sender):
|
|
||||||
self.window.orderOut_(None)
|
|
||||||
from subprocess import call
|
|
||||||
call(["/usr/bin/killall", "McBopomofo"])
|
|
||||||
|
|
||||||
inputMethodDir = os.path.expanduser("~/Library/Input Methods")
|
|
||||||
if os.path.exists(inputMethodDir) is False:
|
|
||||||
os.makedirs(inputMethodDir)
|
|
||||||
|
|
||||||
packagePath = NSBundle.mainBundle().pathForResource_ofType_("McBopomofo", "app")
|
|
||||||
McBopomofoPath = os.path.join(inputMethodDir, "McBopomofo.app")
|
|
||||||
if os.path.exists(McBopomofoPath) is True:
|
|
||||||
try:
|
|
||||||
call(["/bin/cp", "-R", packagePath, McBopomofoPath])
|
|
||||||
except:
|
|
||||||
NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""),
|
|
||||||
NSLocalizedString("Failed to overwrite existing installation.", ""),
|
|
||||||
NSLocalizedString("OK", ""), None, None)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
shutil.copytree(packagePath, McBopomofoPath)
|
|
||||||
except:
|
|
||||||
NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""),
|
|
||||||
NSLocalizedString("Failed to copy application.", ""),
|
|
||||||
NSLocalizedString("OK", ""), None, None)
|
|
||||||
NSApp.terminate_(self)
|
|
||||||
|
|
||||||
print McBopomofoPath
|
def windowWillClose_(self, notification):
|
||||||
try:
|
NSApp.terminate_(self)
|
||||||
call([os.path.join(McBopomofoPath, "Contents/MacOS/McBopomofo"), "install"])
|
|
||||||
except:
|
def checkOSVerion(self):
|
||||||
NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""),
|
mac_version = platform.mac_ver()[0].split(".")
|
||||||
NSLocalizedString("Failed to activate McBopomofo", ""),
|
if int(mac_version[1]) < 6:
|
||||||
NSLocalizedString("OK", ""), None, None)
|
NSRunAlertPanel(NSLocalizedString("McBopomofo requires on Mac OS X 10.6 or later verion.", ""),
|
||||||
NSApp.terminate_(self)
|
NSLocalizedString("Unable to install McBopomofo on your Mac.",""),
|
||||||
NSRunAlertPanel(NSLocalizedString("Done!", ""),
|
NSLocalizedString("OK", ""), None, None)
|
||||||
NSLocalizedString("McBopomofo has been installed on your Mac.", ""),
|
NSApp.terminate_(self)
|
||||||
NSLocalizedString("OK", ""), None, None)
|
|
||||||
NSApp.terminate_(self)
|
def showLicenseWindow(self):
|
||||||
|
windowFrame = self.window.frame()
|
||||||
|
windowFrame.size = self.licenseView.frame().size
|
||||||
|
windowFrame.size.height += 20.0
|
||||||
|
self.window.setFrame_display_animate_(windowFrame, True, True)
|
||||||
|
self.window.contentView().addSubview_(self.licenseView)
|
||||||
|
self.window.center()
|
||||||
|
self.window.setDefaultButtonCell_(self.agreeButton.cell())
|
||||||
|
self.window.makeKeyAndOrderFront_(None)
|
||||||
|
|
||||||
|
@objc.IBAction
|
||||||
|
def agreeLicenseAction_(self, sender):
|
||||||
|
self.window.orderOut_(None)
|
||||||
|
from subprocess import call
|
||||||
|
call(["/usr/bin/killall", "McBopomofo"])
|
||||||
|
|
||||||
|
inputMethodDir = os.path.expanduser("~/Library/Input Methods")
|
||||||
|
if os.path.exists(inputMethodDir) is False:
|
||||||
|
os.makedirs(inputMethodDir)
|
||||||
|
|
||||||
|
packagePath = NSBundle.mainBundle().pathForResource_ofType_("McBopomofo", "app")
|
||||||
|
McBopomofoPath = os.path.join(inputMethodDir, "McBopomofo.app")
|
||||||
|
WrongPath = os.path.join(McBopomofoPath, "McBopomofo.app")
|
||||||
|
if os.path.exists(WrongPath) is True:
|
||||||
|
try:
|
||||||
|
shutil.rmtree(WrongPath)
|
||||||
|
except:
|
||||||
|
"""do nothing"""
|
||||||
|
|
||||||
|
if os.path.exists(McBopomofoPath) is True:
|
||||||
|
try:
|
||||||
|
call(["/bin/cp", "-R", packagePath, inputMethodDir])
|
||||||
|
except:
|
||||||
|
NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""),
|
||||||
|
NSLocalizedString("Failed to overwrite existing installation.", ""),
|
||||||
|
NSLocalizedString("OK", ""), None, None)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
shutil.copytree(packagePath, McBopomofoPath)
|
||||||
|
except:
|
||||||
|
NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""),
|
||||||
|
NSLocalizedString("Failed to copy application.", ""),
|
||||||
|
NSLocalizedString("OK", ""), None, None)
|
||||||
|
NSApp.terminate_(self)
|
||||||
|
|
||||||
|
print McBopomofoPath
|
||||||
|
try:
|
||||||
|
call([os.path.join(McBopomofoPath, "Contents/MacOS/McBopomofo"), "install"])
|
||||||
|
except:
|
||||||
|
NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""),
|
||||||
|
NSLocalizedString("Failed to activate McBopomofo", ""),
|
||||||
|
NSLocalizedString("OK", ""), None, None)
|
||||||
|
NSApp.terminate_(self)
|
||||||
|
NSRunAlertPanel(NSLocalizedString("Done!", ""),
|
||||||
|
NSLocalizedString("McBopomofo has been installed on your Mac.", ""),
|
||||||
|
NSLocalizedString("OK", ""), None, None)
|
||||||
|
NSApp.terminate_(self)
|
||||||
|
|
||||||
|
@objc.IBAction
|
||||||
|
def disagreeLicenseAction_(self, sender):
|
||||||
|
NSApp.terminate_(self)
|
||||||
|
|
||||||
|
def applicationDidFinishLaunching_(self, sender):
|
||||||
|
NSApp.activateIgnoringOtherApps_(True)
|
||||||
|
self.checkOSVerion()
|
||||||
|
self.showLicenseWindow()
|
||||||
|
|
||||||
@objc.IBAction
|
|
||||||
def disagreeLicenseAction_(self, sender):
|
|
||||||
NSApp.terminate_(self)
|
|
||||||
|
|
||||||
def applicationDidFinishLaunching_(self, sender):
|
|
||||||
NSApp.activateIgnoringOtherApps_(True)
|
|
||||||
self.checkOSVerion()
|
|
||||||
self.showLicenseWindow()
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue