2010-07-08 20:01:03 +02:00
|
|
|
#!/usr/bin/env python
|
2010-07-04 03:05:16 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-09-07 15:50:29 +02:00
|
|
|
"""XWindows specific methods for TableWindows Class.
|
2009-05-21 17:13:39 +02:00
|
|
|
"""
|
2010-03-03 05:12:55 +01:00
|
|
|
# Copyright 2008 - 2010, Ray E. Barker
|
2009-05-21 17:13:39 +02:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
|
2010-09-23 08:31:16 +02:00
|
|
|
import L10n
|
|
|
|
_ = L10n.get_translation()
|
|
|
|
|
2009-05-21 17:13:39 +02:00
|
|
|
# Standard Library modules
|
|
|
|
import re
|
2009-11-16 19:04:25 +01:00
|
|
|
import os
|
2009-05-21 17:13:39 +02:00
|
|
|
|
|
|
|
# pyGTK modules
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
# Other Library modules
|
|
|
|
import Xlib.display
|
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
# FPDB modules
|
2009-05-21 17:13:39 +02:00
|
|
|
from TableWindow import Table_Window
|
|
|
|
|
|
|
|
# We might as well do this once and make them globals
|
|
|
|
disp = Xlib.display.Display()
|
|
|
|
root = disp.screen().root
|
|
|
|
|
|
|
|
class Table(Table_Window):
|
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
def find_table_parameters(self):
|
2009-05-21 17:13:39 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
self.number = None
|
2009-11-16 19:04:25 +01:00
|
|
|
for listing in os.popen('xwininfo -root -tree').readlines():
|
2010-09-07 15:50:29 +02:00
|
|
|
if re.search(self.search_string, listing):
|
2010-07-31 12:38:24 +02:00
|
|
|
mo = re.match('\s+([\dxabcdef]+) (.+):\s\(\"([a-zA-Z0-9\-.]+)\".+ (\d+)x(\d+)\+\d+\+\d+ \+(\d+)\+(\d+)', listing)
|
2010-09-09 02:35:59 +02:00
|
|
|
title = re.sub('\"', '', mo.group(2))
|
|
|
|
if self.check_bad_words(title): continue
|
2009-11-16 21:35:58 +01:00
|
|
|
self.number = int( mo.group(1), 0)
|
2010-09-09 02:35:59 +02:00
|
|
|
self.title = title
|
2010-09-07 15:50:29 +02:00
|
|
|
self.hud = None # specified later
|
|
|
|
break
|
2010-09-17 02:29:58 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
if self.number is None:
|
2009-05-21 17:13:39 +02:00
|
|
|
return None
|
2010-09-07 15:50:29 +02:00
|
|
|
|
|
|
|
self.window = self.get_window_from_xid(self.number)
|
|
|
|
self.parent = self.window.query_tree().parent
|
|
|
|
|
|
|
|
def get_window_from_xid(self, id):
|
|
|
|
for outside in root.query_tree().children:
|
|
|
|
if outside.id == id:
|
|
|
|
return outside
|
|
|
|
for inside in outside.query_tree().children:
|
|
|
|
if inside.id == id:
|
|
|
|
return inside
|
|
|
|
return None
|
2009-05-21 17:13:39 +02:00
|
|
|
|
|
|
|
def get_geometry(self):
|
|
|
|
try:
|
|
|
|
my_geo = self.window.get_geometry()
|
|
|
|
pa_geo = self.parent.get_geometry()
|
2010-09-07 15:50:29 +02:00
|
|
|
return {'x' : my_geo.x + pa_geo.x,
|
|
|
|
'y' : my_geo.y + pa_geo.y,
|
2009-05-21 17:13:39 +02:00
|
|
|
'width' : my_geo.width,
|
|
|
|
'height' : my_geo.height
|
|
|
|
}
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_window_title(self):
|
2010-09-17 02:29:58 +02:00
|
|
|
s = os.popen("xwininfo -wm -id %d" % self.number).read()
|
2010-09-07 15:50:29 +02:00
|
|
|
mo = re.search('"(.+)"', s)
|
|
|
|
try:
|
|
|
|
return mo.group(1)
|
|
|
|
except AttributeError:
|
|
|
|
return None
|
2010-09-17 02:29:58 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
|
2009-05-21 17:13:39 +02:00
|
|
|
def topify(self, hud):
|
|
|
|
hud.main_window.gdkhandle = gtk.gdk.window_foreign_new(hud.main_window.window.xid)
|
|
|
|
hud.main_window.gdkhandle.set_transient_for(self.gdk_handle)
|