Something wrong with the python code

This commit is contained in:
Mengjuei 2012-03-20 22:27:03 -07:00
parent abfcbe4a4e
commit b3803637ba
1 changed files with 90 additions and 83 deletions

View File

@ -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): def awakeFromNib(self):
self.window.setDelegate_(self) self.window.setDelegate_(self)
self.window.setTitle_(NSLocalizedString("McBopomofo", "")) self.window.setTitle_(NSLocalizedString("McBopomofo", ""))
self.agreeButton.setTitle_(NSLocalizedString("Agree", "")) self.agreeButton.setTitle_(NSLocalizedString("Agree", ""))
self.cancelButton.setTitle_(NSLocalizedString("Cancel", "")) self.cancelButton.setTitle_(NSLocalizedString("Cancel", ""))
self.messageLabel.setStringValue_(NSLocalizedString("Do you agree with the license?", "")) self.messageLabel.setStringValue_(NSLocalizedString("Do you agree with the license?", ""))
self.licenseTextView.textStorage().mutableString().setString_(MIT_LICENSE) self.licenseTextView.textStorage().mutableString().setString_(MIT_LICENSE)
def windowWillClose_(self, notification): def windowWillClose_(self, notification):
NSApp.terminate_(self) NSApp.terminate_(self)
def checkOSVerion(self): def checkOSVerion(self):
mac_version = platform.mac_ver()[0].split(".") mac_version = platform.mac_ver()[0].split(".")
if int(mac_version[1]) < 6: if int(mac_version[1]) < 6:
NSRunAlertPanel(NSLocalizedString("McBopomofo requires on Mac OS X 10.6 or later verion.", ""), NSRunAlertPanel(NSLocalizedString("McBopomofo requires on Mac OS X 10.6 or later verion.", ""),
NSLocalizedString("Unable to install McBopomofo on your Mac.",""), NSLocalizedString("Unable to install McBopomofo on your Mac.",""),
NSLocalizedString("OK", ""), None, None) NSLocalizedString("OK", ""), None, None)
NSApp.terminate_(self) NSApp.terminate_(self)
def showLicenseWindow(self): def showLicenseWindow(self):
windowFrame = self.window.frame() windowFrame = self.window.frame()
windowFrame.size = self.licenseView.frame().size windowFrame.size = self.licenseView.frame().size
windowFrame.size.height += 20.0 windowFrame.size.height += 20.0
self.window.setFrame_display_animate_(windowFrame, True, True) self.window.setFrame_display_animate_(windowFrame, True, True)
self.window.contentView().addSubview_(self.licenseView) self.window.contentView().addSubview_(self.licenseView)
self.window.center() self.window.center()
self.window.setDefaultButtonCell_(self.agreeButton.cell()) self.window.setDefaultButtonCell_(self.agreeButton.cell())
self.window.makeKeyAndOrderFront_(None) self.window.makeKeyAndOrderFront_(None)
@objc.IBAction @objc.IBAction
def agreeLicenseAction_(self, sender): def agreeLicenseAction_(self, sender):
self.window.orderOut_(None) self.window.orderOut_(None)
from subprocess import call from subprocess import call
call(["/usr/bin/killall", "McBopomofo"]) call(["/usr/bin/killall", "McBopomofo"])
inputMethodDir = os.path.expanduser("~/Library/Input Methods") inputMethodDir = os.path.expanduser("~/Library/Input Methods")
if os.path.exists(inputMethodDir) is False: if os.path.exists(inputMethodDir) is False:
os.makedirs(inputMethodDir) os.makedirs(inputMethodDir)
packagePath = NSBundle.mainBundle().pathForResource_ofType_("McBopomofo", "app") packagePath = NSBundle.mainBundle().pathForResource_ofType_("McBopomofo", "app")
McBopomofoPath = os.path.join(inputMethodDir, "McBopomofo.app") McBopomofoPath = os.path.join(inputMethodDir, "McBopomofo.app")
if os.path.exists(McBopomofoPath) is True: WrongPath = os.path.join(McBopomofoPath, "McBopomofo.app")
try: if os.path.exists(WrongPath) is True:
call(["/bin/cp", "-R", packagePath, McBopomofoPath]) try:
except: shutil.rmtree(WrongPath)
NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""), except:
NSLocalizedString("Failed to overwrite existing installation.", ""), """do nothing"""
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 if os.path.exists(McBopomofoPath) is True:
try: try:
call([os.path.join(McBopomofoPath, "Contents/MacOS/McBopomofo"), "install"]) call(["/bin/cp", "-R", packagePath, inputMethodDir])
except: except:
NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""), NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""),
NSLocalizedString("Failed to activate McBopomofo", ""), NSLocalizedString("Failed to overwrite existing installation.", ""),
NSLocalizedString("OK", ""), None, None) NSLocalizedString("OK", ""), None, None)
NSApp.terminate_(self) else:
NSRunAlertPanel(NSLocalizedString("Done!", ""), try:
NSLocalizedString("McBopomofo has been installed on your Mac.", ""), shutil.copytree(packagePath, McBopomofoPath)
NSLocalizedString("OK", ""), None, None) except:
NSApp.terminate_(self) NSRunAlertPanel(NSLocalizedString("Failed to install McBopomofo!", ""),
NSLocalizedString("Failed to copy application.", ""),
NSLocalizedString("OK", ""), None, None)
NSApp.terminate_(self)
@objc.IBAction print McBopomofoPath
def disagreeLicenseAction_(self, sender): try:
NSApp.terminate_(self) 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)
def applicationDidFinishLaunching_(self, sender): @objc.IBAction
NSApp.activateIgnoringOtherApps_(True) def disagreeLicenseAction_(self, sender):
self.checkOSVerion() NSApp.terminate_(self)
self.showLicenseWindow()
def applicationDidFinishLaunching_(self, sender):
NSApp.activateIgnoringOtherApps_(True)
self.checkOSVerion()
self.showLicenseWindow()