Skip to content

Commit

Permalink
Merge pull request #21 from LJxFFFF/fix
Browse files Browse the repository at this point in the history
v0.1.1
  • Loading branch information
LJxFFFF authored Aug 9, 2020
2 parents add96ff + 512fdb4 commit d85fca9
Show file tree
Hide file tree
Showing 23 changed files with 5,673 additions and 5,582 deletions.
2 changes: 1 addition & 1 deletion Excel2RpyScript.spec
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ exe = EXE(pyz,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False , icon='sos.ico')
console=False , icon='asset\\sos.ico')
12 changes: 11 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Excel文件转Rpy脚本
# Excel文件转Rpy脚本(0.1.1)

## 开发环境
- Python 3.8
Expand All @@ -19,3 +19,13 @@
|--app.py 程序入口
```


## 打包程序
- 工具: pyinstaller
- CMD: `pyinstaller -F -w -i .\asset\sos.ico .\app.py -n Excel2RpyScript`

## relase notes
- 0.1.1
- fix [立绘回收 #20](https://github.com/HaruhiFanClub/Excel2RpyScript/issues/20)
- fix [Nvl模式与adv模式的切换 #19](https://github.com/HaruhiFanClub/Excel2RpyScript/issues/19)
- 去掉Exe文件的外部依赖
17 changes: 10 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import base64
from io import BytesIO
from tkinter import Tk, Text, PhotoImage, Canvas
from tkinter.messagebox import showerror, showinfo
from tkinter.ttk import Frame, Style, Entry, Combobox, Button, Label
from tkinter import filedialog
from corelib.exception import ConvertException, SaveFileException
from handler.converter import Converter
from tools.image_data import *


class Application_ui(Frame):
#这个类仅实现界面生成功能,具体事件处理代码在子类Application中。
Expand All @@ -21,8 +24,7 @@ def createWidgets(self):
self.top = self.winfo_toplevel()

self.style = Style()

self.bkg_gif = PhotoImage(file='background.gif')
self.bkg_gif = PhotoImage(data=base64.b64decode(back_ground_gif_data))
self.background_label = Label(self.top, image=self.bkg_gif)
self.background_label.place(x=0, y=0, relwidth=1, relheight=1)

Expand All @@ -42,8 +44,7 @@ def createWidgets(self):
self.InputButton = Button(self.top, text='浏览', command=self.InputButton_Cmd, style='InputButton.TButton')
self.InputButton.place(relx=0.184, rely=0.7, relwidth=0.133, relheight=0.073)


self.Haruhi_gif = PhotoImage(file='Haruhi.gif')
self.Haruhi_gif = PhotoImage(data=base64.b64decode(haruhi_gif_data))
self.style.configure('ConvertButton.TButton',font=('宋体',9))
self.ConvertButton = Button(self.top, image=self.Haruhi_gif, command=self.ConvertButton_Cmd, style='ConvertButton.TButton')
self.ConvertButton.place(relx=0.788, rely=0.7, relwidth=0.146, relheight=0.236)
Expand All @@ -70,7 +71,8 @@ def convert(self, input_path, output_path):
with open(output_path, 'w', encoding='utf-8') as f:
for k, v in c.role_name_mapping.items():
f.write(v.render() + "\n")
f.write("define narrator = Character(None, kind=nvl)\n")
f.write("define narrator_nvl = Character(None, kind=nvl)\n")
f.write("define narrator_adv = Character(None, kind=adv)\n")
f.write("\nlabel start:\n")
for text in texts:
for t in text.triggers:
Expand Down Expand Up @@ -137,7 +139,8 @@ def ConvertButton_Cmd(self, event=None):

if __name__ == "__main__":
top = Tk()
top.iconbitmap('sos.ico')
# top.iconbitmap('sos.ico')
top.iconphoto(False, PhotoImage(data=base64.b64decode(haruhi_gif_data)))
Application(top).mainloop()
try: top.destroy()
except: pass
File renamed without changes
File renamed without changes
File renamed without changes.
3,677 changes: 1,840 additions & 1,837 deletions build/Excel2RpyScript/Analysis-00.toc

Large diffs are not rendered by default.

3,656 changes: 1,828 additions & 1,828 deletions build/Excel2RpyScript/EXE-00.toc

Large diffs are not rendered by default.

Binary file modified build/Excel2RpyScript/PKG-00.pkg
Binary file not shown.
3,652 changes: 1,826 additions & 1,826 deletions build/Excel2RpyScript/PKG-00.toc

Large diffs are not rendered by default.

Binary file modified build/Excel2RpyScript/PYZ-00.pyz
Binary file not shown.
21 changes: 12 additions & 9 deletions build/Excel2RpyScript/PYZ-00.toc
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@
('ssl',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\ssl.py',
'PYMODULE'),
('base64',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\base64.py',
'PYMODULE'),
('getopt',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\getopt.py',
'PYMODULE'),
('asyncio.proactor_events',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\asyncio\\proactor_events.py',
'PYMODULE'),
Expand Down Expand Up @@ -353,6 +347,9 @@
('mimetypes',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\mimetypes.py',
'PYMODULE'),
('getopt',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\getopt.py',
'PYMODULE'),
('http.cookiejar',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\http\\cookiejar.py',
'PYMODULE'),
Expand Down Expand Up @@ -614,18 +611,21 @@
('tracemalloc',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\tracemalloc.py',
'PYMODULE'),
('stringprep',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\stringprep.py',
'PYMODULE'),
('_py_abc',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\_py_abc.py',
'PYMODULE'),
('stringprep',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\stringprep.py',
('tools.image_data',
'D:\\Github\\Excel2RpyScript\\tools\\image_data.py',
'PYMODULE'),
('tools', 'D:\\Github\\Excel2RpyScript\\tools\\__init__.py', 'PYMODULE'),
('handler.converter',
'D:\\Github\\Excel2RpyScript\\handler\\converter.py',
'PYMODULE'),
('handler', 'D:\\Github\\Excel2RpyScript\\handler\\__init__.py', 'PYMODULE'),
('tools.excel', 'D:\\Github\\Excel2RpyScript\\tools\\excel.py', 'PYMODULE'),
('tools', 'D:\\Github\\Excel2RpyScript\\tools\\__init__.py', 'PYMODULE'),
('xlrd',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\site-packages\\xlrd\\__init__.py',
'PYMODULE'),
Expand Down Expand Up @@ -702,4 +702,7 @@
'PYMODULE'),
('tkinter.constants',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\tkinter\\constants.py',
'PYMODULE'),
('base64',
'c:\\users\\31404\\appdata\\local\\programs\\python\\python38\\lib\\base64.py',
'PYMODULE')])
Binary file modified build/Excel2RpyScript/base_library.zip
Binary file not shown.
Binary file added build/Excel2RpyScript/runw.exe.otml0ygh
Binary file not shown.
22 changes: 21 additions & 1 deletion build/Excel2RpyScript/xref-Excel2RpyScript.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h1>modulegraph cross reference for app.py, pyi_rth__tkinter.py, pyi_rth_multipr
&#8226; <a href="#_collections_abc">_collections_abc</a>
&#8226; <a href="#_weakrefset">_weakrefset</a>
&#8226; <a href="#abc">abc</a>
&#8226; <a href="#base64">base64</a>
&#8226; <a href="#codecs">codecs</a>
&#8226; <a href="#collections">collections</a>
&#8226; <a href="#collections.abc">collections.abc</a>
Expand Down Expand Up @@ -170,6 +171,7 @@ <h1>modulegraph cross reference for app.py, pyi_rth__tkinter.py, pyi_rth_multipr
&#8226; <a href="#tkinter.filedialog">tkinter.filedialog</a>
&#8226; <a href="#tkinter.messagebox">tkinter.messagebox</a>
&#8226; <a href="#tkinter.ttk">tkinter.ttk</a>
&#8226; <a href="#tools.image_data">tools.image_data</a>
&#8226; <a href="#traceback">traceback</a>
&#8226; <a href="#types">types</a>
&#8226; <a href="#warnings">warnings</a>
Expand Down Expand Up @@ -2134,7 +2136,8 @@ <h1>modulegraph cross reference for app.py, pyi_rth__tkinter.py, pyi_rth_multipr
</div>
<div class="import">
imported by:
<a href="#email._encoded_words">email._encoded_words</a>
<a href="#app.py">app.py</a>
&#8226; <a href="#email._encoded_words">email._encoded_words</a>
&#8226; <a href="#email.base64mime">email.base64mime</a>
&#8226; <a href="#email.encoders">email.encoders</a>
&#8226; <a href="#encodings.base64_codec">encodings.base64_codec</a>
Expand Down Expand Up @@ -9867,6 +9870,7 @@ <h1>modulegraph cross reference for app.py, pyi_rth__tkinter.py, pyi_rth_multipr
<span class="moduletype">Package</span> <div class="import">
imported by:
<a href="#tools.excel">tools.excel</a>
&#8226; <a href="#tools.image_data">tools.image_data</a>

</div>

Expand All @@ -9890,6 +9894,22 @@ <h1>modulegraph cross reference for app.py, pyi_rth__tkinter.py, pyi_rth_multipr

</div>

<div class="node">
<a name="tools.image_data"></a>
<a target="code" href="///D:/Github/Excel2RpyScript/tools/image_data.py" type="text/plain"><tt>tools.image_data</tt></a>
<span class="moduletype">SourceModule</span> <div class="import">
imports:
<a href="#tools">tools</a>

</div>
<div class="import">
imported by:
<a href="#app.py">app.py</a>

</div>

</div>

<div class="node">
<a name="traceback"></a>
<a target="code" href="///C:/users/31404/appdata/local/programs/python/python38/lib/traceback.py" type="text/plain"><tt>traceback</tt></a>
Expand Down
Binary file modified dist/Excel2RpyScript.exe
Binary file not shown.
29 changes: 18 additions & 11 deletions handler/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"truecenter": "truecenter",
}

ImageCmdMapping = {
"hide": "hide",
}

TransitionMapping = {
"溶解": "dissolve",
"褪色": "fade",
Expand Down Expand Up @@ -81,15 +85,27 @@ def parse_by_row(self, last_role, last_mode, row_data):
current_role_name, text = row_data[0], row_data[1]
# 音乐、立绘、换页、背景、备注、模式、音效、转场、特殊效果
music, character, change_page, background, remark, mode, sound, transition, _ = row_data[18:]
# nvl模式
if mode == 'nvl':
current_mode = 'nvl'
elif mode == 'adv':
current_mode = 'adv'
else:
current_mode = last_mode
# 角色信息
if last_role and current_role_name == "":
current_role = last_role
elif current_role_name not in ["", "旁白"]:
current_role = self.add_role(current_role_name)
elif current_mode == 'adv':
current_role = Role("narrator_adv", "None")
elif current_mode == 'nvl':
current_role = Role("narrator_nvl", "None")
else:
current_role = None

text = Text(text, current_role)
text.add_triggers(Mode(current_mode))
# 音乐信息
if music:
cmd = "stop" if music == "none" else "play"
Expand All @@ -112,15 +128,6 @@ def parse_by_row(self, last_role, last_mode, row_data):
if transition:
t_style = TransitionMapping.get(transition, "")
text.add_triggers(Transition(t_style))
# nvl模式
if mode == 'nvl':
text.add_triggers(Mode('nvl'))
current_mode = 'nvl'
elif mode == 'adv' and last_mode == 'nvl':
text.add_triggers(Mode('adv'))
current_mode = 'adv'
else:
current_mode = last_mode
# 换页
if change_page:
text.add_triggers(Command("nvl clear"))
Expand All @@ -138,8 +145,8 @@ def generate_rpy_elements(self):
@classmethod
def generate_character(cls, img_str):
last_word = img_str.split(" ")[-1]
position = PositionMapping.get(last_word, "left")
position = PositionMapping.get(last_word)
if position:
return Image(img_str.replace(last_word, "").strip(), "show", position)
else:
return Image(img_str, "show")
return Image(img_str.replace(last_word, "").strip(), ImageCmdMapping.get(last_word, "hide"))
11 changes: 6 additions & 5 deletions model/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ def __init__(self, text, role, triggers=None):
self.role = role
self.triggers = triggers or list()

def render(self):
def render(self, mode='nvl'):
# result = [t.render() for t in self.triggers]
result = []
if self.role:
result.append("{character}{text}".format(character=self.role.pronoun, text=self.text))

else:
result.append(self.text)
elif mode == 'nvl':
result.append("{character}{text}".format(character="narrator_nvl", text=self.text))
elif mode == 'adv':
result.append("{character}{text}".format(character="narrator_adv", text=self.text))
return "\n".join(result)

def add_triggers(self, *triggers):
Expand Down Expand Up @@ -180,7 +181,7 @@ def __init__(self, mode):
self.mode = mode

def render(self):
if self.mode == 'nvl':
if self.mode in ['nvl', 'adv']:
return ''
else:
return 'nvl clear'
Expand Down
56 changes: 0 additions & 56 deletions test/script.rpy

This file was deleted.

Loading

0 comments on commit d85fca9

Please sign in to comment.