macfreezegui.py :  » Language-Interface » ChinesePython » chinesepython2.1.3-0.4 » Mac » Tools » macfreeze » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » ChinesePython 
ChinesePython » chinesepython2.1.3 0.4 » Mac » Tools » macfreeze » macfreezegui.py
"""macfreezegui - The GUI for macfreeze"""
import Dlg
import macfs
import EasyDialogs
import sys
import os
import string
import Res

ID_MAINDIALOG=512

ITEM_SCRIPTNAME=2
ITEM_SCRIPTBROWSE=3
ITEM_GENSOURCE=4
ITEM_GENSOURCE_ITEMS=(7,)
ITEM_SOURCEDIRNAME=6
ITEM_SOURCEDIRBROWSE=7
ITEM_GENRESOURCE=8
ITEM_GENRESOURCE_ITEMS=(11,)
ITEM_RESOURCENAME=10
ITEM_RESOURCEBROWSE=11
ITEM_GENAPPLET=12
ITEM_GENAPPLET_ITEMS=(15,)
ITEM_APPLETNAME=14
ITEM_APPLETBROWSE=15
ITEM_OK=16
ITEM_CANCEL=17
ITEM_DEBUG=19
ITEM_GENINFO=20

RADIO_GROUPING={
  ITEM_GENSOURCE: ITEM_GENSOURCE_ITEMS,
  ITEM_GENRESOURCE: ITEM_GENRESOURCE_ITEMS,
  ITEM_GENAPPLET: ITEM_GENAPPLET_ITEMS,
  ITEM_GENINFO: ()
}

def dialog(script=None):

  # Invent the various names
  if not script:
    fss, ok = macfs.PromptGetFile("Script?", "TEXT")
    if not ok:
      sys.exit(0)
    script = fss.as_pathname()
  basename, ext = os.path.splitext(script)
  if ext:
    appletname = basename
    rsrcname = basename + 'modules.rsrc'
  else:
    appletname = script + '.applet'
    rsrcname = script + 'modules.rsrc'
  dirname, basebase = os.path.split(basename)
  dirname = os.path.join(dirname, 'build.'+basebase)
  
  # Get the dialog, possibly opening the resource file (if needed)
  try:
    d = Dlg.GetNewDialog(ID_MAINDIALOG, -1)
  except Dlg.Error:
    d = None
  if d == None:
    try:
      Res.FSpOpenResFile('macfreeze.rsrc', 1)
    except Res.Error:
      d = None
    else:
      d = Dlg.GetNewDialog(ID_MAINDIALOG, -1)
  if d == None:
    EasyDialogs.Message("Dialog resource not found or faulty")
    sys.exit(1)
  
  # Fill the dialog
  d.SetDialogDefaultItem(ITEM_OK)
  d.SetDialogCancelItem(ITEM_CANCEL)
  
  _dialogsetfile(d, ITEM_SCRIPTNAME, script)
  _dialogsetfile(d, ITEM_SOURCEDIRNAME, dirname)
  _dialogsetfile(d, ITEM_RESOURCENAME, rsrcname)
  _dialogsetfile(d, ITEM_APPLETNAME, appletname)

  gentype = ITEM_GENSOURCE
  _dialogradiogroup(d, ITEM_GENSOURCE)

  # Interact
  d.GetDialogWindow().SetWTitle("Standalone application creation options")
  d.GetDialogWindow().ShowWindow()
  d.DrawDialog()
  while 1:
    item = Dlg.ModalDialog(None)
    if item == ITEM_OK:
      break
    elif item == ITEM_CANCEL:
      sys.exit(0)
    elif item in RADIO_GROUPING.keys():
      gentype = item
      _dialogradiogroup(d, item)
    elif item == ITEM_SCRIPTBROWSE:
      fss, ok = macfs.PromptGetFile("Script?")
      if ok:
        script = fss.as_pathname()
        _dialogsetfile(d, ITEM_SCRIPTNAME, script)
    elif item == ITEM_SOURCEDIRBROWSE:
      fss, ok = macfs.StandardPutFile("Output folder name", os.path.split(dirname)[1])
      if ok:
        dirname = fss.as_pathname()
        _dialogsetfile(d, ITEM_SOURCEDIRNAME, dirname)
    elif item == ITEM_RESOURCEBROWSE:
      fss, ok = macfs.StandardPutFile("Resource output file", os.path.split(rsrcname)[1])
      if ok:
        rsrcname = fss.as_pathname()
        _dialogsetfile(d, ITEM_RESOURCENAME, rsrcname)
    elif item == ITEM_APPLETBROWSE:
      fss, ok = macfs.StandardPutFile("Applet output file", os.path.split(appletname)[1])
      if ok:
        appletname = fss.as_pathname()
        _dialogsetfile(d, ITEM_APPLETNAME, appletname)
    else:
      pass
  tp, h, rect = d.GetDialogItem(ITEM_DEBUG)
  debug = Dlg.GetDialogItemText(h)
  try:
    debug = string.atoi(string.strip(debug))
  except ValueError:
    EasyDialogs.Message("Illegal debug value %s, set to zero."%`debug`)
    debug = 0
  if gentype == ITEM_GENSOURCE:
    return 'source', script, dirname, debug
  elif gentype == ITEM_GENRESOURCE:
    return 'resource', script, rsrcname, debug
  elif gentype == ITEM_GENAPPLET:
    return 'applet', script, appletname, debug
  elif gentype == ITEM_GENINFO:
    return 'info', script, '', debug
  raise 'Error in gentype', gentype

def _dialogradiogroup(d, item):
  for k in RADIO_GROUPING.keys():
    subitems = RADIO_GROUPING[k]
    tp, h, rect = d.GetDialogItem(k)
    if k == item:
      h.as_Control().SetControlValue(1)
      for i2 in subitems:
        d.ShowDialogItem(i2)
    else:
      h.as_Control().SetControlValue(0)
      for i2 in subitems:
        d.HideDialogItem(i2)

def _dialogsetfile(d, item, file):
  if len(file) > 32:
    file = '\311:' + os.path.split(file)[1]
  tp, h, rect = d.GetDialogItem(item)
  Dlg.SetDialogItemText(h, file)
      
if __name__ == '__main__':
  type, script, file, debug = dialog()
  print type, script, file, 'debug=%d'%debug
  sys.exit(1)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.