def show_file(self, _type, _file_path, _file_name, _chat_window_id): _chat_window = None _chat_scroll = self.ids.chat_scroll if _chat_window_id == self.member_list_current._id: _chat_window = _chat_scroll.children[0] else: _chat_window = self.chat_record.setdefault(_chat_window_id, None) if _chat_window is None: _chat_window = StackLayout(orientation='tb-lr', size_hint=[1, None]) _chat_window.width = _chat_scroll.width _chat_window.height = 0 _label_left = Label() _button_main = Button(text=_file_name) _button_main.filepath = _file_path # _label_main.bind(on_touch_down=self.zoom_img) _label_right = Label() _pos_x_hint_main = [0.7, None] if _type == 'receive': _pos_x_hint_left = [0.05, None] _pos_x_hint_right = [0.25, None] elif _type == 'send': _pos_x_hint_left = [0.25, None] _pos_x_hint_right = [0.05, None] _label_left.size_hint = _pos_x_hint_left _button_main.size_hint = _pos_x_hint_main _label_right.size_hint = _pos_x_hint_right _box = BoxLayout(size_hint=[1, None]) _box.height = _button_main.height + 30 _box.add_widget(_label_left) _box.add_widget(_button_main) _box.add_widget(_label_right) _chat_window.add_widget(_box) if _chat_window_id is None: # _chat_scroll.scroll_y = 0 self.chat_window_height = self.chat_window_height + _box.height _chat_window.height = self.chat_window_height + 30 else: _chat_window.height = _chat_window.height + _box.height self.chat_record.update({_chat_window_id: _chat_window}) pass
def search_contact_setp2(self, _result_friend, _result_room): _main = BoxLayout() _popup = Popup(title='搜索结果', title_font=cn_font_1) # 显示好友搜索结果 _scroll_friends = ScrollView(size_hint=[1, 1]) _box_friends = StackLayout(spacing=[5, 5], size_hint=[1, None]) for _result_name, _result_value in _result_friend.items(): _btn = Button(text=_result_name, font_name=cn_font_1, size_hint=[0.25, None]) _btn._id = _result_value['username'] _btn.bind(on_release=partial(self.search_result_choose, _popup)) _box_friends.add_widget(_btn) _scroll_friends.add_widget(_box_friends) _box_friends.height = self.height / 9 * (int(len(_result_friend) / 4) + 1) _scroll_friends.height = self.height * 0.8 # 显示群组搜索结果 _scroll_rooms = ScrollView(size_hint=[1, 1]) _box_rooms = StackLayout(spacing=[5, 5], size_hint=[1, None]) for _result_name, _result_value in _result_room.items(): _btn = Button(text=_result_name, font_name=cn_font_1, size_hint=[0.25, None]) _btn._id = _result_value['username'] _btn.bind(on_release=partial(self.search_result_choose, _popup)) _box_rooms.add_widget(_btn) _scroll_rooms.add_widget(_box_rooms) _box_rooms.height = self.height / 9 * (int(len(_result_room) / 4) + 1) _scroll_rooms.height = self.height * 0.8 _main.add_widget(_scroll_friends) _main.add_widget(_scroll_rooms) _popup.content = _main _popup.open()
def __init__(self, **kwargs): ModalView.__init__(self, size_hint=(.15, 1), pos_hint={'right': 1}, **kwargs) app = App.get_running_app() scroller = ScrollView(do_scroll_x=False) layout = StackLayout(padding=[dp(10)], size_hint_y=None) layout.height = layout.width * len(app.powerups.purchased) for powerup in app.powerups.purchased: if not isinstance(powerup, Powerup): continue if powerup.type == PowerupType.PLAY_CARD: if not app.loaded_deck.get_cards(app.powerups.cards()): continue layout.add_widget(UsablePowerupIcon(powerup=powerup, size_hint=(1, None))) scroller.add_widget(layout) self.add_widget(scroller)
def get_configuration_subpanel(self, prop, owner, key): layout = StackLayout(orientation='lr-tb', size_hint=(None, None), width=dc.col_width, height=20) clr_picker = ColorPicker() if (key in rvit.core.pars.keys()): current_color = rvit.core.pars[key] clr_picker.color = current_color def on_color(instance, value): prop.set(owner, list(instance.color)) rvit.core.pars[key] = list(instance.color) clr_picker.bind(color=on_color) layout.add_widget( Label(text=prop.name, size_hint=(1.0, None), height=dc.text_height)) layout.add_widget(clr_picker) layout.height = 550 return layout
def getConfigurationSubpanel(self): #subpanel = BoxLayout(size_hint=(1.0, None), height=(40)) if isinstance(self.prop, ColorProperty): subpanel = self.prop.get_configuration_subpanel( self.prop, self.owner, self.key) elif isinstance(self.prop, BoundsProperty): subpanel = self.prop.get_configuration_subpanel( self.prop, self.owner, self.key) elif isinstance(self.prop, OptionProperty): subpanel = StackLayout(size_hint=(None, None), width=dc.col_width, orientation='lr-tb') subpanel.add_widget( Label(text=self.prop.name, size_hint=(1.0, None), height=dc.text_height)) rows = float(np.ceil(len(self.prop.options) / 4)) + 1 for opt in self.prop.options: def setNewValue(_, new_value=''): self.prop.set(self.owner, new_value) rvit.core.pars[self.key] = new_value set_fn = partial(setNewValue, new_value=opt) btn = ToggleButton(text=opt, group=self.prop.name, on_press=set_fn, size=(100, dc.text_height), size_hint=(0.25, 1. / rows)) if self.prop.get(self.owner) == opt: btn.state = 'down' subpanel.add_widget(btn) subpanel.height = dc.text_height * rows elif isinstance(self.prop, StringProperty): subpanel = BoxLayout(size_hint=(None, None), width=dc.col_width, height=dc.text_height) #,minimum_height=350) def on_text(instance, value): self.prop.set(self.owner, value) rvit.core.pars[self.key] = value ti = TextInput(text=str(self.prop.get(self.owner)), multiline=False, height=40) subpanel.add_widget(ti) ti.bind(text=on_text) # elif isinstance(self.prop, BooleanProperty): # pass elif isinstance(self.prop, NumericProperty): subpanel = BoxLayout( size_hint=(None, None), #orientation='rl-tb', width=dc.col_width * 1.0, height=dc.text_height) def is_number(s): try: float(s) return True except ValueError: return False def on_text(instance, value): if (is_number(value)): value = float(value) self.prop.set(self.owner, value) rvit.core.pars[self.key] = value subpanel.add_widget( Label(text=str(self.prop.name), size_hint=(0.4, 1.0))) ti = TextInput(text=str(self.prop.get(self.owner)), size_hint=(0.6, 1.0)) subpanel.add_widget(ti) ti.bind(text=on_text) else: subpanel.add_widget( Label(text=str(self.prop.get(self.owner)), size_hint=(1.0, 1.0))) return subpanel
def show_label(self, _type, _text, _chat_window_id=None): # show_label can record to all chat,not only current chat _chat_window = None _chat_scroll = self.ids.chat_scroll if _chat_window_id == self.member_list_current._id: _chat_window = _chat_scroll.children[0] else: _chat_window = self.chat_record.setdefault(_chat_window_id, None) if _chat_window is None: _chat_window = StackLayout(orientation='tb-lr', size_hint=[1, None]) _chat_window.width = _chat_scroll.width _chat_window.height = 0 _label_left = Label() _label_main = ChatLabel(text=_text, font_name=cn_font_1) _label_right = Label() _pos_x_hint_left = [0, 0] _pos_x_hint_main = [0, 0] _pos_x_hint_right = [0, 0] while _pos_x_hint_main[0] == 0: if _type != 'send': time.sleep(1) else: _label_main.texture_update() # 通过kivy自身操作是texture_size不会自动更新,但外部调用也会更新,所以send操 / # 作时增加texture_update if _label_main.texture_size[0] >= _chat_window.width * 0.7: _label_main.text_size = [_chat_window.width * 0.7, None] _pos_x_hint_main = [0.7, None] else: _pos_x_hint_main = [ _label_main.texture_size[0] / _chat_window.width, None ] if _type == 'receive': _pos_x_hint_left = [0.05, None] _pos_x_hint_right = [ 1 - _pos_x_hint_left[0] - _pos_x_hint_main[0], None ] elif _type == 'send': _pos_x_hint_left = [1 - 0.05 - _pos_x_hint_main[0], None] _pos_x_hint_right = [0.05, None] _label_left.size_hint = _pos_x_hint_left _label_main.size_hint = _pos_x_hint_main _label_right.size_hint = _pos_x_hint_right _box = BoxLayout(size_hint=[1, None]) _box.height = _label_main.texture_size[1] + 50 _box.add_widget(_label_left) _box.add_widget(_label_main) _box.add_widget(_label_right) _chat_window.add_widget(_box) if _chat_window_id is None: # _chat_scroll.scroll_y = 0 self.chat_window_height = self.chat_window_height + _box.height _chat_window.height = self.chat_window_height else: _chat_window.height = _chat_window.height + _box.height self.chat_record.update({_chat_window_id: _chat_window}) pass
def show_img(self, _type, _img_path, _chat_window_id): _chat_window = None _chat_scroll = self.ids.chat_scroll if _chat_window_id == self.member_list_current._id: _chat_window = _chat_scroll.children[0] else: _chat_window = self.chat_record.setdefault(_chat_window_id, None) if _chat_window is None: _chat_window = StackLayout(orientation='tb-lr', size_hint=[1, None]) _chat_window.width = _chat_scroll.width _chat_window.height = 0 _label_left = Label() _label_main = AsyncImage(source=_img_path, nocache=True) # _label_main.reload() _label_main.bind(on_touch_down=self.zoom_img) _label_main.size = [ _label_main.norm_image_size[0], _label_main.norm_image_size[1] ] _label_right = Label() _pos_x_hint_left = [0, 0] _pos_x_hint_main = [0, 0] _pos_x_hint_right = [0, 0] while _pos_x_hint_main[0] == 0: if _label_main.texture_size[0] >= _chat_window.width * 0.7: _pos_x_hint_main = [0.7, None] else: _pos_x_hint_main = [ _label_main.texture_size[0] / _chat_window.width, None ] if _type == 'receive': _pos_x_hint_left = [0.05, None] _pos_x_hint_right = [ 1 - _pos_x_hint_left[0] - _pos_x_hint_main[0], None ] elif _type == 'send': _pos_x_hint_left = [1 - 0.05 - _pos_x_hint_main[0], None] _pos_x_hint_right = [0.05, None] elif _type == 'time': _pos_x_hint_left = [(1 - _pos_x_hint_main[0]) / 2, None] _pos_x_hint_right = _pos_x_hint_left _chat_window.last_msg_time = time.time() _label_left.size_hint = _pos_x_hint_left _label_main.size_hint = _pos_x_hint_main _label_right.size_hint = _pos_x_hint_right _box = BoxLayout(size_hint=[1, None]) _box.height = _label_main.texture_size[1] + 30 _box.add_widget(_label_left) _box.add_widget(_label_main) _box.add_widget(_label_right) _chat_window.add_widget(_box) if _chat_window_id is None: # _chat_scroll.scroll_y = 0 self.chat_window_height = self.chat_window_height + _box.height _chat_window.height = self.chat_window_height + 30 else: _chat_window.height = _chat_window.height + _box.height self.chat_record.update({_chat_window_id: _chat_window}) pass