Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface Tkinter one commit #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# ignore les fichiers et dossiers



*.orig
*.bak
*.BAK
Expand All @@ -16,11 +13,11 @@
*.DS_Store
npm-debug.log
Thumbs.db
.idea
.vscode
.sass-cache
__pycache__
.coverage
pylint.txt
package-lock.json

venv/
__pycache__
venv
50 changes: 27 additions & 23 deletions App.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
# * @modify date 2021-06-18 10:37:22
# */



import platform, json
import platform
import json
import os
import re
import subprocess
Expand All @@ -20,42 +19,46 @@ class Application():
filesOS = []
i18n = {}


def Initialisation(self):
#Initialisation du language en premier

# Initialisation du language en premier
self.DetectionLanguages()

print("*"*5, self.i18n['START'] , "*"*5)
print("*"*5, self.i18n['START'], "*"*5)
self.DetectionSysteme()

def DetectionLanguages(self):
"""Détection de la langue du system"""


if platform.system() == "Linux":
f = open(os.path.join('lang',os.getenv('LANG') + ".json"), 'r', encoding='utf8')
f = open(os.path.join('lang', os.getenv(
'LANG') + ".json"), 'r', encoding='utf8')

elif platform.system() == "Windows":
f = open(os.path.join('lang',locale.getdefaultlocale()[0] + ".json"), 'r', encoding='utf8')

f = open(os.path.join('lang', locale.getdefaultlocale()
[0] + ".json"), 'r', encoding='utf8')

self.i18n = json.loads(f.read())

def DetectionSysteme(self):
"""Détection du system Host et lance le script approprier """

self.ListFileSystemOS()

print("System :", platform.system(), self.i18n['BASE']['detected'])
print("Language:", locale.getdefaultlocale()[0], self.i18n['BASE']['detected'])

print("Language:", locale.getdefaultlocale()
[0], self.i18n['BASE']['detected'])

if platform.system() == "Linux":
self.LinuxDetecter()

elif platform.system() == "Windows":
self.WindowsDetecter()

else:
print(str(self.i18n['ERROR']['no_charge_sytem']).format(platform.system(), platform.release()))
print(str(self.i18n['ERROR']['no_charge_sytem']).format(
platform.system(), platform.release()))
return False

def LinuxDetecter(self):
Expand All @@ -64,15 +67,15 @@ def LinuxDetecter(self):
choix = str(input("utiliser le Benchmarck par défault y/n: "))

if choix == "y" or choix == "Y":

os_release = dict(Mylib.read_os_releases())

for n, f in enumerate(self.filesOS):
if(re.search(os_release.get('ID')+"_"+os_release.get('VERSION_ID'), f)):
subprocess.run(['python', f])
else:
print("Votre system", platform.system(), platform.release() ,"na pas encore de CIS benchmarck ")

print("Votre system", platform.system(),
platform.release(), "na pas encore de CIS benchmarck ")

elif choix == "n" or choix == "N":
for n, f in enumerate(self.filesOS):
Expand All @@ -83,16 +86,17 @@ def LinuxDetecter(self):

def WindowsDetecter(self):
"""Vérification du systeme windows détection"""

choix = str(input(str(self.i18n['INPUT']['choise_benchmarck'])))

if choix == "y" or choix == "Y":
for n,f in enumerate(self.filesOS):

for n, f in enumerate(self.filesOS):
if(re.search(platform.win32_ver()[0], f)):
subprocess.run(['python',f])
subprocess.run(['python', f])
else:
print(str(self.i18n['ERROR']['no_benchmarck_system']).format(platform.system(), platform.release()))
print(str(self.i18n['ERROR']['no_benchmarck_system']).format(
platform.system(), platform.release()))

elif choix == "n" or choix == "N":
for n, f in enumerate(self.filesOS):
Expand All @@ -117,4 +121,4 @@ def ListFileSystemOS(self):

if __name__ == '__main__':
app = Application()
app.Initialisation()
app.Initialisation()
2 changes: 2 additions & 0 deletions CIS/Windows/windows_2012ServerR2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import subprocess
import json



class CIS():
Expand Down
5 changes: 5 additions & 0 deletions Controllers/Controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

class Controller(object):
def __init__(self, view):
super().__init__()
self.view = view
24 changes: 24 additions & 0 deletions Controllers/Home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import platform
from .Controller import Controller


class HomeController(Controller):

def DetectionSystem(self):
"""Détection du system Host et lance le script approprier """

if platform.system() == "Linux":
self.LinuxStartScript()

elif platform.system() == "Windows":
self.WindowsStartScript()
else:
self.view.NoPlatformSupport


def WindowsStartScript(self):
pass


def LinuxStartScript(self):
pass
File renamed without changes.
118 changes: 118 additions & 0 deletions Main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import locale
import platform
import tkinter as tk
import os
import json

from Views.Widget import NavBar, DisclaimerPage, SettingPage
from Views.HomePage import MainPage


class Application(tk.Tk):

