Skip to content

Commit

Permalink
fix #3 encoding and other issues
Browse files Browse the repository at this point in the history
  • Loading branch information
K1DV5 committed Jun 16, 2024
1 parent 1d32661 commit f0d7c72
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ rnd
help/html
help/docal.chm
help/toc.hhc
.venv
4 changes: 2 additions & 2 deletions docal_tkinter/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -{cd .. | python -m docal_tkinter}
from tkinter import Tk, Menu
# $ cd .. && python -m docal_tkinter
from tkinter import Tk
from .sidebar import Sidebar
from .worksheet import Worksheet
from .menubar import Menubar
Expand Down
9 changes: 5 additions & 4 deletions docal_tkinter/menubar.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -{cd .. | python -m docal_tkinter}
from tkinter import Menu, filedialog, messagebox, Toplevel, Label
from json import dump, loads, dumps
from docal.parsers.excel import parse as parse_xl
from docal.parsers.dcl import to_py
from os import path, startfile
from os import path
from webbrowser import open_new_tab

from docal_tkinter.sidebar import start_file

class Menubar(Menu):
def __init__(self, master):
super().__init__(master, tearoff=0)
Expand Down Expand Up @@ -72,7 +73,7 @@ def open(self, filename=None):
if not self.new(): return
ext = path.splitext(filename)[1]
self.worksheet.frame.grid_slaves()[0].destroy() # start from scratch
with open(filename) as file:
with open(filename, encoding='utf-8') as file:
in_file = file.read()
if ext == '.dcl':
data = loads(in_file)
Expand Down Expand Up @@ -195,7 +196,7 @@ def __init__(self, master):
self.add_command(label='About', command=self.about)

def help(self):
startfile('docal.chm')
start_file('docal.chm')

def about(self):
win = Toplevel()
Expand Down
17 changes: 13 additions & 4 deletions docal_tkinter/sidebar.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# -{cd .. | python -m docal_tkinter}
from tkinter.ttk import Frame, Label, Entry, Button, Labelframe, OptionMenu, Label
from tkinter.ttk import Frame, Entry, Button, Labelframe
from tkinter import filedialog, messagebox, StringVar
from os import startfile, path
import os
import sys
import subprocess
from os import path

from docal import processor
from docal.document import word, latex
from docal.parsers.dcl import parse

def start_file(filename):
if sys.platform == "win32":
os.startfile(filename)
else:
opener = "open" if sys.platform == "darwin" else "xdg-open"
subprocess.call([opener, filename])

class Sidebar(Frame):
def __init__(self, master):
super().__init__(master, borderwidth='.25cm')
Expand Down Expand Up @@ -113,7 +122,7 @@ def open_file(self, which):
return
filename = self.outfile.get()
try:
startfile(filename)
start_file(filename)
except OSError as err:
messagebox.showerror('Error', err.args[1])

Expand Down

0 comments on commit f0d7c72

Please sign in to comment.