Untitled

Anonymous
plain_text
03/30/2026 5:02 PM
2.9 KB
13
Indexable
import os
from PyQt5.QtWidgets import (
    QApplication, QWidget, QFileDialog,
    QLabel, QPushButton, QListWidget,
    QHBoxLayout, QVBoxLayout
)
from ImageEditor import ImageEditor

app = QApplication([])
win = QWidget()
win.resize(700, 500)
win.setWindowTitle('Easy Editor')

lb_image = QLabel("Картинка")
btn_dir = QPushButton("Папка")
lw_files = QListWidget()

btn_left = QPushButton("Вліво")
btn_right = QPushButton("Вправо")
btn_flip = QPushButton("Дзеркало")
btn_sharp = QPushButton("Різкість")
btn_bw = QPushButton("Ч/Б")

row = QHBoxLayout()
col1 = QVBoxLayout()
col2 = QVBoxLayout()

col1.addWidget(btn_dir)
col1.addWidget(lw_files)

col2.addWidget(lb_image)

row_tools = QHBoxLayout()
row_tools.addWidget(btn_left)
row_tools.addWidget(btn_right)
row_tools.addWidget(btn_flip)
row_tools.addWidget(btn_sharp)
row_tools.addWidget(btn_bw)

col2.addLayout(row_tools)

row.addLayout(col1, 15)
row.addLayout(col2, 85)
win.setLayout(row)

workdir = ""
extensions = [".png", ".jpg", ".svg", ".gif", ".jpeg", ".webp", ".bmp"]

new_image_editor = ImageEditor()

def chooseWorkDir():
    global workdir
    workdir = QFileDialog.getExistingDirectory()

def filter(files, extensions):
    result = []
    for filename in files:
        for ext in extensions:
            if filename.endswith(ext):
                result.append(filename)
                break
    return result

def showFileNames():
    chooseWorkDir()
    if not workdir:
        return
    filenames = filter(os.listdir(workdir), extensions)
    lw_files.clear()
    for filename in filenames:
        lw_files.addItem(filename)

def showChosenImage():
    if lw_files.currentRow() >= 0:
        filename = lw_files.currentItem().text()
        new_image_editor.dir = workdir
        new_image_editor.load_image(filename)
        full_path = os.path.join(workdir, filename)
        new_image_editor.showImage(full_path)

new_image_editor.lb_image = lb_image

btn_dir.clicked.connect(showFileNames)
lw_files.currentRowChanged.connect(showChosenImage)
btn_bw.clicked.connect(new_image_editor.do_bw)

win.show()
app.exec()
Editor is loading...
Leave a Comment