@@ -301,7 +301,7 @@ def _setChar(self, char, x, y, fgcolor=None, bgcolor=None, bgblend=BND_SET):
301301 if bgcolor is not None :
302302 _setback (self , x , y , _formatColor (bgcolor ), bgblend )
303303
304- def drawChar (self , char , x = None , y = None , fgcolor = None , bgcolor = None ):
304+ def drawChar (self , x = None , y = None , char = None , fgcolor = C_WHITE , bgcolor = C_BLACK ):
305305 """Draws a single character.
306306
307307 char should be an integer, single character string, or None
@@ -315,19 +315,15 @@ def drawChar(self, char, x=None, y=None, fgcolor=None, bgcolor=None):
315315 """
316316 # hardcode alpha settings for now
317317 bgblend = BND_SET
318- #if isinstance(char, (str, bytes)):
319- # assert len(char) == 1, 'strings must only have one character'
320- # char = ord(char)
321- #assert isinstance(char, int) or char is None, \
322- # 'char must be an integer, single character string, or None'
318+
323319 char = _formatChar (char )
324320 _verify_colors (fgcolor , bgcolor )
325321 x , y = self ._cursor_move (x , y )
326322
327323 self ._setChar (char , x , y , _formatColor (fgcolor ), _formatColor (bgcolor ), bgblend )
328324 self ._cursor_advance ()
329325
330- def drawStr (self , string , x = None , y = None , fgcolor = None , bgcolor = None ):
326+ def drawStr (self , x = None , y = None , string = '' , fgcolor = C_WHITE , bgcolor = C_BLACK ):
331327 """Draws a string starting at x and y.
332328
333329 A string that goes past the end will wrap around. No warning will be
@@ -347,10 +343,10 @@ def drawStr(self, string, x=None, y=None, fgcolor=None, bgcolor=None):
347343 fgcolor , bgcolor = _formatColor (fgcolor ), _formatColor (bgcolor )
348344
349345 for char in string :
350- self ._setChar (char , self .cursorX , self .cursorY , fgcolor , bgcolor , bgblend )
346+ self ._setChar (x = self .cursorX , y = self .cursorY , char = char , fgcolor = fgcolor , bgcolor = bgcolor )
351347 self ._cursor_advance ()
352348
353- def drawRect (self , char , x = 0 , y = 0 , width = None , height = None , fgcolor = None , bgcolor = None ):
349+ def drawRect (self , x = 0 , y = 0 , width = None , height = None , char = None , fgcolor = C_WHITE , bgcolor = C_BLACK ):
354350 """Draws a rectangle starting from x and y and extending to width and
355351 height. If width or height are None then it will extend to the edge
356352 of the console. The rest are the same as drawChar.
@@ -370,7 +366,7 @@ def drawRect(self, char, x=0, y=0, width=None, height=None, fgcolor=None, bgcolo
370366 for cellX in range (x , x + width ):
371367 self ._setChar (char , cellX , cellY , fgcolor , bgcolor , bgblend )
372368
373- def drawFrame (self , char , x = 0 , y = 0 , width = None , height = None , fgcolor = None , bgcolor = None ):
369+ def drawFrame (self , x = 0 , y = 0 , width = None , height = None , char = None , fgcolor = C_WHITE , bgcolor = C_BLACK ):
374370 "Similar to drawRect but only draws the outline of the rectangle"
375371 # hardcode alpha settings for now
376372 bgblend = BND_SET
@@ -425,8 +421,8 @@ def __init__(self, console, x=0, y=0, width=None, height=None):
425421 raise TypeError ('console parameter must be a Console or Window instance' )
426422 assert isinstance (x , int )
427423 assert isinstance (y , int )
428- assert isinstance (width , int ) or width is None
429- assert isinstance (height , int ) or height is None
424+ assert ( isinstance (width , int ) or width is None )
425+ assert ( isinstance (height , int ) or height is None )
430426 if not console ._rectInBounds (x , y , width , height ):
431427 raise TDLError ('New Window is not within bounds of it\' s parent' )
432428 self .parent = console
@@ -481,8 +477,6 @@ def __repr__(self):
481477 self .height )
482478
483479
484-
485-
486480def init (width , height , title = 'TDL' , fullscreen = False ):
487481 """Start the main console with the given width and height and return the
488482 root console.
@@ -521,10 +515,14 @@ def flush():
521515 """
522516 if not _rootinitialized :
523517 raise TDLError ('Cannot flush without first initializing with tdl.init' )
518+
519+ # old hack to prevent locking up on old libtcod
520+ # you can probably delete all autoflush releated stuff
524521 if event ._autoflush and not event ._eventsflushed :
525522 event .get ()
526523 else : # do not flush events after the user starts using them
527524 event ._autoflush = False
525+
528526 event ._eventsflushed = False
529527 _lib .TCOD_console_flush ()
530528
@@ -582,15 +580,16 @@ def screenshot(fileobj=None):
582580 raise TDLError ('Initialize first with tdl.init' )
583581 if isinstance (fileobj , str ):
584582 _lib .TCOD_sys_save_screenshot (_format_string (fileobj ))
585- elif isinstance (fileobj , file ):
586- filename = os .tempnam ()
587- _lib .TCOD_sys_save_screenshot (_format_string (filename ))
588- fileobj .write (file (filename , 'r' ).read ())
589- os .remove (filename )
590- elif fileobj is None :
583+ elif isinstance (fileobj , file ): # save to temp file and copy to file-like obj
584+ tmpname = os .tempnam ()
585+ _lib .TCOD_sys_save_screenshot (_format_string (tmpname ))
586+ with tmpname as tmpfile :
587+ fileobj .write (tmpfile .read ())
588+ os .remove (tmpname )
589+ elif fileobj is None : # save to screenshot001.png, screenshot002.png, ...
591590 filelist = os .listdir ('.' )
592- n = 0
593- filename = 'screenshot%.4i .png' % n
591+ n = 1
592+ filename = 'screenshot%.3i .png' % n
594593 while filename in filelist :
595594 n += 1
596595 filename = 'screenshot%.4i.png' % n
0 commit comments