Coverage for OSXTables.py: 0%
50 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-27 18:50 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-27 18:50 +0000
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3"""OSX specific methods for TableWindows Class.
4"""
5# Copyright 2008 - 2011, Ray E. Barker
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21########################################################################
23#import L10n
24#_ = L10n.get_translation()
26# Standard Library modules
27import re
29# Other Library modules
30import ctypes
32import AppKit # Work around some pyinstaller weirdness.
34from AppKit import NSView, NSWindowAbove, NSWorkspace
35from Quartz.CoreGraphics import (CGWindowListCreate,
36 CGWindowListCreateDescriptionFromArray,kCGWindowOwnerName,NSWorkspace,
37 kCGWindowBounds, kCGWindowName,CGWindowListCopyWindowInfo,kCGNullWindowID,
38 kCGWindowNumber,kCGWindowListExcludeDesktopElements,kCGWindowListOptionOnScreenOnly)
40# FPDB modules
41from TableWindow import Table_Window
43class Table(Table_Window):
45 def find_table_parameters(self):
47# This is called by __init__(). Find the poker table window of interest,
48# given the self.search_string. Then populate self.number, self.title,
49# self.window, and self.parent (if required).
51 self.number = None
52 WinList = CGWindowListCreate(0,0)
53 WinListDict = CGWindowListCreateDescriptionFromArray(WinList)
54 windows = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements|kCGWindowListOptionOnScreenOnly,kCGNullWindowID)
57 # for index in range(len(WinListDict)):
58 # for d in WinListDict[index]:
59 curr_app = NSWorkspace.sharedWorkspace().runningApplications()
60 curr_pid = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationProcessIdentifier']
61 #curr_app_name = curr_app.localizedName()
62 options = kCGWindowListOptionOnScreenOnly
63 windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID)
64 for window in windowList:
65 pid = window['kCGWindowOwnerPID']
66 windowNumber = window['kCGWindowNumber']
67 ownerName = window['kCGWindowOwnerName']
68 geometry = window['kCGWindowBounds']
69 windowTitle = window.get('kCGWindowName', self.search_string)
70 if curr_pid == pid:
71 print("%s - %s (PID: %d, WID: %d): %s" % (ownerName, windowTitle, pid, windowNumber, geometry))
75 title = windowTitle
76 if self.check_bad_words(title): continue
77 self.number = int(windowNumber)
78 self.title = title
79 return self.title
80 if self.number is None:
81 return None
83 def get_geometry(self):
84 WinListDict = CGWindowListCreateDescriptionFromArray((self.number,))
86 for d in WinListDict:
87 if d[kCGWindowNumber] == self.number:
88 return {'x' : int(d[kCGWindowBounds]['X']),
89 'y' : int(d[kCGWindowBounds]['Y']),
90 'width' : int(d[kCGWindowBounds]['Width']),
91 'height' : int(d[kCGWindowBounds]['Height'])
92 }
93 return None
95 def get_window_title(self):
96 WinListDict = CGWindowListCreateDescriptionFromArray((self.number,))
97 options = kCGWindowListOptionOnScreenOnly
98 #windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID)
99 for d in WinListDict:
100 #for b in windowList:
101 if d[kCGWindowNumber] == self.number:#and b[kCGWindowNumber] == self.number :
102 #print("kCGWindowName", b.get(kCGWindowName, ''))
103 return d[kCGWindowOwnerName]
104 return None
106 def topify(self, window):
107 winid = window.effectiveWinId()
108 cvp = ctypes.c_void_p(int(winid))
109 view = NSView(c_void_p=cvp)
110 if window.isVisible():
111 view.window().orderWindow_relativeTo_(NSWindowAbove, self.number)