I am trying to create A new folder and new data base file to be the startup page of an application, what i am looking for is to make the folder name and DB file name to be seen (globally)in all scripts. file 1
import os
import pandas as pd
from PyQt5.QtCore import *
from PyQt5 import QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.title = "Create a New Project"
self.setGeometry(200, 200 , 700, 400)
self.InitWindow()
def InitWindow(self):
self.setWindowTitle(self.title)
self.labelA = QLabel(' New Project:', self)
self.labelA.setGeometry(50, 50, 120, 30)
self.labelA.setStyleSheet('QLabel { color: blue; background-color: lightgreen; font-family: Times New Roman ; font-weight: bold; font-size: 10pt}')
self.lineA = QLineEdit(self)
self.lineA.setGeometry(200, 50, 300, 30)
self.lineA.setStyleSheet('QLineEdit { color: blue; background-color: lightgreen; font-family: Times New Roman ; font-weight: bold; font-size: 10pt}')
#self.lineA.textChanged.connect(self.project)
self.btn1 = QPushButton("Create", self)
self.btn1.setStyleSheet('QPushButton { color: blue; background-color: lightgreen; font-family: Times New Roman ; font-weight: bold; font-size: 10pt}')
self.btn1.setGeometry(600, 50, 70, 30)
self.btn1.clicked.connect(self.project)
self.labelc = QLabel(' DB File:', self)
self.labelc.setGeometry(50, 250, 120, 30)
self.labelc.setStyleSheet('QLabel { color: blue; background-color: lightgreen; font-family: Times New Roman ; font-weight: bold; font-size: 10pt}')
self.linec = QLineEdit(self)
self.linec.setGeometry(200, 250, 300, 30)
self.linec.setObjectName("linec")
self.linec.setStyleSheet('QLineEdit { color: blue; background-color: lightgreen; font-family: Times New Roman ; font-weight: bold; font-size: 10pt}')
#self.linec.textChanged.connect(self.project)
self.btn3 = QPushButton("Browse", self)
self.btn3.setStyleSheet('QPushButton { color: blue; background-color: lightgreen; font-family: Times New Roman ; font-weight: bold; font-size: 10pt}')
self.btn3.setGeometry(600, 250, 70, 30)
self.btn3.clicked.connect(self.database_file)
def project(self):
Dirname = str(QFileDialog.getExistingDirectory(self, 'Select Directory'))
if Dirname:
self.lineA.setText(Dirname)
self.database_file(Dirname)
print(Dirname)
return Dirname
def database_file(self, dir_name):
global path
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
Name, _ = QFileDialog.getSaveFileName(self, "Data Base File()", "",
"Data base Files (*.db)")
if Name:
file = open(Name,'w')
self.linec.setText(Name)
path = os.path.join(dir_name, Name )
print(path)
return path
if __name__ == '__main__':
import sys
App = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(App.exec_())
and then need to work with the database file and the project folder in all scripts considering that the folder and file names could be changed for every new project. and one of the other scripts maybe like this
import sys
import sqlite3
import pandas as pd
conn = sqlite3.connect('path')
data = pd.read_sql_query("select * from Curves_Calc_table ", conn)
data.to_csv('Dirname/data.csv',sep='\t' )
any advise will be appreciated