~ubuntu-branches/ubuntu/quantal/python-pyo/quantal

« back to all changes in this revision

Viewing changes to utils/PyoDoc.py

  • Committer: Package Import Robot
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2012-07-03 23:45:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120703234541-jh5jg00lvljnwq8m
Tags: 0.6.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
# encoding: utf-8
3
3
from __future__ import with_statement
4
 
import subprocess
 
4
import subprocess, threading, os
5
5
import wx
6
6
import wx.stc  as  stc
7
7
from wx.lib.embeddedimage import PyEmbeddedImage
9
9
 
10
10
DOC_AS_SINGLE_APP = False
11
11
 
12
 
if wx.Platform == '__WXMSW__':
13
 
    TEMP_PATH = os.path.join(os.path.expanduser('~'), "My Documents", ".epyo")
14
 
else:
15
 
    TEMP_PATH = os.path.join(os.path.expanduser('~'), '.epyo')
 
12
TEMP_PATH = os.path.join(os.path.expanduser('~'), '.epyo')
16
13
if not os.path.isdir(TEMP_PATH):
17
14
    os.mkdir(TEMP_PATH)
18
15
DOC_PATH = os.path.join(TEMP_PATH, 'doc')
34
31
for key, value in DOC_STYLES['Default'].items():
35
32
  DOC_FACES[key] = value
36
33
 
37
 
terminal_client_script = """set my_path to quoted form of POSIX path of "%s"
38
 
set my_file to quoted form of POSIX path of "%s"
39
 
set which_python to quoted form of POSIX path of "%s"
40
 
tell application "System Events"
41
 
tell application process "Terminal"
42
 
    set frontmost to true
43
 
    keystroke "clear"
44
 
    keystroke return
45
 
    delay 0.25
46
 
    keystroke "cd " & my_path
47
 
    keystroke return
48
 
    delay 0.25
49
 
    keystroke %swhich_python & " " & my_file & " &"
50
 
    keystroke return
51
 
    delay 0.25
52
 
    end tell
53
 
    tell application process "E-Pyo"
54
 
    set frontmost to true
55
 
    end tell
56
 
end tell
57
 
"""
58
 
terminal_client_script_path = os.path.join(TEMP_PATH, "terminal_client_script.scpt")
59
 
 
60
34
# ***************** Catalog starts here *******************
61
35
 
62
36
catalog = {}
651
625
                    panel.win = stc.StyledTextCtrl(panel, -1, size=panel.GetSize(), style=wx.SUNKEN_BORDER)
652
626
                    panel.win.LoadFile(os.path.join(DOC_PATH, word))
653
627
                    panel.win.SetMarginWidth(1, 0)
654
 
                    #panel.win.SetReadOnly(True)
655
628
                    panel.win.Bind(wx.EVT_LEFT_DOWN, self.MouseDown)
656
629
                    if self.searchKey != None:
657
630
                        words = complete_words_from_str(panel.win.GetText(), self.searchKey)
915
888
        text = self.doc_panel.getExampleScript()
916
889
        with open(DOC_EXAMPLE_PATH, "w") as f:
917
890
            f.write(text)
918
 
        if not DOC_AS_SINGLE_APP and self.osx_app_bundled:
919
 
            f = open(terminal_client_script_path, "w")
 
891
        th = RunningThread(DOC_EXAMPLE_PATH, TEMP_PATH, self.which_python, self.osx_app_bundled, self.caller_need_to_invoke_32_bit, self.set_32_bit_arch)
 
892
        th.start()
 
893
        wx.FutureCall(8000, self.status.SetStatusText, "", 0)
 
894
 
 
895
class RunningThread(threading.Thread):
 
896
    def __init__(self, path, cwd, which_python, osx_app_bundled, caller_need_to_invoke_32_bit, set_32_bit_arch):
 
897
        threading.Thread.__init__(self)
 
898
        self.path = path
 
899
        self.cwd = cwd
 
900
        self.which_python = which_python
 
901
        self.osx_app_bundled = osx_app_bundled
 
902
        self.caller_need_to_invoke_32_bit = caller_need_to_invoke_32_bit
 
903
        self.set_32_bit_arch = set_32_bit_arch
 
904
        self.terminated = False
 
905
 
 
906
    def kill(self):
 
907
        self.terminated = True
 
908
        self.proc.terminate()
 
909
 
 
910
    def run(self):
 
911
        if self.osx_app_bundled:
 
912
            vars_to_remove = "PYTHONHOME PYTHONPATH EXECUTABLEPATH RESOURCEPATH ARGVZERO PYTHONOPTIMIZE"
 
913
            prelude = "export -n %s;export PATH=/usr/local/bin:/usr/local/lib:$PATH;env;" % vars_to_remove
920
914
            if self.caller_need_to_invoke_32_bit:
921
 
                f.write(terminal_client_script % (TEMP_PATH, DOC_EXAMPLE_PATH, self.which_python, self.set_32_bit_arch))
 
915
                self.proc = subprocess.Popen(["%s%s%s %s" % (prelude, self.set_32_bit_arch, self.which_python, self.path)], 
 
916
                                shell=True, cwd=self.cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
922
917
            else:
923
 
                f.write(terminal_client_script % (TEMP_PATH, DOC_EXAMPLE_PATH, self.which_python, ""))
924
 
            f.close()
925
 
            pid = subprocess.Popen(["osascript", terminal_client_script_path]).pid
 
918
                self.proc = subprocess.Popen(["%s%s %s" % (prelude, self.which_python, self.path)], cwd=self.cwd, 
 
919
                                    shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
926
920
        elif wx.Platform == '__WXMAC__':
927
921
            if self.caller_need_to_invoke_32_bit:
928
 
                pid = subprocess.Popen(["%s%s %s" % (self.set_32_bit_arch, self.which_python, DOC_EXAMPLE_PATH)],
929
 
                                        cwd=TEMP_PATH, shell=True).pid
 
922
                self.proc = subprocess.Popen(["%s%s %s" % (self.set_32_bit_arch, self.which_python, self.path)], 
 
923
                                shell=True, cwd=self.cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
930
924
            else:
931
 
                pid = subprocess.Popen([self.which_python, DOC_EXAMPLE_PATH], cwd=TEMP_PATH).pid
 
925
                self.proc = subprocess.Popen(["%s %s" % (self.which_python, self.path)], cwd=self.cwd, 
 
926
                                shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
932
927
        else:
933
 
            pid = subprocess.Popen([self.which_python, DOC_EXAMPLE_PATH], cwd=TEMP_PATH).pid
934
 
        wx.FutureCall(8000, self.status.SetStatusText, "", 0)
 
928
                self.proc = subprocess.Popen([self.which_python, self.path], cwd=self.cwd, 
 
929
                                shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
930
 
 
931
        while self.proc.poll() == None and not self.terminated:
 
932
            time.sleep(.25)
935
933
 
936
934
if __name__ == "__main__":
937
935
    DOC_AS_SINGLE_APP = True