Commit e891e007 authored by Francois Mares's avatar Francois Mares
Browse files

upgrade export

correct error
parent 6f1c2d03
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
["dezduef"]
\ No newline at end of file
["dezduef"]
\ No newline at end of file
2
\ No newline at end of file
......@@ -12,10 +12,12 @@ class Parameters():
FRAME_BD=2
INFORM_BG='#DCFFFF'
INFORM_BG='#C0C0C0'
INFORM_FG='black'
ExportAsDialog_BG='white'
HIGHLIGHTCOLOR_BUTTON="#649BB4"
parameters=Parameters()
from os import getcwd
from tkinter import TOP, YES, BOTH, \
from tkinter import TOP, YES, BOTH, X, \
Tk, Frame, Label, Menu, Toplevel, Entry, Button, \
filedialog, messagebox
......@@ -23,7 +23,7 @@ class MainWindow:
_menu=None
"""
INITIALISATION
INITIALISATIONS
"""
def __init__(self, controller, *args, **kwargs):
assert controller
......@@ -94,13 +94,14 @@ class MainWindow:
self._root.config(menu=self._menu)
"""
CONTROLLER CALLS
IMPORTS/EXPORTS
"""
def importerJSON(self):
filepath = filedialog.askopenfilename(title="Importer un objet",
filepaths = filedialog.askopenfilenames(title="Importer un objet",
filetypes=[('JSON file','.json')],
initialdir=getcwd()+"/JSON")
self._controller.getModel().addObject(self._controller.importJSON(filepath))
for filepath in filepaths:
self._controller.getModel().addObject(self._controller.importJSON(filepath))
def exporterJSON(self):
uids=self._objFrame.getSelectedObjects()
......@@ -117,7 +118,13 @@ class MainWindow:
initialdir=getcwd()+"/JSON")+".json"
self._controller.exportJSON(filepath, row["object"])
else:
ExportAsDialog(data=data)
ExportAsDialog(self, data=data)
def multipleExportJSON(self, filepaths:list, data):
i=0
for index, row in data.iterrows():
self._controller.exportJSON(filepaths[i], row["object"])
i+=1
def exporterGraphviz(self):
#transformer_graphviz()
......@@ -125,13 +132,18 @@ class MainWindow:
class ExportAsDialog(Toplevel):
_registered=None
_frame=None
_dir=None
_data=None
def __init__(self, data, master=None, **kwargs):
_selectFileNameFrames=None
def __init__(self, register, data, master=None, **kwargs):
super().__init__(master, **kwargs)
self.title("Paramètres d'export'")
self._registered=register
self.title("Paramètres d'export")
self.config(bg=parameters.ExportAsDialog_BG)
self.grab_set()
......@@ -144,35 +156,90 @@ class ExportAsDialog(Toplevel):
self._frame.columnconfigure(0, weight=1, minsize=200)
self._frame.rowconfigure(1, weight=1, minsize=20)
self._initDirectoryFrame(self._frame)
self._initObjectsFrame(self._frame)
self._initDirectoryFrame()
self._initObjectsFrame()
self._initDialogFrame()
def _initDirectoryFrame(self, parent):
frame=Frame(parent)
def _initDirectoryFrame(self):
frame=Frame(self._frame)
frame.grid(row=0, column=0, sticky="new")
frame.columnconfigure(1, weight=1)
Label(frame, text="Directory: ").grid(row=0, column=0, sticky="w")
Label(frame, text="Dossier: ").grid(row=0, column=0, sticky="nsew")
self._dir=Entry(frame)
self._dir.insert(0, getcwd()+"/JSON/")
self._dir.grid(row=0, column=1, sticky="ew")
Button(frame, text="Browse...", command=self.setDirectory).grid(row=0, column=2, sticky="e")
Button(frame, text="Browse...", command=self.setDirectory).grid(row=0, column=2, sticky="nsew")
def _initObjectsFrame(self, parent):
frame=Frame(parent)
def _initObjectsFrame(self):
frame=Frame(self._frame)
frame.grid(row=1, column=0, sticky="nsew")
self._selectFileNameFrames=[]
self._data.apply(lambda row: self._selectFileNameFrames.append(SelectFileNameFrame(frame, row)),axis=1)
for f in self._selectFileNameFrames:
f.pack(expand = YES, fill=X)
def _initDialogFrame(self):
frame=Frame(self._frame)
frame.grid(row=2, column=0, sticky="sew")
frame.columnconfigure(0, weight=1)
b=Button(frame, text="Exporter",
highlightcolor=parameters.HIGHLIGHTCOLOR_BUTTON,
command=self.validate)
b.grid(row=0, column=1, sticky="e")
b.focus_set()
b.bind('<Return>', self.validate)
Button(frame, text="Annuler", command=self.destroy).grid(row=0, column=2, sticky="e")
"""
BIND FUNCTIONS
"""
def setDirectory(self):
dir=filedialog.askdirectory(initialdir=getcwd()+"/JSON",
title = "Select directory")
self._dir.delete(0,"end")
self._dir.insert(0, dir+"/")
def validate(self, event=None):
basePath=self._dir.get()
filePaths=[]
for frame in self._selectFileNameFrames:
filePaths.append(basePath+frame.getFileName())
self._registered.multipleExportJSON(filePaths, self._data)
self.destroy()
class SelectFileNameFrame(Frame):
_row=None
_nameEntry=None
def __init__(self, parent, row, *args, **kwargs):
Frame.__init__(self, parent, *args, **kwargs)
self._row=row
self.columnconfigure(0, weight=1, minsize=10)
self.columnconfigure(2, weight=1, minsize=10)
self.rowconfigure(1, weight=1, minsize=20)
self._initFrame()
def _initFrame(self):
Label(self, text=str(self._row.name)+" <"+str(self._row["class"])+"> "+str(self._row["object"])).grid(row=0, column=0, sticky="nsew")
self._nameEntry=Entry(self)
self._nameEntry.insert(0, str(self._row["class"])+str(self._row.name))
self._nameEntry.grid(row=0, column=1, sticky="ew")
Label(self, text=".json").grid(row=0, column=2, sticky="nsew")
"""
GETTERS
"""
def getFileName(self):
return self._nameEntry.get()+".json"
......
......@@ -3,7 +3,9 @@
"""
from pandas import DataFrame
from ModelCallable import ModelCallable
from tk.InformFrame import InformFrame
from tk.Factory import *
from tkinter import TOP, X, NO, W, Y, YES, BOTH, RIGHT, VERTICAL, \
Frame, Label
......@@ -28,21 +30,22 @@ class ObjetsFrame(Frame, ModelCallable):
self.columnconfigure(0, weight=1, minsize=100)
self.columnconfigure(1, weight=1, minsize=16)#default value of scrollbar width
self.rowconfigure(0, weight=4, minsize=100)
self.rowconfigure(1, weight=1, minsize=10)
self.rowconfigure(0, minsize=20)
self.rowconfigure(1, weight=4, minsize=100)
self._initFrame()
def _initFrame(self):
factory.buildSectionLabel(self,"Objets").grid(row=0, column=0, columnspan = 2, sticky="nwe")
# TREE
self._tree=Treeview(self, selectmode='extended')
self._tree.grid(row=0, column=0, sticky="nesw")
self._tree.grid(row=1, column=0, sticky="nesw")
style = Style()
style.theme_use("default")
style.map("Treeview")
self._scrollbarY=Scrollbar(self, orient =VERTICAL)
self._scrollbarY.grid(row=0, column=1, sticky="nsw")
self._scrollbarY.grid(row=1, column=1, sticky="nsw")
self._tree.configure(yscrollcommand = self._scrollbarY.set)
self._scrollbarY.config(command=self._tree.yview)
......@@ -61,7 +64,7 @@ class ObjetsFrame(Frame, ModelCallable):
# INFORM
self._informFrame=InformFrame(self)
self._informFrame.grid(row=1, column=0, sticky="nesw")
self._informFrame.grid(row=2, columnspan = 2, column=0, sticky="nesw")
"""
GETTERS
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment