Commit e8789cc8 authored by Guillaume Sabbagh's avatar Guillaume Sabbagh
Browse files
parents 7c3c5c23 e891e007
import demjson
from Model import Model
from tk.MainWindow import MainWindow
class Controller:
_model=None
def getModel(self): return self._model
_view=None
def getView(self): return self._view
"""
INITIALISATION
"""
def __init__(self):
self._model=Model()
self._view=MainWindow(self)
"""
IMPORT/EXPORT (JSON)
"""
def exportJSON(self, file:str, obj:object):
assert len(file)>5 and file[-4:]=="json"
with open(file, "w") as jsonFile:
jsonFile.write(demjson.encode(obj))
def importJSON(self, file:str):
assert len(file)>5 and file[-4:]=="json"
with open(file, "r") as jsonFile:
return demjson.decode(jsonFile.read())
\ No newline at end of file
0
\ No newline at end of file
1
\ No newline at end of file
1
\ No newline at end of file
1
\ No newline at end of file
1
\ No newline at end of file
1
\ No newline at end of file
import pandas as pd
from ModelCallable import ModelCallable
from GrapheDeComposition import GrapheDeComposition, GC
class Model:
"""
Contient tous les objets construits.
"""
_data=None
def __init__(self):
self._data=pd.DataFrame(columns=["class","object"])
self._data["class"]=self._data["class"].astype("string")
"""
CREATION D'OBJETS
"""
def addObject(self, obj:object):
newData={"class": type(obj).__name__,
"object": obj}
self._data=self._data.append(newData, ignore_index=True)
self.informObjectAdded(self._data.index[-1], obj)
def addObjects(self, objects:list):
newData=[]
for obj in objects:
newData.append({"class": type(obj).__name__,
"object": obj})
i=self._data.index[-1]
self._data=self._data.append(newData, ignore_index=True)
self.informObjectsAdded(list(range(i, self._data.index[-1]+1)))
def createGrapheDeComposition(self, objets:set = set(), nom:str = None):
gc=GC(objets=objets, nom=nom)
self.addObject([gc])
"""
GETTERS
"""
def getData(self):
return self._data
def getObject(self, uid):
"""
@return DataFrame
"""
return self._data.iloc[uid]
"""
INFORM
"""
_registeredModelCallable=[]
def registerModelCallable(self, mc:ModelCallable):
self._registeredModelCallable.append(mc)
def informDataModified(self):
for rdm in self._registeredModelCallable:
rdm.informDataModified()
def informObjectAdded(self, uid, obj:object):
for rdm in self._registeredModelCallable:
rdm.informObjectAdded(uid, obj)
def informObjectDeleted(self, uid):
for rdm in self._registeredModelCallable:
rdm.informObjectDeleted(uid)
def informObjectsAdded(self, uids:list):
for rdm in self._registeredModelCallable:
rdm.informObjectsAdded(uids)
def informObjectsDeleted(self, uids:list):
for rdm in self._registeredModelCallable:
rdm.informObjectsDeleted(uids)
class ModelCallable:
"""
A surcharger
Permet de s'enregistrer pour recevoir des notifications
d'une instance Model.
"""
def informDataModified(self):
pass
def informObjectAdded(self, uid, obj:object):
pass
def informObjectDeleted(self, uid):
pass
def informObjectsAdded(self, uids:list):
pass
def informObjectsDeleted(self, uids:list):
pass
"""
Paramètres de la GUI
"""
class Parameters():
SECTION_COLOR = "#649BB4"
SECTION_RELIEF="groove"
SECTION_FONT_SIZE = 10
SECTION_FONT_WEIGHT = 'bold'
SECTION_FONT_UNDERLINE= 0
FRAME_BD=2
INFORM_BG='#C0C0C0'
INFORM_FG='black'
ExportAsDialog_BG='white'
HIGHLIGHTCOLOR_BUTTON="#649BB4"
parameters=Parameters()
from Controller import Controller
if __name__ == '__main__':
Controller()
"""
define constants and wrap OpenGL functions to Python
"""
from ctypes import c_bool, c_char_p, c_double, c_float, c_int, c_uint, c_ulong, c_void_p, POINTER
import sys
'''
wrap GDI constants and functions to Python
'''
if sys.platform.startswith('win32'):
from ctypes import WinDLL
_libGL = WinDLL('opengl32')
elif sys.platform.startswith('linux'):
from ctypes import cdll
# Shared library path hardcode for Xubuntu 15.10
_libGL = cdll.LoadLibrary('/usr/lib/i386-linux-gnu/mesa/libGL.so')
else:
raise NotImplementedError
# Data types for Linux Platform
XID = c_ulong
GLXDrawable = XID
# Data types for OpenGL
GLbitfield = c_uint
GLubyte = c_char_p
GLclampf = c_float
GLclampd = c_double
GLdouble = c_double
GLenum = c_uint
GLfloat = c_float
GLint = c_int
GL_BLEND = 0x0BE2
GL_COLOR_BUFFER_BIT = 0x00004000
GL_DEPTH_BUFFER_BIT = 0x00000100
GL_DEPTH_TEST = 0x0B71
GL_MODELVIEW = 0x1700
GL_ONE_MINUS_SRC_ALPHA = 0x0303
GL_PROJECTION = 0x1701
GL_QUADS = 0x0007
GL_RENDERER = 0x1F01
GL_SRC_ALPHA = 0x0302
GL_VENDOR = 0x1F00
GL_VERSION = 0x1F02
GL_TRUE = 1
# Constants for Linux Platform
# Hardcode number of array elements of int type
# used in this example
PGLint = GLint * 11
GLX_RGBA = 4
GLX_RED_SIZE = 8
GLX_GREEN_SIZE = 9
GLX_BLUE_SIZE = 10
GLX_DEPTH_SIZE = 12
GLX_DOUBLEBUFFER = 5
# OpenGL Function Definitions
glBegin = _libGL.glBegin
glBegin.restype = None
glBegin.argtypes = [GLenum]
glClear = _libGL.glClear
glClear.restype = None
glClear.argtypes = [GLbitfield]
glBlendFunc = _libGL.glBlendFunc
glBlendFunc.restype = None
glBlendFunc.argtypes = [GLenum, GLenum]
glClearColor = _libGL.glClearColor
glClearColor.restype = None
glClearColor.argtypes = [GLclampf, GLclampf, GLclampf, GLclampf]
glClearDepth = _libGL.glClearDepth
glClearDepth.restype = None
glClearDepth.argtypes = [GLclampd]
glColor3f = _libGL.glColor3f
glColor3f.restype = None
glColor3f.argtypes = [GLfloat, GLfloat, GLfloat]
glEnable = _libGL.glEnable
glEnable.restype = None
glEnable.argtypes = [GLenum]
glEnd = _libGL.glEnd
glEnd.restype = None
glEnd.argtypes = None
glFlush = _libGL.glFlush
glFlush.restype = None
glFlush.argtypes = None
glGetString = _libGL.glGetString
glGetString.restype = GLubyte
glGetString.argtypes = [GLenum]
glLoadIdentity = _libGL.glLoadIdentity
glLoadIdentity.restype = None
glLoadIdentity.argtypes = None
glMatrixMode = _libGL.glMatrixMode
glMatrixMode.restype = None
glMatrixMode.argtypes = None
glOrtho = _libGL.glOrtho
glOrtho.restype = None
glOrtho.argtypes = [GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble]
glRotatef = _libGL.glRotatef
glRotatef.restype = None
glRotatef.argtypes = [GLfloat, GLfloat, GLfloat, GLfloat]
glVertex3f = _libGL.glVertex3f
glVertex3f.restype = None
glVertex3f.argtypes = [GLfloat, GLfloat, GLfloat]
glViewport = _libGL.glViewport
glViewport.restype = None
glViewport.argtypes = [GLint, GLint, GLint, GLint]
if sys.platform.startswith('win32'):
wglCreateContext = _libGL.wglCreateContext
wglCreateContext.restype = c_void_p
wglCreateContext.argtypes = [c_void_p]
wglMakeCurrent = _libGL.wglMakeCurrent
wglMakeCurrent.restype = c_bool
wglMakeCurrent.argtypes = [c_void_p, c_void_p]
elif sys.platform.startswith('linux'):
glXChooseVisual = _libGL.glXChooseVisual
glXChooseVisual.argtypes = [c_void_p, c_int, POINTER(c_int)]
glXChooseVisual.restype = c_void_p
glXCreateContext = _libGL.glXCreateContext
glXCreateContext.argtypes = [c_void_p, c_void_p, c_void_p, c_bool]
glXCreateContext.restype = c_void_p
glXMakeCurrent = _libGL.glXMakeCurrent
glXMakeCurrent.argtypes = [c_void_p, GLXDrawable, c_void_p]
glXMakeCurrent.restype = c_bool
glXSwapBuffers = _libGL.glXSwapBuffers
glXSwapBuffers.argtypes = [c_void_p, GLXDrawable]
glXSwapBuffers.resttype = None
""" wrap GDI constants and functions to Python
"""
from ctypes import c_int, c_void_p, POINTER, Structure, WinDLL
from ctypes.wintypes import BOOL, BYTE, DWORD, HDC, WORD
_gdi32 = WinDLL('gdi32')
_user32 = WinDLL('user32')
class PixelFormatDescriptor(Structure):
_fields_ = [
('nSize', WORD),
('nVersion', WORD),
('dwFlags', DWORD),
('iPixelType', BYTE),
('cColorBits', BYTE),
('cRedBits', BYTE),
('cRedShift', BYTE),
('cGreenBits', BYTE),
('cGreenShift', BYTE),
('cBlueBits', BYTE),
('cBlueShift', BYTE),
('cAlphaBits', BYTE),
('cAlphaShift', BYTE),
('cAccumBits', BYTE),
('cAccumRedBits', BYTE),
('cAccumGreenBits', BYTE),
('cAccumBlueBits', BYTE),
('cAccumAlphaBits', BYTE),
('cDepthBits', BYTE),
('cStencilBits', BYTE),
('cAuxBuffers', BYTE),
('iLayerType', BYTE),
('bReserved', BYTE),
('dwLayerMask', DWORD),
('dwVisibleMask', DWORD),
('dwDamageMask', DWORD),
]
PFD_DRAW_TO_WINDOW = 4 # Variable c_int
PFD_SUPPORT_OPENGL = 32 # Variable c_int
PFD_DOUBLEBUFFER = 1 # Variable c_int
PFD_TYPE_RGBA = 0 # Variable c_int
get_dc = _user32.GetDC
get_dc.restype = HDC
get_dc.argtypes = [c_void_p]
choose_pixel_format = _gdi32.ChoosePixelFormat
choose_pixel_format.restype = c_int
choose_pixel_format.argtypes = [c_void_p, POINTER(PixelFormatDescriptor)]
set_pixel_format = _gdi32.SetPixelFormat
set_pixel_format.restype = BOOL
set_pixel_format.argtypes = [c_void_p, c_int, POINTER(PixelFormatDescriptor)]
get_pixel_format = _gdi32.GetPixelFormat
get_pixel_format.restype = c_int
get_pixel_format.argtypes = [c_void_p]
swap_buffers = _gdi32.SwapBuffers
swap_buffers.restype = BOOL
swap_buffers.argtypes = [HDC]
from ctypes import c_char_p, c_void_p, cdll
# Shared library path hardcode for Xubuntu 15.10
_x11lib = cdll.LoadLibrary('/usr/lib/i386-linux-gnu/libX11.so')
X11_None = 0
x_open_display = _x11lib.XOpenDisplay
x_open_display.argtypes = [c_char_p]
x_open_display.restype = c_void_p
"""
Paramètres de la GUI
"""
from tkinter import Label
import tkinter.font as tkFont
from Parameters import parameters
class Factory():
@staticmethod
def buildSectionLabel(parent, text):
return Label(parent, text=text,
bg=parameters.SECTION_COLOR,
relief=parameters.SECTION_RELIEF,
font=tkFont.Font(size=parameters.SECTION_FONT_SIZE,
weight=parameters.SECTION_FONT_WEIGHT,
underline=parameters.SECTION_FONT_UNDERLINE))
factory=Factory()
\ No newline at end of file
from tkinter import TOP, BOTTOM, LEFT, RIGHT, BOTH, \
Frame, Label, StringVar
from Parameters import parameters
class InformFrame(Frame):
_label=None
_text=None
def __init__(self, parent, *args, **kwargs):
Frame .__init__(self, parent,
*args, **kwargs)
self._initFrame()
def _initFrame(self):
self._text=StringVar()
self._label=Label(self,
bg=parameters.INFORM_BG,
fg=parameters.INFORM_FG,
anchor='nw',
textvariable=self._text)
self._label.pack(expand=True, fill=BOTH)
"""
SETTERS
"""
def setText(self, text:str):
self._text.set(text)
def inform(self, text:str):
self._text.set(self._text.get()+text+"\n")
from os import getcwd
from tkinter import TOP, YES, BOTH, X, \
Tk, Frame, Label, Menu, Toplevel, Entry, Button, \
filedialog, messagebox
from Parameters import parameters
from tko.AppOgl import AppOgl
from tk.OutilsFrame import OutilsFrame
from tk.ObjetsFrame import ObjetsFrame
class MainWindow:
_controller:None
_root=None
_frame=None
_glFrame=None
_outFrame=None
_objFrame=None
_glApp=None
_menu=None
"""
INITIALISATIONS
"""
def __init__(self, controller, *args, **kwargs):
assert controller
self._controller=controller
self._initRoot()
self._initFrames()
self._initMenu()
self._root.mainloop()
def _initRoot(self):
self._root= Tk()
w=self._root.winfo_screenwidth()
h=self._root.winfo_screenheight()
self._root.geometry("%dx%d%+d%+d" % (w/2,h-80,0,0))
self._root.title('Théorie des catégories ')
self._root.iconbitmap("ressources\graphe.ico")
self._root.config(bg = "#787878")
def _initFrames(self):
# main frame
self._frame = Frame(self._root)
self._frame.pack(expand=YES, fill=BOTH)
self._frame.columnconfigure(0, weight=1, minsize=500)
self._frame.columnconfigure(1, weight=1, minsize=200)
self._frame.columnconfigure(2, weight=1, minsize=200)
self._frame.rowconfigure(0, weight=1, minsize=300)
# OGL frame
self._glFrame=Frame(self._frame)
self._glFrame.grid(row=0, column=0, sticky="nesw")
self.initGLApp()
# Outils frame
self._outFrame = OutilsFrame(self._frame)
self._outFrame.grid(row=0, column=1, sticky="nesw")
# Objets frame
self._objFrame = ObjetsFrame(self._frame, self._controller)
self._objFrame.grid(row=0, column=2, sticky="nesw")