Added correct HOME path into win.

This commit is contained in:
Sergey Kalinin 2017-03-20 12:38:14 +03:00
parent f9da7147d2
commit 07bb927271
2 changed files with 52 additions and 17 deletions

18
dm.py
View File

@ -1,20 +1,21 @@
# -*- coding: utf-8 -*-
import json, os, configparser, shutil
print(os.getenv("HOME"))
def firstInit():
# Инициализация переменныхб создание конфигруационного файла, копирование шаблонов
global db_type, db_hostname, db_user, db_password, db_name, template_file, db_type
config = configparser.RawConfigParser()
# проверяем тип ОС
if os.name == "nt":
cfg_dir = os.path.join(os.getenv("USERPROFILE"), ".dm")
elif os.name == "posix":
cfg_dir = os.path.join(os.getenv("HOME"), ".dm")
# определим каталог для конфигруции и создадим если его нет
cfg_dir = os.path.join(os.getenv("HOME"), ".dm")
if os.path.isdir(cfg_dir):
print(cfg_dir + " already exists")
else:
os.mkdir(cfg_dir)
cfg_file = os.path.join(cfg_dir, 'dm.cfg')
print(cfg_file)
# создадим файл конфигурации
config.add_section('DataBase')
config.set('DataBase', 'db_type', 'mysql')
@ -44,8 +45,8 @@ def firstInit():
db_name = os.path.join(work_dir, config.get('DataBase', 'db_name'))
else:
db_name = config.get('DataBase', 'db_name')
db_user = config.get('DataBase', 'db_user')
db_password = config.get('DataBase', 'db_password')
db_user = config.get('DataBase', 'db_user')
db_password = config.get('DataBase', 'db_password')
# Создаём нужные каталоги
if os.path.isdir(work_dir):
@ -66,8 +67,6 @@ def firstInit():
def dbConnect():
global c, db_type, db_hostname, db_user, db_password, db_name
print(db_name)
print(db_type)
if db_type == "mysql":
import pymysql
conn = pymysql.connect(
@ -78,7 +77,6 @@ def dbConnect():
charset='utf8')
elif db_type == "sqlite":
import sqlite3
print(db_name)
conn = sqlite3.connect(db_name)
else:
print(db_type + " database type does`t support")
@ -137,7 +135,7 @@ def createTables(tbl_list):
tbl_descr_list.append(one_Table_descr)
tbl_struct_list.append(one_Table_struct)
print(qwery_create)
#c.execute(qwery_create)
c.execute(qwery_create)
return tbl_names_list
def initDBstructure():

51
gui.py
View File

@ -8,7 +8,7 @@ from PyQt5.QtCore import Qt
#from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication, QListView, QListWidget, QTableWidget , QTableView, QTableWidgetItem, QHeaderView, QPushButton, QMenu
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
#import PyQt5.QtGui
#from PyQt5 import QtGui
from PyQt5.QtSql import *
#import pymysql
@ -29,8 +29,11 @@ class MainWin(QMainWindow):
self.initUI()
#заглушка
def qqqq(self):
print("Нажата клавиша DEL")
def addNewRecord(self):
editForm = EditForm()
editForm.setParent(self)
editForm.show()
#tablesDataWidget.setCellWidget(0, 0, edit)
#callEdit = tablesDataWidget.cellWidget(0, 0)
#callEdit.text()
@ -45,12 +48,12 @@ class MainWin(QMainWindow):
newAction = QAction(QIcon('img/new.gif'), 'Добавить', self)
newAction.setShortcut('Ins')
newAction.setStatusTip('Добавить')
newAction.triggered.connect(self.qqqq)
newAction.triggered.connect(self.addNewRecord)
deleteAction = QAction(QIcon('img/delete.gif'), 'Удалить', self)
deleteAction.setShortcut('Del')
deleteAction.setStatusTip('Удалить')
deleteAction.triggered.connect(self.qqqq)
#deleteAction.triggered.connect(self.qqqq)
exitAction = QAction(QIcon('img/exit.gif'), 'Выход', self)
exitAction.setShortcut('Ctrl+Q')
@ -125,13 +128,14 @@ class MyTable(QTableWidget):
self.resizeColumnsToContents()
self.horizontalHeader().setSortIndicatorShown(True)
self.horizontalHeader().setStretchLastSection(True)
#self.horizontalHeader().stretchLastSection()
self.horizontalHeader().setCascadingSectionResizes(True)
# равномерное изменение ширины столбцов
#self.horizontalHeader().setSectionResizeMode(1)
# изменение ширины столбцов по размеру текста
self.horizontalHeader().setSectionResizeMode(3)
#self.horizontalHeader().setSectionResizeMode(3)
self.horizontalHeader().setStyleSheet("color: blue;")
self.setWordWrap(True)
self.setSortingEnabled(True)
#print(self.tbl)
n = 0
@ -155,6 +159,7 @@ class MyTable(QTableWidget):
# показ контекстного меню
def contextMenuEvent(self, event):
Rmenu = QMenu(self)
addRecord = Rmenu.addAction("Добавить запись")
delRecord = Rmenu.addAction("Удалить запись")
relations = Rmenu.addAction("Показать связанные документы")
action = Rmenu.exec_(self.mapToGlobal(event.pos()))
@ -252,6 +257,38 @@ class WorkArea(QWidget):
self.lbl.setText(text)
self.lbl.adjustSize()
# Форма для добавления и редактирования
class EditForm(QWidget):
def __init__(self):
QWidget.__init__(self)
self.initUI()
#self.setWindowFlags(Qt.SubWindow)
#print(self.parent)
#self.parent = parent
def initUI(self):
title = QLabel('Title')
author = QLabel('Author')
review = QLabel('Review')
titleEdit = QLineEdit()
authorEdit = QLineEdit()
reviewEdit = QTextEdit()
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(title, 1, 0)
grid.addWidget(titleEdit, 1, 1)
grid.addWidget(author, 2, 0)
grid.addWidget(authorEdit, 2, 1)
grid.addWidget(review, 3, 0)
grid.addWidget(reviewEdit, 3, 1, 5, 1)
self.setLayout(grid)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Review')
#self.setParent(parent)
#self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)