Commit 2aa575f0 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

nxdialog: pylint improvements

parent 486cc6f5
...@@ -76,7 +76,8 @@ VALID_DLG_TYPES = frozenset([ ...@@ -76,7 +76,8 @@ VALID_DLG_TYPES = frozenset([
DLG_TYPE_QUIT, DLG_TYPE_QUIT,
DLG_TYPE_YESNO, DLG_TYPE_YESNO,
DLG_TYPE_YESNOSUSPEND, DLG_TYPE_YESNOSUSPEND,
]) ])
class PullDownMenu(object): class PullDownMenu(object):
""" Shows a popup menu to disconnect/terminate session. """ """ Shows a popup menu to disconnect/terminate session. """
...@@ -88,16 +89,16 @@ class PullDownMenu(object): ...@@ -88,16 +89,16 @@ class PullDownMenu(object):
@param window_id: X11 window id of target window @param window_id: X11 window id of target window
""" """
self._window_id = window_id self.window_id = window_id
self._result = None self.result = None
def Show(self): def show(self):
""" Shows popup and returns result. """ """ Shows popup and returns result. """
win = gtk.gdk.window_foreign_new(self._window_id) win = gtk.gdk.window_foreign_new(self.window_id)
menu = gtk.Menu() menu = gtk.Menu()
menu.connect("deactivate", self._MenuDeactivate) menu.connect("deactivate", self.menu_deactivate)
# TODO: Show title item in bold font # TODO: Show title item in bold font
title = gtk.MenuItem(label="Session control") title = gtk.MenuItem(label="Session control")
...@@ -105,11 +106,11 @@ class PullDownMenu(object): ...@@ -105,11 +106,11 @@ class PullDownMenu(object):
menu.append(title) menu.append(title)
disconnect = gtk.MenuItem(label=DISCONNECT_TEXT) disconnect = gtk.MenuItem(label=DISCONNECT_TEXT)
disconnect.connect("activate", self._ItemActivate, DISCONNECT) disconnect.connect("activate", self.item_activate, DISCONNECT)
menu.append(disconnect) menu.append(disconnect)
terminate = gtk.MenuItem(label=TERMINATE_TEXT) terminate = gtk.MenuItem(label=TERMINATE_TEXT)
terminate.connect("activate", self._ItemActivate, TERMINATE) terminate.connect("activate", self.item_activate, TERMINATE)
menu.append(terminate) menu.append(terminate)
menu.append(gtk.SeparatorMenuItem()) menu.append(gtk.SeparatorMenuItem())
...@@ -120,23 +121,25 @@ class PullDownMenu(object): ...@@ -120,23 +121,25 @@ class PullDownMenu(object):
menu.show_all() menu.show_all()
menu.popup(parent_menu_shell=None, parent_menu_item=None, menu.popup(parent_menu_shell=None, parent_menu_item=None,
func=self._PosMenu, data=win, func=self.pos_menu, data=win,
button=0, activate_time=gtk.get_current_event_time()) button=0, activate_time=gtk.get_current_event_time())
gtk.main() gtk.main()
return self._result return self.result
def _ItemActivate(self, _, result): def item_activate(self, _, result):
""" called when a menu item is selected """ """ called when a menu item is selected """
self._result = result self.result = result
gtk.main_quit() gtk.main_quit()
def _MenuDeactivate(self, _): @staticmethod
def menu_deactivate(_):
""" called when menu is deactivated """ """ called when menu is deactivated """
gtk.main_quit() gtk.main_quit()
def _PosMenu(self, menu, parent): @staticmethod
def pos_menu(menu, parent):
""" Positions menu at the top center of the parent window. """ """ Positions menu at the top center of the parent window. """
# Get parent geometry and origin # Get parent geometry and origin
(_, _, win_width, _, _) = parent.get_geometry() (_, _, win_width, _, _) = parent.get_geometry()
...@@ -146,12 +149,12 @@ class PullDownMenu(object): ...@@ -146,12 +149,12 @@ class PullDownMenu(object):
(menu_width, _) = menu.size_request() (menu_width, _) = menu.size_request()
# Calculate center # Calculate center
x = win_x + ((win_width - menu_width) / 2) center_x = win_x + ((win_width - menu_width) / 2)
return (x, win_y, True) return (center_x, win_y, True)
def ShowYesNoSuspendBox(title, text): def show_yes_no_suspend_box(title, text):
""" Shows a message box to disconnect/terminate session. """ Shows a message box to disconnect/terminate session.
@type title: str @type title: str
...@@ -177,7 +180,7 @@ def ShowYesNoSuspendBox(title, text): ...@@ -177,7 +180,7 @@ def ShowYesNoSuspendBox(title, text):
return None return None
def ShowYesNoBox(title, text): def show_yes_no_box(title, text):
""" Shows a message box with answers yes and no. """ Shows a message box with answers yes and no.
@type title: str @type title: str
...@@ -202,7 +205,7 @@ def ShowYesNoBox(title, text): ...@@ -202,7 +205,7 @@ def ShowYesNoBox(title, text):
return None return None
def HandleSessionAction(agentpid, action): def handle_session_action(agentpid, action):
""" Execute session action choosen by user. """ Execute session action choosen by user.
@type agentpid: int @type agentpid: int
...@@ -227,7 +230,7 @@ def HandleSessionAction(agentpid, action): ...@@ -227,7 +230,7 @@ def HandleSessionAction(agentpid, action):
raise NotImplementedError() raise NotImplementedError()
def ShowSimpleMessageBox(icon, title, text): def show_simple_message_box(icon, title, text):
""" Shows a simple message box. """ Shows a simple message box.
@type icon: QMessageBox.Icon @type icon: QMessageBox.Icon
...@@ -247,31 +250,33 @@ def ShowSimpleMessageBox(icon, title, text): ...@@ -247,31 +250,33 @@ def ShowSimpleMessageBox(icon, title, text):
class NxDialogProgram(object): class NxDialogProgram(object):
""" the main program """ """ the main program """
def __init__(self): def __init__(self):
self.args = None self.args = None
self.options = None self.options = None
def Main(self): def main(self):
""" let's do something """ """ let's do something """
try: try:
(self.options, self.args) = self.ParseArgs() (self.options, self.args) = self.parse_args()
self.Run() self.run()
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
raise raise
except Exception, e: except Exception, expt:
sys.stderr.write("Caught exception: %s\n" % (e)) sys.stderr.write("Caught exception: %s\n" % (expt))
sys.exit(EXIT_FAILURE) sys.exit(EXIT_FAILURE)
def ParseArgs(self): def parse_args(self):
""" init parser """ """ init parser """
parser = optparse.OptionParser(option_list=self.BuildOptions(), parser = optparse.OptionParser(option_list=self.build_options(),
formatter=optparse.TitledHelpFormatter()) formatter=optparse.TitledHelpFormatter())
return parser.parse_args() return parser.parse_args()
def BuildOptions(self): @staticmethod
def build_options():
""" build options for the parser """ """ build options for the parser """
return [ return [
# nxagent 3.5.99.18 only uses yesno, ok, pulldown and yesnosuspend # nxagent 3.5.99.18 only uses yesno, ok, pulldown and yesnosuspend
...@@ -306,7 +311,7 @@ class NxDialogProgram(object): ...@@ -306,7 +311,7 @@ class NxDialogProgram(object):
the same message [currently unimplemented]"), the same message [currently unimplemented]"),
] ]
def Run(self): def run(self):
""" Disconnect/terminate NX session upon user's request. """ """ Disconnect/terminate NX session upon user's request. """
if not self.options.dialog_type: if not self.options.dialog_type:
...@@ -343,22 +348,24 @@ class NxDialogProgram(object): ...@@ -343,22 +348,24 @@ class NxDialogProgram(object):
os.environ["DISPLAY"] = self.options.display os.environ["DISPLAY"] = self.options.display
if dlgtype == DLG_TYPE_OK: if dlgtype == DLG_TYPE_OK:
ShowSimpleMessageBox(gtk.MESSAGE_INFO, message_caption, message_text) show_simple_message_box(
gtk.MESSAGE_INFO, message_caption, message_text)
elif dlgtype in (DLG_TYPE_ERROR, DLG_TYPE_PANIC): elif dlgtype in (DLG_TYPE_ERROR, DLG_TYPE_PANIC):
ShowSimpleMessageBox(gtk.MESSAGE_ERROR, message_caption, message_text) show_simple_message_box(
gtk.MESSAGE_ERROR, message_caption, message_text)
elif dlgtype == DLG_TYPE_PULLDOWN: elif dlgtype == DLG_TYPE_PULLDOWN:
HandleSessionAction(self.options.agentpid, handle_session_action(self.options.agentpid,
PullDownMenu(self.options.window).Show()) PullDownMenu(self.options.window).show())
elif dlgtype == DLG_TYPE_YESNOSUSPEND: elif dlgtype == DLG_TYPE_YESNOSUSPEND:
HandleSessionAction(self.options.agentpid, handle_session_action(self.options.agentpid,
ShowYesNoSuspendBox(message_caption, message_text)) show_yes_no_suspend_box(message_caption, message_text))
elif dlgtype == DLG_TYPE_YESNO: elif dlgtype == DLG_TYPE_YESNO:
HandleSessionAction(self.options.agentpid, handle_session_action(self.options.agentpid,
ShowYesNoBox(message_caption, message_text)) show_yes_no_box(message_caption, message_text))
else: else:
# TODO: Implement all dialog types # TODO: Implement all dialog types
...@@ -366,4 +373,4 @@ class NxDialogProgram(object): ...@@ -366,4 +373,4 @@ class NxDialogProgram(object):
sys.exit(EXIT_FAILURE) sys.exit(EXIT_FAILURE)
NxDialogProgram().Main() NxDialogProgram().main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment