patternpythonMinor
Python Manga Image Viewer
Viewed 0 times
mangaimagepythonviewer
Problem
I'm currently making a manga (read: comic) viewer in Python. This project has been a code-as-you-learn project, because I have been trying to code this as I learned about Tkinter. Python I have known for some time, but not too long.
Performance-wise, I'm worried about the image loading and resizing time; it seems slow. I found out one thing by experimenting: when resizing "P" type images it is a lot slower than converting it to "L" (greyscale) and then resizing. Also the fullscreen is buggy, but this (and other minor bugs, coding format problems) is because I have thrown this together and haven't really re-coded it nicely yet (as I often do after I learn what I want it to be like, if you understand what I mean).
Format-wise, I don't think I have the best organization there is, maybe there is a better practice to hold up, or multiple files maybe (but Python can't do this?)?
Once again there are a lot of little bugs, like scrolling with the keyboard reveals extra space on the bottom, and the folder viewer doesn't always scroll to the selected folder in the dialog, and I would like to know how to fix this, but I would like more to know some good practices and optimization for image loading and resizing.
```
from Tkinter import *
from ttk import *
import Image, ImageTk, tkFileDialog, os
VERSION = "v0.0.3"
"""
folderDialog Class
Dialog that asks the user to select a folder. Returns folder and gets destroyed.
"""
class folderDialog(Toplevel):
def __init__(self, parent, callback, dir="./", fileFilter=None):
Toplevel.__init__(self, parent)
self.transient(parent)
self.title("Browse Folders")
self.parent = parent
self.dir = StringVar()
self.callback = callback
self.fileFilter = fileFilter
if os.path.exists(dir) and os.path.isdir(dir):
self.dir.set(os.path.abspath(dir))
else:
self.dir.set(os.path.abspath("./"))
self.body = Frame(self)
self.body.grid(r
Performance-wise, I'm worried about the image loading and resizing time; it seems slow. I found out one thing by experimenting: when resizing "P" type images it is a lot slower than converting it to "L" (greyscale) and then resizing. Also the fullscreen is buggy, but this (and other minor bugs, coding format problems) is because I have thrown this together and haven't really re-coded it nicely yet (as I often do after I learn what I want it to be like, if you understand what I mean).
Format-wise, I don't think I have the best organization there is, maybe there is a better practice to hold up, or multiple files maybe (but Python can't do this?)?
Once again there are a lot of little bugs, like scrolling with the keyboard reveals extra space on the bottom, and the folder viewer doesn't always scroll to the selected folder in the dialog, and I would like to know how to fix this, but I would like more to know some good practices and optimization for image loading and resizing.
```
from Tkinter import *
from ttk import *
import Image, ImageTk, tkFileDialog, os
VERSION = "v0.0.3"
"""
folderDialog Class
Dialog that asks the user to select a folder. Returns folder and gets destroyed.
"""
class folderDialog(Toplevel):
def __init__(self, parent, callback, dir="./", fileFilter=None):
Toplevel.__init__(self, parent)
self.transient(parent)
self.title("Browse Folders")
self.parent = parent
self.dir = StringVar()
self.callback = callback
self.fileFilter = fileFilter
if os.path.exists(dir) and os.path.isdir(dir):
self.dir.set(os.path.abspath(dir))
else:
self.dir.set(os.path.abspath("./"))
self.body = Frame(self)
self.body.grid(r
Solution
As Moisei pointed out, Code Review isn't about functional issues. I guess performance can be discuted, but I don't know how to make resizing fast.
Your code looks good overall, but I don't know about Tkinter idioms. Here are a few comments:
-
You should check
-
Write this as
-
Please care about comments.
Your code looks good overall, but I don't know about Tkinter idioms. Here are a few comments:
-
You should check
if __name__ == "__main__": before running the mainloop. This will allow you or someone else to import the code you written without having it launching the GUI.-
st = ""
for title in titles:
st = st + " " + str(title)Write this as
" ".join(titles)-
#special super cool stuff here or even #newDir = os.path.join(newDir, "..")Please care about comments.
Code Snippets
st = ""
for title in titles:
st = st + " " + str(title)Context
StackExchange Code Review Q#4377, answer score: 5
Revisions (0)
No revisions yet.