Coverage for XTables.py: 0%

54 statements  

« 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"""XWindows specific methods for TableWindows Class. 

4""" 

5# Copyright 2008 - 2011, Ray E. Barker 

6 

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 

20 

21######################################################################## 

22 

23#import L10n 

24#_ = L10n.get_translation() 

25 

26# Standard Library modules 

27import re 

28import logging 

29 

30from PyQt5.QtGui import QWindow 

31from PyQt5.QtCore import Qt 

32from PyQt5.QtWidgets import QWidget 

33 

34# Other Library modules 

35import xcffib, xcffib.xproto 

36 

37# FPDB modules 

38from TableWindow import Table_Window 

39import Configuration 

40 

41xconn = xcffib.Connection() 

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

43 

44def getAtom(name): 

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

46 

47nclatom = getAtom("_NET_CLIENT_LIST") 

48winatom = getAtom("WINDOW") 

49wnameatom = getAtom("_NET_WM_NAME") 

50utf8atom = getAtom("UTF8_STRING") 

51 

52c = Configuration.Config() 

53log = logging.getLogger("hud") 

54 

55class Table(Table_Window): 

56 

57 def find_table_parameters(self): 

58 

59# This is called by __init__(). Find the poker table window of interest, 

60# given the self.search_string. Then populate self.number, self.title,  

61# self.window, and self.parent (if required). 

62 

63 wins = xconn.core.GetProperty(False, root, nclatom, winatom, 0, (2**32) - 1).reply().value.to_atoms() 

64 for win in wins: 

65 w_title = xconn.core.GetProperty(False, win, wnameatom, utf8atom, 0, (2**32) - 1).reply().value.to_string() 

66 print("w_title:" , w_title) 

67 #escaped_search_string = re.escape(self.search_string) 

68 #if re.search(escaped_search_string, w_title, re.I): 

69 if re.search(self.search_string, w_title, re.I): 

70 log.debug('%s matches: %s', w_title, self.search_string) 

71 log.info('"%s" matches: "%s"', w_title, self.search_string) 

72 title = w_title.replace('"', '') 

73 if self.check_bad_words(title): continue 

74 self.number = win 

75 print("self.number:", self.number) 

76 self.title = title 

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

78 break 

79 

80 if self.number is None: 

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

82 

83 # This function serves a double purpose. It fetches the X geometry 

84 # but it also is used to track for window lifecycle. When 

85 # get_geometry() returns False [None is deal as False], the table is 

86 # assumed dead and thus the HUD instance may be killed off. 

87 def get_geometry(self): 

88 wins = xconn.core.GetProperty(False, root, nclatom, winatom, 0, (2**32) - 1).reply().value.to_atoms() 

89 if self.number not in wins: 

90 return None 

91 try: 

92 geo = xconn.core.GetGeometry(self.number).reply() 

93 absxy = xconn.core.TranslateCoordinates(self.number, root, geo.x, geo.y).reply() 

94 #print('coord:', absxy.dst_x, absxy.dst_y) 

95 return {'x' : absxy.dst_x, 

96 'y' : absxy.dst_y, 

97 'width' : geo.width, 

98 'height' : geo.height 

99 } 

100 except xcffib.xproto.DrawableError: 

101 return None 

102 

103 def get_window_title(self): 

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

105 

106 

107 def topify(self, window): 

108# The idea here is to call setTransientParent on the HUD window, with the table window 

109# as the argument. This should keep the HUD window on top of the table window, as if  

110# the hud window was a dialog belonging to the table. 

111 

112# X doesn't like calling the foreign_new function in XTables. 

113# Nope don't know why. Moving it here seems to make X happy. 

114 if self.gdkhandle is None: 

115 self.gdkhandle = QWindow.fromWinId(int(self.number)) 

116 

117# This is the gdkhandle for the HUD window 

118 qwindow = (window.windowHandle()) 

119 qwindow.setTransientParent(self.gdkhandle) 

120 # Qt.Dialog keeps HUD windows above the table (but not above anything else) 

121 # Qy.CustomizedWindowHing removes the title bar. 

122 qwindow.setFlags(Qt.CustomizeWindowHint | Qt.Dialog)