Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

[{*.yml,*.yaml}]
indent_style = space
indent_size = 2

[*.py]
indent_style = space
indent_size = 2

# Tab indentation (no size specified)
[Makefile*]
indent_style = tab

13 changes: 7 additions & 6 deletions ldtp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
path = "."
sys.path.append(path)

import state
import client
from client_exception import LdtpExecutionError
from . import state
from . import client
from .client_exception import LdtpExecutionError

_t = None
_pollEvents = None
Expand Down Expand Up @@ -320,6 +320,7 @@ def poll_server(self):
# self._callback[name][0] - Event type
# self._callback[name][1] - Callback function
# self._callback[name][2] - Arguments to callback function
print(str(event.source) + " " + str(event.type))
for name in self._callback:
# Window created event
# User registered window events
Expand Down Expand Up @@ -397,7 +398,7 @@ def imagecapture(window_name = None, out_file = None, x = 0, y = 0,
try:
f.write(b64decode(data)) # Python 2
except TypeError:
f.write(b64decode(bytes(data,'utf-8'))) # Python 3
f.write(b64decode(data.data)) # Python 3
f.close()

return out_file
Expand All @@ -414,8 +415,8 @@ def waittillguinotexist(window_name, object_name = '',
guiTimeOut)
def guiexist(window_name, object_name = ''):
return _remote_guiexist(window_name, object_name)
def launchapp(cmd, args = [], delay = 0, env = 1, lang = "C"):
return _remote_launchapp(cmd, args, delay, env, lang)
def launchapp(cmd, args = [], delay = 0, env = 1, lang = "C", logfiles = None ):
return _remote_launchapp(cmd, args, delay, env, lang, logfiles)
def hasstate(window_name, object_name, state, guiTimeOut = 0):
return _remote_hasstate(window_name, object_name, state, guiTimeOut)
def selectrow(window_name, object_name, row_text):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 449, there is a unicode() call that should be converted to str() for python3

Expand Down
10 changes: 7 additions & 3 deletions ldtp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import traceback
import subprocess
from socket import error as SocketError
from ldtp.log import logger
from ldtp.client_exception import LdtpExecutionError, ERROR_CODE
from .log import logger
from .client_exception import LdtpExecutionError, ERROR_CODE

try:
import xmlrpclib
Expand Down Expand Up @@ -70,8 +70,12 @@ class _Method(xmlrpclib._Method):
def __call__(self, *args, **kwargs):
if _ldtp_debug:
logger.debug('%s(%s)' % (self.__name, \
', '.join(map(repr, args) + ['%s=%s' % (k, repr(v)) \
', '.join(list(map(repr, args)) + ['%s=%s' % (k, repr(v)) \
for k, v in kwargs.items()])))
try:
return self.__send(self.__name, args)
except BaseException as be:
logger.debug('%s(%s) Trying once more' % (self.__name, str(be)))
return self.__send(self.__name, args)

class Transport(xmlrpclib.Transport):
Expand Down
2 changes: 1 addition & 1 deletion ldtpd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def send(self):
os.kill(int(self.parentpid), signal.SIGUSR1)


from xmlrpc_daemon import XMLRPCLdtpd
from .xmlrpc_daemon import XMLRPCLdtpd
def main(port=4118, parentpid=None, XMLRPCLdtpdFactory=lambda: XMLRPCLdtpd()):
import os
os.environ['NO_GAIL'] = '1'
Expand Down
6 changes: 3 additions & 3 deletions ldtpd/combo_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"""

import pyatspi
from utils import Utils
from server_exception import LdtpServerException
from .utils import Utils
from .server_exception import LdtpServerException

class LayeredPane(Utils):
def _lp_selectitem(self, obj, item_name):
Expand Down Expand Up @@ -283,7 +283,7 @@ def unselectall(self, window_name, object_name):
except:
raise LdtpServerException('Unable to select all item')

class ComboBox(Utils, LayeredPane):
class ComboBox(LayeredPane):
def selectitem(self, window_name, object_name, item_name):
"""
Select combo box / layered pane item
Expand Down
78 changes: 55 additions & 23 deletions ldtpd/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import subprocess
try:
# If we have gtk3+ gobject introspection, use that
import gi
gi.require_version('Wnck', '3.0')
from gi.repository import Wnck as wnck
from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
Expand All @@ -40,14 +42,14 @@
# Not all environments support wnck package
pass
gtk3=False
from utils import Utils, ProcessStats
from constants import abbreviated_roles
from keypress_actions import KeyboardOp
from waiters import ObjectExistsWaiter, GuiExistsWaiter, \
from .utils import Utils, ProcessStats
from .constants import abbreviated_roles
from .keypress_actions import KeyboardOp
from .waiters import ObjectExistsWaiter, GuiExistsWaiter, \
GuiNotExistsWaiter, ObjectNotExistsWaiter, NullWaiter, \
MaximizeWindow, MinimizeWindow, UnmaximizeWindow, UnminimizeWindow, \
ActivateWindow, CloseWindow
from server_exception import LdtpServerException
from .server_exception import LdtpServerException
import os
import re
import sys
Expand All @@ -56,19 +58,19 @@
import traceback
from fnmatch import translate as glob_trans

from menu import Menu
from text import Text
from mouse import Mouse
from table import Table
from value import Value
from generic import Generic
from combo_box import ComboBox
from page_tab_list import PageTabList
from .menu import Menu
from .text import Text
from .mouse import Mouse
from .table import Table
from .value import Value
from .generic import Generic
from .combo_box import ComboBox
from .page_tab_list import PageTabList
from gi.repository import GLib

import thread
import _thread

class Ldtpd(Utils, ComboBox, Table, Menu, PageTabList,
class Ldtpd(ComboBox, Table, Menu, PageTabList,
Text, Mouse, Generic, Value):
"""
Core LDTP class.
Expand Down Expand Up @@ -101,6 +103,15 @@ def __del__(self):
self._process_stats[key].stop()

def _registered_event_cb(self, event):
l = [ "object:text-changed", "object:bounds-changed"]
show = True
for x in l:
if str(event.type).startswith(x):
show = False
if show:
print("event: " + str(event.source) + " " + str(event.type))
#import pdb
#pdb.set_trace()
try:
if event and event.source and event.type:
abbrev_role, abbrev_name, label_by=self._ldtpize_accessible( \
Expand Down Expand Up @@ -132,6 +143,9 @@ def _registered_kb_event_cb(self, event):

def _event_cb(self, event):
try:
if event:
print(dir(event))
print(event)
if event and event.type == "window:create" and event.source:
for window in self._callback:
if window and self._match_name_to_acc(window, event.source):
Expand Down Expand Up @@ -183,7 +197,7 @@ def getapplist(self):
# A11Y lookup error
continue
except GLib.Error as ge:
if "The application no longer exists" in ge:
if "The application no longer exists" in repr(ge):
continue
raise
return app_list
Expand Down Expand Up @@ -247,7 +261,16 @@ def delaycmdexec(self, delay=None):
"""
self._delaycmdexec=delay

def launchapp(self, cmd, args=[], delay=0, env=1, lang="C"):
def _cleanupProcess(self, process, logfile_fds):
""" Helper function to wait until the process has finished and then clean it up
"""
process.wait()
if logfile_fds:
for f in logfile_fds:
if f:
f.close()

def launchapp(self, cmd, args=[], delay=0, env=1, lang="C", logfiles=None):
"""
Launch application.

Expand All @@ -261,6 +284,8 @@ def launchapp(self, cmd, args=[], delay=0, env=1, lang="C"):
@type env: int
@param lang: Application language to be used
@type lang: string
@param logfiles: Optional filename-tuple to capture standard output and standard error. Output will be appended.
@type logfiles: (string, string)

@return: PID of new process
@rtype: integer
Expand All @@ -276,13 +301,18 @@ def launchapp(self, cmd, args=[], delay=0, env=1, lang="C"):
if lang:
os.environ['LANG']=lang
try:
process=subprocess.Popen([cmd]+args, close_fds=True)
files = None
if logfiles is None:
process=subprocess.Popen([cmd]+args, close_fds=True)
else:
files = [open(f, "a") if f else None for f in logfiles]
process=subprocess.Popen([cmd]+args, stdout=files[0], stderr=files[1])
# Let us wait so that the application launches
try:
time.sleep(int(delay))
except ValueError:
time.sleep(5)
thread.start_new_thread(process.wait,())
_thread.start_new_thread(self._cleanupProcess,(process, files))
except Exception as e:
raise LdtpServerException(str(e))
os.environ['NO_GAIL']='1'
Expand Down Expand Up @@ -456,7 +486,7 @@ def removecallback(self, window_name):

return 1

def registerevent(self, event_name):
def registerevent(self, event_name, cb=None):
"""
Register at-spi event

Expand All @@ -466,11 +496,13 @@ def registerevent(self, event_name):
@return: 1 if registration was successful, 0 if not.
@rtype: integer
"""
if cb is None:
cb = self._registered_event_cb

pyatspi.Registry.deregisterEventListener( \
self._registered_event_cb, *self._registered_events)
cb, *self._registered_events)
self._registered_events.append(event_name)
pyatspi.Registry.registerEventListener(self._registered_event_cb,
pyatspi.Registry.registerEventListener(cb,
*self._registered_events)
return 1

Expand Down Expand Up @@ -1574,7 +1606,7 @@ def getaccesskey(self, window_name, object_name):
key_binding = ''
try:
iaction = obj.queryAction()
for j in xrange(iaction.nActions):
for j in range(iaction.nActions):
if iaction.getKeyBinding(j) != '':
key_binding = iaction.getKeyBinding(j)
break
Expand Down
6 changes: 3 additions & 3 deletions ldtpd/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import tempfile
from base64 import b64encode

from utils import Utils
from server_exception import LdtpServerException
from .utils import Utils
from .server_exception import LdtpServerException

class Generic(Utils):
def imagecapture(self, window_name = None, x = 0, y = 0,
Expand Down Expand Up @@ -193,7 +193,7 @@ def imagecapture(self, window_name = None, x = 0, y = 0,
pb.save(tmpFile, 'png')
del pb
gc.collect()
rv = b64encode(open(tmpFile).read())
rv = b64encode(open(tmpFile,'rb').read())
os.remove(tmpFile)
return rv

5 changes: 3 additions & 2 deletions ldtpd/keypress_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

import re
import time

try:
from gi.repository import GObject as gobject
except:
import gobject
import pyatspi
import subprocess

from sequence_step import AtomicAction
from .sequence_step import AtomicAction
_ = lambda x: x

# Highest granularity, define timing for every single press and release
Expand Down Expand Up @@ -62,7 +63,7 @@ def _get_keyboard_keycodes():
shell = True, close_fds = True).communicate()
if output[0] != '':
output = output[0]
for line in output.split('\n'):
for line in output.decode().split('\n'):
if line.strip() == '':
continue
split = re.split('=', line, maxsplit = 2)
Expand Down
2 changes: 1 addition & 1 deletion ldtpd/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import re
import pyatspi
from utils import Utils
from .utils import Utils

class Menu(Utils):
def selectmenuitem(self, window_name, object_name):
Expand Down
Loading