Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nx-libs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dimbor
nx-libs
Commits
2aa575f0
Commit
2aa575f0
authored
Feb 28, 2019
by
Ulrich Sibiller
Committed by
Mike Gabriel
Mar 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nxdialog: pylint improvements
parent
486cc6f5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
38 deletions
+45
-38
nxdialog
nxdialog/nxdialog
+45
-38
No files found.
nxdialog/nxdialog
View file @
2aa575f0
...
@@ -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
S
how
(
self
):
def
s
how
(
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
.
_MenuD
eactivate
)
menu
.
connect
(
"deactivate"
,
self
.
menu_d
eactivate
)
# 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
.
_ItemA
ctivate
,
DISCONNECT
)
disconnect
.
connect
(
"activate"
,
self
.
item_a
ctivate
,
DISCONNECT
)
menu
.
append
(
disconnect
)
menu
.
append
(
disconnect
)
terminate
=
gtk
.
MenuItem
(
label
=
TERMINATE_TEXT
)
terminate
=
gtk
.
MenuItem
(
label
=
TERMINATE_TEXT
)
terminate
.
connect
(
"activate"
,
self
.
_ItemA
ctivate
,
TERMINATE
)
terminate
.
connect
(
"activate"
,
self
.
item_a
ctivate
,
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
.
_PosM
enu
,
data
=
win
,
func
=
self
.
pos_m
enu
,
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
_ItemA
ctivate
(
self
,
_
,
result
):
def
item_a
ctivate
(
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
ShowYesNoSuspendB
ox
(
title
,
text
):
def
show_yes_no_suspend_b
ox
(
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
ShowYesNoB
ox
(
title
,
text
):
def
show_yes_no_b
ox
(
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
HandleSessionA
ction
(
agentpid
,
action
):
def
handle_session_a
ction
(
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
ShowSimpleMessageB
ox
(
icon
,
title
,
text
):
def
show_simple_message_b
ox
(
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
M
ain
(
self
):
def
m
ain
(
self
):
""" let's do something """
""" let's do something """
try
:
try
:
(
self
.
options
,
self
.
args
)
=
self
.
ParseA
rgs
()
(
self
.
options
,
self
.
args
)
=
self
.
parse_a
rgs
()
self
.
R
un
()
self
.
r
un
()
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
ParseA
rgs
(
self
):
def
parse_a
rgs
(
self
):
""" init parser """
""" init parser """
parser
=
optparse
.
OptionParser
(
option_list
=
self
.
BuildO
ptions
(),
parser
=
optparse
.
OptionParser
(
option_list
=
self
.
build_o
ptions
(),
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
R
un
(
self
):
def
r
un
(
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
:
HandleSessionA
ction
(
self
.
options
.
agentpid
,
handle_session_a
ction
(
self
.
options
.
agentpid
,
PullDownMenu
(
self
.
options
.
window
)
.
S
how
())
PullDownMenu
(
self
.
options
.
window
)
.
s
how
())
elif
dlgtype
==
DLG_TYPE_YESNOSUSPEND
:
elif
dlgtype
==
DLG_TYPE_YESNOSUSPEND
:
HandleSessionA
ction
(
self
.
options
.
agentpid
,
handle_session_a
ction
(
self
.
options
.
agentpid
,
ShowYesNoSuspendB
ox
(
message_caption
,
message_text
))
show_yes_no_suspend_b
ox
(
message_caption
,
message_text
))
elif
dlgtype
==
DLG_TYPE_YESNO
:
elif
dlgtype
==
DLG_TYPE_YESNO
:
HandleSessionA
ction
(
self
.
options
.
agentpid
,
handle_session_a
ction
(
self
.
options
.
agentpid
,
ShowYesNoB
ox
(
message_caption
,
message_text
))
show_yes_no_b
ox
(
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
()
.
M
ain
()
NxDialogProgram
()
.
m
ain
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment