debugwindow.py (4730B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\launchdarkly\debugwindow.py 2 import uthread2 3 from carbonui.control.window import Window 4 from eve.client.script.ui import eveColor 5 from eve.client.script.ui.control.eveScroll import Scroll 6 from eve.client.script.ui.control.eveLabel import Label 7 from carbonui.control.scrollentries import ScrollEntryNode, SE_GenericCore 8 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 9 from carbonui.control.button import Button 10 from carbonui import TextColor 11 import carbonui.const as uiconst 12 import launchdarkly 13 from featuremanagement.client.flag import get_poller 14 from player_messaging.client.ui_message import prompt_player_fsd_dialog 15 _headers = ['flag', 'callbacks', 'variation'] 16 _initialized_label_text = 'SDK Initialized: {}' 17 _ld_user_key_label_text = 'LD User Key: {}' 18 _user_attributes_label_text = 'Current Contexts: {}' 19 _last_log_label_text = 'Last Log: {}' 20 21 class LaunchDarklyDebugWindow(Window): 22 __guid__ = 'LaunchDarklyDebugWindow' 23 default_width = 600 24 default_height = 600 25 default_windowID = 'launchDarklyDebugWindow' 26 default_minSize = [default_width, default_height] 27 refresh_delay_seconds = 1.0 28 29 def refresh(self): 30 while not self.destroyed: 31 self.update_labels() 32 self.update_variations() 33 uthread2.Sleep(self.refresh_delay_seconds) 34 35 def ApplyAttributes(self, attributes): 36 Window.ApplyAttributes(self, attributes) 37 self.SetCaption('LaunchDarkly') 38 self.ld_initialized = Label(name='ld_initialized', parent=self.content, align=uiconst.TOTOP) 39 self.ld_user_key = Label(name='ld_user_key', parent=self.content, align=uiconst.TOTOP) 40 self.ld_user_attributes = Label(name='ld_user_attributes', parent=self.content, align=uiconst.TOTOP) 41 self.ld_last_log = Label(name='ld_last_log', parent=self.content, align=uiconst.TOTOP) 42 self.ld_evaluate_text = SingleLineEditText(name='ld_evaluate_text', parent=self.content, align=uiconst.TOTOP) 43 self.ld_evaluate_button = Button(name='ld_evaluate_button', parent=self.content, align=uiconst.TOTOP, label='Evaluate') 44 c = launchdarkly.get_client() 45 46 def evaluate_flag(flag_key): 47 result = c.json_variation_detail(key=str(flag_key), default_value='{}') 48 value, detail, reason = result 49 if not reason: 50 reason_kind = 'None' 51 else: 52 reason_kind = reason.kind() 53 message = 'Variation: {}<br/>Index: {}<br/>Reason: {}'.format(value.value(), detail.variation_index(), reason_kind) 54 prompt_player_fsd_dialog('CustomInfo', {'info': message}, modal=0) 55 56 self.ld_evaluate_button.SetFunc(lambda x: evaluate_flag(self.ld_evaluate_text.GetValue())) 57 self.ld_queue_text = SingleLineEditText(name='ld_queue_text', parent=self.content, align=uiconst.TOTOP) 58 self.ld_queue_button = Button(name='ld_queue_button', parent=self.content, align=uiconst.TOTOP, label='Queue Event') 59 60 def queue_event(event_name): 61 c.track(event_name) 62 prompt_player_fsd_dialog('CustomInfo', {'info': 'Queued event {}'.format(event_name)}, modal=0) 63 64 self.ld_queue_button.SetFunc(lambda x: queue_event(self.ld_queue_text.GetValue())) 65 self.ld_flush_button = Button(name='ld_flush_button', parent=self.content, align=uiconst.TOTOP, label='Flush') 66 self.ld_flush_button.SetFunc(lambda x: c.flush()) 67 self.variations = Scroll(id='variations', name='variations', parent=self.content, align=uiconst.TOALL) 68 uthread2.StartTasklet(self.refresh) 69 70 def update_labels(self): 71 c = launchdarkly.get_client() 72 initialized = c.initialized() 73 self.ld_initialized.text = _initialized_label_text.format(initialized) 74 if initialized: 75 self.ld_initialized.SetTextColor(TextColor.NORMAL) 76 else: 77 self.ld_initialized.SetTextColor(eveColor.DANGER_RED) 78 contexts = c.build_contexts() 79 self.ld_user_attributes.text = _user_attributes_label_text.format(contexts) 80 self.ld_user_key.text = _ld_user_key_label_text.format(c.eve_user_id) 81 self.ld_last_log.text = _last_log_label_text.format('Logs not implemented') 82 83 def update_variations(self): 84 variations = [] 85 for flag, variation in get_poller().flag_value.items(): 86 callbacks = len(get_poller().callbacks.get(flag)) 87 variations.append(ScrollEntryNode(decoClass=SE_GenericCore, id=flag, name=flag, label='{}<t>{}<t>{}'.format(flag, callbacks, variation))) 88 89 self.variations.Load(contentList=variations, headers=_headers)