Skip to content

Commit

Permalink
uHAL : Update gui to support Python 3; refs #127
Browse files Browse the repository at this point in the history
  • Loading branch information
tswilliams committed Jan 4, 2019
1 parent fb3dc5b commit 156f4aa
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 40 deletions.
2 changes: 1 addition & 1 deletion uhal/gui/pkg/uhal/gui/customguis/customwindow1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class CustomWindow1(defaultgui.DefaultGui):

def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
wx.Frame.__init__(self, parent, id, title)


def start():
Expand Down
2 changes: 1 addition & 1 deletion uhal/gui/pkg/uhal/gui/guiloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def loader(default=True, guilist=[]):
guilist.append(def_gui_mod_obj)
logger.info('GUI modules successfully imported')

except ImportError, e:
except ImportError as e:
logger.critical('Failed to import defaultgui module: %s', str(e))


Expand Down
4 changes: 2 additions & 2 deletions uhal/gui/pkg/uhal/gui/guis/defaultgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def __start_hw_thread(self, file_name):
self.__hw_tree_struct = self.__hw_mon.get_hw_tree()
self.__logger.info('Starting HW monitoring thread...')

except Exception, e:
except Exception as e:

self.__logger.critical('Exception while instantiating HW monitoring thread! %s Exiting...', str(e))
import sys
Expand All @@ -256,7 +256,7 @@ def __start_hw_thread(self, file_name):

self.__hw_mon.start()

except RuntimeError, e:
except RuntimeError as e:

self.__logger.critical('Tried to initiate twice the HW monitoring thread! Message %s Exiting...', str(e))
self.__hw_mon.set_thread_running(False)
Expand Down
4 changes: 2 additions & 2 deletions uhal/gui/pkg/uhal/gui/guis/hardware_table_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class StaticFields(wx.Panel):

def __init__(self, parent):

print "DEBUG: Init StaticFields"
print("DEBUG: Init StaticFields")
wx.Panel.__init__(self, parent)

# Attributes
Expand Down Expand Up @@ -329,7 +329,7 @@ def __fill_widget(self, nodes, hw_tree, widget):
try:
# Item is a Node object
id = k.getId()
except AttributeError, e:
except AttributeError as e:
# The item is an IP End point object (HardwareInterface)
id = k.id()

Expand Down
2 changes: 1 addition & 1 deletion uhal/gui/pkg/uhal/gui/guis/hardware_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __add_tree_nodes(self, parent, items):
try:
# Case node is an IP End point
id = k.id()
except AttributeError, e:
except AttributeError as e:
# Case node is a Node
id = k.getId()

Expand Down
4 changes: 2 additions & 2 deletions uhal/gui/pkg/uhal/gui/guis/plotreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def add_pair(self, y):

if self.__data:
previous_y = self.__data[-1][1]
print "previous y is %s" % previous_y
print("previous y is %s" % previous_y)
self.__data.append((time_elapsed, previous_y))

self.__data.append((time_elapsed, y))


def plot(self):
print "DEBUG: plotting with data", str(self.__data)
print("DEBUG: plotting with data", str(self.__data))
self.__canvas.Draw(self.__draw_reg_plot())


Expand Down
25 changes: 13 additions & 12 deletions uhal/gui/pkg/uhal/gui/test/test_uhal_gui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import unittest

from uhal.gui.guiloader import test
Expand All @@ -21,39 +22,39 @@ def tearDown(self):


def test_default_on(self):
print '\n********** Simple configuration **********'
print('\n********** Simple configuration **********')
self.assertEqual(test(guilist=[self.default_gui_mod]), 'OK')
print
print()


def test_default_off(self):
print '\n********** Configuration: default=No, guilist=[] **********'
print('\n********** Configuration: default=No, guilist=[] **********')
self.assertEqual(test(guilist=[]), 'OK')
print
print()


def test_default_on_custom_one(self):
print '\n********** Configuration: default=Yes, guilist=[\'CustomWindow1\'] **********'
print('\n********** Configuration: default=Yes, guilist=[\'CustomWindow1\'] **********')
self.assertEqual(test(guilist=[self.default_gui_mod, self.custom_gui1]), 'OK')
print
print()


def test_default_off_custom_one(self):
print '\n********** Configuration: default=No, guilist=[\'CustomWindow1\'] **********'
print('\n********** Configuration: default=No, guilist=[\'CustomWindow1\'] **********')
self.assertEqual(test(guilist=[self.custom_gui1]), 'OK')
print
print()


def test_default_on_custom_one_two(self):
print '\n********** Configuration: default=Yes, guilist=[\'CustomWindow1\',\'CustomWindow2\']**********'
print('\n********** Configuration: default=Yes, guilist=[\'CustomWindow1\',\'CustomWindow2\']**********')
self.assertEqual(test(guilist=[self.default_gui_mod, self.custom_gui1, self.custom_gui2]), 'OK')
print
print()


def test_default_off_custom_one_two(self):
print '\n********** Configuration: default=No, guilist=[\'CustomWindow1\',\'CustomWindow2\'] **********'
print('\n********** Configuration: default=No, guilist=[\'CustomWindow1\',\'CustomWindow2\'] **********')
self.assertEqual(test(guilist=[self.custom_gui1, self.custom_gui2]), 'OK')
print
print()


def main():
Expand Down
30 changes: 16 additions & 14 deletions uhal/gui/pkg/uhal/gui/utilities/hardware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import uhal

########## NODE RELATED CLASSES ##########
Expand All @@ -8,7 +10,7 @@ class Node:
def __init__(self, node, parent_id=""):

if not node:
print "ERROR: tried to initialize Node object with invalid uhal Node argument"
print("ERROR: tried to initialize Node object with invalid uhal Node argument")
return

