- Fixed loading of directorys

- Adapted to new gerbil Version
This commit is contained in:
Thomas Herrmann 2023-12-22 20:53:46 +01:00
parent 56076fc4b4
commit 20dc9754d9
2 changed files with 18 additions and 12 deletions

View File

@ -5,8 +5,6 @@ from tkinter import filedialog as fd
import os import os
from gerbil.gerbil import Gerbil from gerbil.gerbil import Gerbil
class touchCNC: class touchCNC:
def __init__(self, root): def __init__(self, root):
self.root = root self.root = root
@ -368,6 +366,7 @@ class touchCNC:
grbl.send_immediately(cmd) grbl.send_immediately(cmd)
def feed_over_write(self, change: int): def feed_over_write(self, change: int):
pass
new_feed = self.feedspeed / 100 * change new_feed = self.feedspeed / 100 * change
print(new_feed) print(new_feed)
grbl.request_feed(new_feed) grbl.request_feed(new_feed)
@ -420,7 +419,7 @@ class touchCNC:
def openGCODE(self): def openGCODE(self):
filetypes = (('GCODE', '*.nc'), ('All files', '*.*')) filetypes = (('GCODE', '*.nc'), ('All files', '*.*'))
if not self.file_list: if not self.file_list:
GCODE = fd.askopenfilename(title='Open a file', initialdir='/home/thomas/Nextcloud/CAM/', filetypes=filetypes) GCODE = fd.askopenfilename(title='Open a file', initialdir='/home/', filetypes=filetypes)
else: else:
GCODE = self.load_gcode_from_listbox() GCODE = self.load_gcode_from_listbox()
@ -441,6 +440,7 @@ class touchCNC:
def get_filenames(self, base_path): def get_filenames(self, base_path):
filenames = [] filenames = []
full_path_list = []
# Use os.listdir to get the list of files and directories in the base path # Use os.listdir to get the list of files and directories in the base path
entries = os.listdir(base_path) entries = os.listdir(base_path)
@ -452,8 +452,8 @@ class touchCNC:
# Check if the entry is a file (not a directory) # Check if the entry is a file (not a directory)
if os.path.isfile(full_path): if os.path.isfile(full_path):
# If it's a file, add it to the list of filenames filenames.append(full_path)
filenames.append(entry) print(filenames)
else: else:
filenames = ["Such Empty"] filenames = ["Such Empty"]
@ -461,17 +461,19 @@ class touchCNC:
def openDir(self): def openDir(self):
self.file_list = [] self.file_list = []
directory = fd.askdirectory(title='Open a Folder', initialdir='/home/thomas/Nextcloud/CAM/') self.path_list = []
#print(directory) directory = fd.askdirectory(title='Open a Folder', initialdir='/home/')
allowed_extensions = {'nc', 'GCODE'} # Use a set for efficient membership testing allowed_extensions = {'nc', 'GCODE'} # Use a set for efficient membership testing
print(directory)
if directory: if directory:
filenames = self.get_filenames(directory) path = self.get_filenames(directory)
self.files.delete(0, constants.END) self.files.delete(0, constants.END)
for file in filenames: for file in path:
# Check if the file has an allowed extension # Check if the file has an allowed extension
if any(file.lower().endswith(ext) for ext in allowed_extensions): if any(file.lower().endswith(ext) for ext in allowed_extensions):
self.path_list.append(file)
file = file.split('/')[-1]
self.file_list.append(file) self.file_list.append(file)
self.files.insert("end", file) # Add the filename to the Listbox self.files.insert("end", file) # Add the filename to the Listbox
else: else:
@ -480,10 +482,11 @@ class touchCNC:
#print(self.file_list) #print(self.file_list)
def load_gcode_from_listbox(self): def load_gcode_from_listbox(self):
"""Loads selected file path from the listbox selection for passing it to the loaded indirectly"""
selected_indices = self.files.curselection() selected_indices = self.files.curselection()
if selected_indices: if selected_indices:
selected_index = selected_indices[0] selected_index = selected_indices[0]
selected_item = self.files.get(selected_index) selected_item = self.path_list[selected_index]
print("Selected item:", selected_item) print("Selected item:", selected_item)
else: else:
print("No item selected") print("No item selected")
@ -507,7 +510,9 @@ class touchCNC:
grbl.killalarm() grbl.killalarm()
def extract_GCODE(self, gcode_path: str): # Aufschlüsseln der enthaltenen Koordinaten in ein per Schlüssel zugängiges Dictionary def extract_GCODE(self, gcode_path: str): # Aufschlüsseln der enthaltenen Koordinaten in ein per Schlüssel zugängiges Dictionary
print(gcode_path)
with open(gcode_path, 'r') as gcode: with open(gcode_path, 'r') as gcode:
list_dict_GCODE = [] list_dict_GCODE = []
for line in gcode: for line in gcode:
lines = line.split() # Elemente trennen und in Liste konvertieren lines = line.split() # Elemente trennen und in Liste konvertieren

1
gerbil Submodule

@ -0,0 +1 @@
Subproject commit 78aa148f0ae98c7dc686eeeb47e2040f40486dab