Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some fixes for python 3 #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
.venv
26 changes: 17 additions & 9 deletions punchcards/punchcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def _crop(self):
self.xmax = self.xsize
if self.ymax == 0:
self.ymax = self.ysize
self.midx = self.xmin + (self.xmax - self.xmin) / 2 + self.xadjust
self.midy = self.ymin + (self.ymax - self.ymin) / 2
self.midx = int(self.xmin + (self.xmax - self.xmin) / 2) + self.xadjust
self.midy = int( self.ymin + (self.ymax - self.ymin) / 2)

# heuristic for finding a reasonable cutoff brightness
def _find_threshold_brightness(self):
Expand Down Expand Up @@ -213,7 +213,7 @@ def _find_data_vert_dimensions(self):
self.debug_pix[x,bottom_border] = 255
if self.logger.isEnabledFor(logging.DEBUG):
# mark search parameters
for x in range(self.midx - self.xsize/20, self.midx + self.xsize/20):
for x in range(self.midx - int(self.xsize/20), int(self.midx + self.xsize/20)):
self.debug_pix[x,self.ymin] = 255
self.debug_pix[x,self.ymax - 1] = 255
for y in range(0, self.ymin):
Expand Down Expand Up @@ -273,7 +273,7 @@ def _scan(self, bright=-1):
if self.logger.isEnabledFor(logging.DEBUG):
self.debug_image.show()
# prevent run-a-way debug shows causing my desktop to run out of memory
raw_input("Press Enter to continue...")
self._input("Press Enter to continue...")
self.decoded = []
# Could fold this loop into the previous one - but would it be faster?
for col in range(0, CARD_COLUMNS):
Expand All @@ -295,7 +295,7 @@ def _scan(self, bright=-1):
# ASCII art image of card
def dump(self, id, raw_data=False):
print(' Card Dump of Image file:', id, 'Format', 'Raw' if raw_data else 'Dump', 'threshold=', self.threshold)
print(' ' + '123456789-' * (CARD_COLUMNS/10))
print(' ' + '123456789-' * int(CARD_COLUMNS/10))
print(' ' + '_' * CARD_COLUMNS + ' ')
print('/' + self.text + '_' * (CARD_COLUMNS - len(self.text)) + '|')
for rnum in range(len(self.decoded[0])):
Expand All @@ -308,12 +308,16 @@ def dump(self, id, raw_data=False):
sys.stdout.write(col[rnum] if col[rnum] == 'O' else '.')
print('|')
print('`' + '-' * CARD_COLUMNS + "'")
print(' ' + '123456789-' * (CARD_COLUMNS/10))
print(' ' + '123456789-' * int(CARD_COLUMNS/10))
print('')



if __name__ == '__main__':
main()
# simple shim for python 2/3 compatibility
def _input( self, prompt ):
try:
return raw_input( prompt )
except NameError:
return input( prompt)


def main():
Expand All @@ -340,3 +344,7 @@ def main():
card.dump(arg)
if (options.dumpraw):
card.dump(arg, raw_data=True)


if __name__ == '__main__':
main()