Skip to content

Commit 206db32

Browse files
committed
using argparse
1 parent b33a94d commit 206db32

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

main.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import os
55
import tkinter as tk
66
import traceback
7+
import argparse
78
from collections import defaultdict
89
from pprint import pprint
9-
from tkinter import ttk, messagebox
10+
from tkinter import ttk, messagebox, font
1011

1112
from ttkthemes import ThemedStyle
1213

@@ -23,12 +24,19 @@
2324
class Application:
2425

2526
# Create the application window
26-
def __init__(self, width, height):
27+
def __init__(self):
28+
self.parse_arguments()
2729
# Create the root
2830
self.root = tk.Tk()
29-
self.root.geometry("%dx%d+50+30" % (width, height))
31+
self.root.geometry("%dx%d+50+30" % (self.args.width, self.args.height))
32+
print(4.0 if self.args.high_resolution else self.args.scaling_factor)
33+
self.root.call('tk', 'scaling', 2.0 if self.args.high_resolution else self.args.scaling_factor)
3034
self.root.title("Read tree")
3135

36+
# Use a font that scales with the scaling factor
37+
fontSize = 12 # base font size before scaling
38+
scaled_font = font.nametofont("TkDefaultFont")
39+
scaled_font.configure(size=int(fontSize * self.args.scaling_factor))
3240

3341
# App icon :). Save or will be garbage collected
3442
self.icon = PIL.ImageTk.PhotoImage(PIL.Image.open("static/zoneplate.png"))
@@ -60,6 +68,15 @@ def __init__(self, width, height):
6068
self.root.update()
6169
self.root.attributes('-topmost', False)
6270

71+
def parse_arguments(self):
72+
parser = argparse.ArgumentParser(description='Loom Activation Script')
73+
74+
parser.add_argument('-wd', '--width', default=1200, type=int, help='Window Width')
75+
parser.add_argument('-ht', '--height', default=675, type=int, help='Window Height')
76+
parser.add_argument('-sf', '--scaling-factor', default=1.0)
77+
parser.add_argument('-hr', '--high-resolution', action='store_true', help='hr as in High Resolution')
78+
79+
self.args = parser.parse_args()
6380

6481
def initialize_app_state(self):
6582
try:
@@ -137,6 +154,7 @@ def set_tab_names(self):
137154
def build_menus(self):
138155
if hasattr(self, "menu"):
139156
self.menu.destroy()
157+
140158
menu_list = defaultdict(list, {
141159
"File": [
142160
#('New Tab', 'Ctrl+N', '<Control-n>', self.create_tab),
@@ -181,5 +199,5 @@ def main(self):
181199

182200
# Create the display application and run it
183201
if __name__ == "__main__":
184-
app = Application(1200, 675)
202+
app = Application()
185203
app.main()

0 commit comments

Comments
 (0)