# Initialisation de la fenetre
def __init__(self):
super().__init__()
self.SETTING = setting
self.title("Extractor Configuration")
main_frame = tk.Frame(self, width=setting.GUI['WIDTH'], height=setting.GUI['HEIGHT'])
main_frame.pack_propagate(0)
main_frame.pack(fill="both", expand=True)
self.resizable(0, 0)
self.geometry(f"{setting.GUI['WIDTH']}x{setting.GUI['HEIGHT']}")

# Menu de l'applications
menubar = NavBar(parent=self)
self.config(menu=menubar)

# Frame de l'applications
self.frames = {}
pages = (MainPage,) # TODO Liste des Pages

for page in pages:
frame = page(parent=main_frame, setting=self.SETTING)
self.frames[page] = frame
frame.place(rely=0, relx=0)

self.show_frame(MainPage)

def show_frame(self, frame_name):
"""Affiche la page passer en parameter."""
frame = self.frames[frame_name]
frame.tkraise()

def ChangeLanguageAndTheme(self, args={}):
"""Récuper un tableau d'argument pour l'envoie a la class setting"""
if args is not None:
setting.ChangeSetting(args)

def OpenSettingPage(self):
SettingPage(parent=self)

def OpenDisclaimerPage(self):
DisclaimerPage(parent=self)


class Setting():
"""Class qui stock l'ensemble des paramètre du fichier setting.json"""

def __init__(self):
self.APP = []
self.GUI = []
self.THEME = []
self.MODE_DARK = 0
self.LANG = []

self.InitSettings()
self.InitLanguages()

def InitSettings(self):
"""Chargement du fichier setting.json"""
with open(os.path.join('setting.json')) as Settings:
data = json.load(Settings)
self.APP = data['APP']
self.GUI = data['GUI']
self.MODE_DARK = data['GUI']['MODE_DARK']

# check le dark mode si il est Activer dans le fichier setting.json
if self.MODE_DARK == 1:
self.THEME = data['GUI']['THEME_DARK']
else:
self.THEME = data['GUI']['THEME_LIGHT']

if self.APP["AUTO_LANG"] == 1 and platform.system() == "Windows":
self.APP["LANG"] = locale.getdefaultlocale()[0]
elif self.APP["AUTO_LANG"] == 1 and platform.system() == "Linux":
self.APP["LANG"] = os.getenv('LANG')


def InitLanguages(self):
"""Chargement du language dans le fichier setting.json"""
with open(os.path.join('lang', self.APP['LANG'] + ".json"), 'r', encoding='utf8') as lang:
data = json.load(lang)
self.LANG = data

def ChangeSetting(self, args={}):
data = []

#Récuper tout le fichier setting.json pour le stocké dans data
with open(os.path.join('setting.json'), 'r', encoding='utf8')as r_file:
data = json.load(r_file)

#Réécrie les donnéés avant de les sauvegarders
with open(os.path.join('setting.json'), 'w') as w_file:
try:
data["APP"]["LANG"] = args["LANG"]
data["APP"]["AUTO_LANG"] = args["AUTO_LANG"]
data["GUI"]["MODE_DARK"] = args["MODE_DARK"]

json.dump(data, w_file)
except print(0):
print("File Setting no save")



if __name__ == "__main__":
setting = Setting()
root = Application()
root.mainloop()
2 changes: 2 additions & 0 deletions Models/Model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Model:
uuid = []
File renamed without changes.
Empty file added Models/language.py
Empty file.
49 changes: 49 additions & 0 deletions Views/HomePage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import platform
import tkinter as tk
from tkinter import LabelFrame, Label, messagebox

from Controllers.Home import HomeController

class MainPage(tk.Frame):
def __init__(self, parent, setting):
super().__init__(parent)
self.setting = setting

self.controller = HomeController(view=self)
self.controller.DetectionSystem()


##########################################:: INTERFACE ::####################################

#Frame information sur la platform
frame_InfoSystem = LabelFrame(parent, text=setting.LANG["info_platform"])
frame_InfoSystem.grid(pady=10, padx=10)

label_PlatformSystem = Label(frame_InfoSystem, text=str("• " + setting.LANG["system_detected"]).format(platform.system() + " " + platform.release()))
label_PlatformSystem.pack(padx=5, pady=5)

label_BuildSystem = Label(frame_InfoSystem,text=str("• "+"Build: " + platform.version()))
label_BuildSystem.pack(padx=5, pady=5)

##########################################:: END INTERFACE ::####################################

##########################################:: FUNCTION ::####################################

def IsAutoStartScriptPlatform(self):
"""Si dans le controller,si il exist un script pour la platform en question
ont demande a l'utilisateur de choisir si ont veux exécuter
[Return] Boolean
"""
msg_IsAutoScrip = messagebox.askyesnocancel(title=self.setting.LANG["WARNING"]["information"],
message=self.setting.LANG["WARNING"]["is_detect_scrip_auto_start"])

return msg_IsAutoScrip


def NoPlatformSupport(self):
"""Affiche un messageBox pour avertir que le script n'est pas compatible"""

msgBox_PlatformNoSupport = messagebox.askyesnocancel(title=self.setting.LANG["ERROR"]["error"],
message=self.setting.LANG["ERROR"]["no_support_platform"])
return msgBox_PlatformNoSupport
##########################################:: END FUNCTION ::####################################
Loading