Skip to content

Commit b340841

Browse files
committed
Merge branch 'development'
2 parents 43d1d8b + 2886ef6 commit b340841

File tree

10 files changed

+128
-34
lines changed

10 files changed

+128
-34
lines changed

.github/workflows/python-app.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ on:
55
branches: ["main"]
66

77
jobs:
8+
build-macos-intel:
9+
runs-on: macos-15-intel
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: "3.11"
16+
- name: Install uv
17+
uses: astral-sh/setup-uv@v6
18+
- name: Install the project
19+
run: uv sync
20+
- name: Install pyinstaller
21+
run: uv add --dev pyinstaller
22+
- name: Compile
23+
run: uv run --dev pyinstaller ShoggothStandalone.spec
24+
- uses: actions/upload-artifact@v4
25+
with:
26+
name: shoggoth-mac-intel
27+
path: dist/
28+
829
build-macos:
930
runs-on: macos-latest
1031
steps:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
*.sublime-workspace
88
uv.lock
99
/assets/
10+
shoggoth.ini

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "shoggoth"
3-
version = "0.0.28"
3+
version = "0.0.29"
44
authors = [{ name = "Toke Ivø", email = "[email protected]" }]
55
description = "A card creator for Arkham Horror: The Card Game"
66
readme = "README.md"

shoggoth/editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def load_html(self):
8282
self.ids.code_input.text = self.guide.get_html()
8383

8484
def get_page(self, page):
85-
img = self.guide.get_page(page)
85+
img = self.guide.get_page(page, html=self.ids.code_input.text)
8686
texture = CoreImage(img, ext='jpeg').texture
8787
shoggoth.app.root.ids.card_preview.set_card_images(texture, None)
8888

shoggoth/guide.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,30 @@
44
import subprocess
55
from subprocess import PIPE
66

7-
PRINCE_DIR = '/home/toke/Downloads/prince-16.1-linux-generic-x86_64/lib/prince'
8-
PRINCE_CMD = './bin/prince'
9-
107

118
class Guide:
12-
def __init__(self, path, name, id, project):
9+
def __init__(self, path, name, id, project, prince_cmd=None, prince_dir=None):
1310
self.path = path
1411
self.name = name
1512
self.id = id
1613
self.project = project
1714
self._html = None
15+
self._prince_cmd = prince_cmd
16+
self._prince_dir = prince_dir
17+
18+
@property
19+
def prince_dir(self):
20+
if self._prince_dir is None:
21+
import shoggoth
22+
return shoggoth.app.config.get('Shoggoth', 'prince_dir') or None
23+
return self._prince_dir
24+
25+
@property
26+
def prince_cmd(self):
27+
if self._prince_cmd is None:
28+
import shoggoth
29+
return shoggoth.app.config.get('Shoggoth', 'prince_cmd')
30+
return self._prince_cmd
1831

1932
@property
2033
def target_path(self):
@@ -26,10 +39,21 @@ def get_html(self):
2639
self._html = file.read()
2740
return self._html
2841

29-
def get_page(self, page):
30-
print('get page', [PRINCE_CMD, self.path, '-o', str(self.target_path)])
31-
p = subprocess.call([PRINCE_CMD, self.path, '-o', str(self.target_path)], cwd=PRINCE_DIR)
32-
pdf = pymupdf.open(self.target_path)
42+
def get_page(self, page, html: str = ''):
43+
if not html:
44+
p = subprocess.call([self.prince_cmd, self.path, '-o', str(self.target_path)], cwd=self.prince_dir)
45+
pdf = pymupdf.open(self.target_path)
46+
else:
47+
p = subprocess.run(
48+
[self.prince_cmd, '-', '-o', '-'],
49+
cwd=self.prince_dir,
50+
input=html.encode(),
51+
stdout=subprocess.PIPE,
52+
)
53+
data = p.stdout
54+
print('got data of len', len(data))
55+
pdf = pymupdf.open(stream=data)
56+
3357
image = pdf[page].get_pixmap().pil_image()
3458

