lightning: channel details popup
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
import binascii
|
import binascii
|
||||||
from kivy.lang import Builder
|
from kivy.lang import Builder
|
||||||
from kivy.factory import Factory
|
from kivy.factory import Factory
|
||||||
|
from kivy.uix.popup import Popup
|
||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
import electrum.lightning as lightning
|
import electrum.lightning as lightning
|
||||||
from electrum_gui.kivy.uix.context_menu import ContextMenu
|
from electrum_gui.kivy.uix.context_menu import ContextMenu
|
||||||
|
|
||||||
Builder.load_string('''
|
Builder.load_string('''
|
||||||
<LightningChannelItem@CardItem>
|
<LightningChannelItem@CardItem>
|
||||||
|
details: {}
|
||||||
active: False
|
active: False
|
||||||
channelPoint: '<channelPoint not set>'
|
channelPoint: '<channelPoint not set>'
|
||||||
Label:
|
Label:
|
||||||
@@ -26,8 +28,59 @@ Builder.load_string('''
|
|||||||
height: self.minimum_height
|
height: self.minimum_height
|
||||||
spacing: '2dp'
|
spacing: '2dp'
|
||||||
padding: '12dp'
|
padding: '12dp'
|
||||||
|
|
||||||
|
<ChannelDetailsItem@BoxLayout>:
|
||||||
|
canvas.before:
|
||||||
|
Color:
|
||||||
|
rgba: 0.5, 0.5, 0.5, 1
|
||||||
|
Rectangle:
|
||||||
|
size: self.size
|
||||||
|
pos: self.pos
|
||||||
|
value: ''
|
||||||
|
Label:
|
||||||
|
text: root.value
|
||||||
|
text_size: self.size # this makes the text not overflow, but wrap
|
||||||
|
|
||||||
|
<ChannelDetailsRow@BoxLayout>:
|
||||||
|
keyName: ''
|
||||||
|
value: ''
|
||||||
|
ChannelDetailsItem:
|
||||||
|
value: root.keyName
|
||||||
|
size_hint_x: 0.5 # this makes the column narrower
|
||||||
|
|
||||||
|
# see https://blog.kivy.org/2014/07/wrapping-text-in-kivys-label/
|
||||||
|
ScrollView:
|
||||||
|
Label:
|
||||||
|
text: root.value
|
||||||
|
size_hint_y: None
|
||||||
|
text_size: self.width, None
|
||||||
|
height: self.texture_size[1]
|
||||||
|
|
||||||
|
<ChannelDetailsList@RecycleView>:
|
||||||
|
scroll_type: ['bars', 'content']
|
||||||
|
scroll_wheel_distance: dp(114)
|
||||||
|
bar_width: dp(10)
|
||||||
|
viewclass: 'ChannelDetailsRow'
|
||||||
|
RecycleBoxLayout:
|
||||||
|
default_size: None, dp(56)
|
||||||
|
default_size_hint: 1, None
|
||||||
|
size_hint_y: None
|
||||||
|
height: self.minimum_height
|
||||||
|
orientation: 'vertical'
|
||||||
|
spacing: dp(2)
|
||||||
|
|
||||||
|
<ChannelDetailsPopup@Popup>:
|
||||||
|
id: popuproot
|
||||||
|
data: []
|
||||||
|
ChannelDetailsList:
|
||||||
|
data: popuproot.data
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
class ChannelDetailsPopup(Popup):
|
||||||
|
def __init__(self, data, **kwargs):
|
||||||
|
super(ChanenlDetailsPopup,self).__init__(**kwargs)
|
||||||
|
self.data = data
|
||||||
|
|
||||||
class LightningChannelsDialog(Factory.Popup):
|
class LightningChannelsDialog(Factory.Popup):
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
super(LightningChannelsDialog, self).__init__()
|
super(LightningChannelsDialog, self).__init__()
|
||||||
@@ -35,13 +88,19 @@ class LightningChannelsDialog(Factory.Popup):
|
|||||||
self.app = app
|
self.app = app
|
||||||
self.context_menu = None
|
self.context_menu = None
|
||||||
|
|
||||||
|
def show_channel_details(self, obj):
|
||||||
|
p = Factory.ChannelDetailsPopup()
|
||||||
|
p.data = [{'keyName': key, 'value': str(obj.details[key])} for key in obj.details.keys()]
|
||||||
|
p.open()
|
||||||
|
|
||||||
def close_channel(self, obj):
|
def close_channel(self, obj):
|
||||||
print("asked to close channel", obj.channelPoint)
|
print("asked to close channel", obj.channelPoint)
|
||||||
lightning.lightningCall(self.app.wallet.network.lightningrpc, "closechannel")(*([obj.channelPoint] + (["--force"] if not obj.active else [])))
|
lightning.lightningCall(self.app.wallet.network.lightningrpc, "closechannel")(*([obj.channelPoint] + (["--force"] if not obj.active else [])))
|
||||||
|
|
||||||
def show_menu(self, obj):
|
def show_menu(self, obj):
|
||||||
self.hide_menu()
|
self.hide_menu()
|
||||||
self.context_menu = ContextMenu(obj, [("Close", self.close_channel)])
|
self.context_menu = ContextMenu(obj, [("Close", self.close_channel),
|
||||||
|
("Details", self.show_channel_details)])
|
||||||
self.ids.box.add_widget(self.context_menu)
|
self.ids.box.add_widget(self.context_menu)
|
||||||
|
|
||||||
def hide_menu(self):
|
def hide_menu(self):
|
||||||
@@ -76,6 +135,7 @@ class LightningChannelsDialog(Factory.Popup):
|
|||||||
print(i)
|
print(i)
|
||||||
item.channelPoint = i["channel_point"].split(":")[0]
|
item.channelPoint = i["channel_point"].split(":")[0]
|
||||||
item.active = i["active"]
|
item.active = i["active"]
|
||||||
|
item.details = i
|
||||||
channel_cards.add_widget(item)
|
channel_cards.add_widget(item)
|
||||||
else:
|
else:
|
||||||
self.app.show_info(res)
|
self.app.show_info(res)
|
||||||
|
|||||||
Reference in New Issue
Block a user