0
votes

The attachment shows what I'm trying to achieve.

a) The program reads in a csv file containing names of songs (song1 - song5 etc).

b) the exact names from the csv file display in a text widget i.e. the widget shows song1, song2, song 3 etc

c) a user clicks one of those names and the program looks in a directory that contains those exact names but with a mp3 suffix i.e. song1.mp3, song2.mp3 etc and loads vlc media player.

d) The song names obviously differ in real life, but I wanted to show that the CSV, text widget and windows explorer names are all common.

I need to understand how to make this happen.

1) I understand loading the csv and tagging the text, so the user knows where to click

2) I dont understand the procedure when a user clicks the text, i.e. how to work out the area in the text widget the user clicked and from that how to create some sort of binding to load the file, a mp3 suffix would need to be automatically attached also.

Program Overview

EDIT Working Code added

def viewFile(event):
        path = "c:\\pdf"
        suffix= ".pdf"
        self.outputbox.tag_remove("dwg", "1.0", "end")
        self.outputbox.tag_configure("dwg", background="red")
        self.outputbox.tag_add("dwg", "insert linestart", "insert lineend")
        getdwg=self.outputbox.get("insert linestart", "insert linestart+10c")
        getdwg=getdwg.strip()
        linkname = (getdwg + suffix)
        self.outputbox.tag_bind("dwg", "<ButtonRelease-1>", lambda event, filename=path + '/' + linkname: subprocess.run(filename, shell=True))

There is a couple of fixed items that are used to generate the final filename and path which may not be relevant to others namely 'path', 'suffix' but it appears to work as required :)

1

1 Answers

-1
votes

In Qt, which you could use with Pyqt or Pyside, you would populate a QListWidget where each of the items has label text and can be associated with files. You then connect the event of selecting an item on the list, i.e. Clicked or doubleClicked with a function that determines which list item is selected in the list, retrieve the Associated filename, and then execute the command you want calling the external program with the filename as input.