Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
banagale committed Jul 16, 2024
2 parents c176bc6 + f872476 commit d04c79d
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions filekitty/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import os
from PyQt5.QtCore import QSettings
from PyQt5.QtGui import QIcon, QGuiApplication, QKeySequence
from PyQt5.QtWidgets import (QApplication, QWidget, QFileDialog, QVBoxLayout, QPushButton, QTextEdit,
QLabel, QListWidget, QDialog, QLineEdit, QHBoxLayout, QAction, QMenuBar, QMenu)

from PyQt5.QtCore import QSettings, QTimer, Qt
from PyQt5.QtGui import QIcon, QGuiApplication, QKeySequence, QDragEnterEvent, QDropEvent
from PyQt5.QtWidgets import (
QApplication, QWidget, QFileDialog, QVBoxLayout, QPushButton, QTextEdit,
QLabel, QListWidget, QDialog, QLineEdit, QHBoxLayout, QAction, QMenuBar,
QGraphicsColorizeEffect
)

ICON_PATH = 'assets/icon/FileKitty-icon.png'


class PreferencesDialog(QDialog):
def __init__(self, parent=None):
super(PreferencesDialog, self).__init__(parent)
Expand Down Expand Up @@ -46,12 +51,14 @@ def get_path(self):
def set_path(self, path):
self.pathEdit.setText(path)


class FilePicker(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('FileKitty')
self.setWindowIcon(QIcon(ICON_PATH))
self.setGeometry(100, 100, 800, 600)
self.setAcceptDrops(True)
self.initUI()
self.createActions()
self.createMenu()
Expand Down Expand Up @@ -114,8 +121,10 @@ def set_default_path(self, path):
def openFiles(self):
default_path = self.get_default_path() or ""
options = QFileDialog.Options()
files, _ = QFileDialog.getOpenFileNames(self, "Select files to concatenate", default_path,
"All Files (*);;Text Files (*.txt)", options=options)
files, _ = QFileDialog.getOpenFileNames(
self, "Select files to concatenate", default_path,
"All Files (*);;Text Files (*.txt)", options=options
)
if files:
self.fileList.clear()
self.currentFiles = files
Expand All @@ -132,8 +141,8 @@ def concatenate_files(self, files):
relative_path = os.path.relpath(file, start=common_prefix)
self.fileList.addItem(relative_path)
concatenated_content += f"### `{relative_path}`\n\n```\n"
with open(file, 'r', encoding='utf-8') as file:
content = file.read()
with open(file, 'r', encoding='utf-8') as f:
content = f.read()
concatenated_content += content
concatenated_content += "\n```\n\n"
return concatenated_content.rstrip()
Expand All @@ -153,6 +162,42 @@ def refreshFiles(self):
concatenated_content = self.concatenate_files(self.currentFiles)
self.textEdit.setText(concatenated_content)

def dragEnterEvent(self, event: QDragEnterEvent):
if event.mimeData().hasUrls():
event.acceptProposedAction()
else:
event.ignore()

def dropEvent(self, event: QDropEvent):
if event.mimeData().hasUrls():
files = []
for url in event.mimeData().urls():
if url.isLocalFile():
files.append(url.toLocalFile())
if files:
self.fileList.clear()
self.currentFiles = files
self.refreshFiles()
self.btnRefresh.setEnabled(True)
self.animateDropSuccess()
event.acceptProposedAction()
else:
event.ignore()

def applyBrightnessEffect(self):
self.effect = QGraphicsColorizeEffect(self)
self.effect.setColor(Qt.darkBlue)
self.effect.setStrength(0.25)
self.setGraphicsEffect(self.effect)

def removeBrightnessEffect(self):
self.setGraphicsEffect(None)

def animateDropSuccess(self):
self.applyBrightnessEffect()
QTimer.singleShot(100, self.removeBrightnessEffect)


if __name__ == '__main__':
app = QApplication([])
app.setOrganizationName('YourCompany')
Expand Down

0 comments on commit d04c79d

Please sign in to comment.