Coverage for XTables.py: 0%
54 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"""XWindows 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# TODO: as suspected display management protocols wayland used in some linux distro like ubuntu is not working
23# probably need to use lib pyWayland, pywlroots or direct low level binding with ctype of C lib ...to study
25# import L10n
26# _ = L10n.get_translation()
28# Standard Library modules
29import re
30import logging
32from PyQt5.QtGui import QWindow
33from PyQt5.QtCore import Qt
35# Other Library modules
36import xcffib, xcffib.xproto
38# FPDB modules
39from TableWindow import Table_Window
40import Configuration
42xconn = xcffib.Connection()
43root = xconn.get_setup().roots[xconn.pref_screen].root
46def getAtom(name):
47 return xconn.core.InternAtom(False, len(name), name).reply().atom
50nclatom = getAtom("_NET_CLIENT_LIST")
51winatom = getAtom("WINDOW")
52wnameatom = getAtom("_NET_WM_NAME")
53utf8atom = getAtom("UTF8_STRING")
55c = Configuration.Config()
56log = logging.getLogger("hud")
59class Table(Table_Window):
60 def find_table_parameters(self):
61 # This is called by __init__(). Find the poker table window of interest,
62 # given the self.search_string. Then populate self.number, self.title,
63 # self.window, and self.parent (if required).
65 wins = xconn.core.GetProperty(False, root, nclatom, winatom, 0, (2**32) - 1).reply().value.to_atoms()
66 for win in wins:
67 w_title = xconn.core.GetProperty(False, win, wnameatom, utf8atom, 0, (2**32) - 1).reply().value.to_utf8()
68 log.debug(f"w_title: {w_title}")
69 # escaped_search_string = re.escape(self.search_string)
70 # if re.search(escaped_search_string, w_title, re.I):
71 if re.search(self.search_string, w_title, re.I):
72 log.debug("%s matches: %s", w_title, self.search_string)
73 log.info('"%s" matches: "%s"', w_title, self.search_string)
74 title = w_title.replace('"', "")
75 if self.check_bad_words(title):
76 continue
77 self.number = win
78 log.debug("self.number:", self.number)
79 self.title = title
80 log.debug("self.title:", self.title)
81 break
83 if self.number is None:
84 log.warning(("No match in XTables for table '%s'."), self.search_string)
86 # This function serves a double purpose. It fetches the X geometry
87 # but it also is used to track for window lifecycle. When
88 # get_geometry() returns False [None is deal as False], the table is
89 # assumed dead and thus the HUD instance may be killed off.
90 def get_geometry(self):
91 wins = xconn.core.GetProperty(False, root, nclatom, winatom, 0, (2**32) - 1).reply().value.to_atoms()
92 if self.number not in wins:
93 return None
94 try:
95 geo = xconn.core.GetGeometry(self.number).reply()
96 absxy = xconn.core.TranslateCoordinates(self.number, root, geo.x, geo.y).reply()
97 # log.debug('coord:', absxy.dst_x, absxy.dst_y)
98 return {"x": absxy.dst_x, "y": absxy.dst_y, "width": geo.width, "height": geo.height}
99 except xcffib.xproto.DrawableError:
100 return None
102 def get_window_title(self):
103 return xconn.core.GetProperty(False, self.number, wnameatom, utf8atom, 0, (2**32) - 1).reply().value.to_string()
105 def topify(self, window):
106 # The idea here is to call setTransientParent on the HUD window, with the table window
107 # as the argument. This should keep the HUD window on top of the table window, as if
108 # the hud window was a dialog belonging to the table.
110 # X doesn't like calling the foreign_new function in XTables.
111 # Nope don't know why. Moving it here seems to make X happy.
112 if self.gdkhandle is None:
113 self.gdkhandle = QWindow.fromWinId(int(self.number))
115 # This is the gdkhandle for the HUD window
116 qwindow = window.windowHandle()
117 qwindow.setTransientParent(self.gdkhandle)
118 # Qt.Dialog keeps HUD windows above the table (but not above anything else)
119 # Qy.CustomizedWindowHing removes the title bar.
120 qwindow.setFlags(Qt.CustomizeWindowHint | Qt.Dialog)