3559
buffer = BytesIO()
@@ -38,9 +62,7 @@ def get_page(self, page):
3862
return buffer
3963

4064
def render_to_file(self):
41-
with open(self.target_path, "w+b") as result_file:
42-
# convert HTML to PDF
43-
subprocess.call([PRINCE_CMD, str(self.path), str(result_file)], cwd=PRINCE_DIR)
65+
subprocess.run([self.prince_cmd, self.path, '-o', str(self.target_path)], cwd=self.prince_dir)
4466

4567

4668
# todo:

shoggoth/main.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import shutil
33
import threading
4+
import json
45
from tokenize import String
56
import shoggoth
67
from time import time
@@ -12,6 +13,7 @@
1213
Config.set('kivy', 'log_enable', '0')
1314
Config.set('graphics', 'width', '800')
1415
Config.set('graphics', 'height', '600')
16+
Config.set('kivy', 'exit_on_escape', 0)
1517
Config.write()
1618

1719
from kivy.app import App # noqa: E402
@@ -149,7 +151,8 @@ def on_selected_node(self):
149151
app.show_card(self.tree.selected_node.element)
150152
elif self.tree.selected_node.element_type == 'guide':
151153
app.show_guide(self.tree.selected_node.element)
152-
self.selected_item = self.tree.selected_node.element
154+
if self.tree.selected_node.element:
155+
self.selected_item = self.tree.selected_node.element
153156

154157
def refresh(self, *args):
155158
opens = set()
@@ -327,6 +330,56 @@ def build(self):
327330

328331
return self.root
329332

333+
def build_config(self, config):
334+
config.setdefaults('Shoggoth', {
335+
'prince_cmd': 'prince',
336+
'prince_dir': '',
337+
'strange_eons': '',
338+
'java': 'java',
339+
})
340+
341+
def build_settings(self, settings):
342+
data = [
343+
{
344+
"type": "title",
345+
"title": "External applications",
346+
},
347+
{
348+
"type": "string",
349+
"title": "Prince command",
350+
"desc": "Command to run prince",
351+
"section": "Shoggoth",
352+
"key": "prince_cmd",
353+
},
354+
{
355+
"type": "path",
356+
"title": "Prince location",
357+
"desc": "Location of the Prince directory, if not installed system wide.",
358+
"section": "Shoggoth",
359+
"key": "prince_dir",
360+
},
361+
{
362+
"type": "path",
363+
"title": "Strange Eons",
364+
"desc": "Location of the Strange Eons jar file. For use with importing SE projects.",
365+
"section": "Shoggoth",
366+
"key": "strange_eons",
367+
},
368+
{
369+
"type": "string",
370+
"title": "Java command",
371+
"desc": "Command to run java. Used in conjunction with Strange Eons.",
372+
"section": "Shoggoth",
373+
"key": "java",
374+
},
375+
]
376+
377+
settings.add_json_panel(
378+
'Shoggoth',
379+
self.config,
380+
data=json.dumps(data)
381+
)
382+
330383
def goto_project(self, project_id):
331384
self.current_project = Project.load(project_id)
332385
self.root.ids.file_browser.project = self.current_project

