Автоматическое определение пути к базе данных
Закончена работа над 1м окном
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import tkinter as tk
|
import sys
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
def hex_to_rgb(value):
|
def hex_to_rgb(value):
|
||||||
@@ -28,24 +28,17 @@ def setBckgroundButtonColor():
|
|||||||
|
|
||||||
return color
|
return color
|
||||||
|
|
||||||
def getFullPath(file):
|
|
||||||
put = os.getcwd()
|
|
||||||
path = str(put) + '\\' + file
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def setFrameSize():
|
|
||||||
"""
|
|
||||||
:parameter sh,sw - ширина и высота экрана, на котором
|
|
||||||
запускается программа
|
|
||||||
:return: w,h - размеры фрейма для отрисовки gui
|
|
||||||
"""
|
|
||||||
root = tk.Tk()
|
|
||||||
sw = root.winfo_screenwidth()
|
|
||||||
sh = root.winfo_screenheight()
|
|
||||||
w,h = int(0.75 * sw), int(0.75 * sh)
|
|
||||||
|
|
||||||
if w < 800 and h < 600:
|
|
||||||
w, h = 800, 600
|
|
||||||
|
|
||||||
|
def getSizeH():
|
||||||
|
app = wx.App(False)
|
||||||
|
sw, sh = wx.GetDisplaySize()
|
||||||
|
w = 0.75 * sw
|
||||||
|
h = 0.75 * sh
|
||||||
|
app.Destroy()
|
||||||
return w, h
|
return w, h
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ from sqlalchemy import Column, Integer, String, Float
|
|||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
import os
|
||||||
|
|
||||||
path = "C:\\Users\\danamir\\PycharmProjects\\odd-perekrestok\\db\\odd.db"
|
path_db = os.path.abspath("db/odd.db")
|
||||||
engine = create_engine("sqlite:///C:\\Users\\danamir\\PycharmProjects\\odd-perekrestok\\db\\odd.db", echo=True)
|
path = "sqlite:////" + path_db
|
||||||
|
engine = create_engine(path, echo=True)
|
||||||
Session = sessionmaker(bind=engine)
|
Session = sessionmaker(bind=engine)
|
||||||
Base = declarative_base(engine)
|
Base = declarative_base(engine)
|
||||||
meta = Base.metadata
|
meta = Base.metadata
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import wx
|
import wx
|
||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
|
import controller
|
||||||
|
|
||||||
|
|
||||||
class SeconPageFrame(wx.Frame):
|
class SeconPageFrame(wx.Frame):
|
||||||
@@ -37,6 +38,11 @@ class SeconPageFrame(wx.Frame):
|
|||||||
# begin wxGlade: SeconPageFrame.__set_properties
|
# begin wxGlade: SeconPageFrame.__set_properties
|
||||||
self.SetTitle("Расчет цикла светофорного регулирования")
|
self.SetTitle("Расчет цикла светофорного регулирования")
|
||||||
|
|
||||||
|
self.color = controller.setBacgroundColor()
|
||||||
|
self.SetBackgroundColour(self.color)
|
||||||
|
self.btnColor = controller.setBckgroundButtonColor()
|
||||||
|
self.btn2.SetBackgroundColour(self.btnColor)
|
||||||
|
|
||||||
def __do_layout(self):
|
def __do_layout(self):
|
||||||
# begin wxGlade: SeconPageFrame.__do_layout
|
# begin wxGlade: SeconPageFrame.__do_layout
|
||||||
sizer_1 = wx.BoxSizer(wx.VERTICAL)
|
sizer_1 = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
|||||||
37
main.py
37
main.py
@@ -6,6 +6,9 @@ from db.models import Student
|
|||||||
from sqlalchemy import exists
|
from sqlalchemy import exists
|
||||||
from db.models import Session
|
from db.models import Session
|
||||||
from gui import SecondPage
|
from gui import SecondPage
|
||||||
|
import tkinter as tk
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class MyFrame(wx.Frame):
|
class MyFrame(wx.Frame):
|
||||||
def __init__(self, *args, **kwds):
|
def __init__(self, *args, **kwds):
|
||||||
@@ -19,10 +22,13 @@ class MyFrame(wx.Frame):
|
|||||||
self.inpt_zachetka = wx.TextCtrl(self.panel_1, wx.ID_ANY, "")
|
self.inpt_zachetka = wx.TextCtrl(self.panel_1, wx.ID_ANY, "")
|
||||||
self.btn2 = wx.Button(self.panel_1, wx.ID_ANY, u"\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438")
|
self.btn2 = wx.Button(self.panel_1, wx.ID_ANY, u"\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438")
|
||||||
self.button_1 = wx.Button(self.panel_1, wx.ID_ANY, u"\u0414\u0430\u043b\u0435\u0435")
|
self.button_1 = wx.Button(self.panel_1, wx.ID_ANY, u"\u0414\u0430\u043b\u0435\u0435")
|
||||||
|
self.size = self.SetSize(600, 600)
|
||||||
|
|
||||||
self.__set_properties()
|
self.__set_properties()
|
||||||
self.__do_layout()
|
self.__do_layout()
|
||||||
|
self.__binds()
|
||||||
|
|
||||||
|
|
||||||
# end wxGlade
|
# end wxGlade
|
||||||
|
|
||||||
def __set_properties(self):
|
def __set_properties(self):
|
||||||
@@ -32,15 +38,13 @@ class MyFrame(wx.Frame):
|
|||||||
self.inpt_familia.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
|
self.inpt_familia.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
|
||||||
self.inpt_zachetka.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
|
self.inpt_zachetka.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
|
||||||
|
|
||||||
self.framesize = controller.setFrameSize()
|
|
||||||
print(self.framesize)
|
|
||||||
self.btn2.SetMinSize((100, 50))
|
|
||||||
self.button_1.SetMinSize((100, 50))
|
|
||||||
|
|
||||||
self.color = controller.setBacgroundColor()
|
self.color = controller.setBacgroundColor()
|
||||||
self.panel_1.SetBackgroundColour(self.color)
|
self.SetBackgroundColour(self.color)
|
||||||
|
self.btnColor = controller.setBckgroundButtonColor()
|
||||||
|
self.btn2.SetBackgroundColour(self.btnColor)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.button_1.SetBackgroundColour(controller.setBckgroundButtonColor())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -85,11 +89,22 @@ class MyFrame(wx.Frame):
|
|||||||
self.Layout()
|
self.Layout()
|
||||||
# end wxGlade
|
# end wxGlade
|
||||||
|
|
||||||
|
def __binds(self):
|
||||||
|
self.button_1.Bind(wx.EVT_BUTTON, self.go_page2)
|
||||||
|
|
||||||
|
def getSize(self):
|
||||||
|
app = wx.App(False)
|
||||||
|
sw, sh = wx.GetDisplaySize()
|
||||||
|
self.w = 0.75 * sw
|
||||||
|
self.h = 0.75 * sh
|
||||||
|
return self.w, self.h
|
||||||
|
|
||||||
def empty_pole(self):
|
def empty_pole(self):
|
||||||
dlg = wx.MessageDialog(self, 'Не все поля заполнены. Заполните все поля перед продолжением', 'Ошибка', wx.OK)
|
dlg = wx.MessageDialog(self, 'Не все поля заполнены. Заполните все поля перед продолжением', 'Ошибка', wx.OK)
|
||||||
val = dlg.ShowModal()
|
val = dlg.ShowModal()
|
||||||
if val == wx.ID_OK:
|
if val == wx.ID_OK:
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
def go_page2(self, event):
|
def go_page2(self, event):
|
||||||
|
|
||||||
name = self.inpt_name.GetValue()
|
name = self.inpt_name.GetValue()
|
||||||
@@ -123,8 +138,8 @@ class MyFrame(wx.Frame):
|
|||||||
new_session.commit()
|
new_session.commit()
|
||||||
|
|
||||||
|
|
||||||
self.frame.Destroy()
|
|
||||||
SecondPage.SecondPage.OnInit(SecondPage)
|
SecondPage.SecondPage.OnInit(SecondPage)
|
||||||
|
self.Destroy()
|
||||||
|
|
||||||
# todo Перенести весь функционал из main.py
|
# todo Перенести весь функционал из main.py
|
||||||
|
|
||||||
@@ -138,5 +153,9 @@ class MyApp(wx.App):
|
|||||||
# end of class MyApp
|
# end of class MyApp
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
app = MyApp(0)
|
app = MyApp(0)
|
||||||
|
import wx.lib.inspection
|
||||||
|
|
||||||
|
wx.lib.inspection.InspectionTool().Show()
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|||||||
12
run.sh
Executable file
12
run.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# what real Python executable to use
|
||||||
|
PYVER=3.7
|
||||||
|
PYTHON=/Library/Frameworks/Python.framework/Versions/$PYVER/bin/python$PYVER
|
||||||
|
|
||||||
|
# find the root of the virtualenv, it should be the parent of the dir this script is in
|
||||||
|
ENV=`$PYTHON -c "import os; print os.path.abspath(os.path.join(os.path.dirname(\"$0\"), '..'))"`
|
||||||
|
|
||||||
|
# now run Python with the virtualenv set as Python's HOME
|
||||||
|
export PYTHONHOME=$ENV
|
||||||
|
exec $PYTHON "$@"
|
||||||
Reference in New Issue
Block a user