commit 68a962c7d5cf0f2f4b34cba34296d0ba4eff64df Author: Damian Johnson atagar@torproject.org Date: Wed Aug 3 09:27:28 2011 -0700
Deprecating and removing DrawEntry class
The DrawEntry was a helper class added when writing the connection panel to pass around lines that could be rendered. However, this was the only place it was ever used and, in the end, a list of (msg, attr) tuples does a nicer job. --- src/cli/connections/circEntry.py | 23 ++++++------- src/cli/connections/connEntry.py | 20 ++++++------ src/cli/connections/connPanel.py | 17 ++++++++-- src/cli/connections/entries.py | 13 ++++++-- src/util/uiTools.py | 67 -------------------------------------- 5 files changed, 45 insertions(+), 95 deletions(-)
diff --git a/src/cli/connections/circEntry.py b/src/cli/connections/circEntry.py index f94f53a..7bf21db 100644 --- a/src/cli/connections/circEntry.py +++ b/src/cli/connections/circEntry.py @@ -135,7 +135,7 @@ class CircHeaderLine(connEntry.ConnectionLine): def getDetails(self, width): if not self.isBuilt: detailFormat = curses.A_BOLD | uiTools.getColor(connEntry.CATEGORY_COLOR[self.getType()]) - return [uiTools.DrawEntry("Building Circuit...", detailFormat)] + return [("Building Circuit...", detailFormat)] else: return connEntry.ConnectionLine.getDetails(self, width)
class CircLine(connEntry.ConnectionLine): @@ -157,10 +157,14 @@ class CircLine(connEntry.ConnectionLine): def getType(self): return connEntry.Category.CIRCUIT
+ def getListingPrefix(self): + if self.isLast: return (ord(' '), curses.ACS_LLCORNER, curses.ACS_HLINE, ord(' ')) + else: return (ord(' '), curses.ACS_VLINE, ord(' '), ord(' ')) + def getListingEntry(self, width, currentTime, listingType): """ - Provides the DrawEntry for this relay in the circuilt listing. Lines are - composed of the following components: + Provides the [(msg, attr)...] listing for this relay in the circuilt + listing. Lines are composed of the following components: <bracket> <dst> <etc> <placement label>
The dst and etc entries largely match their ConnectionEntry counterparts. @@ -182,9 +186,7 @@ class CircLine(connEntry.ConnectionLine): # placementLabel (14 characters) # gap between etc and placement label (5 characters)
- if self.isLast: bracket = (curses.ACS_LLCORNER, curses.ACS_HLINE, ord(' ')) - else: bracket = (curses.ACS_VLINE, ord(' '), ord(' ')) - baselineSpace = len(bracket) + 14 + 5 + 1 + baselineSpace = 14 + 5
dst, etc = "", "" if listingType == entries.ListingType.IP_ADDRESS: @@ -213,10 +215,7 @@ class CircLine(connEntry.ConnectionLine): dstLayout = "%%-%is" % (width - baselineSpace - len(etc)) dst = dstLayout % self.foreign.getNickname()
- drawEntry = uiTools.DrawEntry("%-14s" % self.placementLabel, lineFormat) - drawEntry = uiTools.DrawEntry(" " * (width - baselineSpace - len(dst) - len(etc) + 5), lineFormat, drawEntry) - drawEntry = uiTools.DrawEntry(dst + etc, lineFormat, drawEntry) - drawEntry = uiTools.DrawEntry(bracket, curses.A_NORMAL, drawEntry, lockFormat = True) - drawEntry = uiTools.DrawEntry(" ", curses.A_NORMAL, drawEntry, lockFormat = True) - return drawEntry + return ((dst + etc, lineFormat), + (" " * (width - baselineSpace - len(dst) - len(etc) + 5), lineFormat), + ("%-14s" % self.placementLabel, lineFormat))
diff --git a/src/cli/connections/connEntry.py b/src/cli/connections/connEntry.py index 5feafdb..0c82495 100644 --- a/src/cli/connections/connEntry.py +++ b/src/cli/connections/connEntry.py @@ -250,7 +250,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
def getListingEntry(self, width, currentTime, listingType): """ - Provides the DrawEntry for this connection's listing. Lines are composed + Provides the tuple list for this connection's listing. Lines are composed of the following components: <src> --> <dst> <etc> <uptime> (<type>)
@@ -289,8 +289,8 @@ class ConnectionLine(entries.ConnectionPanelLine): timePrefix = "+" if self.isInitialConnection else " " else: timePrefix = ""
- timeEntry = myListing.getNext().getNext() - timeEntry.text = timePrefix + "%5s" % uiTools.getTimeLabel(currentTime - self.startTime, 1) + timeLabel = timePrefix + "%5s" % uiTools.getTimeLabel(currentTime - self.startTime, 1) + myListing[2] = (timeLabel, myListing[2][1])
return myListing
@@ -315,12 +315,12 @@ class ConnectionLine(entries.ConnectionPanelLine): lineFormat = uiTools.getColor(CATEGORY_COLOR[entryType]) timeWidth = 6 if CONFIG["features.connection.markInitialConnections"] else 5
- drawEntry = uiTools.DrawEntry(")" + " " * (9 - len(entryType)), lineFormat) - drawEntry = uiTools.DrawEntry(entryType.upper(), lineFormat | curses.A_BOLD, drawEntry) - drawEntry = uiTools.DrawEntry(" (", lineFormat, drawEntry) - drawEntry = uiTools.DrawEntry(" " * timeWidth, lineFormat, drawEntry) - drawEntry = uiTools.DrawEntry(self._getListingContent(width - (12 + timeWidth) - 1, listingType), lineFormat, drawEntry) - drawEntry = uiTools.DrawEntry(" ", lineFormat, drawEntry) + drawEntry = [(" ", lineFormat), + (self._getListingContent(width - (12 + timeWidth) - 1, listingType), lineFormat), + (" " * timeWidth, lineFormat), + (" (", lineFormat), + (entryType.upper(), lineFormat | curses.A_BOLD), + (")" + " " * (9 - len(entryType)), lineFormat)] return drawEntry
def _getDetails(self, width): @@ -333,7 +333,7 @@ class ConnectionLine(entries.ConnectionPanelLine): """
detailFormat = curses.A_BOLD | uiTools.getColor(CATEGORY_COLOR[self.getType()]) - return [uiTools.DrawEntry(line, detailFormat) for line in self._getDetailContent(width)] + return [(line, detailFormat) for line in self._getDetailContent(width)]
def resetDisplay(self): entries.ConnectionPanelLine.resetDisplay(self) diff --git a/src/cli/connections/connPanel.py b/src/cli/connections/connPanel.py index ae50674..705fd77 100644 --- a/src/cli/connections/connPanel.py +++ b/src/cli/connections/connPanel.py @@ -291,7 +291,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
drawEntries = cursorSelection.getDetails(width) for i in range(min(len(drawEntries), DETAILS_HEIGHT)): - drawEntries[i].render(self, 1 + i, 2) + self.addstr(1 + i, 2, drawEntries[i][0], drawEntries[i][1])
# title label with connection counts if self.isTitleVisible(): @@ -318,9 +318,20 @@ class ConnectionPanel(panel.Panel, threading.Thread): # hilighting if this is the selected line extraFormat = curses.A_STANDOUT if entryLine == cursorSelection else curses.A_NORMAL
- drawEntry = entryLine.getListingEntry(width - scrollOffset, currentTime, self._listingType) drawLine = lineNum + detailPanelOffset + 1 - scrollLoc - drawEntry.render(self, drawLine, scrollOffset, extraFormat) + + prefix = entryLine.getListingPrefix() + for i in range(len(prefix)): + self.addch(drawLine, scrollOffset + i, prefix[i]) + + xOffset = scrollOffset + len(prefix) + drawEntry = entryLine.getListingEntry(width - scrollOffset - len(prefix), currentTime, self._listingType) + + for msg, attr in drawEntry: + attr |= extraFormat + self.addstr(drawLine, xOffset, msg, attr) + xOffset += len(msg) + if drawLine >= height: break
self.valsLock.release() diff --git a/src/cli/connections/entries.py b/src/cli/connections/entries.py index 6b24412..f832b6a 100644 --- a/src/cli/connections/entries.py +++ b/src/cli/connections/entries.py @@ -112,9 +112,16 @@ class ConnectionPanelLine: self._descriptorCache = None self._descriptorCacheArgs = None
+ def getListingPrefix(self): + """ + Provides a list of characters to be appended before the listing entry. + """ + + return () + def getListingEntry(self, width, currentTime, listingType): """ - Provides a DrawEntry instance for contents to be displayed in the + Provides a [(msg, attr)...] tuple list for contents to be displayed in the connection panel listing.
Arguments: @@ -137,8 +144,8 @@ class ConnectionPanelLine:
def getDetails(self, width): """ - Provides a list of DrawEntry instances with detailed information for this - connection. + Provides a list of [(msg, attr)...] tuple listings with detailed + information for this connection.
Arguments: width - available space to display in diff --git a/src/util/uiTools.py b/src/util/uiTools.py index 68b93af..01d2ad1 100644 --- a/src/util/uiTools.py +++ b/src/util/uiTools.py @@ -528,73 +528,6 @@ def parseShortTimeLabel(timeEntry): except ValueError: raise ValueError(errorMsg)
-class DrawEntry: - """ - Renderable content, encapsulating the text and formatting. These can be - chained together to compose lines with multiple types of formatting. - """ - - def __init__(self, text, format=curses.A_NORMAL, nextEntry=None, lockFormat=False): - """ - Constructor for prepared draw entries. - - Arguments: - text - content to be drawn, this can either be a string or list of - integer character codes - format - properties to apply when drawing - nextEntry - entry to be drawn after this one - lockFormat - prevents extra formatting attributes from being applied - when rendered if true - """ - - self.text = text - self.format = format - self.nextEntry = nextEntry - self.lockFormat = lockFormat - - def getNext(self): - """ - Provides the next DrawEntry in the chain. - """ - - return self.nextEntry - - def setNext(self, nextEntry): - """ - Sets additional content to be drawn after this entry. If None then - rendering is terminated after this entry. - - Arguments: - nextEntry - DrawEntry instance to be rendered after this one - """ - - self.nextEntry = nextEntry - - def render(self, drawPanel, y, x, extraFormat=curses.A_NORMAL): - """ - Draws this content at the given position. - - Arguments: - drawPanel - context in which to be drawn - y - vertical location - x - horizontal location - extraFormat - additional formatting - """ - - if self.lockFormat: drawFormat = self.format - else: drawFormat = self.format | extraFormat - - if isinstance(self.text, str): - drawPanel.addstr(y, x, self.text, drawFormat) - else: - for i in range(len(self.text)): - drawChar = self.text[i] - drawPanel.addch(y, x + i, drawChar, drawFormat) - - # if there's additional content to show then render it too - if self.nextEntry: - self.nextEntry.render(drawPanel, y, x + len(self.text), extraFormat) - class Scroller: """ Tracks the scrolling position when there might be a visible cursor. This