2019-10-03 04:57:42 +00:00
#!/usr/bin/python3
#tooltips
# Please read this tutorial on how to prepare your images for use with DeepCreamPy.
# The greater the number of variations, the longer decensoring process will be.
2019-10-09 05:20:28 +00:00
import sys , time
2020-01-02 16:53:57 +00:00
from PySide2 . QtWidgets import QWidget , QHBoxLayout , QVBoxLayout , QGridLayout , QGroupBox , QDesktopWidget , QApplication
from PySide2 . QtWidgets import QAction , qApp , QApplication , QMessageBox , QRadioButton , QPushButton , QTextEdit , QLabel
from PySide2 . QtWidgets import QSizePolicy , QMainWindow , QStatusBar , QProgressBar
2019-10-09 05:20:28 +00:00
from PySide2 . QtCore import Qt , QObject
from PySide2 . QtGui import QFont , QTextCursor
2019-10-03 04:57:42 +00:00
from decensor import Decensor
2020-01-02 16:53:57 +00:00
from signals import Signals
# from decensor import Decensor
2019-10-03 04:57:42 +00:00
2020-01-02 16:53:57 +00:00
# from progressWindow import ProgressWindow
2019-10-21 08:08:03 +00:00
2019-10-03 04:57:42 +00:00
class MainWindow ( QWidget ) :
def __init__ ( self ) :
super ( ) . __init__ ( )
2020-01-02 16:53:57 +00:00
self . signals = Signals ( )
2019-10-03 04:57:42 +00:00
self . initUI ( )
2020-01-02 16:53:57 +00:00
self . setSignals ( )
self . decensor = Decensor ( self )
self . load_model ( )
2019-10-03 04:57:42 +00:00
def initUI ( self ) :
grid_layout = QGridLayout ( )
grid_layout . setSpacing ( 10 )
self . setLayout ( grid_layout )
2019-10-04 01:32:00 +00:00
#Tutorial
self . tutorialLabel = QLabel ( )
2019-11-01 03:11:00 +00:00
self . tutorialLabel . setText ( " Welcome to DeepCreamPy! \n \n If you ' re new to DCP, please read the README. \n This program does nothing without the proper setup of your images. \n \n Report any bugs you encounter to me on Github or Twitter @deeppomf. " )
2019-10-04 01:32:00 +00:00
self . tutorialLabel . setAlignment ( Qt . AlignCenter )
self . tutorialLabel . setFont ( QFont ( ' Sans Serif ' , 13 ) )
2019-10-03 04:57:42 +00:00
#Censor type group
self . censorTypeGroupBox = QGroupBox ( ' Censor Type ' )
barButton = QRadioButton ( ' Bar censor ' )
mosaicButton = QRadioButton ( ' Mosaic censor ' )
barButton . setChecked ( True )
censorLayout = QVBoxLayout ( )
censorLayout . addWidget ( barButton )
censorLayout . addWidget ( mosaicButton )
2019-10-04 01:32:00 +00:00
# censorLayout.addStretch(1)
2019-10-03 04:57:42 +00:00
self . censorTypeGroupBox . setLayout ( censorLayout )
#Variation count group
self . variationsGroupBox = QGroupBox ( ' Number of Decensor Variations ' )
var1Button = QRadioButton ( ' 1 ' )
var2Button = QRadioButton ( ' 2 ' )
var3Button = QRadioButton ( ' 4 ' )
var1Button . setChecked ( True )
varLayout = QVBoxLayout ( )
varLayout . addWidget ( var1Button )
varLayout . addWidget ( var2Button )
varLayout . addWidget ( var3Button )
2019-10-04 01:32:00 +00:00
# varLayout.addStretch(1)
2019-10-03 04:57:42 +00:00
self . variationsGroupBox . setLayout ( varLayout )
2019-10-09 05:20:28 +00:00
#Decensor button
self . decensorButton = QPushButton ( ' Decensor Your Images ' )
self . decensorButton . clicked . connect ( self . decensorClicked )
self . decensorButton . setSizePolicy (
2019-10-04 01:32:00 +00:00
QSizePolicy . Preferred ,
QSizePolicy . Preferred )
2019-10-03 04:57:42 +00:00
2019-10-09 05:20:28 +00:00
#Progress message
# self.progressGroupBox = QGroupBox('Progress')
self . progressMessage = QTextEdit ( )
self . progressCursor = QTextCursor ( self . progressMessage . document ( ) )
self . progressMessage . setTextCursor ( self . progressCursor )
2019-10-09 06:02:47 +00:00
self . progressMessage . setReadOnly ( True )
2019-10-09 05:20:28 +00:00
self . progressCursor . insertText ( " After you prepared your images, click on the decensor button once to begin decensoring. \n Please be patient. \n Decensoring will take time. \n " )
2020-01-02 16:53:57 +00:00
# Progress Bar
self . statusBar = QStatusBar ( self )
self . progressBar = QProgressBar ( )
self . progressBar . setMinimum ( 0 )
self . progressBar . setMaximum ( 100 )
self . progressBar . setValue ( 0 )
self . statusLabel = QLabel ( " Showing Progress " )
self . statusBar . addWidget ( self . statusLabel , 1 )
self . statusBar . addWidget ( self . progressBar , 2 )
2019-10-03 04:57:42 +00:00
#put all groups into grid
2020-01-02 16:53:57 +00:00
# addWidget(row, column, rowSpan, columnSpan)
2019-10-04 01:32:00 +00:00
grid_layout . addWidget ( self . tutorialLabel , 0 , 0 , 1 , 2 )
grid_layout . addWidget ( self . censorTypeGroupBox , 1 , 0 , 1 , 1 )
grid_layout . addWidget ( self . variationsGroupBox , 1 , 1 , 1 , 1 )
2019-10-09 05:20:28 +00:00
grid_layout . addWidget ( self . decensorButton , 2 , 0 , 1 , 2 )
2020-01-02 16:53:57 +00:00
grid_layout . addWidget ( self . progressMessage , 3 , 0 , 1 , 2 )
grid_layout . addWidget ( self . statusBar , 4 , 0 , 1 , 2 )
2019-10-03 04:57:42 +00:00
#window size settings
2020-01-02 16:53:57 +00:00
self . resize ( 900 , 600 )
2019-10-03 04:57:42 +00:00
self . center ( )
2019-11-01 03:11:00 +00:00
self . setWindowTitle ( ' DeepCreamPy v2.2.0-beta ' )
2019-10-03 04:57:42 +00:00
self . show ( )
2020-01-02 16:53:57 +00:00
def load_model ( self ) :
# load model to make able to decensor several times
self . decensorButton . setEnabled ( False )
self . decensorButton . setText ( " Loading Machine Learning Model (Please Wait...) " )
self . decensor . start ( )
self . decensor . signals = self . signals
self . progressCursor . insertText ( " Loading Decensor app consumes 6 GB memory at maximum " )
def setSignals ( self ) :
self . signals . update_decensorButton_Text . connect ( self . decensorButton . setText )
self . signals . update_decensorButton_Enabled . connect ( self . decensorButton . setEnabled )
self . signals . update_statusLabel_Text . connect ( self . statusLabel . setText )
self . signals . update_ProgressBar_SET_VALUE . connect ( self . progressBar . setValue )
self . signals . update_ProgressBar_MAX_VALUE . connect ( self . progressBar . setMaximum )
self . signals . update_ProgressBar_MIN_VALUE . connect ( self . progressBar . setMinimum )
# self.signals.insertText_progressCursor.connect(self.progressCursor.insertText)
self . signals . insertText_progressCursor . connect ( self . progressMessage . append )
self . signals . clear_progressMessage . connect ( self . progressMessage . clear )
self . signals . appendText_progressMessage . connect ( self . progressMessage . append )
2019-10-03 04:57:42 +00:00
def decensorClicked ( self ) :
2019-10-09 05:20:28 +00:00
self . decensorButton . setEnabled ( False )
self . progressMessage . clear ( )
self . progressCursor . insertText ( " Decensoring has begun! \n " )
2020-01-02 16:53:57 +00:00
# for now, decensor is initiated when this app is started
# self.decensor = Decensor(text_edit = self.progressMessage, text_cursor = self.progressCursor, ui_mode = True)
2019-10-03 04:57:42 +00:00
#https://stackoverflow.com/questions/42349470/pyqt-find-checked-radiobutton-in-a-group
#set decensor to right settings
#censor type
censorTypeElements = self . censorTypeGroupBox . children ( )
censorButtons = [ elem for elem in censorTypeElements if isinstance ( elem , QRadioButton ) ]
for cb in censorButtons :
if cb . isChecked ( ) :
censorType = cb . text ( )
if censorType == ' Bar censor ' :
2020-01-02 16:53:57 +00:00
self . decensor . is_mosaic = False
2019-10-03 04:57:42 +00:00
else :
2020-01-02 16:53:57 +00:00
self . decensor . is_mosaic = True
2019-10-03 04:57:42 +00:00
#variations count
variationsElements = self . variationsGroupBox . children ( )
variationsButtons = [ elem for elem in variationsElements if isinstance ( elem , QRadioButton ) ]
for vb in variationsButtons :
if vb . isChecked ( ) :
variations = int ( vb . text ( ) )
2020-01-02 16:53:57 +00:00
self . decensor . variations = variations
2019-10-03 04:57:42 +00:00
2020-01-02 16:53:57 +00:00
self . decensorButton . setEnabled ( False )
self . decensor . start ( )
2019-10-21 08:08:03 +00:00
# decensor.decensor_all_images_in_folder()
2019-10-03 04:57:42 +00:00
# #centers the main window
def center ( self ) :
qr = self . frameGeometry ( )
cp = QDesktopWidget ( ) . availableGeometry ( ) . center ( )
qr . moveCenter ( cp )
self . move ( qr . topLeft ( ) )
if __name__ == ' __main__ ' :
2019-10-21 08:08:03 +00:00
import os
# you could remove this if statement if there's no error without this
if os . name == ' nt ' :
import PySide2
pyqt = os . path . dirname ( PySide2 . __file__ )
QApplication . addLibraryPath ( os . path . join ( pyqt , " plugins " ) )
2019-10-03 04:57:42 +00:00
app = QApplication ( sys . argv )
ex = MainWindow ( )
2019-10-21 08:08:03 +00:00
sys . exit ( app . exec_ ( ) )