Skip to content

Commit

Permalink
<feature> support generate empty in extraction
Browse files Browse the repository at this point in the history
update version to v1.7.2
  • Loading branch information
anonymousException committed Mar 4, 2024
1 parent 511ce38 commit 7302db4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def extract(self):
if len(tl_name) == 0:
log_print('tl name is empty skip extract file(s)')
continue
t = extractThread(threadID=cnt, p=i, tl_name=tl_name,dir=None,tl_dir=None,is_open_filter=self.filterCheckBox.isChecked(),filter_length=int(self.filterLengthLineEdit.text()))
t = extractThread(threadID=cnt, p=i, tl_name=tl_name,dir=None,tl_dir=None,is_open_filter=self.filterCheckBox.isChecked(),filter_length=int(self.filterLengthLineEdit.text()),is_gen_empty=self.emptyCheckBox.isChecked())
t.start()
extract_threads.append(t)
cnt = cnt + 1
Expand All @@ -370,7 +370,7 @@ def extract(self):
continue
t = extractThread(threadID=cnt, p=None, tl_name=tl_name, dir=i, tl_dir=None,
is_open_filter=self.filterCheckBox.isChecked(),
filter_length=int(self.filterLengthLineEdit.text()))
filter_length=int(self.filterLengthLineEdit.text()),is_gen_empty=self.emptyCheckBox.isChecked())
t.start()
extract_threads.append(t)
cnt = cnt + 1
Expand All @@ -385,7 +385,7 @@ def extract(self):
else:
if select_dir[len(select_dir) - 1] != '/' and select_dir[len(select_dir) - 1] != '\\':
select_dir = select_dir + '/'
t = extractThread(threadID=cnt, p=None, tl_name=tl_name,dir=None,tl_dir=select_dir,is_open_filter=self.filterCheckBox.isChecked(),filter_length=int(self.filterLengthLineEdit.text()))
t = extractThread(threadID=cnt, p=None, tl_name=tl_name,dir=None,tl_dir=select_dir,is_open_filter=self.filterCheckBox.isChecked(),filter_length=int(self.filterLengthLineEdit.text()),is_gen_empty=self.emptyCheckBox.isChecked())
t.start()
extract_threads.append(t)
cnt = cnt + 1
Expand Down
27 changes: 17 additions & 10 deletions src/renpy_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class extractThread(threading.Thread):
def __init__(self, threadID, p, tl_name,dir, tl_dir, is_open_filter, filter_length=8):
def __init__(self, threadID, p, tl_name,dir, tl_dir, is_open_filter, filter_length,is_gen_empty):
threading.Thread.__init__(self)
self.threadID = threadID
self.p = p
Expand All @@ -25,6 +25,7 @@ def __init__(self, threadID, p, tl_name,dir, tl_dir, is_open_filter, filter_leng
self.tl_dir = tl_dir
self.is_open_filter = is_open_filter
self.filter_length = filter_length
self.is_gen_empty = is_gen_empty

def run(self):
try:
Expand All @@ -35,11 +36,11 @@ def run(self):
ori_tl = os.path.basename(self.tl_dir)
self.tl_dir = self.tl_dir[:-len(ori_tl)] + self.tl_name
log_print(self.tl_dir + ' begin extract!')
ExtractAllFilesInDir(self.tl_dir, self.is_open_filter, self.filter_length)
ExtractAllFilesInDir(self.tl_dir, self.is_open_filter, self.filter_length,self.is_gen_empty)
else:
if self.p is not None:
log_print(self.p + ' begin extract!')
ExtractWriteFile(self.p, self.tl_name, self.is_open_filter, self.filter_length)
ExtractWriteFile(self.p, self.tl_name, self.is_open_filter, self.filter_length,self.is_gen_empty)
if self.dir is not None:
log_print(self.dir + ' begin extract!')
paths = os.walk(self.dir, topdown=False)
Expand All @@ -48,7 +49,7 @@ def run(self):
i = os.path.join(path, file_name)
if not file_name.endswith("rpy"):
continue
ExtractWriteFile(i, self.tl_name, self.is_open_filter, self.filter_length)
ExtractWriteFile(i, self.tl_name, self.is_open_filter, self.filter_length,self.is_gen_empty)

except Exception as e:
msg = traceback.format_exc()
Expand Down Expand Up @@ -338,7 +339,7 @@ def GetExtractedSet(p):
return e


def WriteExtracted(p, extractedSet,is_open_filter, filter_length):
def WriteExtracted(p, extractedSet,is_open_filter, filter_length,is_gen_empty):
if (p[len(p) - 1] != '/' and p[len(p) - 1] != '\\'):
p = p + '/'
index = p.rfind('tl\\')
Expand Down Expand Up @@ -378,7 +379,10 @@ def WriteExtracted(p, extractedSet,is_open_filter, filter_length):
head = head + 'new ' + timestamp + '\n\n'
f.write(head)
for j in eDiff:
writeData = ' old ' + j + '\n new ' + j + '\n'
if not is_gen_empty:
writeData = ' old ' + j + '\n new ' + j + '\n'
else:
writeData = ' old ' + j + '\n new ' + '""' + '\n'
f.write(writeData + '\n')
f.close()
extractedSet = e | extractedSet
Expand Down Expand Up @@ -406,7 +410,7 @@ def GetHeaderPath(p):
return dic


def ExtractWriteFile(p, tl_name, is_open_filter, filter_length):
def ExtractWriteFile(p, tl_name, is_open_filter, filter_length,is_gen_empty):
dic = GetHeaderPath(p)
header = dic['header']
if (header == ''):
Expand Down Expand Up @@ -437,14 +441,17 @@ def ExtractWriteFile(p, tl_name, is_open_filter, filter_length):
head = head + 'new ' + timestamp + '\n\n'
f.write(head)
for j in eDiff:
writeData = ' old ' + j + '\n new ' + j + '\n'
if not is_gen_empty:
writeData = ' old ' + j + '\n new ' + j + '\n'
else:
writeData = ' old ' + j + '\n new ' + '""' + '\n'
f.write(writeData + '\n')
f.close()
extractedSet = e | extractedSet
log_print(target + ' extracted success!')


def ExtractAllFilesInDir(dirName, is_open_filter, filter_length):
def ExtractAllFilesInDir(dirName, is_open_filter, filter_length,is_gen_empty):
CreateEmptyFileIfNotExsit(dirName)
ret = GetExtractedSet(dirName)
WriteExtracted(dirName,ret,is_open_filter, filter_length)
WriteExtracted(dirName,ret,is_open_filter, filter_length,is_gen_empty)
26 changes: 15 additions & 11 deletions src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(1463, 909)
MainWindow.resize(1463, 953)
self.actioncopyright = QAction(MainWindow)
self.actioncopyright.setObjectName(u"actioncopyright")
self.proxySettings = QAction(MainWindow)
Expand All @@ -35,7 +35,7 @@ def setupUi(self, MainWindow):
self.centralwidget.setObjectName(u"centralwidget")
self.log_text = QTextEdit(self.centralwidget)
self.log_text.setObjectName(u"log_text")
self.log_text.setGeometry(QRect(630, 50, 821, 801))
self.log_text.setGeometry(QRect(630, 50, 821, 821))
self.log_text.setReadOnly(True)
self.clearLogBtn = QPushButton(self.centralwidget)
self.clearLogBtn.setObjectName(u"clearLogBtn")
Expand Down Expand Up @@ -92,7 +92,7 @@ def setupUi(self, MainWindow):
self.backupCheckBox.setGeometry(QRect(20, 280, 231, 24))
self.widget_2 = QWidget(self.centralwidget)
self.widget_2.setObjectName(u"widget_2")
self.widget_2.setGeometry(QRect(10, 320, 601, 311))
self.widget_2.setGeometry(QRect(10, 320, 601, 341))
self.selectFilesText_2 = QTextEdit(self.widget_2)
self.selectFilesText_2.setObjectName(u"selectFilesText_2")
self.selectFilesText_2.setGeometry(QRect(100, 40, 411, 41))
Expand All @@ -118,7 +118,7 @@ def setupUi(self, MainWindow):
self.selectDirText_2.setGeometry(QRect(100, 160, 411, 41))
self.extractBtn = QPushButton(self.widget_2)
self.extractBtn.setObjectName(u"extractBtn")
self.extractBtn.setGeometry(QRect(270, 280, 75, 24))
self.extractBtn.setGeometry(QRect(270, 310, 75, 24))
self.label_8 = QLabel(self.widget_2)
self.label_8.setObjectName(u"label_8")
self.label_8.setGeometry(QRect(20, 235, 61, 31))
Expand All @@ -137,22 +137,25 @@ def setupUi(self, MainWindow):
self.selectDirsBtn.setGeometry(QRect(510, 100, 81, 41))
self.filterCheckBox = QCheckBox(self.widget_2)
self.filterCheckBox.setObjectName(u"filterCheckBox")
self.filterCheckBox.setGeometry(QRect(20, 280, 161, 20))
self.filterCheckBox.setGeometry(QRect(20, 280, 91, 20))
self.label_14 = QLabel(self.widget_2)
self.label_14.setObjectName(u"label_14")
self.label_14.setGeometry(QRect(380, 282, 131, 16))
self.label_14.setGeometry(QRect(120, 282, 131, 16))
self.filterLengthLineEdit = QLineEdit(self.widget_2)
self.filterLengthLineEdit.setObjectName(u"filterLengthLineEdit")
self.filterLengthLineEdit.setGeometry(QRect(510, 280, 61, 20))
self.filterLengthLineEdit.setGeometry(QRect(250, 280, 61, 20))
self.emptyCheckBox = QCheckBox(self.widget_2)
self.emptyCheckBox.setObjectName(u"emptyCheckBox")
self.emptyCheckBox.setGeometry(QRect(330, 280, 271, 20))
self.versionLabel = QLabel(self.centralwidget)
self.versionLabel.setObjectName(u"versionLabel")
self.versionLabel.setGeometry(QRect(10, 860, 91, 16))
self.versionLabel.setGeometry(QRect(10, 880, 91, 16))
self.copyrightLabel = QLabel(self.centralwidget)
self.copyrightLabel.setObjectName(u"copyrightLabel")
self.copyrightLabel.setGeometry(QRect(1190, 860, 241, 16))
self.copyrightLabel.setGeometry(QRect(1190, 880, 241, 16))
self.widget_3 = QWidget(self.centralwidget)
self.widget_3.setObjectName(u"widget_3")
self.widget_3.setGeometry(QRect(10, 630, 601, 221))
self.widget_3.setGeometry(QRect(10, 660, 601, 221))
self.label_11 = QLabel(self.widget_3)
self.label_11.setObjectName(u"label_11")
self.label_11.setGeometry(QRect(280, 0, 60, 20))
Expand Down Expand Up @@ -247,7 +250,8 @@ def retranslateUi(self, MainWindow):
self.selectDirsBtn.setText(QCoreApplication.translate("MainWindow", u"...", None))
self.filterCheckBox.setText(QCoreApplication.translate("MainWindow", u"Enable filter for extract", None))
self.label_14.setText(QCoreApplication.translate("MainWindow", u"filter length less than", None))
self.versionLabel.setText(QCoreApplication.translate("MainWindow", u"Version 1.7.1", None))
self.emptyCheckBox.setText(QCoreApplication.translate("MainWindow", u"Generate empty strings instead of original", None))
self.versionLabel.setText(QCoreApplication.translate("MainWindow", u"Version 1.7.2", None))
self.copyrightLabel.setText(QCoreApplication.translate("MainWindow", u"\u00a92024 Last moment,All rights reserved.", None))
self.label_11.setText(QCoreApplication.translate("MainWindow", u"font", None))
self.selectFontText.setPlaceholderText(QCoreApplication.translate("MainWindow", u"input or choose or drag the font which supports the language after translation. Example : DejaVuSans.ttf (ren'py 's default font)", None))
Expand Down
35 changes: 24 additions & 11 deletions src/ui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1463</width>
<height>909</height>
<height>953</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -20,7 +20,7 @@
<x>630</x>
<y>50</y>
<width>821</width>
<height>801</height>
<height>821</height>
</rect>
</property>
<property name="readOnly">
Expand Down Expand Up @@ -246,7 +246,7 @@
<x>10</x>
<y>320</y>
<width>601</width>
<height>311</height>
<height>341</height>
</rect>
</property>
<widget class="QTextEdit" name="selectFilesText_2">
Expand Down Expand Up @@ -355,7 +355,7 @@
<property name="geometry">
<rect>
<x>270</x>
<y>280</y>
<y>310</y>
<width>75</width>
<height>24</height>
</rect>
Expand Down Expand Up @@ -440,7 +440,7 @@
<rect>
<x>20</x>
<y>280</y>
<width>161</width>
<width>91</width>
<height>20</height>
</rect>
</property>
Expand All @@ -451,7 +451,7 @@
<widget class="QLabel" name="label_14">
<property name="geometry">
<rect>
<x>380</x>
<x>120</x>
<y>282</y>
<width>131</width>
<height>16</height>
Expand All @@ -464,32 +464,45 @@
<widget class="QLineEdit" name="filterLengthLineEdit">
<property name="geometry">
<rect>
<x>510</x>
<x>250</x>
<y>280</y>
<width>61</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QCheckBox" name="emptyCheckBox">
<property name="geometry">
<rect>
<x>330</x>
<y>280</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Generate empty strings instead of original</string>
</property>
</widget>
</widget>
<widget class="QLabel" name="versionLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>860</y>
<y>880</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Version 1.7.1</string>
<string>Version 1.7.2</string>
</property>
</widget>
<widget class="QLabel" name="copyrightLabel">
<property name="geometry">
<rect>
<x>1190</x>
<y>860</y>
<y>880</y>
<width>241</width>
<height>16</height>
</rect>
Expand All @@ -502,7 +515,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>630</y>
<y>660</y>
<width>601</width>
<height>221</height>
</rect>
Expand Down

0 comments on commit 7302db4

Please sign in to comment.