def value(self, path: str) -> None: """Set the current path. This calls the callback function.""" from app import tooltip self.callback(path) self._location = path tooltip.set_tooltip(self, path) self._text_var.set(self._truncate(path))
def make_widgets(self, master: 'CheckDetails'): if self.master is not None: # If we let items move between lists, the old widgets will become # orphaned! raise ValueError("Can't move Item objects between lists!") self.master = master self.check = ttk.Checkbutton( master.wid_frame, variable=self.state_var, onvalue=1, offvalue=0, takefocus=False, width=0, style='CheckDetails.TCheckbutton', command=self.master.update_allcheck, ) if self.locked: self.check.state(['disabled']) self.val_widgets = [] for value in self.values: wid = tk.Label( master.wid_frame, text=value, justify=tk.LEFT, anchor=tk.W, background='white', ) add_tooltip(wid) if self.hover_text: set_tooltip(wid, self.hover_text) wid.hover_override = True else: set_tooltip(wid) wid.hover_override = False if not self.locked: # Allow clicking on the row to toggle the checkbox wid.bind('<Enter>', self.hover_start, add=True) wid.bind('<Leave>', self.hover_stop, add=True) tk_tools.bind_leftclick(wid, self.row_click, add=True) wid.bind(tk_tools.EVENTS['LEFT_RELEASE'], self.row_unclick, add=True) self.val_widgets.append(wid) tk_tools.add_mousewheel(self.master.wid_canvas, self.check, *self.val_widgets)
def place(self, check_width, head_pos, y): """Position the widgets on the frame.""" self.check.place( x=0, y=y, width=check_width, height=ROW_HEIGHT, ) for text, widget, (x, width) in zip(self.values, self.val_widgets, head_pos): widget.place( x=x + check_width, y=y, width=width, height=ROW_HEIGHT, ) text = str(text) short_text = widget['text'] = truncate(text, width - 5) if not widget.hover_override: set_tooltip(widget, text if short_text != text else '') x += width
def refresh_counts(reload: bool = True) -> None: """Set the last-compile limit display.""" if reload: COMPILE_CFG.load() # Don't re-run the flash function if it's already on. run_flash = not (count_entity.should_flash or count_overlay.should_flash or count_brush.should_flash) for bar_var, name, default, tip_blurb in COUNT_CATEGORIES: value = COMPILE_CFG.get_int('Counts', name) if name == 'entity': # The in-engine entity limit is different to VBSP's limit # (that one might include prop_static, lights etc). max_value = default else: # Use or to ensure no divide-by-zero occurs.. max_value = COMPILE_CFG.get_int('Counts', 'max_' + name) or default # If it's hit the limit, make it continuously scroll to draw # attention to the bar. if value >= max_value: bar_var.should_flash = True else: bar_var.should_flash = False bar_var.set(100 * value / max_value) set_tooltip( UI['count_' + name], '{}/{} ({:.2%}):\n{}'.format( value, max_value, value / max_value, tip_blurb, )) if run_flash: flash_count()
def load_item_data(): """Refresh the window to use the selected item's data.""" global version_lookup item_data = selected_item.data for ind, pos in enumerate(SUBITEM_POS[len(selected_item.visual_subtypes)]): if pos == -1: wid['subitem', ind]['image'] = img.invis_square(64) else: wid['subitem', ind]['image'] = selected_item.get_icon( selected_item.visual_subtypes[pos]) wid['subitem', ind]['relief'] = 'flat' wid['subitem', pos_for_item(selected_sub_item.subKey)]['relief'] = 'raised' wid['author']['text'] = ', '.join(item_data.authors) wid['name']['text'] = selected_sub_item.name wid['ent_count']['text'] = item_data.ent_count or '??' wid['desc'].set_text( get_description( global_last=selected_item.item.glob_desc_last, glob_desc=selected_item.item.glob_desc, style_desc=item_data.desc, )) if optionWindow.DEV_MODE.get(): source = selected_item.data.source.replace("from", "\nfrom") wid['item_id'][ 'text'] = f'{source}\n-> {selected_item.id}:{selected_sub_item.subKey}' wid['item_id'].grid() else: wid['item_id'].grid_remove() if itemPropWin.can_edit(selected_item.properties()): wid['changedefaults'].state(['!disabled']) else: wid['changedefaults'].state(['disabled']) version_lookup = set_version_combobox(wid['variant'], selected_item) if selected_item.url is None: wid['moreinfo'].state(['disabled']) else: wid['moreinfo'].state(['!disabled']) tooltip.set_tooltip(wid['moreinfo'], selected_item.url) editor = item_data.editor has_timer = any(isinstance(prop, TimerDelay) for prop in editor.properties) if editor.has_prim_input(): if editor.has_sec_input(): set_sprite(SPR.INPUT, 'in_dual') # Real funnels work slightly differently. if selected_item.id.casefold() == 'item_tbeam': tooltip.set_tooltip( wid['sprite', SPR.INPUT], _('Excursion Funnels accept a on/off ' 'input and a directional input.')) else: set_sprite(SPR.INPUT, 'in_norm') else: set_sprite(SPR.INPUT, 'in_none') if editor.has_output(): if has_timer: set_sprite(SPR.OUTPUT, 'out_tim') else: set_sprite(SPR.OUTPUT, 'out_norm') else: set_sprite(SPR.OUTPUT, 'out_none') set_sprite(SPR.ROTATION, ROT_TYPES[editor.handle]) if editor.embed_voxels: set_sprite(SPR.COLLISION, 'space_embed') else: set_sprite(SPR.COLLISION, 'space_none') face_spr = "surf" if Surface.WALL not in editor.invalid_surf: face_spr += "_wall" if Surface.FLOOR not in editor.invalid_surf: face_spr += "_floor" if Surface.CEIL not in editor.invalid_surf: face_spr += "_ceil" if face_spr == "surf": # This doesn't seem right - this item won't be placeable at all... LOGGER.warning( "Item <{}> disallows all orientations. Is this right?", selected_item.id, ) face_spr += "_none" set_sprite(SPR.FACING, face_spr) # Now some special overrides for certain classes. if selected_item.id == "ITEM_CUBE": # Cubes - they should show info for the dropper. set_sprite(SPR.FACING, 'surf_ceil') set_sprite(SPR.INPUT, 'in_norm') set_sprite(SPR.COLLISION, 'space_embed') set_sprite(SPR.OUTPUT, 'out_none') set_sprite(SPR.ROTATION, 'rot_36') tooltip.set_tooltip( wid['sprite', SPR.ROTATION], SPRITE_TOOL['rot_36'] + _('This item can be rotated on the floor to face 360 ' 'degrees, for Reflection Cubes only.'), ) if editor.cls is ItemClass.GEL: # Reflection or normal gel.. set_sprite(SPR.FACING, 'surf_wall_ceil') set_sprite(SPR.INPUT, 'in_norm') set_sprite(SPR.COLLISION, 'space_none') set_sprite(SPR.OUTPUT, 'out_none') set_sprite(SPR.ROTATION, 'rot_paint') elif editor.cls is ItemClass.TRACK_PLATFORM: # Track platform - always embeds into the floor. set_sprite(SPR.COLLISION, 'space_embed')
def set_sprite(pos, sprite): """Set one of the property sprites to a value.""" widget = wid['sprite', pos] widget['image'] = img.spr(sprite) tooltip.set_tooltip(widget, SPRITE_TOOL.get(sprite, ''))