Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: Lib/tkinter/test/support.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/threading.py ('k') | Lib/tkinter/test/test_ttk/test_widgets.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import sys
2 import tkinter 1 import tkinter
3 import unittest
4
5 _tk_unavailable = None
6
7 def check_tk_availability():
8 """Check that Tk is installed and available."""
9 global _tk_unavailable
10
11 if _tk_unavailable is None:
12 _tk_unavailable = False
13 if sys.platform == 'darwin':
14 # The Aqua Tk implementations on OS X can abort the process if
15 # being called in an environment where a window server connection
16 # cannot be made, for instance when invoked by a buildbot or ssh
17 # process not running under the same user id as the current console
18 # user. To avoid that, raise an exception if the window manager
19 # connection is not available.
20 from ctypes import cdll, c_int, pointer, Structure
21 from ctypes.util import find_library
22
23 app_services = cdll.LoadLibrary(find_library("ApplicationServices"))
24
25 if app_services.CGMainDisplayID() == 0:
26 _tk_unavailable = "cannot run without OS X window manager"
27 else:
28 class ProcessSerialNumber(Structure):
29 _fields_ = [("highLongOfPSN", c_int),
30 ("lowLongOfPSN", c_int)]
31 psn = ProcessSerialNumber()
32 psn_p = pointer(psn)
33 if ( (app_services.GetCurrentProcess(psn_p) < 0) or
34 (app_services.SetFrontProcess(psn_p) < 0) ):
35 _tk_unavailable = "cannot run without OS X gui process"
36 else: # not OS X
37 import tkinter
38 try:
39 tkinter.Button()
40 except tkinter.TclError as msg:
41 # assuming tk is not available
42 _tk_unavailable = "tk not available: %s" % msg
43
44 if _tk_unavailable:
45 raise unittest.SkipTest(_tk_unavailable)
46 return
47 2
48 def get_tk_root(): 3 def get_tk_root():
49 check_tk_availability() # raise exception if tk unavailable
50 try: 4 try:
51 root = tkinter._default_root 5 root = tkinter._default_root
52 except AttributeError: 6 except AttributeError:
53 # it is possible to disable default root in Tkinter, although 7 # it is possible to disable default root in Tkinter, although
54 # I haven't seen people doing it (but apparently someone did it 8 # I haven't seen people doing it (but apparently someone did it
55 # here). 9 # here).
56 root = None 10 root = None
57 11
58 if root is None: 12 if root is None:
59 # create a new master only if there isn't one already 13 # create a new master only if there isn't one already
(...skipping 10 matching lines...) Expand all
70 root.withdraw() 24 root.withdraw()
71 25
72 26
73 def simulate_mouse_click(widget, x, y): 27 def simulate_mouse_click(widget, x, y):
74 """Generate proper events to click at the x, y position (tries to act 28 """Generate proper events to click at the x, y position (tries to act
75 like an X server).""" 29 like an X server)."""
76 widget.event_generate('<Enter>', x=0, y=0) 30 widget.event_generate('<Enter>', x=0, y=0)
77 widget.event_generate('<Motion>', x=x, y=y) 31 widget.event_generate('<Motion>', x=x, y=y)
78 widget.event_generate('<ButtonPress-1>', x=x, y=y) 32 widget.event_generate('<ButtonPress-1>', x=x, y=y)
79 widget.event_generate('<ButtonRelease-1>', x=x, y=y) 33 widget.event_generate('<ButtonRelease-1>', x=x, y=y)
OLDNEW
« no previous file with comments | « Lib/threading.py ('k') | Lib/tkinter/test/test_ttk/test_widgets.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+