chiark / gitweb /
editor: miscellaneous source cleanups.
authorSimon Tatham <anakin@pobox.com>
Sun, 13 Oct 2024 10:05:01 +0000 (11:05 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 13 Oct 2024 14:04:53 +0000 (15:04 +0100)
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.

editor

diff --git a/editor b/editor
index 34159001fc97f3ca6c148877ba455517108acc18..e62e7313b324c20ce5839e728000cf2141ca1226 100755 (executable)
--- 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