Skip to content

Commit

Permalink
rename item._name to item.objName, and more Private member accessed
Browse files Browse the repository at this point in the history
… fixes
  • Loading branch information
ilius committed Mar 1, 2024
1 parent d8c0772 commit 66e40b2
Show file tree
Hide file tree
Showing 27 changed files with 93 additions and 94 deletions.
4 changes: 2 additions & 2 deletions natz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, tz):
if os.sep == "\\":
self._name = tz.tzname(datetime.datetime.now())
else:
parts = tz._filename.split("/")
parts = tz._filename.split("/") # noqa: SLF001
self._name = "/".join(parts[-2:])

def __str__(self):
Expand Down Expand Up @@ -79,7 +79,7 @@ def gettz(*args, **kwargs) -> "TimeZone | None":
log.error(f"failed to detect timezone: {args} {kwargs}")
tzErrCount += 1
return defaultTZ
if tz._filename.lstrip("/") == "etc/localtime":
if tz._filename.lstrip("/") == "etc/localtime": # noqa: SLF001
tz = readEtcLocaltime()
if tz is None:
if tzErrCount < 5:
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ lint.select = [
# To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration.

lint.ignore = [
"PYI034", # py3.11: `__iadd__` methods in classes like `SqEntryList` usually return `self` at runtime
"INT001", # f-string is resolved before function call; consider `_("string %s") % arg`
"PERF203", # `try`-`except` within a loop incurs performance overhead
"RUF001", # String contains ambiguous `٠` (ARABIC-INDIC DIGIT ZERO). Did you mean `.` (FULL STOP)
"RUF003", # Comment contains ambiguous `۰` (EXTENDED ARABIC-INDIC DIGIT ZERO). Did you mean `.` (FULL STOP)?
"SLF", # Private member accessed
"PYI034", # py3.11: `__iadd__` methods in classes like `SqEntryList` usually return `self` at runtime
"DTZ001", # The use of `datetime.datetime()` without `tzinfo` argument is not allowed
"DTZ005", # The use of `datetime.datetime.now()` without `tz` argument is not allowed
"PGH003", # Use specific rule codes when ignoring type issues

"PT027", # Use `pytest.raises` instead of unittest-style `assertRaises`, why?
"PD011", # Use `.to_numpy()` instead of `.values`, WTF?
"ICN001", # `tkinter` should be imported as `tk`, WTF?
Expand Down Expand Up @@ -169,6 +167,7 @@ lint.unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
"scal3/account/google.py",
"scal3/import_config_2to3.py",
"scal3/ui_gtk/import_config_2to3.py",
"libs",
Expand Down
4 changes: 2 additions & 2 deletions scal3/ui_gtk/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(
) -> None:
ud.CalObjType.__init__(self)
self.enable = False
self._name = name
self.objName = name
self.desc = desc
self.moduleName = ".".join([pkg, name])
self.customizable = customizable
Expand Down Expand Up @@ -110,7 +110,7 @@ def initVars(self) -> None:
log.exception("")

def getItemsData(self) -> list[tuple[str, bool]]:
return [(item._name, item.enable) for item in self.items]
return [(item.objName, item.enable) for item in self.items]

def updateVars(self) -> None:
for item in self.items:
Expand Down
10 changes: 5 additions & 5 deletions scal3/ui_gtk/customize_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ def newItemList(
continue
if item.hasOptions:
anyItemHasOptions = True
if not item._name:
raise ValueError(f"{item._name = }")
if not item.objName:
raise ValueError(f"{item.objName = }")
model.append(
[
item.enable,
parentPagePath + "." + item._name,
parentPagePath + "." + item.objName,
item.desc,
self.itemPixbuf(item),
],
Expand Down Expand Up @@ -359,7 +359,7 @@ def addPageObj(self, page):
pagePath = page.pagePath
title = page.pageTitle
item = page.pageItem
log.debug(f"addPageObj: {page.pagePath=}, {page.pageParent=}, {item._name=}")
log.debug(f"addPageObj: {page.pagePath=}, {page.pageParent=}, {item.objName=}")

if self.stack.hasPage(pagePath):
return
Expand Down Expand Up @@ -414,7 +414,7 @@ def _addPage(
item = parentItem.items[itemIndex]

title = item.desc
if parentItem._name != "mainWin":
if parentItem.objName != "mainWin":
title = title + " - " + parentItem.desc

page = StackPage()
Expand Down
2 changes: 1 addition & 1 deletion scal3/ui_gtk/day_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@


class DayCal(gtk.DrawingArea, CalBase):
_name = "dayCal"
objName = "dayCal"
desc = _("Day Calendar")
itemListCustomizable = False
backgroundColorParam = ""
Expand Down
4 changes: 2 additions & 2 deletions scal3/ui_gtk/day_cal_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def popupMenuOnButtonPress(self, _obj, gevent):

@registerSignals
class DayCalWindow(gtk.Window, ud.BaseCalObj):
_name = "dayCalWin"
objName = "dayCalWin"
desc = _("Day Calendar Window")

def __init__(self):
Expand All @@ -289,7 +289,7 @@ def __init__(self):
self.stick()
###
self._widget = DayCalWindowWidget(self)
self._widget._window = self
self._widget._window = self # noqa: SLF001

self.connect("key-press-event", self._widget.onKeyPress)
self.connect("delete-event", self.onDeleteEvent)
Expand Down
8 changes: 4 additions & 4 deletions scal3/ui_gtk/day_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@registerSignals
class AllDateLabelsVBox(gtk.Box, ud.BaseCalObj):
_name = "allDateLabels"
objName = "allDateLabels"
desc = _("Dates")

def __init__(self):
Expand Down Expand Up @@ -64,7 +64,7 @@ def onDateChange(self, *a, **ka):

@registerSignals
class PluginsTextView(gtk.TextView, ud.BaseCalObj):
_name = "pluginsText"
objName = "pluginsText"
desc = _("Plugins Text")

def __init__(self):
Expand All @@ -83,7 +83,7 @@ def onDateChange(self, *a, **ka):

@registerSignals
class DayInfoJulianDayHBox(gtk.Box, ud.BaseCalObj):
_name = "jd"
objName = "jd"
desc = _("Julian Day Number")

def __init__(self):
Expand All @@ -105,7 +105,7 @@ def onDateChange(self, *a, **ka):

@registerSignals
class DayInfoDialog(gtk.Dialog, ud.BaseCalObj):
_name = "dayInfo"
objName = "dayInfo"
desc = _("Day Info")

def __init__(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion scal3/ui_gtk/event/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(self, parent):

@registerSignals
class EventManagerDialog(gtk.Dialog, MyDialog, ud.BaseCalObj): # FIXME
_name = "eventMan"
objName = "eventMan"
desc = _("Event Manager")

def onShow(self, widget: gtk.Widget) -> None:
Expand Down
4 changes: 2 additions & 2 deletions scal3/ui_gtk/event/occurrence_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

@registerSignals
class DayOccurrenceView(gtk.TextView, CustomizableCalObj):
_name = "eventDayView"
objName = "eventDayView"
desc = _("Events of Day")
itemListCustomizable = False

Expand Down Expand Up @@ -508,7 +508,7 @@ def addExtraMenuItems(self, menu):
class LimitedHeightDayOccurrenceView(gtk.ScrolledWindow, CustomizableCalObj):
itemListCustomizable = False
optionsPageSpacing = 20
_name = DayOccurrenceView._name
objName = DayOccurrenceView.objName
desc = DayOccurrenceView.desc

def __init__(self, **kwargs):
Expand Down
14 changes: 7 additions & 7 deletions scal3/ui_gtk/gtk_ud.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CalObjType(Object):

@registerSignals
class BaseCalObj(CalObjType):
_name = ""
objName = ""
desc = ""
loaded = True
customizable = False
Expand All @@ -104,8 +104,8 @@ def onConfigChange(self, sender=None, toParent=True):
if sender is None:
sender = self
log.debug(
f"onConfigChange: name={self._name}, toParent={toParent}, "
f"sender={sender._name if sender else sender}",
f"onConfigChange: name={self.objName}, toParent={toParent}, "
f"sender={sender.objName if sender else sender}",
)
if toParent:
self.emit("config-change")
Expand All @@ -119,8 +119,8 @@ def onDateChange(self, sender=None, toParent=True):
if sender is None:
sender = self
log.debug(
f"onDateChange: name={self._name}, toParent={toParent}, "
f"sender={sender._name if sender else sender}",
f"onDateChange: name={self.objName}, toParent={toParent}, "
f"sender={sender.objName if sender else sender}",
)
if toParent:
self.emit("date-change")
Expand All @@ -136,7 +136,7 @@ def onEnableCheckClick(self):

def __getitem__(self, key):
for item in self.items:
if item._name == key:
if item.objName == key:
return item
return None

Expand Down Expand Up @@ -177,7 +177,7 @@ def showHide(self):


class IntegatedWindowList(BaseCalObj):
_name = "windowList"
objName = "windowList"
desc = "Window List"

def __init__(self):
Expand Down
16 changes: 8 additions & 8 deletions scal3/ui_gtk/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
raise ValueError("vertical= argument is missing")
if expand is None:
raise ValueError("expand= argument is missing")
self._name = name
self.objName = name
self.desc = desc
self.enableParam = enableParam
self.vertical = vertical
Expand Down Expand Up @@ -129,13 +129,13 @@ def set_visible(self, visible: bool) -> None:
pass

def getOptionsButtonBox(self):
# log.debug(f"WinLayoutObj: getOptionsButtonBox: name={self._name}")
# log.debug(f"WinLayoutObj: getOptionsButtonBox: name={self.objName}")
if self.optionsButtonBox is not None:
return self.optionsButtonBox
item = self.getWidget()
page = StackPage()
page.pageWidget = VBox(spacing=item.optionsPageSpacing)
page.pageName = item._name
page.pageName = item.objName
page.pageTitle = item.desc
pageLabel = self.desc
if not item.enable:
Expand Down Expand Up @@ -236,18 +236,18 @@ def onConfigChange(self, *args, **kwargs):
box.remove(child)
itemNames = []
for item in self.items:
itemNames.append(item._name)
itemNames.append(item.objName)
if item.loaded:
pack(box, item.getWidget(), item.expand, item.expand)
item.showHide()
setattr(ui, self.itemsParam, itemNames)

def setItemsOrder(self, itemNames):
itemByName = {item._name: item for item in self.items}
itemByName = {item.objName: item for item in self.items}
self.items = [itemByName[name] for name in itemNames]

def getOptionsButtonBox(self):
# log.debug(f"WinLayoutBox: getOptionsButtonBox: name={self._name}")
# log.debug(f"WinLayoutBox: getOptionsButtonBox: name={self.objName}")
if self.optionsButtonBox is not None:
return self.optionsButtonBox

Expand Down Expand Up @@ -324,8 +324,8 @@ def getSubPages(self):
for page in item.getSubPages():
if not page.pageName:
raise ValueError(f"pageName empty, pagePath={page.pagePath}")
page.pageParent = self._name
page.pagePath = self._name + "." + page.pageName
page.pageParent = self.objName
page.pagePath = self.objName + "." + page.pageName
subPages.append(page)
self.subPages = subPages
return subPages
6 changes: 3 additions & 3 deletions scal3/ui_gtk/mainwin_items/labelBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, calType, active=0):
BaseLabel.__init__(self)
self.get_style_context().add_class(self.styleClass)
###
self._name = f"monthLabel({calType})"
self.objName = f"monthLabel({calType})"
# self.set_border_width(1)#???????????
self.initVars()
self.calType = calType
Expand Down Expand Up @@ -382,7 +382,7 @@ def getCSS() -> str:

def __init__(self, calType, **kwargs):
IntLabel.__init__(self, **kwargs)
self._name = f"yearLabel({calType})"
self.objName = f"yearLabel({calType})"
self.initVars()
self.calType = calType
###
Expand Down Expand Up @@ -512,7 +512,7 @@ def onFontConfigChange(self):

@registerSignals
class CalObj(gtk.Box, CustomizableCalObj):
_name = "labelBox"
objName = "labelBox"
desc = _("Year & Month Labels")
itemListCustomizable = False
hasOptions = True
Expand Down
8 changes: 4 additions & 4 deletions scal3/ui_gtk/mainwin_items/monthCal.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

@registerSignals
class CalObj(gtk.DrawingArea, CalBase):
_name = "monthCal"
objName = "monthCal"
desc = _("Month Calendar")
expand = True
itemListCustomizable = False
Expand Down Expand Up @@ -154,9 +154,9 @@ def __init__(self, win):
self.initCal()
self.pagePath = ".".join(
[
win._name,
win.mainVBox._name,
self._name,
win.objName,
win.mainVBox.objName,
self.objName,
],
)
######################
Expand Down
2 changes: 1 addition & 1 deletion scal3/ui_gtk/mainwin_items/monthPBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@registerSignals
class CalObj(gtk.Frame, CustomizableCalObj):
_name = "monthPBar"
objName = "monthPBar"
desc = _("Month Progress Bar")
itemListCustomizable = False
hasOptions = True
Expand Down
2 changes: 1 addition & 1 deletion scal3/ui_gtk/mainwin_items/seasonPBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@registerSignals
class CalObj(gtk.Frame, CustomizableCalObj):
_name = "seasonPBar"
objName = "seasonPBar"
desc = _("Season Progress Bar")
itemListCustomizable = False

Expand Down
4 changes: 2 additions & 2 deletions scal3/ui_gtk/mainwin_items/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class CalObj(CustomizableToolBox):
continuousClick=False,
),
]
defaultItemsDict = {item._name: item for item in defaultItems}
defaultItemsDict = {item.objName: item for item in defaultItems}

def __init__(self, win):
self.win = win
Expand All @@ -143,7 +143,7 @@ def __init__(self, win):
)
if not ud.mainToolbarData["items"]:
ud.mainToolbarData["items"] = [
(item._name, True) for item in self.defaultItems
(item.objName, True) for item in self.defaultItems
]
else:
currentNames = {item[0] for item in ud.mainToolbarData["items"]}
Expand Down
Loading

0 comments on commit 66e40b2

Please sign in to comment.