print: less os dependent path handling
This commit is contained in:
parent
415535eeb8
commit
91b505bfef
@ -55,7 +55,7 @@ class PrintPanel(ScreenPanel):
|
|||||||
pbox = Gtk.Box(spacing=0)
|
pbox = Gtk.Box(spacing=0)
|
||||||
pbox.set_hexpand(True)
|
pbox.set_hexpand(True)
|
||||||
pbox.set_vexpand(False)
|
pbox.set_vexpand(False)
|
||||||
self.labels['path'] = Gtk.Label(" /")
|
self.labels['path'] = Gtk.Label()
|
||||||
pbox.add(self.labels['path'])
|
pbox.add(self.labels['path'])
|
||||||
self.labels['path_box'] = pbox
|
self.labels['path_box'] = pbox
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class PrintPanel(ScreenPanel):
|
|||||||
self.change_dir(None, "gcodes")
|
self.change_dir(None, "gcodes")
|
||||||
|
|
||||||
def add_directory(self, directory, show=True):
|
def add_directory(self, directory, show=True):
|
||||||
parent_dir = '/'.join(directory.split('/')[:-1])
|
parent_dir = os.path.dirname(directory)
|
||||||
if directory not in self.filelist:
|
if directory not in self.filelist:
|
||||||
self.filelist[directory] = {'directories': [], 'files': [], 'modified': 0}
|
self.filelist[directory] = {'directories': [], 'files': [], 'modified': 0}
|
||||||
self.filelist[parent_dir]['directories'].append(directory)
|
self.filelist[parent_dir]['directories'].append(directory)
|
||||||
@ -102,14 +102,14 @@ class PrintPanel(ScreenPanel):
|
|||||||
fileinfo = self._screen.files.get_file_info(filepath)
|
fileinfo = self._screen.files.get_file_info(filepath)
|
||||||
if fileinfo is None:
|
if fileinfo is None:
|
||||||
return
|
return
|
||||||
filename = os.path.split(filepath)[-1]
|
filename = os.path.basename(filepath)
|
||||||
if filename.startswith("."):
|
if filename.startswith("."):
|
||||||
return
|
return
|
||||||
directory = os.path.dirname(os.path.join("gcodes", filepath))
|
directory = os.path.dirname(os.path.join("gcodes", filepath))
|
||||||
d = directory.split('/')
|
d = directory.split(os.sep)
|
||||||
for i in range(1, len(d)):
|
for i in range(1, len(d)):
|
||||||
curdir = "/".join(d[:i])
|
curdir = os.path.join(*d[:i])
|
||||||
newdir = "/".join(d[:i + 1])
|
newdir = os.path.join(*d[:i + 1])
|
||||||
if newdir not in self.filelist[curdir]['directories']:
|
if newdir not in self.filelist[curdir]['directories']:
|
||||||
if d[i].startswith("."):
|
if d[i].startswith("."):
|
||||||
return
|
return
|
||||||
@ -117,7 +117,7 @@ class PrintPanel(ScreenPanel):
|
|||||||
|
|
||||||
if filename not in self.filelist[directory]['files']:
|
if filename not in self.filelist[directory]['files']:
|
||||||
for i in range(1, len(d)):
|
for i in range(1, len(d)):
|
||||||
curdir = "/".join(d[:i + 1])
|
curdir = os.path.join(*d[:i + 1])
|
||||||
if curdir != "gcodes" and fileinfo['modified'] > self.filelist[curdir]['modified']:
|
if curdir != "gcodes" and fileinfo['modified'] > self.filelist[curdir]['modified']:
|
||||||
self.filelist[curdir]['modified'] = fileinfo['modified']
|
self.filelist[curdir]['modified'] = fileinfo['modified']
|
||||||
self.labels['directories'][curdir]['info'].set_markup(
|
self.labels['directories'][curdir]['info'].set_markup(
|
||||||
@ -221,8 +221,8 @@ class PrintPanel(ScreenPanel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def back(self):
|
def back(self):
|
||||||
if len(self.cur_directory.split('/')) > 1:
|
if os.path.dirname(self.cur_directory):
|
||||||
self.change_dir(None, '/'.join(self.cur_directory.split('/')[:-1]))
|
self.change_dir(None, os.path.dirname(self.cur_directory))
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ class PrintPanel(ScreenPanel):
|
|||||||
for child in self.scroll.get_children():
|
for child in self.scroll.get_children():
|
||||||
self.scroll.remove(child)
|
self.scroll.remove(child)
|
||||||
self.cur_directory = directory
|
self.cur_directory = directory
|
||||||
self.labels['path'].set_text(f" /{self.cur_directory[7:]}")
|
self.labels['path'].set_text(f" {self.cur_directory[7:]}")
|
||||||
|
|
||||||
self.scroll.add(self.dir_panels[directory])
|
self.scroll.add(self.dir_panels[directory])
|
||||||
self.content.show_all()
|
self.content.show_all()
|
||||||
@ -295,27 +295,27 @@ class PrintPanel(ScreenPanel):
|
|||||||
self._screen._ws.klippy.print_start(filename)
|
self._screen._ws.klippy.print_start(filename)
|
||||||
|
|
||||||
def delete_file(self, filename):
|
def delete_file(self, filename):
|
||||||
dir_parts = f"gcodes/{filename}".split('/')[:-1]
|
directory = os.path.join("gcodes", os.path.dirname(filename)) if os.path.dirname(filename) else "gcodes"
|
||||||
directory = '/'.join(dir_parts)
|
if directory not in self.filelist or os.path.basename(filename).startswith("."):
|
||||||
if directory not in self.filelist or filename.split('/')[-1].startswith("."):
|
|
||||||
return
|
return
|
||||||
self.filelist[directory]["files"].pop(self.filelist[directory]["files"].index(filename.split('/')[-1]))
|
self.filelist[directory]["files"].pop(self.filelist[directory]["files"].index(os.path.basename(filename)))
|
||||||
|
dir_parts = directory.split(os.sep)
|
||||||
i = len(dir_parts)
|
i = len(dir_parts)
|
||||||
while i > 1:
|
while i > 1:
|
||||||
cur_dir = '/'.join(dir_parts[:i])
|
cur_dir = os.path.join(*dir_parts[:i])
|
||||||
if len(self.filelist[cur_dir]['directories']) > 0 or len(self.filelist[cur_dir]['files']) > 0:
|
if len(self.filelist[cur_dir]['directories']) > 0 or len(self.filelist[cur_dir]['files']) > 0:
|
||||||
break
|
break
|
||||||
par_dir = '/'.join(cur_dir.split('/')[:-1])
|
parent_dir = os.path.dirname(cur_dir)
|
||||||
|
|
||||||
if self.cur_directory == cur_dir:
|
if self.cur_directory == cur_dir:
|
||||||
self.change_dir(None, par_dir)
|
self.change_dir(None, parent_dir)
|
||||||
|
|
||||||
del self.filelist[cur_dir]
|
del self.filelist[cur_dir]
|
||||||
self.filelist[par_dir]['directories'].pop(self.filelist[par_dir]['directories'].index(cur_dir))
|
self.filelist[parent_dir]['directories'].pop(self.filelist[parent_dir]['directories'].index(cur_dir))
|
||||||
self.dir_panels[par_dir].remove(self.directories[cur_dir])
|
self.dir_panels[parent_dir].remove(self.directories[cur_dir])
|
||||||
del self.directories[cur_dir]
|
del self.directories[cur_dir]
|
||||||
del self.labels['directories'][cur_dir]
|
del self.labels['directories'][cur_dir]
|
||||||
self.dir_panels[par_dir].show_all()
|
self.dir_panels[parent_dir].show_all()
|
||||||
i -= 1
|
i -= 1
|
||||||
|
|
||||||
self.dir_panels[directory].remove(self.files[filename])
|
self.dir_panels[directory].remove(self.files[filename])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user