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

Migrate project to Python3 #8

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
74 changes: 37 additions & 37 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

"""Graphical user-interface for mymc."""

_SCCS_ID = "@(#) mymc gui.py 1.8 22/02/05 19:20:59\n"
_SCCS_ID = "@(#) mymc gui.py 1.9 23/07/06 19:35:21\n"

import os
import sys
import struct
import cStringIO
from io import BytesIO
import time
from functools import partial

Expand Down Expand Up @@ -101,7 +101,7 @@ def single_title(title):
def _get_icon_resource_as_images(name):
ico = guires.resources[name]
images = []
f = cStringIO.StringIO(ico)
f = BytesIO(ico)
count = struct.unpack("<HHH", ico[0:6])[2]
# count = wx.Image_GetImageCount(f, wx.BITMAP_TYPE_ICO)
for i in range(count):
Expand Down Expand Up @@ -159,7 +159,7 @@ def __init__(self, parent, evt_focus, evt_select, config):

def _update_dirtable(self, mc, dir):
self.dirtable = table = []
enc = "unicode"
enc = "utf-8"
if self.config.get_ascii():
enc = "ascii"
for ent in dir:
Expand Down Expand Up @@ -347,7 +347,7 @@ def __init__(self, parent, focus):
r = mymcicon.init_icon_renderer(focus.GetHandle(),
self.GetHandle())
if r == -1:
print "init_icon_renderer failed"
print("init_icon_renderer failed")
self.failed = True
return

Expand Down Expand Up @@ -384,7 +384,7 @@ def load_icon(self, icon_sys, icon):
r = mymcicon.load_icon(icon_sys, len(icon_sys),
icon, len(icon))
if r != 0:
print "load_icon", r
print("load_icon", r)
self.failed = True

def _set_lighting(self, lighting, vertex_diffuse, alt_lighting,
Expand Down Expand Up @@ -634,22 +634,22 @@ def _close_mc(self):
if self.mc != None:
try:
self.mc.close()
except EnvironmentError, value:
self.mc_error(value)
except EnvironmentError as e:
self.mc_error(e)
self.mc = None
if self.f != None:
try:
self.f.close()
except EnvironmentError, value:
self.mc_error(value)
except EnvironmentError as e:
self.mc_error(e)
self.f = None
self.mcname = None

def refresh(self):
try:
self.dirlist.update(self.mc)
except EnvironmentError, value:
self.mc_error(value)
except EnvironmentError as e:
self.mc_error(e)
self._close_mc()
self.dirlist.update(None)

Expand All @@ -674,12 +674,12 @@ def open_mc(self, filename):

f = None
try:
f = file(filename, "r+b")
f = open(filename, "r+b")
mc = ps2mc.ps2mc(f)
except EnvironmentError, value:
except EnvironmentError as e:
if f != None:
f.close()
self.mc_error(value, filename)
self.mc_error(e, filename)
self.SetTitle(self.title)
self.refresh()
return
Expand Down Expand Up @@ -718,8 +718,8 @@ def evt_dirlist_item_focused(self, event):
icon = f.read()
finally:
f.close()
except EnvironmentError, value:
print "icon failed to load", value
except EnvironmentError as e:
print("icon failed to load", e)
self.icon_win.load_icon(None, None)
return

Expand Down Expand Up @@ -758,8 +758,8 @@ def evt_cmd_export(self, event):
sf = mc.export_save_file("/" + dirname)
longname = ps2save.make_longname(dirname, sf)
sfiles.append((dirname, sf, longname))
except EnvironmentError, value:
self.mc_error(value. dirname)
except EnvironmentError as e:
self.mc_error(e.dirname)

if len(sfiles) == 0:
return
Expand All @@ -778,16 +778,16 @@ def evt_cmd_export(self, event):
if fn == "":
return
try:
f = file(fn, "wb")
f = open(fn, "wb")
try:
if fn.endswith(".max"):
sf.save_max_drive(f)
else:
sf.save_ems(f)
finally:
f.close()
except EnvironmentError, value:
self.mc_error(value, fn)
except EnvironmentError as e:
self.mc_error(e, fn)
return

dir = os.path.dirname(fn)
Expand All @@ -804,12 +804,12 @@ def evt_cmd_export(self, event):
for (dirname, sf, longname) in sfiles:
fn = os.path.join(dir, longname) + ".psu"
try:
f = file(fn, "wb")
f = open(fn, "wb")
sf.save_ems(f)
f.close()
count += 1
except EnvironmentError, value:
self.mc_error(value, fn)
except EnvironmentError as e:
self.mc_error(e, fn)
if count > 0:
if os.path.isabs(dir):
self.config.set_savefile_dir(dir)
Expand All @@ -819,7 +819,7 @@ def evt_cmd_export(self, event):

def _do_import(self, fn):
sf = ps2save.ps2_save_file()
f = file(fn, "rb")
f = open(fn, "rb")
try:
ft = ps2save.detect_file_type(f)
f.seek(0)
Expand Down Expand Up @@ -868,8 +868,8 @@ def evt_cmd_import(self, event):
try:
self._do_import(fn)
success = fn
except EnvironmentError, value:
self.mc_error(value, fn)
except EnvironmentError as e:
self.mc_error(e, fn)

if success != None:
dir = os.path.dirname(success)
Expand Down Expand Up @@ -904,8 +904,8 @@ def evt_cmd_delete(self, event):
for dn in dirnames:
try:
mc.rmdir("/" + dn)
except EnvironmentError, value:
self.mc_error(value, dn)
except EnvironmentError as e:
self.mc_error(e, dn)

mc.check()
self.refresh()
Expand Down Expand Up @@ -934,13 +934,13 @@ def run(filename = None):

run("test.ps2")

gc.collect()
for o in gc.garbage:
print
print o
if type(o) == ps2mc.ps2mc_file:
gc.collect()
for o in gc.garbage:
print()
print(o)
if type(o) == ps2mc.ps2mc_file:
for m in dir(o):
print m, getattr(o, m)
print(m, getattr(o, m))


# while True:
Expand All @@ -954,7 +954,7 @@ def run(filename = None):
# or m == "__dict__"
# or m == "__weakref__"):
# continue
# print m
# print(m)
# setattr(o, m, None)
# o = None
# break
Expand Down
Loading