Skip to content

Commit ae30e5c

Browse files
committed
made attribute classes private to declutter the API
1 parent f934e9d commit ae30e5c

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

tdl/__init__.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ def _format_str(string):
128128
_rootConsoleRef = None
129129

130130
_put_char_ex = _lib.TDL_console_put_char_ex
131-
132-
# python 2 to 3 workaround
133-
if _sys.version_info[0] == 2:
134-
int_types = (int, long)
135-
else:
136-
int_types = int
137-
138131

139132
def _format_color(color, default=Ellipsis):
140133
if color is Ellipsis:
@@ -253,7 +246,7 @@ class _BaseConsole(object):
253246
@ivar height: The height of this console in tiles. Do not overwrite this.
254247
"""
255248

256-
class ConsoleAttribute(object):
249+
class _ConsoleAttribute(object):
257250
"""Base class for easy access to console attributes
258251
259252
@since: 1.5.0
@@ -272,7 +265,7 @@ def _get_slice(self, slice_x, slice_y):
272265
return self.__class__(self._console, self._range_x[slice_x],
273266
self._range_y[slice_y])
274267

275-
class AttributeCh(ConsoleAttribute):
268+
class _AttributeCh(_ConsoleAttribute):
276269

277270
def __getitem__(self, key):
278271
if isinstance(key[0], slice) or isinstance(key[1], slice):
@@ -286,7 +279,7 @@ def __setitem__(self, key, ch):
286279
y = self._range_y[key[1]]
287280
_lib.TCOD_console_set_char(self._console.tcod_console, x, y, ch)
288281

289-
class AttributeFG(ConsoleAttribute):
282+
class _AttributeFG(_ConsoleAttribute):
290283

291284
def __getitem__(self, key):
292285
if isinstance(key[0], slice) or isinstance(key[1], slice):
@@ -301,7 +294,7 @@ def __setitem__(self, key, fg):
301294
y = self._range_y[key[1]]
302295
_lib.TDL_console_set_fg(self._console.tcod_console, x, y, fg)
303296

304-
class AttributeBG(ConsoleAttribute):
297+
class _AttributeBG(_ConsoleAttribute):
305298

306299
def __getitem__(self, key):
307300
if isinstance(key[0], slice) or isinstance(key[1], slice):
@@ -939,9 +932,9 @@ def __init__(self, width, height):
939932
self._range_y = range(self.height)
940933

941934
# special attributes for slightly lower level access to ch, fg, bg
942-
self.ch = self.AttributeCh(self, self._range_x, self._range_y)
943-
self.fg = self.AttributeFG(self, self._range_x, self._range_y)
944-
self.bg = self.AttributeBG(self, self._range_x, self._range_y)
935+
self.ch = self._AttributeCh(self, self._range_x, self._range_y)
936+
self.fg = self._AttributeFG(self, self._range_x, self._range_y)
937+
self.bg = self._AttributeBG(self, self._range_x, self._range_y)
945938

946939
@classmethod
947940
def _newConsole(cls, console):
@@ -955,9 +948,9 @@ def _newConsole(cls, console):
955948

956949
self._range_x = range(self.width)
957950
self._range_y = range(self.height)
958-
self.ch = self.AttributeCh(self, self._range_x, self._range_y)
959-
self.fg = self.AttributeFG(self, self._range_x, self._range_y)
960-
self.bg = self.AttributeBG(self, self._range_x, self._range_y)
951+
self.ch = self._AttributeCh(self, self._range_x, self._range_y)
952+
self.fg = self._AttributeFG(self, self._range_x, self._range_y)
953+
self.bg = self._AttributeBG(self, self._range_x, self._range_y)
961954
return self
962955

963956
def _root_unhook(self):
@@ -1083,11 +1076,11 @@ def __getitem__(self, key):
10831076
window = Window(self, 0, 0, 0, 0)
10841077
window._range_x = range(self.width)[x]
10851078
window._range_y = range(self.height)[y]
1086-
window.ch = window.AttributeCh(self, window._range_x,
1079+
window.ch = window._AttributeCh(self, window._range_x,
10871080
window._range_y)
1088-
window.fg = window.AttributeFG(self, window._range_x,
1081+
window.fg = window._AttributeFG(self, window._range_x,
10891082
window._range_y)
1090-
window.bg = window.AttributeBG(self, window._range_x,
1083+
window.bg = window._AttributeBG(self, window._range_x,
10911084
window._range_y)
10921085
return window
10931086
x = self._range_x[x]
@@ -1155,9 +1148,9 @@ def __init__(self, console, x, y, width, height):
11551148
else:
11561149
self.console = self.parent.console
11571150

1158-
self.ch = self.AttributeCh(self.console, self._range_x, self._range_y)
1159-
self.fg = self.AttributeFG(self.console, self._range_x, self._range_y)
1160-
self.bg = self.AttributeBG(self.console, self._range_x, self._range_y)
1151+
self.ch = self._AttributeCh(self.console, self._range_x, self._range_y)
1152+
self.fg = self._AttributeFG(self.console, self._range_x, self._range_y)
1153+
self.bg = self._AttributeBG(self.console, self._range_x, self._range_y)
11611154

11621155
@property
11631156
def x(self):
@@ -1244,11 +1237,11 @@ def __getitem__(self, key):
12441237
window = Window(self, 0, 0, 0, 0)
12451238
window._range_x = range(self.width)[x]
12461239
window._range_y = range(self.height)[y]
1247-
window.ch = window.AttributeCh(self.console, window._range_x,
1240+
window.ch = window._AttributeCh(self.console, window._range_x,
12481241
window._range_y)
1249-
window.fg = window.AttributeFG(self.console, window._range_x,
1242+
window.fg = window._AttributeFG(self.console, window._range_x,
12501243
window._range_y)
1251-
window.bg = window.AttributeBG(self.console, window._range_x,
1244+
window.bg = window._AttributeBG(self.console, window._range_x,
12521245
window._range_y)
12531246
return window
12541247
x = self._range_x[x]

0 commit comments

Comments
 (0)