3

I have to represent a directory structure as a graph using PyQt. e.g. Inside the 'Main' directory I have some files along with few other directories viz 'Inbox', 'Sent', 'Outbox', etc. These sub-directories will consist of emails downloaded from an IMAP server. The user should definitely have the access to drag and pull nodes (especially the leaves).

I referred to the example set of PyQt but did not find any such example where I can dynamically add a node and edge to the graph. Although, I saw an example at Bezier curve with control points but could not figure out a way.

All the examples in PyQt example set usually accept a numpy array as an input, and plots it to x & y coordinates of a 2D graph. I am not sure how to map directories with a numpy array, as I do not intend to plot using coordinates. The example code from PyQt looks like:

## Define positions of nodes
pos = np.array([[0,0],[10,0],[0,10],[10,10],[5,5],[15,5]])

## Define the set of connections in the graph
adj = np.array([[0,1],[1,3],[3,2],[2,0],[1,5],[3,5],])

## Define the symbol to use for each node (this is optional)
symbols = ['o','o','o','o','t','+']

## Define the line style for each connection (this is optional)
lines = np.array([(255,0,0,255,1),(255,0,255,255,2),(255,0,255,255,3),
       (255,255,0,255,2),(255,0,0,255,1),(255,255,255,255,4),],
       dtype=[('red',np.ubyte),('green',np.ubyte), ('blue',np.ubyte), 'alpha',np.ubyte),('width',float)])

## Update the graph
g.setData(pos=pos, adj=adj, pen=lines, size=1, symbol=symbols, pxMode=False)

To present what I meant, I created a simple non-interactive plot using Plotly. The direcory Inbox and Outbox will have subdirectories as well. Directory structure.

Can anybody help me implementing the same using PyQt without showing any axes on the graph or point to me to some other resource?

Rishik Mani
  • 490
  • 8
  • 27

0 Answers0