From: Simon Tatham Date: Sun, 13 Oct 2024 10:05:01 +0000 (+0100) Subject: editor: miscellaneous source cleanups. X-Git-Tag: bedstead-002.009~3 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=d523da367126766d206d830692de1d16c3841435;p=bedstead.git editor: miscellaneous source cleanups. Apparently I didn't know about chained comparisons when I wrote this code, so I didn't take the opportunity to write '0 <= x < limit'. Also, removed the wildcard import from tkinter, replacing it with explicit references to the things needed. There weren't that many of them, so I think the 'import *' didn't gain much. --- diff --git a/editor b/editor index 3415900..e62e731 100755 --- a/editor +++ b/editor @@ -26,8 +26,7 @@ import re import sys import string import subprocess - -from tkinter import * +import tkinter gutter = 20 pixel = 32 @@ -38,12 +37,12 @@ class EditorGui: def __init__(self, bedstead): self.bedstead = bedstead - self.tkroot = Tk() + self.tkroot = tkinter.Tk() - self.canvas = Canvas(self.tkroot, - width=2 * (XSIZE*pixel) + 3*gutter, - height=YSIZE*pixel + 2*gutter, - bg='white') + self.canvas = tkinter.Canvas(self.tkroot, + width=2 * (XSIZE*pixel) + 3*gutter, + height=YSIZE*pixel + 2*gutter, + bg='white') self.bitmap = [0] * YSIZE self.oldbitmap = self.bitmap[:] self.pixels = [[None]*XSIZE for y in range(YSIZE)] @@ -188,10 +187,9 @@ class EditorGui: def drag(self, event): x = (event.x - self.dragstartx) // pixel y = (event.y - gutter) // pixel - if x >= 0 and x < XSIZE and y >= 0 and y < YSIZE: + if 0 <= x < XSIZE and 0 <= y < YSIZE: self.setpixel(x, y, self.dragstate) self.regenerate() - return def key(self, event): if event.char in (' '): @@ -206,7 +204,7 @@ class EditorGui: sys.exit(0) def run(self): - mainloop() + tkinter.mainloop() def main(): # By default, assume that the user ran 'make' in the bedstead