added gui directory check and creation, created module for referencing gui directories
This commit is contained in:
parent
0f78acaa0c
commit
f10acbc8d9
6 changed files with 46 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
|
||||
from coretk import appdirs
|
||||
from coretk.coreclient import CoreClient
|
||||
from coretk.coremenubar import CoreMenubar
|
||||
from coretk.coretoolbar import CoreToolbar
|
||||
|
@ -86,5 +87,6 @@ class Application(tk.Frame):
|
|||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
appdirs.check_directory()
|
||||
app = Application()
|
||||
app.mainloop()
|
||||
|
|
39
coretk/coretk/appdirs.py
Normal file
39
coretk/coretk/appdirs.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import logging
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
# gui home paths
|
||||
HOME_PATH = Path.home().joinpath(".coretk")
|
||||
BACKGROUNDS_PATH = HOME_PATH.joinpath("backgrounds")
|
||||
CUSTOM_EMANE_PATH = HOME_PATH.joinpath("custom_emane")
|
||||
CUSTOM_SERVICE_PATH = HOME_PATH.joinpath("custom_services")
|
||||
ICONS_PATH = HOME_PATH.joinpath("icons")
|
||||
MOBILITY_PATH = HOME_PATH.joinpath("mobility")
|
||||
XML_PATH = HOME_PATH.joinpath("xml")
|
||||
CONFIG_PATH = HOME_PATH.joinpath("gui.yaml")
|
||||
|
||||
# local paths
|
||||
LOCAL_ICONS_PATH = Path(__file__).parent.joinpath("icons").absolute()
|
||||
LOCAL_BACKGROUND_PATH = Path(__file__).parent.joinpath("backgrounds").absolute()
|
||||
|
||||
|
||||
def check_directory():
|
||||
if HOME_PATH.exists():
|
||||
logging.info("~/.coretk exists")
|
||||
return
|
||||
logging.info("creating ~/.coretk")
|
||||
HOME_PATH.mkdir()
|
||||
BACKGROUNDS_PATH.mkdir()
|
||||
CUSTOM_EMANE_PATH.mkdir()
|
||||
CUSTOM_SERVICE_PATH.mkdir()
|
||||
ICONS_PATH.mkdir()
|
||||
MOBILITY_PATH.mkdir()
|
||||
XML_PATH.mkdir()
|
||||
for image in LOCAL_ICONS_PATH.glob("*"):
|
||||
new_image = ICONS_PATH.joinpath(image.name)
|
||||
shutil.copy(image, new_image)
|
||||
for background in LOCAL_BACKGROUND_PATH.glob("*"):
|
||||
new_background = BACKGROUNDS_PATH.joinpath(background.name)
|
||||
shutil.copy(background, new_background)
|
||||
with CONFIG_PATH.open("w") as f:
|
||||
f.write("# gui config")
|
Before Width: | Height: | Size: 312 KiB After Width: | Height: | Size: 312 KiB |
Before Width: | Height: | Size: 196 KiB After Width: | Height: | Size: 196 KiB |
|
@ -1,13 +1,10 @@
|
|||
import logging
|
||||
import os
|
||||
from enum import Enum
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
from core.api.grpc import core_pb2
|
||||
|
||||
PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
ICONS_DIR = os.path.join(PATH, "icons")
|
||||
from coretk.appdirs import LOCAL_ICONS_PATH
|
||||
|
||||
|
||||
class Images:
|
||||
|
@ -15,14 +12,11 @@ class Images:
|
|||
|
||||
@classmethod
|
||||
def load_all(cls):
|
||||
for file_name in os.listdir(ICONS_DIR):
|
||||
file_path = os.path.join(ICONS_DIR, file_name)
|
||||
name = file_name.split(".")[0]
|
||||
cls.load(name, file_path)
|
||||
for image in LOCAL_ICONS_PATH.glob("*"):
|
||||
cls.load(image.stem, str(image))
|
||||
|
||||
@classmethod
|
||||
def load(cls, name, file_path):
|
||||
# file_path = os.path.join(PATH, file_path)
|
||||
image = Image.open(file_path)
|
||||
tk_image = ImageTk.PhotoImage(image)
|
||||
cls.images[name] = tk_image
|
||||
|
|
|
@ -3,14 +3,12 @@ set wallpaper
|
|||
"""
|
||||
import enum
|
||||
import logging
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
WALLPAPER_DIR = os.path.join(PATH, "wallpaper")
|
||||
from coretk.appdirs import BACKGROUNDS_PATH
|
||||
|
||||
|
||||
class ScaleOption(enum.Enum):
|
||||
|
@ -60,7 +58,7 @@ class CanvasWallpaper:
|
|||
|
||||
def open_image_link(self):
|
||||
filename = filedialog.askopenfilename(
|
||||
initialdir=WALLPAPER_DIR,
|
||||
initialdir=str(BACKGROUNDS_PATH),
|
||||
title="Open",
|
||||
filetypes=(
|
||||
("images", "*.gif *.jpg *.png *.bmp *pcx *.tga ..."),
|
||||
|
@ -207,7 +205,6 @@ class CanvasWallpaper:
|
|||
cropy = img_h = tk_img.height()
|
||||
|
||||
if img_w > canvas_w:
|
||||
|
||||
cropx -= img_w - canvas_w
|
||||
if img_h > canvas_h:
|
||||
cropy -= img_h - canvas_h
|
||||
|
|
Loading…
Add table
Reference in a new issue