shoggoth/shoggoth.kv

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,6 @@
168168
size_hint: .6, .3
169169
BoxLayout:
170170
orientation: 'vertical'
171-
BoxLayout:
172-
orientation: 'horizontal'
173-
Label:
174-
text: 'Path to Strange Eons jar file'
175-
TextInput:
176-
size_hint_x: 0.6
177-
id: jar_path
178-
size_hint_y: None
179-
Button:
180-
size_hint_x: 0.2
181-
text: 'Browse'
182-
on_release: ui.browse_file(target=jar_path)
183171
BoxLayout:
184172
orientation: 'horizontal'
185173
Label:
@@ -205,7 +193,7 @@
205193
text: 'Browse'
206194
on_release: ui.browse_folder(target=new_path)
207195
Label:
208-
text: "Once it starts, it will take a while (~30 seconds) with no response. Then Shoggoth will close. This is expected for now."
196+
text: "Once it starts, it will take a while (~30 seconds) with no response. Then Shoggoth will close. Then the new project file will be available in the output folder. This is expected for now."
209197
BoxLayout:
210198
orientation: 'horizontal'
211199
Button:
@@ -438,6 +426,10 @@
438426
disabled: not app.current_project
439427
on_release: ui.ExportPopup().open()
440428
ContextMenuDivider:
429+
ContextMenuTextItem:
430+
text: 'Settings'
431+
on_release: app.open_settings()
432+
ContextMenuDivider:
441433
ContextMenuTextItem:
442434
text: 'Exit'
443435
on_release: app.stop()
@@ -730,7 +722,7 @@
730722
TextInput:
731723
value: '1'
732724
id: page_count
733-
on_text: root.get_page(int(self.text)) if int(self.text) else root.get_page(0)
725+
on_text: root.get_page(int(self.text)) if self.text else root.get_page(0)
734726

735727
<ProjectEditor>:
736728
orientation: 'vertical'

shoggoth/strange_eons.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
import jpype.imports
33
from shoggoth.files import asset_dir
44

5-
def run_conversion(jar_path, project_path, output_path):
5+
def run_conversion(java_path, jar_path, project_path, output_path):
6+
if not jar_path:
7+
raise Exception("Path to Strange Eons jar file not set. Press F1 and change the settings. This needs to be the .jar file - other versions won't work.")
8+
69
# start the JVM to make further imports available
710
jpype.startJVM(
8-
jpype.getDefaultJVMPath(),
11+
java_path or jpype.getDefaultJVMPath(),
912
f'-javaagent:{jar_path}',
1013
classpath=[f'{jar_path}'],
1114
)

shoggoth/tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def version_is_up_to_date() -> bool:
1010
if not (asset_dir/'version.txt').exists():
1111
return False
1212
with (asset_dir/'version.txt').open('r') as f:
13-
if not f.read().startswith('0.3.3'):
13+
if not f.read().startswith('0.4.0'):
1414
return False
1515
return True
1616

@@ -35,7 +35,7 @@ def run():
3535
if not asset_dir.is_dir() or not version_is_up_to_date():
3636
print("Asset pack not found. Downloading assets...")
3737
# download assets
38-
url = 'https://www.dropbox.com/scl/fi/qv5ei158rqoem3gs6cd9k/assets-0-3-3.zip?rlkey=4l3ms5tmkir20zpifnurheze6&st=7uwnnbh9&dl=1'
38+
url = 'https://www.dropbox.com/scl/fi/htwenk0k3vxxr4bl69b4z/assets-0-4-0.zip?rlkey=30ch88hivad2j6g08xfxehs4h&st=g9libbot&dl=1'
3939
filehandle, _ = urllib.request.urlretrieve(url)
4040
with zipfile.ZipFile(filehandle, 'r') as file:
4141
file.extractall(root_dir)

shoggoth/ui.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ def submit(self):
152152
from shoggoth import strange_eons
153153

154154
project_path = self.ids.se_path.text
155-
jar_path = self.ids.jar_path.text
155+
jar_path = shoggoth.app.config.get('Shoggoth', 'strange_eons')
156+
java_path = shoggoth.app.config.get('Shoggoth', 'java')
156157
output_path = self.ids.new_path.text
157158

158-
threading.Thread(target=strange_eons.run_conversion, args=(jar_path, project_path, output_path)).start()
159+
threading.Thread(target=strange_eons.run_conversion, args=(java_path, jar_path, project_path, output_path)).start()
160+
159161

160162
class Thumbnail(ButtonBehavior, Image):
161163
card_id = StringProperty("")

0 commit comments

Comments
 (0)