Coverage for XTables.py: 0%

54 statements  

« prev     ^ index     » next       coverage.py v7.6.3, created at 2024-10-15 19:33 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3"""XWindows specific methods for TableWindows Class.""" 

4# Copyright 2008 - 2011, Ray E. Barker 

5 

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 

19 

20######################################################################## 

21 

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 

24 

25# import L10n 

26# _ = L10n.get_translation() 

27 

28# Standard Library modules 

29import re 

30import logging 

31 

32from PyQt5.QtGui import QWindow 

33from PyQt5.QtCore import Qt 

34 

35# Other Library modules 

36import xcffib, xcffib.xproto 

37 

38# FPDB modules 

39from TableWindow import Table_Window 

40import Configuration 

41 

42xconn = xcffib.Connection() 

43root = xconn.get_setup().roots[xconn.pref_screen].root 

44 

45 

46def getAtom(name): 

47 return xconn.core.InternAtom(False, len(name), name).reply().atom 

48 

49 

50nclatom = getAtom("_NET_CLIENT_LIST") 

51winatom = getAtom("WINDOW") 

52wnameatom = getAtom("_NET_WM_NAME") 

53utf8atom = getAtom("UTF8_STRING") 

54 

55c = Configuration.Config() 

56log = logging.getLogger("hud") 

57 

58 

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). 

64 

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_string() 

68 print("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 print("self.number:", self.number) 

79 self.title = title 

80 print("self.title:", self.title) 

81 break 

82 

83 if self.number is None: 

84 log.warning(("No match in XTables for table '%s'."), self.search_string) 

85 

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 # print('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 

101 

102 def get_window_title(self): 

103 return xconn.core.GetProperty(False, self.number, wnameatom, utf8atom, 0, (2**32) - 1).reply().value.to_string() 

104 

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. 

109 

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)) 

114 

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)