Clients: copyable log labels
This commit is contained in:
parent
7c3ba3bc42
commit
824b932961
|
@ -1,9 +1,9 @@
|
|||
<TabbedPanel>
|
||||
tab_width: 200
|
||||
<Row@Label>:
|
||||
<SelectableLabel>:
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: 0.2, 0.2, 0.2, 1
|
||||
rgba: (.0, 0.9, .1, .3) if self.selected else (0.2, 0.2, 0.2, 1)
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
|
@ -13,10 +13,10 @@
|
|||
font_size: dp(20)
|
||||
markup: True
|
||||
<UILog>:
|
||||
viewclass: 'Row'
|
||||
viewclass: 'SelectableLabel'
|
||||
scroll_y: 0
|
||||
effect_cls: "ScrollEffect"
|
||||
RecycleBoxLayout:
|
||||
SelectableRecycleBoxLayout:
|
||||
default_size: None, dp(20)
|
||||
default_size_hint: 1, None
|
||||
size_hint_y: None
|
||||
|
|
40
kvui.py
40
kvui.py
|
@ -2,7 +2,6 @@ import os
|
|||
import logging
|
||||
import typing
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
os.environ["KIVY_NO_CONSOLELOG"] = "1"
|
||||
os.environ["KIVY_NO_FILELOG"] = "1"
|
||||
|
@ -11,6 +10,7 @@ os.environ["KIVY_LOG_ENABLE"] = "0"
|
|||
|
||||
from kivy.app import App
|
||||
from kivy.core.window import Window
|
||||
from kivy.core.clipboard import Clipboard
|
||||
from kivy.base import ExceptionHandler, ExceptionManager, Config, Clock
|
||||
from kivy.factory import Factory
|
||||
from kivy.properties import BooleanProperty, ObjectProperty
|
||||
|
@ -25,6 +25,10 @@ from kivy.uix.label import Label
|
|||
from kivy.uix.progressbar import ProgressBar
|
||||
from kivy.utils import escape_markup
|
||||
from kivy.lang import Builder
|
||||
from kivy.uix.recycleview.views import RecycleDataViewBehavior
|
||||
from kivy.uix.behaviors import FocusBehavior
|
||||
from kivy.uix.recycleboxlayout import RecycleBoxLayout
|
||||
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
|
||||
|
||||
import Utils
|
||||
from NetUtils import JSONtoTextParser, JSONMessagePart
|
||||
|
@ -140,6 +144,36 @@ class ContainerLayout(FloatLayout):
|
|||
pass
|
||||
|
||||
|
||||
class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
|
||||
RecycleBoxLayout):
|
||||
""" Adds selection and focus behaviour to the view. """
|
||||
|
||||
|
||||
class SelectableLabel(RecycleDataViewBehavior, Label):
|
||||
""" Add selection support to the Label """
|
||||
index = None
|
||||
selected = BooleanProperty(False)
|
||||
|
||||
def refresh_view_attrs(self, rv, index, data):
|
||||
""" Catch and handle the view changes """
|
||||
self.index = index
|
||||
return super(SelectableLabel, self).refresh_view_attrs(
|
||||
rv, index, data)
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
""" Add selection on touch down """
|
||||
if super(SelectableLabel, self).on_touch_down(touch):
|
||||
return True
|
||||
if self.collide_point(*touch.pos):
|
||||
return self.parent.select_with_touch(self.index, touch)
|
||||
|
||||
def apply_selection(self, rv, index, is_selected):
|
||||
""" Respond to the selection of items in the view. """
|
||||
self.selected = is_selected
|
||||
if is_selected:
|
||||
Clipboard.copy(self.text)
|
||||
|
||||
|
||||
class GameManager(App):
|
||||
logging_pairs = [
|
||||
("Client", "Archipelago"),
|
||||
|
@ -224,7 +258,11 @@ class GameManager(App):
|
|||
self.progressbar.value = 0
|
||||
|
||||
def command_button_action(self, button):
|
||||
if self.ctx.server:
|
||||
logging.getLogger("Client").info("/help for client commands and !help for server commands.")
|
||||
else:
|
||||
logging.getLogger("Client").info("/help for client commands and once you are connected, "
|
||||
"!help for server commands.")
|
||||
|
||||
def connect_button_action(self, button):
|
||||
if self.ctx.server:
|
||||
|
|
Loading…
Reference in New Issue