Skip to content

Commit

Permalink
[BUGFIX] Fixed background blinking: stabilized theme
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Jan 13, 2022
1 parent ddc824b commit 4e992f0
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions ifl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
CC-BY: hasherezade, run via IDA Pro >= 7.0
"""
__VERSION__ = '1.4.2.2'
__VERSION__ = '1.4.3'
__AUTHOR__ = 'hasherezade'

PLUGIN_NAME = "IFL - Interactive Functions List"
Expand Down Expand Up @@ -51,11 +51,15 @@
# custom functions:
# --------------------------------------------------------------------------

# Theme
# Theme

def get_bg_color():
w = ida_kernwin.get_current_widget()
if not w:
return None
widget = ida_kernwin.PluginForm.FormToPyQtWidget(w)
if not widget:
return None
color = widget.palette().color(QtGui.QPalette.Background)
return color

Expand All @@ -64,20 +68,17 @@ def is_darker(color1, color2):
return False
return True

def is_dark_theme():
if is_darker(get_bg_color(), COLOR_HILIGHT_FUNC):
return False
return True

def color_to_val(color):
return (((color.red() << 8) | color.green()) << 8) | color.blue()

def get_theme():
theme = light_theme
if is_dark_theme():
theme = dark_theme
return theme

bgcolor = get_bg_color()
if bgcolor is None:
return None
if is_darker(bgcolor, COLOR_HILIGHT_FUNC):
return light_theme
return dark_theme

# Addressing

def rva_to_va(rva: int) -> int:
Expand Down Expand Up @@ -311,7 +312,7 @@ class TableModel_t(QtCore.QAbstractTableModel):
COL_IMPORT = 7
COL_COUNT = 8
header_names = ['Start', 'End', 'Name', 'Type', 'Args', 'Is referred by', 'Refers to', 'Imported?']

# private:

def _displayHeader(self, orientation: QtCore.Qt.Orientation, col: int) -> Optional[str]:
Expand Down Expand Up @@ -370,15 +371,17 @@ def _displayToolTip(self, row: int, col: int) -> str:
return ""

def _displayBackground(self, row: int, col: int) -> Any:
theme = get_theme()

curr_theme = get_theme()
if curr_theme is not None:
self.theme = curr_theme

func_info = self.function_info_list[row]
if col == self.COL_START or col == self.COL_END:
return QtGui.QColor(theme[0])
return QtGui.QColor(self.theme[0])
if col == self.COL_NAME:
if func_info.is_import:
return QtGui.QColor(theme[1])
return QtGui.QColor(theme[2])
return QtGui.QColor(self.theme[1])
return QtGui.QColor(self.theme[2])
return None

def _listRefs(self, refs_list: List[Tuple[int, int]]) -> str:
Expand All @@ -392,6 +395,7 @@ def _listRefs(self, refs_list: List[Tuple[int, int]]) -> str:
def __init__(self, function_info_list, parent=None, *args) -> None:
super(TableModel_t, self).__init__()
self.function_info_list = function_info_list
self.theme = light_theme

def isFollowable(self, col: int) -> bool:
if col == self.COL_START:
Expand Down Expand Up @@ -537,10 +541,12 @@ def _getAddrToFollow(self, row: int, col: int) -> int:
def _displayBackground(self, row: int, col: int) -> Any:
"""Retrieves a background color appropriate for the data.
"""

theme = get_theme()
curr_theme = get_theme()
if curr_theme is not None:
self.theme = curr_theme

if self.isFollowable(col):
return QtGui.QColor(theme[0])
return QtGui.QColor(self.theme[0])
return None

# public:
Expand All @@ -550,6 +556,7 @@ def __init__(self, function_info_list, is_refs_to=True, parent=None, *args) -> N
self.curr_index = (-1)
self.refs_list = []
self.is_refs_to = is_refs_to
self.theme = light_theme

def isFollowable(self, col: int) -> bool:
"""Is the address possible to follow in the disassembly view?
Expand Down Expand Up @@ -647,8 +654,8 @@ def _set_item_color(self, addr: int, color: int) -> None:
# set desired item color
set_color(addr, CIC_ITEM, color)

def _get_themed_color(self, color: int) -> int:
if is_dark_theme():
def _get_themed_color(self, color: int, theme: list) -> int:
if theme == dark_theme:
color_hilight = color_to_val(QtGui.QColor(color).darker(200))
else:
color_hilight = color
Expand All @@ -667,14 +674,19 @@ def __init__(self, dataManager, color_hilight, func_model, parent=None) -> None:

self.setMouseTracking(True)
self.setAutoFillBackground(True)
self.theme = light_theme

# Qt API
def currentChanged(self, current, previous) -> None:
index_data = self.get_index_data(current)
self.dataManager.setCurrentRva(index_data)

def hilight_addr(self, addr: int) -> None:
color_hilight = self._get_themed_color(self.color_hilight)
curr_theme = get_theme()
if curr_theme is not None:
self.theme = curr_theme

color_hilight = self._get_themed_color(self.color_hilight, self.theme)

if self.prev_addr != BADADDR:
self._set_item_color(self.prev_addr, self.color_normal)
Expand Down

0 comments on commit 4e992f0

Please sign in to comment.