Can I get the XY coordinates of the mouse as an output

53 Views Asked by At

I am using camelot.plot to create a utility to aid table extraction from PDF files I would like to be able to get the XY coordinates of the mouse in order to define table areas and columns. I have used the following code to display a page from my PDF.

{
import camelot
import matplotlib.pyplot as plt

def mouseMotion(event):
    print('Mouse X - Mouse Y:',event.x,event.y)

tables = camelot.read_pdf('mydatafile.pdf', pages='1', flavor='stream',edge_tool=1500)

print ("Total Tables Extracted: ", tables.n)
#print(tables[0].df)

for i in range(0,tables.n):
camelot.plot(tables[i], kind='text').show
plt.connect('motion_notify_event',mouseMotion)
plt.show(block=True)
}

Using plt.connect I can get the mouse coordinates from the main window as shown in Figure 1 but I would like to access the coordinates of the mouse when in the chart area. RH corner of figure 2 shows the display of mouse coordinates which camelot.plot generates.

My plan is to be able to generate the table_areas and columns coordinate parameters used by camelot.read_pdf.

Figure 1

Figure 2

1

There are 1 best solutions below

0
Jecook On

Have looked into this as much as I can and come to the conclusion that since the display is being created by the Camelot library that there is no easy way to intercept the X-Y coordinates that are displayed in the lower right.

Unless someone else knows better?