[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Move show_message() and input_prompt()
commit 3a2cf0e242d2ed7d8b88f04571aa471bdb1ceed7
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Thu Sep 15 13:12:58 2016 -0700
Move show_message() and input_prompt()
Last controller module functions with the exception of the starter.
---
nyx/__init__.py | 32 ++++++++++++++++++++++++++++++++
nyx/controller.py | 26 +-------------------------
nyx/menu.py | 7 +++----
nyx/panel/config.py | 11 +++++------
nyx/panel/graph.py | 7 +++----
nyx/panel/header.py | 5 ++---
nyx/panel/interpreter.py | 1 -
nyx/panel/log.py | 13 ++++++-------
8 files changed, 52 insertions(+), 50 deletions(-)
diff --git a/nyx/__init__.py b/nyx/__init__.py
index a22e9f3..db78bd4 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -9,6 +9,8 @@ Tor curses monitoring application.
nyx_interface - nyx interface singleton
tor_controller - tor connection singleton
+ show_message - shows a message to the user
+ input_prompt - prompts the user for text input
init_controller - initializes our connection to tor
expand_path - expands path with respect to our chroot
join - joins a series of strings up to a set length
@@ -141,6 +143,36 @@ def tor_controller():
return TOR_CONTROLLER
+def show_message(message = None, *attr, **kwargs):
+ """
+ Shows a message in our header.
+
+ :param str message: message to be shown
+ """
+
+ return nyx_interface().header_panel().show_message(message, *attr, **kwargs)
+
+
+def input_prompt(msg, initial_value = ''):
+ """
+ Prompts the user for input.
+
+ :param str message: prompt for user input
+ :param str initial_value: initial value of the prompt
+
+ :returns: **str** with the user input, this is **None** if the prompt is
+ canceled
+ """
+
+ header_panel = nyx_interface().header_panel()
+
+ header_panel.show_message(msg)
+ user_input = nyx.curses.str_input(len(msg), header_panel.get_height() - 1, initial_value)
+ header_panel.show_message()
+
+ return user_input
+
+
def init_controller(*args, **kwargs):
"""
Sets the Controller used by nyx. This is a passthrough for Stem's
diff --git a/nyx/controller.py b/nyx/controller.py
index 85cf1fe..980f44c 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -19,7 +19,7 @@ import stem
from stem.util import conf, log
from nyx.curses import BOLD
-from nyx import nyx_interface, tor_controller
+from nyx import nyx_interface, tor_controller, show_message
def conf_handler(key, value):
@@ -35,30 +35,6 @@ CONFIG = conf.config_dict('nyx', {
}, conf_handler)
-def show_message(message = None, *attr, **kwargs):
- return nyx_interface().header_panel().show_message(message, *attr, **kwargs)
-
-
-def input_prompt(msg, initial_value = ''):
- """
- Prompts the user for input.
-
- :param str message: prompt for user input
- :param str initial_value: initial value of the prompt
-
- :returns: **str** with the user input, this is **None** if the prompt is
- canceled
- """
-
- header_panel = nyx_interface().header_panel()
-
- header_panel.show_message(msg)
- user_input = nyx.curses.str_input(len(msg), header_panel.get_height() - 1, initial_value)
- header_panel.show_message()
-
- return user_input
-
-
def start_nyx():
"""
Main draw loop context.
diff --git a/nyx/menu.py b/nyx/menu.py
index 4d5f61c..83b8479 100644
--- a/nyx/menu.py
+++ b/nyx/menu.py
@@ -7,13 +7,12 @@ Menu for controlling nyx.
import functools
-import nyx.controller
import nyx.curses
import nyx.popups
import stem
-from nyx import nyx_interface, tor_controller
+from nyx import nyx_interface, tor_controller, show_message
from nyx.curses import RED, WHITE, NORMAL, BOLD, UNDERLINE
from stem.util import str_tools
@@ -205,7 +204,7 @@ def show_menu():
cursor = MenuCursor(menu.children[0].children[0])
with nyx.curses.CURSES_LOCK:
- nyx.controller.show_message('Press m or esc to close the menu.', BOLD)
+ show_message('Press m or esc to close the menu.', BOLD)
while not cursor.is_done:
selection_x = _draw_top_menubar(menu, cursor.selection)
@@ -213,7 +212,7 @@ def show_menu():
cursor.handle_key(nyx.curses.key_input())
nyx_interface().redraw()
- nyx.controller.show_message()
+ show_message()
def _make_menu():
diff --git a/nyx/panel/config.py b/nyx/panel/config.py
index d67afae..42271e2 100644
--- a/nyx/panel/config.py
+++ b/nyx/panel/config.py
@@ -9,7 +9,6 @@ and the resulting configuration files saved.
import curses
import os
-import nyx.controller
import nyx.curses
import nyx.panel
import nyx.popups
@@ -20,7 +19,7 @@ import stem.util.connection
from nyx.curses import WHITE, NORMAL, BOLD, HIGHLIGHT
from nyx.menu import MenuItem, Submenu
-from nyx import DATA_DIR, tor_controller
+from nyx import DATA_DIR, tor_controller, input_prompt, show_message
from stem.util import conf, enum, log, str_tools
@@ -194,9 +193,9 @@ class ConfigPanel(nyx.panel.Panel):
if nyx.popups.confirm_save_torrc(torrc):
try:
controller.save_conf()
- nyx.controller.show_message('Saved configuration to %s' % controller.get_info('config-file', '<unknown>'), HIGHLIGHT, max_wait = 2)
+ show_message('Saved configuration to %s' % controller.get_info('config-file', '<unknown>'), HIGHLIGHT, max_wait = 2)
except IOError as exc:
- nyx.controller.show_message('Unable to save configuration (%s)' % exc.strerror, HIGHLIGHT, max_wait = 2)
+ show_message('Unable to save configuration (%s)' % exc.strerror, HIGHLIGHT, max_wait = 2)
self.redraw()
@@ -211,7 +210,7 @@ class ConfigPanel(nyx.panel.Panel):
def _edit_selected_value():
selected = self._scroller.selection(self._get_config_options())
initial_value = selected.value() if selected.is_set() else ''
- new_value = nyx.controller.input_prompt('%s Value (esc to cancel): ' % selected.name, initial_value)
+ new_value = input_prompt('%s Value (esc to cancel): ' % selected.name, initial_value)
if new_value != initial_value:
try:
@@ -228,7 +227,7 @@ class ConfigPanel(nyx.panel.Panel):
tor_controller().set_conf(selected.name, new_value)
self.redraw()
except Exception as exc:
- nyx.controller.show_message('%s (press any key)' % exc, HIGHLIGHT, max_wait = 30)
+ show_message('%s (press any key)' % exc, HIGHLIGHT, max_wait = 30)
def _toggle_show_all():
self._show_all = not self._show_all
diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index 5266e3f..9c76673 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -18,13 +18,12 @@ import copy
import functools
import time
-import nyx.controller
import nyx.curses
import nyx.panel
import nyx.popups
import nyx.tracker
-from nyx import join, msg, nyx_interface, tor_controller
+from nyx import nyx_interface, tor_controller, msg, join, show_message
from nyx.curses import RED, GREEN, CYAN, BOLD, HIGHLIGHT
from nyx.menu import MenuItem, Submenu, RadioMenuItem, RadioGroup
from stem.control import EventType, Listener
@@ -475,7 +474,7 @@ class GraphPanel(nyx.panel.Panel):
with nyx.curses.CURSES_LOCK:
try:
while True:
- nyx.controller.show_message('press the down/up to resize the graph, and enter when done', BOLD)
+ show_message('press the down/up to resize the graph, and enter when done', BOLD)
key = nyx.curses.key_input()
if key.match('down'):
@@ -496,7 +495,7 @@ class GraphPanel(nyx.panel.Panel):
nyx_interface().redraw()
finally:
- nyx.controller.show_message()
+ show_message()
def set_paused(self, is_pause):
if is_pause:
diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index 06ffb90..394ef7b 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -16,14 +16,13 @@ import stem.util.proc
import stem.util.str_tools
import stem.util.system
-import nyx.controller
import nyx.curses
import nyx.panel
import nyx.popups
import nyx.tracker
from stem.util import conf, log
-from nyx import msg, nyx_interface, tor_controller
+from nyx import nyx_interface, tor_controller, msg, input_prompt
from nyx.curses import RED, GREEN, YELLOW, CYAN, WHITE, BOLD, HIGHLIGHT
@@ -132,7 +131,7 @@ class HeaderPanel(nyx.panel.DaemonPanel):
try:
controller.reconnect(chroot_path = CONFIG['tor.chroot'])
except stem.connection.MissingPassword:
- password = nyx.controller.input_prompt('Controller Password: ')
+ password = input_prompt('Controller Password: ')
if password:
controller.authenticate(password)
diff --git a/nyx/panel/interpreter.py b/nyx/panel/interpreter.py
index 4c63027..679cc30 100644
--- a/nyx/panel/interpreter.py
+++ b/nyx/panel/interpreter.py
@@ -7,7 +7,6 @@ information, tab completion, and other usability features.
"""
import curses
-import nyx.controller
import nyx.curses
import nyx.panel
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 2cc41c7..468d133 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -14,13 +14,12 @@ import time
import stem.response.events
import nyx.arguments
-import nyx.controller
import nyx.curses
import nyx.panel
import nyx.popups
import nyx.log
-from nyx import join, nyx_interface, tor_controller
+from nyx import nyx_interface, tor_controller, join, input_prompt, show_message
from nyx.curses import GREEN, YELLOW, WHITE, NORMAL, BOLD, HIGHLIGHT
from nyx.menu import MenuItem, Submenu, RadioMenuItem, RadioGroup
from stem.util import conf, log
@@ -118,7 +117,7 @@ class LogPanel(nyx.panel.DaemonPanel):
Prompts the user to add a new regex filter.
"""
- regex_input = nyx.controller.input_prompt('Regular expression: ')
+ regex_input = input_prompt('Regular expression: ')
if regex_input:
self._filter.select(regex_input)
@@ -139,14 +138,14 @@ class LogPanel(nyx.panel.DaemonPanel):
Lets user enter a path to take a snapshot, canceling if left blank.
"""
- path_input = nyx.controller.input_prompt('Path to save log snapshot: ')
+ path_input = input_prompt('Path to save log snapshot: ')
if path_input:
try:
self.save_snapshot(path_input)
- nyx.controller.show_message('Saved: %s' % path_input, HIGHLIGHT, max_wait = 2)
+ show_message('Saved: %s' % path_input, HIGHLIGHT, max_wait = 2)
except IOError as exc:
- nyx.controller.show_message('Unable to save snapshot: %s' % exc, HIGHLIGHT, max_wait = 2)
+ show_message('Unable to save snapshot: %s' % exc, HIGHLIGHT, max_wait = 2)
def _clear(self):
"""
@@ -220,7 +219,7 @@ class LogPanel(nyx.panel.DaemonPanel):
def _clear_log():
msg = 'This will clear the log. Are you sure (c again to confirm)?'
- key_press = nyx.controller.show_message(msg, BOLD, max_wait = 30)
+ key_press = show_message(msg, BOLD, max_wait = 30)
if key_press.match('c'):
self._clear()
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits