|
|
@@ -7,20 +7,23 @@ from PySide2.QtCore import *
|
|
|
from PySide2.QtGui import *
|
|
|
from ui.ui_AddFile import Ui_AddFileWindow
|
|
|
from ui.addressBar.addressbar import BreadcrumbsAddressBar
|
|
|
-from ui.file_browser.file_list import get_files_dirs
|
|
|
+from ui.file_browser import file_list
|
|
|
from ui.file_browser.PathObject import PathObject
|
|
|
from ui.file_browser.filewidget import FileWidget
|
|
|
from ui.file_browser.FileObject import FileObject
|
|
|
|
|
|
-class AddFileWindow(Ui_AddFileWindow, QDialog):
|
|
|
+class AddPathWindow(Ui_AddFileWindow, QDialog):
|
|
|
add_file_sig = Signal(str,str)
|
|
|
def __init__(self, parent, path) -> None:
|
|
|
super().__init__()
|
|
|
self.setupUi(self)
|
|
|
- self.file_type = [".v", ".sv", ".f", ".lst", ".list"]
|
|
|
- self.file_suffix = ["Supported Files(%s)" % " ".join(['*'+str(s) for s in self.file_type]), "All files(*.*)"]
|
|
|
+ self.setWindowTitle("Add Path")
|
|
|
+ self.file_suffix = ["All Directories(*.*)"]
|
|
|
+ self.init(parent, path)
|
|
|
+ # self.show_file_list()
|
|
|
+
|
|
|
+ def init(self, parent, path):
|
|
|
self.path_obj = PathObject(path)
|
|
|
-
|
|
|
self.Combobox_FileType.addItems(self.file_suffix)
|
|
|
self.Combobox_FileType.currentIndexChanged.connect(lambda index:self.show_file_list())
|
|
|
self.bnt_Apply.clicked.connect(self.apply)
|
|
|
@@ -29,8 +32,7 @@ class AddFileWindow(Ui_AddFileWindow, QDialog):
|
|
|
# 用于路径前进后退,目前用不上
|
|
|
self.move(parent.x()+(parent.width()-self.width())/2 + self.width()*0.8,parent.y()+(parent.height()-self.height())/2)
|
|
|
self.show()
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
def init_file_browser(self, path):
|
|
|
# 表格随窗口适应大小
|
|
|
self.fileTable.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|
|
@@ -42,21 +44,26 @@ class AddFileWindow(Ui_AddFileWindow, QDialog):
|
|
|
self.address_bar.set_path(path)
|
|
|
self.verticalLayout_3.insertWidget(0, self.address_bar)
|
|
|
|
|
|
- def path_select(self, path):
|
|
|
- self.path_obj.set(path)
|
|
|
- self.open_folder(path)
|
|
|
+ def open_folder(self, dir):
|
|
|
+ self.path_obj.set(dir)
|
|
|
+ self.show_file_list()
|
|
|
+
|
|
|
+ def show_file_list(self):
|
|
|
+ _, self.dirs = file_list.get_files_dirs(self.path_obj)
|
|
|
+ self.fileTable.setRowCount(0)
|
|
|
+
|
|
|
+ height = self.fileTable.verticalHeader().defaultSectionSize()
|
|
|
+ for dir in self.dirs:
|
|
|
+ row = self.fileTable.rowCount()
|
|
|
+ self.fileTable.insertRow(row)
|
|
|
+ fwidget = FileWidget(dir, "Folder", height)
|
|
|
+ self.fileTable.setCellWidget(row, 0, fwidget)
|
|
|
|
|
|
def address_error_connect(self, error, path):
|
|
|
self.path_error_popup(error, path)
|
|
|
self.address_bar._show_address_field(True)
|
|
|
self.address_bar.line_address.deselect()
|
|
|
self.address_bar.line_address.insert('/')
|
|
|
-
|
|
|
- def update_path(self):
|
|
|
- path_text = self.pathBar.text()
|
|
|
- if os.path.isdir(path_text):
|
|
|
- self.path_obj.set(path_text)
|
|
|
- self.show_file_list()
|
|
|
|
|
|
def path_error_popup(self, error='', path=''):
|
|
|
msg = QMessageBox(self)
|
|
|
@@ -65,6 +72,72 @@ class AddFileWindow(Ui_AddFileWindow, QDialog):
|
|
|
msg.setIcon(QMessageBox.Critical)
|
|
|
msg.move(self.x()+(self.width()-msg.width())/2,self.y()+(self.height()-msg.height())/2)
|
|
|
msg.exec_()
|
|
|
+
|
|
|
+ def double_click(self, row, column):
|
|
|
+ if column != 0:
|
|
|
+ return
|
|
|
+ widg:FileWidget = self.fileTable.cellWidget(row, column)
|
|
|
+ name = widg.get_text()
|
|
|
+ abs_path = os.path.join(self.path_obj.pathtext, name)
|
|
|
+ if os.path.isfile(abs_path):
|
|
|
+ self.open_file(abs_path)
|
|
|
+ # 这里不能用 elif os.path.isdir(abs_path) ,因为假如目录没有权限访问,即便它是个目录也会返回 False
|
|
|
+ else:
|
|
|
+ self.address_bar.set_path(abs_path)
|
|
|
+
|
|
|
+ def current_select_path(self):
|
|
|
+ row = self.fileTable.currentRow()
|
|
|
+ if row < 0:
|
|
|
+ return
|
|
|
+ widg:FileWidget = self.fileTable.cellWidget(row, 0)
|
|
|
+ filename = widg.get_text()
|
|
|
+ abs_path = os.path.join(self.path_obj.pathtext, filename)
|
|
|
+ return abs_path
|
|
|
+
|
|
|
+ def current_radio_file_type(self):
|
|
|
+ file_type = None
|
|
|
+ for children in self.findChildren(QRadioButton):
|
|
|
+ children:QRadioButton
|
|
|
+ if children.isChecked():
|
|
|
+ file_type = children.text()
|
|
|
+ return file_type
|
|
|
+
|
|
|
+ def apply(self):
|
|
|
+ abs_path = self.current_select_path()
|
|
|
+ if not abs_path:
|
|
|
+ return
|
|
|
+ if not os.path.isdir(abs_path):
|
|
|
+ return
|
|
|
+ file_type = self.current_radio_file_type()
|
|
|
+ self.add_file_sig.emit(file_type, abs_path)
|
|
|
+ self.fileTable.clearSelection()
|
|
|
+
|
|
|
+ def click_ok(self):
|
|
|
+ self.apply()
|
|
|
+ self.close()
|
|
|
+
|
|
|
+class AddFileWindow(AddPathWindow):
|
|
|
+ def __init__(self, parent, path) -> None:
|
|
|
+ self.file_type = [".v", ".sv", ".f", ".lst", ".list"]
|
|
|
+ self.file_suffix = ["Supported Files(%s)" % " ".join(['*'+str(s) for s in self.file_type]), "All Files(*.*)"]
|
|
|
+ super().__init__(parent, path)
|
|
|
+ self.setWindowTitle("Add File")
|
|
|
+
|
|
|
+ def init(self,parent, path):
|
|
|
+ return super().init(parent, path)
|
|
|
+
|
|
|
+
|
|
|
+ def path_select(self, path):
|
|
|
+ self.path_obj.set(path)
|
|
|
+ self.open_folder(path)
|
|
|
+
|
|
|
+
|
|
|
+ # def update_path(self):
|
|
|
+ # path_text = self.pathBar.text()
|
|
|
+ # if os.path.isdir(path_text):
|
|
|
+ # self.path_obj.set(path_text)
|
|
|
+ # self.show_file_list()
|
|
|
+
|
|
|
|
|
|
def files_filter(self, files):
|
|
|
if self.Combobox_FileType.currentIndex() == self.Combobox_FileType.count()-1:
|
|
|
@@ -77,9 +150,8 @@ class AddFileWindow(Ui_AddFileWindow, QDialog):
|
|
|
return filt_res
|
|
|
|
|
|
def show_file_list(self):
|
|
|
- all_files, self.dirs = get_files_dirs(self.path_obj)
|
|
|
+ all_files, self.dirs = file_list.get_files_dirs(self.path_obj)
|
|
|
self.files = self.files_filter(all_files)
|
|
|
- self.update_counts()
|
|
|
self.fileTable.setRowCount(0)
|
|
|
|
|
|
height = self.fileTable.verticalHeader().defaultSectionSize()
|
|
|
@@ -95,55 +167,16 @@ class AddFileWindow(Ui_AddFileWindow, QDialog):
|
|
|
fwidget = FileWidget(f, "File", height)
|
|
|
self.fileTable.setCellWidget(row, 0, fwidget)
|
|
|
|
|
|
- def format_size(self, size):
|
|
|
- if size < 999:
|
|
|
- return f"{size} B"
|
|
|
- if size < 999999:
|
|
|
- num = Decimal(size / 1000)
|
|
|
- return f"{round(num, 2)} KB"
|
|
|
- if size < 999999999:
|
|
|
- num = Decimal(size / 1000000)
|
|
|
- return f"{round(num, 2)} MB"
|
|
|
- else:
|
|
|
- num = Decimal(size / 1000000000)
|
|
|
- return f"{round(num, 2)} GB"
|
|
|
-
|
|
|
- def update_counts(self):
|
|
|
- self.file_count = len(self.files)
|
|
|
- self.dir_count = len(self.dirs)
|
|
|
-
|
|
|
- def double_click(self, row, column):
|
|
|
- if column != 0:
|
|
|
- return
|
|
|
- widg = self.fileTable.cellWidget(row, column)
|
|
|
- name = widg.get_text()
|
|
|
- abs_path = os.path.join(self.path_obj.pathtext, name)
|
|
|
- if os.path.isfile(abs_path):
|
|
|
- self.open_file(abs_path)
|
|
|
- # 这里不能用 elif os.path.isdir(abs_path) ,因为假如目录没有权限访问,即便它是个目录也会返回 False
|
|
|
- else:
|
|
|
- self.address_bar.set_path(abs_path)
|
|
|
-
|
|
|
- def open_folder(self, dir):
|
|
|
- self.path_obj.set(dir)
|
|
|
- self.show_file_list()
|
|
|
-
|
|
|
def apply(self):
|
|
|
- row = self.fileTable.currentRow()
|
|
|
- if row < 0:
|
|
|
- return 0
|
|
|
- widg:FileWidget = self.fileTable.cellWidget(row, 0)
|
|
|
- filename = widg.get_text()
|
|
|
- abs_path = os.path.join(self.path_obj.pathtext, filename)
|
|
|
+ abs_path = self.current_select_path()
|
|
|
+ if not abs_path:
|
|
|
+ return
|
|
|
if not os.path.isfile(abs_path):
|
|
|
- return -1
|
|
|
- for children in self.findChildren(QRadioButton):
|
|
|
- children:QRadioButton
|
|
|
- if children.isChecked():
|
|
|
- file_type = children.text()
|
|
|
- self.add_file_sig.emit(file_type, abs_path)
|
|
|
+ return
|
|
|
+ file_type = self.current_radio_file_type()
|
|
|
+ self.add_file_sig.emit(file_type, abs_path)
|
|
|
self.fileTable.clearSelection()
|
|
|
-
|
|
|
+
|
|
|
def click_ok(self):
|
|
|
self.apply()
|
|
|
self.close()
|