本文整理汇总了Python中network.Network.is_connected方法的典型用法代码示例。如果您正苦于以下问题:Python Network.is_connected方法的具体用法?Python Network.is_connected怎么用?Python Network.is_connected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.is_connected方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import is_connected [as 别名]
#.........这里部分代码省略.........
actions.append(menu_group.addAction(action))
action.setChecked(True if value == key else False)
action.triggered.connect(
lambda key=key: self.config_set('look', 'toolbar_icons', key))
menu.addActions(actions)
menu.exec_(self.mapToGlobal(event))
def _buffer_switch(self, buf_item):
"""Switch to a buffer."""
if buf_item:
buf = buf_item.active.buf
self.stacked_buffers.setCurrentWidget(buf.widget)
if buf.hot or buf.highlight:
self.buffer_hotlist_clear(buf.data["full_name"])
buf.widget.input.setFocus()
def buffer_hotlist_clear(self, full_name):
"""Set a buffer as read for the hotlist."""
buf = self.buffers[self._buffer_index("full_name", full_name)[0]]
self.notifier.clear_record(full_name)
if buf.pointer in self._hotlist:
buf.highlight = False
buf.hot = 0
self._hotlist.remove(buf.pointer)
self.switch_buffers.update_hot_buffers()
if self.network.server_version >= 1:
self.buffer_input(full_name, '/buffer set hotlist -1')
self.buffer_input(full_name, '/input set_unread_current_buffer')
else:
self.buffer_input('core.weechat', '/buffer ' + full_name)
def buffer_input(self, full_name, text):
"""Send buffer input to WeeChat."""
if self.network.is_connected():
if text[:6] == "/query":
nick = full_name.rsplit(".", 1)[0] + "." + text.split(" ")[-1]
self.requested_buffer_names.add(nick)
message = 'input %s %s\n' % (full_name, text)
self.network.send_to_weechat(message)
self.debug_display(0, '<==', message, forcecolor='#AA0000')
def open_preferences_dialog(self):
"""Open a dialog with preferences."""
self.preferences_dialog = PreferencesDialog('Preferences', self)
def save_connection(self):
"""Save connection configuration."""
if self.network:
options = self.network.get_options()
for option in options.keys():
self.config.set('relay', option, options[option])
def debug_display(self, *args, **kwargs):
"""Display a debug message."""
self.debug_lines.append((args, kwargs))
self.debug_lines = self.debug_lines[-DEBUG_NUM_LINES:]
if self.debug_dialog:
self.debug_dialog.chat.display(*args, **kwargs)
def open_debug_dialog(self):
"""Open a dialog with debug messages."""
if not self.debug_dialog:
self.debug_dialog = DebugDialog(self)
self.debug_dialog.input.textSent.connect(
self.debug_input_text_sent)
self.debug_dialog.finished.connect(self._debug_dialog_closed)
示例2: MainWindow
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import is_connected [as 别名]
#.........这里部分代码省略.........
toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
toolbar.addActions([self.actions['connect'],
self.actions['disconnect'],
self.actions['debug'],
self.actions['preferences'],
self.actions['about'],
self.actions['quit']])
self.buffers[0].widget.input.setFocus()
# open debug dialog
if self.config.getboolean('look', 'debug'):
self.open_debug_dialog()
# auto-connect to relay
if self.config.getboolean('relay', 'autoconnect'):
self.network.connect_weechat(self.config.get('relay', 'server'),
self.config.get('relay', 'port'),
self.config.getboolean('relay',
'ssl'),
self.config.get('relay', 'password'),
self.config.get('relay', 'lines'))
self.show()
def _buffer_switch(self, index):
"""Switch to a buffer."""
if index >= 0:
self.stacked_buffers.setCurrentIndex(index)
self.stacked_buffers.widget(index).input.setFocus()
def buffer_input(self, full_name, text):
"""Send buffer input to WeeChat."""
if self.network.is_connected():
message = 'input %s %s\n' % (full_name, text)
self.network.send_to_weechat(message)
self.debug_display(0, '<==', message, forcecolor='#AA0000')
def open_preferences_dialog(self):
"""Open a dialog with preferences."""
# TODO: implement the preferences dialog box
messages = ['Not yet implemented!',
'']
self.preferences_dialog = AboutDialog('Preferences', messages, self)
def save_connection(self):
"""Save connection configuration."""
if self.network:
options = self.network.get_options()
for option in options.keys():
self.config.set('relay', option, options[option])
def debug_display(self, *args, **kwargs):
"""Display a debug message."""
self.debug_lines.append((args, kwargs))
self.debug_lines = self.debug_lines[-DEBUG_NUM_LINES:]
if self.debug_dialog:
self.debug_dialog.chat.display(*args, **kwargs)
def open_debug_dialog(self):
"""Open a dialog with debug messages."""
if not self.debug_dialog:
self.debug_dialog = DebugDialog(self)
self.debug_dialog.input.textSent.connect(
self.debug_input_text_sent)
self.debug_dialog.finished.connect(self._debug_dialog_closed)
示例3: Daemon
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import is_connected [as 别名]
class Daemon(DaemonThread):
def __init__(self, config, fd):
DaemonThread.__init__(self)
self.config = config
if config.get("offline"):
self.network = None
else:
self.network = Network(config)
self.network.start()
self.gui = None
self.wallets = {}
# Setup server
cmd_runner = Commands(self.config, None, self.network)
host = config.get("rpchost", "localhost")
port = config.get("rpcport", 0)
server = SimpleJSONRPCServer((host, port), logRequests=False, requestHandler=RequestHandler)
os.write(fd, repr((server.socket.getsockname(), time.time())))
os.close(fd)
server.timeout = 0.1
for cmdname in known_commands:
server.register_function(getattr(cmd_runner, cmdname), cmdname)
server.register_function(self.run_cmdline, "run_cmdline")
server.register_function(self.ping, "ping")
server.register_function(self.run_daemon, "daemon")
server.register_function(self.run_gui, "gui")
self.server = server
def ping(self):
return True
def run_daemon(self, config):
sub = config.get("subcommand")
assert sub in ["start", "stop", "status"]
if sub == "start":
response = "Daemon already running"
elif sub == "status":
if self.network:
p = self.network.get_parameters()
response = {
"path": self.network.config.path,
"server": p[0],
"blockchain_height": self.network.get_local_height(),
"server_height": self.network.get_server_height(),
"nodes": self.network.get_interfaces(),
"connected": self.network.is_connected(),
"auto_connect": p[4],
"wallets": {k: w.is_up_to_date() for k, w in self.wallets.items()},
}
else:
response = "Daemon offline"
elif sub == "stop":
self.stop()
response = "Daemon stopped"
return response
def run_gui(self, config_options):
config = SimpleConfig(config_options)
if self.gui:
if hasattr(self.gui, "new_window"):
path = config.get_wallet_path()
self.gui.new_window(path, config.get("url"))
response = "ok"
else:
response = "error: current GUI does not support multiple windows"
else:
response = "Error: Electrum is running in daemon mode. Please stop the daemon first."
return response
def load_wallet(self, path, get_wizard=None):
if path in self.wallets:
wallet = self.wallets[path]
else:
storage = WalletStorage(path)
if get_wizard:
if storage.file_exists:
wallet = Wallet(storage)
action = wallet.get_action()
else:
action = "new"
if action:
wizard = get_wizard()
wallet = wizard.run(self.network, storage)
else:
wallet.start_threads(self.network)
else:
wallet = Wallet(storage)
wallet.start_threads(self.network)
if wallet:
self.wallets[path] = wallet
return wallet
def run_cmdline(self, config_options):
config = SimpleConfig(config_options)
cmdname = config.get("cmd")
cmd = known_commands[cmdname]
path = config.get_wallet_path()
wallet = self.load_wallet(path) if cmd.requires_wallet else None
# arguments passed to function
args = map(lambda x: config.get(x), cmd.params)
#.........这里部分代码省略.........