One user reported an issue with two of the buttons. Run the example code and observe the terminal output to test for the issue. When asked to select a directory select your desktop, enter "test" as the save name. It appears that where the selected folder doesn't include the path on my OS, it includes the path for the user.
import sys
import os
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow, QSizePolicy, QWidget, QFileDialog, QPushButton
from PyQt5.QtCore import Qt
class bug_example(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('bug')
self.setGeometry(10, 10, 400, 200)
self.setContentsMargins(0, 0, 0, 0)
self.singleButton = QPushButton('button', self)
self.singleButton.move(175, 5)
self.singleButton.resize(80, 30)
self.singleButton.clicked.connect(self.button_Button)
self.initUI()
def initUI(self):
self.show()
def button_Button(self):
dirname = QFileDialog.getExistingDirectory(self)
print('GET DIRECTORY NAME: ' + dirname)
pthnm = dirname + os.sep
print('GET PATH NAME: ' + pthnm)
x = pthnm.split(os.sep)
singlefolder = x[len(x) - 2]
print('GET SINGLE FOLDER: ' + singlefolder)
path = pthnm.replace(str(singlefolder) + os.sep, '')
print('GET TOTAL PATH: ' + path)
svpthnm1 = QFileDialog.getSaveFileName(self)
svpthnm = svpthnm1[0]
spltpthnm = svpthnm.split(os.sep)
flnm = spltpthnm[-1]
svpthnm2 = svpthnm + ' add on string'
print('SAVE FILE NAME: ' + flnm)
print('SAVE PATH NAME: ' + svpthnm2)
def main_func():
app = QApplication(sys.argv)
ex = bug_example()
sys.exit(app.exec_())
if __name__ == '__main__':
main_func()
GET DIRECTORY NAME: C:/Users/thoma/Desktop
GET PATH NAME: C:/Users/thoma/Desktop\
GET SINGLE FOLDER: C:/Users/thoma/Desktop
GET TOTAL PATH:
SAVE FILE NAME: C:/Users/thoma/Desktop/test
SAVE PATH NAME: C:/Users/thoma/Desktop/test add on string
(also notice the os.sep that is added to GET PATH NAME is wrong for the user, but this doesn't seem to matter)
GET DIRECTORY NAME: /Users/thomascasey/Desktop
GET PATH NAME: /Users/thomascasey/Desktop/
GET SINGLE FOLDER: Desktop
GET TOTAL PATH: /Users/thomascasey/
SAVE FILE NAME: test
SAVE PATH NAME: /Users/thomascasey/Desktop/test add on string