self.__id = node.getId()
Expand All @@ -23,7 +25,7 @@ def __init__(self, node, parent_id=""):
self.__size = node.getSize()
self.__tags = node.getTags()

print "DEBUG: Creating node %s %s" % (self.__id, self.__permission)
print("DEBUG: Creating node %s %s" % (self.__id, self.__permission))
self.__parent = parent_id
self.__children = []

Expand All @@ -34,7 +36,7 @@ def __init__(self, node, parent_id=""):


def __add_kid(self, node):
print "DEBUG: Adding kid %s to node %s" % (node.get_id(), self.get_id())
print("DEBUG: Adding kid %s to node %s" % (node.get_id(), self.get_id()))
self.__children.append(node)


Expand Down Expand Up @@ -83,9 +85,9 @@ def set_value(self, value):


def print_node(self):
print "DEBUG: Node: %s %s %s" % (self.__id, self.__mode, self.__permission)
print("DEBUG: Node: %s %s %s" % (self.__id, self.__mode, self.__permission))
for c in self.__children:
print "\t",c.print_node()
print("\t",c.print_node())



Expand All @@ -98,19 +100,19 @@ class IPEndPoint:
def __init__(self, ip_ep, status="Undefined"):

if not ip_ep:
print "ERROR: tried to initialize IPEndPoint object with invalid uhal IP End Point argument"
print("ERROR: tried to initialize IPEndPoint object with invalid uhal IP End Point argument")
return

self.__id = ip_ep.id()
self.__uri = ip_ep.uri()
self.__status = status
self.__nodes_list = []
print "DEBUG: IP End Point instantiated: %s %s %s" %(self.__id, self.__uri, self.__status)
print("DEBUG: IP End Point instantiated: %s %s %s" %(self.__id, self.__uri, self.__status))



def add_node(self, node):
print "DEBUG: Adding node %s to the IP End Point %s" % (node.get_id(), self.__id)
print("DEBUG: Adding node %s to the IP End Point %s" % (node.get_id(), self.__id))
self.__nodes_list.append(node)

def get_nodes(self):
Expand Down Expand Up @@ -142,7 +144,7 @@ def set_uri(self, uri):


def print_ip_end_point(self):
print "DEBUG: IP End Point: %s %s %s" % (self.__id, self.__uri, self.__status)
print("DEBUG: IP End Point: %s %s %s" % (self.__id, self.__uri, self.__status))

for n in self.__nodes_list:
n.print_node()
Expand All @@ -169,22 +171,22 @@ def __init__(self, connection_file, id=None, uri=None, address_table=None):
self.__connection_file = connection_file
self.__hw_manager = uhal.ConnectionManager(str("file://" + self.__connection_file))

print "DEBUG: HardwareStruct instantiated with file name %s" % self.__connection_file
print("DEBUG: HardwareStruct instantiated with file name %s" % self.__connection_file)
elif id and uri and address_table:
self.__id = id
self.__uri = uri
self.__address_table = address_table
self.__hw_manager = uhal.ConnectionManager(self.__id, self.__uri, self.__address_table)

print "DEBUG: HardwareStruct instantiated with id: %s, uri: %s, address_table: %s" % (self.__id, self.__uri, self.__address_table)
print("DEBUG: HardwareStruct instantiated with id: %s, uri: %s, address_table: %s" % (self.__id, self.__uri, self.__address_table))
else:
print "ERROR: HardwareStruct object not properly instantiated"
print("ERROR: HardwareStruct object not properly instantiated")


if self.__hw_manager:
self.__load_hardware()
else:
print "ERROR: could not start uhal.ConnectionManager object. Cannot start the default gui"
print("ERROR: could not start uhal.ConnectionManager object. Cannot start the default gui")



Expand Down Expand Up @@ -235,7 +237,7 @@ def get_hw_manager(self):


def add_ip_end_point(self, ip_ep):
print "DEBUG: Adding IP End Point %s to the IP End Point list" % ip_ep.get_id()
print("DEBUG: Adding IP End Point %s to the IP End Point list" % ip_ep.get_id())
self.__ip_end_points.append(ip_ep)


Expand Down
8 changes: 4 additions & 4 deletions uhal/gui/pkg/uhal/gui/utilities/hardware_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, parent, file_name):
self.__init_hw(file_name)
self.__build_hw_tree()

except Exception, e:
except Exception as e:
raise


Expand All @@ -61,7 +61,7 @@ def run(self):

map_devs_to_map_nodes_to_values = {}

for name, dev in self.__devices.iteritems():
for name, dev in self.__devices.items():
'''
if dev.get_status() is not "OK":
continue
Expand All @@ -83,14 +83,14 @@ def run(self):

nodes_vs_values[node] = node_object.read()

except Exception, e:
except Exception as e:
self.__logger.warning('Exception while reading node %s from device %s: %s', node , name, str(e))

# Temporarily add try/except block to cope with the fact that IP End point check status (PING) is not offered right now
try:
dev.dispatch()
map_devs_to_map_nodes_to_values[name] = nodes_vs_values
except Exception, e:
except Exception as e:
self.__logger.warning('Dispatch operation for device %s failed: %s', dev.id(), str(e))


Expand Down
3 changes: 2 additions & 1 deletion uhal/gui/pkg/uhal/gui/utilities/utilities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import wx


Expand Down Expand Up @@ -26,6 +27,6 @@ def dynamic_loader(module_object):
if inspect.isclass(obj):
return (obj, "OK")

print "FAILED to return class from module %s" % module_object.__name__
print("FAILED to return class from module %s" % module_object.__name__)


0 comments on commit 156f4aa

Please sign in to comment.