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