Skip to content

Commit

Permalink
Drop Python2 support and fix Python3 support in all Python files
Browse files Browse the repository at this point in the history
  • Loading branch information
scotty007 committed Jun 25, 2020
1 parent 9a196e5 commit 3917efd
Show file tree
Hide file tree
Showing 75 changed files with 259 additions and 381 deletions.
6 changes: 1 addition & 5 deletions CreateVersionFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# The script generates a header file that contains versioning data for
# the current build.

from __future__ import print_function

import os
import sys
import subprocess
Expand All @@ -36,8 +34,6 @@
import datetime
import pickle

import six

CHECK_FIELDS = ('releaseVersion', 'revision')
OUTPUT_TEMPLATE = '''// version.h
// This file is automatically generated by CreateVersionFile.py
Expand Down Expand Up @@ -132,7 +128,7 @@ def assembleVersionInfo(major, minor, micro):
return locals()

def dumpVersionInfo(versionInfo):
for k, v in six.iteritems(versionInfo):
for k, v in versionInfo.items():
print(' %s: %s' % (k, v))

def hasChanged(versionInfo):
Expand Down
8 changes: 3 additions & 5 deletions python/libavg/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import os
import math

import six

import libavg
from libavg import avg, Point2D, mtemu, player

Expand All @@ -43,7 +41,7 @@ class MainDiv(libavg.avg.DivNode):

def __init__(self, **kargs):
assert not 'parent' in kargs
super(MainDiv, self).__init__(**kargs)
super().__init__(**kargs)
self.registerInstance(self, None)
self.__touchVisOverlay = None

Expand Down Expand Up @@ -76,7 +74,7 @@ def onFrame(self):
pass


class App(object):
class App:
def __init__(self):
self._setupInstance()

Expand Down Expand Up @@ -175,7 +173,7 @@ def dumpTextObjectCount(self):
libavg.logger.configureCategory(libavg.logger.Category.APP,
libavg.logger.Severity.INFO)
libavg.logger.info('Dumping objects count')
for key, value in six.iteritems(objects):
for key, value in objects.items():
libavg.logger.info(' %-25s: %s' % (key, value))

libavg.logger.configureCategory(libavg.logger.Category.APP, savedSeverity)
Expand Down
29 changes: 13 additions & 16 deletions python/libavg/app/debugpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
from collections import deque
import math

import six
from six.moves import range

import libavg
from libavg import avg
from libavg import graph
Expand Down Expand Up @@ -59,7 +56,7 @@ class DebugWidgetFrame(avg.DivNode):
FRAME_HEIGHT_CHANGED = avg.Publisher.genMessageID()

def __init__(self, size, widgetCls, *args, **kwargs):
super(DebugWidgetFrame, self).__init__(size=size, *args, **kwargs)
super().__init__(size=size, *args, **kwargs)
self.registerInstance(self, None)
self.setup(widgetCls)
self.subscribe(self.SIZE_CHANGED, self._onSizeChanged)
Expand Down Expand Up @@ -129,7 +126,7 @@ class DebugWidget(avg.DivNode):
WIDGET_HEIGHT_CHANGED = avg.Publisher.genMessageID()

def __init__(self, parent=None, **kwargs):
super(DebugWidget, self).__init__(**kwargs)
super().__init__(**kwargs)
self.registerInstance(self, parent)
self.publish(DebugWidget.WIDGET_HEIGHT_CHANGED)
if self.CAPTION:
Expand Down Expand Up @@ -164,7 +161,7 @@ class TableRow(avg.DivNode):
ROW_ID = 0

def __init__(self, parent=None, **kwargs):
super(TableRow, self).__init__(**kwargs)
super().__init__(**kwargs)
self.registerInstance(self, parent)
global NUM_COLS
NUM_COLS = int((self.parent.width - COL_WIDTH * 4) / COL_WIDTH)
Expand Down Expand Up @@ -235,7 +232,7 @@ def updateLiveColumn(self, value):

class Table(avg.DivNode):
def __init__(self, parent=None, **kwargs):
super(Table, self).__init__(**kwargs)
super().__init__(**kwargs)
self.registerInstance(self, parent)

def labelColumnSizeChanged(self):
Expand All @@ -248,15 +245,15 @@ class ObjectDumpWidget(DebugWidget):
CAPTION = 'Objects count'

def __init__(self, parent=None, **kwargs):
super(ObjectDumpWidget, self).__init__(**kwargs)
super().__init__(**kwargs)
self.registerInstance(self, parent)
self.tableContainer = Table(parent=self, size=(self.width, self.SLOT_HEIGHT))
self.tableDivs = defaultdict(lambda: TableRow(parent=self.tableContainer))

def update(self):
objDump = libavg.player.getTestHelper().getObjectCount()
pos = (0, 0)
for key in sorted(six.iterkeys(objDump)):
for key in sorted(objDump.keys()):
val = objDump[key]
self.tableDivs[key].updateLiveColumn(val)
self.tableDivs[key].setLabel(key)
Expand All @@ -268,7 +265,7 @@ def update(self):

def persistColumn(self):
objDump = libavg.player.getTestHelper().getObjectCount()
for key, val in six.iteritems(objDump):
for key, val in objDump.items():
self.tableDivs[key].insertValue(val)

def syncSize(self, size):
Expand All @@ -295,7 +292,7 @@ def kill(self):

class GraphWidget(DebugWidget):
def __init__(self, **kwargs):
super(GraphWidget, self).__init__(**kwargs)
super().__init__(**kwargs)
self.registerInstance(self, None)
self.__graph = None

Expand Down Expand Up @@ -353,7 +350,7 @@ class KeyboardManagerBindingsShower(DebugWidget):
CAPTION = 'Keyboard bindings'

def __init__(self, *args, **kwargs):
super(KeyboardManagerBindingsShower, self).__init__(**kwargs)
super().__init__(**kwargs)
self.registerInstance(self, None)
self.keybindingWordNodes = []
kbmgr.publisher.subscribe(kbmgr.publisher.BINDINGS_UPDATED, self.update)
Expand All @@ -378,9 +375,9 @@ def update(self):
key = keystring

if binding.type == libavg.avg.KEYDOWN:
key = '%s %s' % (six.unichr(8595), key)
key = '%s %s' % (chr(8595), key)
else:
key = '%s %s' % (six.unichr(8593), key)
key = '%s %s' % (chr(8593), key)

node = avg.WordsNode(
text='<span size="large"><b>%s</b></span>: %s' %
Expand Down Expand Up @@ -457,7 +454,7 @@ def isSingleBit(number):

class DebugPanel(avg.DivNode):
def __init__(self, parent=None, fontsize=10, **kwargs):
super(DebugPanel, self).__init__(**kwargs)
super().__init__(**kwargs)
self.registerInstance(self, parent)

avg.RectNode(size=self.size, opacity=0, fillopacity=0.3, fillcolor='ff0000',
Expand Down Expand Up @@ -562,7 +559,7 @@ def forceLoadPanel(self):
class _DebugPanel(avg.DivNode):

def __init__(self, parent=None, fontsize=10, **kwargs):
super(_DebugPanel, self).__init__(**kwargs)
super().__init__(**kwargs)
self.registerInstance(self, parent)

self.__slots = []
Expand Down
2 changes: 1 addition & 1 deletion python/libavg/app/flashmessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import libavg

class FlashMessage(object):
class FlashMessage:
DEFAULT_TIMEOUT = 3000
LINE_HEIGHT = 20
BORDER = 2
Expand Down
4 changes: 1 addition & 3 deletions python/libavg/app/keyboardmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

from collections import namedtuple

import six

from libavg import avg, player

IGNORED_KEYMODS = avg.KEYMOD_NUM
Expand All @@ -38,7 +36,7 @@
class KeyboardManagerPublisher(avg.Publisher):
BINDINGS_UPDATED = avg.Publisher.genMessageID()
def __init__(self):
super(KeyboardManagerPublisher, self).__init__()
super().__init__()
self.publish(self.BINDINGS_UPDATED)

def notifyUpdate(self):
Expand Down
18 changes: 7 additions & 11 deletions python/libavg/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@
#
# Original author of this file is OXullo Interecans <x at brainrapers dot org>

from __future__ import print_function

import sys
import re
import optparse

import six

import libavg


class Option(object):
class Option:
def __init__(self, key, value, help=None):
if not isinstance(key, str):
raise ValueError('The type of %s key is not string (value=%s)' % (key, value))
Expand Down Expand Up @@ -86,7 +82,7 @@ def __getComponents(self):
return self.key.split('_', 1)


class KargsExtender(object):
class KargsExtender:
def __init__(self, optionsKargs):
self.__optionsKargs = optionsKargs

Expand All @@ -108,14 +104,14 @@ def __call__(self, optionsList):
class HelpPrintingOptionParser(optparse.OptionParser):
def error(self, *args, **kargs):
self.print_help()
optparse.OptionParser.error(self, *args, **kargs)
super().error(*args, **kargs)

def print_help(self):
optparse.OptionParser.print_help(self)
super().print_help()
print()
print('All options can also be set using the App.run() method.')

class ArgvExtender(object):
class ArgvExtender:
def __init__(self, appVersionInfo, args=None):
self.__appVersionInfo = appVersionInfo
self.__parser = HelpPrintingOptionParser()
Expand Down Expand Up @@ -164,7 +160,7 @@ def __call__(self, optionsList):
print(' version: {0}'.format(self.__appVersionInfo))
sys.exit(0)

for key, value in six.iteritems(parsedOptions.__dict__):
for key, value in parsedOptions.__dict__.items():
if value is not None:
for option in optionsList:
if option.key == key:
Expand Down Expand Up @@ -195,7 +191,7 @@ def __groupOptionsKeys(self, optionsList):
return groups


class Settings(object):
class Settings:
def __init__(self, defaults=[]):
if (type(defaults) not in (tuple, list) or
not all([isinstance(opt, Option) for opt in defaults])):
Expand Down
18 changes: 9 additions & 9 deletions python/libavg/app/touchvisualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class BaseTouchVisualization(avg.DivNode):

def __init__(self, event, parent=None, **kwargs):
avg.DivNode.__init__(self, **kwargs)
super().__init__(**kwargs)
self.registerInstance(self, parent)

event.contact.subscribe(avg.Contact.CURSOR_MOTION, self._onMotion)
Expand Down Expand Up @@ -58,7 +58,7 @@ def _getRadius(self, event):
class DebugTouchVisualization(BaseTouchVisualization):

def __init__(self, event, **kwargs):
BaseTouchVisualization.__init__(self, event, **kwargs)
super().__init__(event, **kwargs)
self.positions = [event.pos]

if event.source == avg.Event.TOUCH:
Expand Down Expand Up @@ -95,10 +95,10 @@ def __init__(self, event, **kwargs):
def unlink(self, kill=True):
if self.motionPath:
self.motionPath.unlink(True)
super(DebugTouchVisualization, self).unlink(kill)
super().unlink(kill)

def _onMotion(self, event):
BaseTouchVisualization._onMotion(self, event)
super()._onMotion(event)
self.positions.append(event.pos)
if len(self.positions) > 100:
self.positions.pop(0)
Expand Down Expand Up @@ -141,7 +141,7 @@ class TouchVisualization(BaseTouchVisualization):
bmp = avg.Bitmap(mediadir+"/TouchFeedback.png")

def __init__(self, event, **kwargs):
BaseTouchVisualization.__init__(self, event, **kwargs)
super().__init__(event, **kwargs)

if event.source in self.sources:
self.__circle = avg.ImageNode(parent=self)
Expand All @@ -153,13 +153,13 @@ def __init__(self, event, **kwargs):
self._abort()

def _onMotion(self, event):
BaseTouchVisualization._onMotion(self, event)
super()._onMotion(event)
self.__setRadius(self._radius)

def _onUp(self, event):

def gone(self):
BaseTouchVisualization._onUp(self, event)
super()._onUp(event)
self.unlink(True)
del self

Expand All @@ -176,7 +176,7 @@ def __setRadius(self, radius):
class TouchVisualizationOverlay(avg.DivNode):
def __init__(self, isDebug, visClass, rootNode=None, parent=None,
**kwargs):
super(TouchVisualizationOverlay, self).__init__(**kwargs)
super().__init__(**kwargs)
self.registerInstance(self, parent)

self.sensitive = False
Expand All @@ -197,7 +197,7 @@ def unlink(self, kill=True):
rootNode.unsubscribe(avg.Node.CURSOR_DOWN, self.__onTouchDown)
rootNode.unsubscribe(avg.Node.HOVER_DOWN, self.__onTouchDown)
rootNode.unsubscribe(avg.Node.TANGIBLE_DOWN, self.__onTouchDown)
super(TouchVisualizationOverlay, self).unlink(kill)
super().unlink(kill)

def __onTouchDown(self, event):
self.visClass(event, parent=self)

0 comments on commit 3917efd

Please sign in to comment.