Skip to content

Commit 1ea5b9c

Browse files
authored
Def main() and proper Error.
I realized my standalone use of the script was not using a proper if __name__ == "__main__" boilerplate which I guess is a no-no. This is now fixed. For all you people who import * lazily like I do. Also added ValueErrors if you cancel directory selection.
1 parent 14f5438 commit 1ea5b9c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

BMP2PDF.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,20 @@ def bmp2pdf(bmp_folder, save_path, pdf_name, save_png):
132132

133133
print("No .bmp files found.")
134134

135-
# Standalone use. Set the variables as needed for your use case. bmp_folder and save_path are determined from tkinter filedialogs. save_png can be a boolean value. pdf_name should be a string.
136-
print("Choose the .bmp file directory.")
137-
bmp_folder = str(filedialog.askdirectory(title="Select .bmp folder"))
138-
save_png = 0
139-
print("Choose PDF save directory.")
140-
save_path = str(filedialog.askdirectory(title="Select PDF save folder"))
141-
pdf_name = "your_pdf_name_here.pdf"
142-
bmp2pdf(bmp_folder, save_path, pdf_name, save_png)
135+
def main():
136+
137+
# Standalone use. Set the variables as needed for your use case. bmp_folder and save_path are determined from tkinter filedialogs. save_png can be a boolean value. pdf_name should be a string.
138+
print("Choose the .bmp file directory.")
139+
bmp_folder = str(filedialog.askdirectory(title="Select .bmp folder"))
140+
if not bmp_folder:
141+
raise ValueError("ERROR: No directory selectd.")
142+
save_png = 0
143+
print("Choose PDF save directory.")
144+
save_path = str(filedialog.askdirectory(title="Select PDF save folder"))
145+
if not save_path:
146+
raise ValueError("ERROR: No directory selectd.")
147+
pdf_name = "your_pdf_name_here.pdf"
148+
bmp2pdf(bmp_folder, save_path, pdf_name, save_png)
149+
150+
if __name__ == "__main__":
151+
main()

0 commit comments

Comments
 (0)