Skip to content

profile_selector

Qt tools for startup.

LocalSelectionWidget

Bases: QWidget

Class that defines contents/logic of local launch tab.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
class LocalSelectionWidget(QWidget):
    """Class that defines contents/logic of local launch tab."""

    def __init__(
        self,
        dialog: ProfileDialog | None = None,
        parent: QWidget | None = None,
    ):
        super().__init__(parent=parent)

        self.dialog = dialog

        # Chosen profile
        self._profile = None
        # keep ref to settings
        self._settings = None

        layout = QVBoxLayout()

        layout.setAlignment(Qt.AlignmentFlag.AlignTop)

        self.lstProfiles = QListWidget()
        self.lstProfiles.setIconSize(QSize(16, 16))
        self.lstProfiles.setSpacing(2)
        self.lstProfiles.setContextMenuPolicy(
            Qt.ContextMenuPolicy.CustomContextMenu
        )
        self.lstProfiles.customContextMenuRequested.connect(
            self._on_profiles_context_menu
        )

        # forward signal upstairs
        def _confirm(*args: list[Any]) -> None:  # noqa: ARG001
            self.dialog.sig_confirm.emit()

        self.lstProfiles.itemActivated.connect(_confirm)
        layout.addWidget(self.lstProfiles)

        self.setLayout(layout)

    def populate_list(self, settings: ComfyLocalSettings) -> None:
        """Adds profiles to list from settings, with appropriate icons."""
        self.lstProfiles.clear()
        self._settings = settings
        for profile_name in settings.profiles:
            self._add_profile_to_list(settings.get(profile_name))

    def _add_profile_to_list(self, item: ComfyLocalProfile) -> None:
        """Perform sanity check on profile and add it to QListWidget."""
        text = item.name
        icon = None
        if not item.is_valid:
            icon = get_pixmap(icon_name="warning")
            list_item = QListWidgetItem(text)
            list_item.setIcon(icon)
        else:
            icon = get_pixmap(icon_name="create")
            list_item = QListWidgetItem(text)
            list_item.setIcon(icon)

        list_item.setData(Qt.ItemDataRole.UserRole, item)
        self.lstProfiles.addItem(list_item)

    def _on_profiles_context_menu(self, pos: QPoint) -> None:
        """Handle context menu for profiles."""
        item = self.lstProfiles.itemAt(pos)
        if not item:
            return

        profile: ComfyLocalProfile = item.data(Qt.ItemDataRole.UserRole)

        menu = QMenu(self)
        launch_action = menu.addAction(f"Launch ComfyUI with: {profile.name}")
        launch_action.triggered.connect(
            partial(self.dialog.confirm_commit_profile, profile)
        )

        menu.addSeparator()

        logs_action = menu.addAction("View logs...")
        logs_action.triggered.connect(partial(self.show_log, profile))

        debug_action = menu.addAction("Debug for all platforms...")
        debug_action.triggered.connect(partial(self.show_debug, profile))

        menu.exec(self.lstProfiles.mapToGlobal(pos))

    def show_log(self, profile: ComfyLocalProfile) -> None:
        """Show subwindow with host os debug info about the profile in it."""
        win = ProfileDebugDialog(self)
        win.log_profile_current_os(profile)
        win.exec()

    def show_debug(self, profile: ComfyLocalProfile) -> None:
        """Show subwindow with all os debug info about the profile in it."""
        win = ProfileDebugDialog(self)
        win.log_profile_all_os(profile)
        win.exec()

populate_list(settings)

Adds profiles to list from settings, with appropriate icons.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
218
219
220
221
222
223
def populate_list(self, settings: ComfyLocalSettings) -> None:
    """Adds profiles to list from settings, with appropriate icons."""
    self.lstProfiles.clear()
    self._settings = settings
    for profile_name in settings.profiles:
        self._add_profile_to_list(settings.get(profile_name))

show_debug(profile)

Show subwindow with all os debug info about the profile in it.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
271
272
273
274
275
def show_debug(self, profile: ComfyLocalProfile) -> None:
    """Show subwindow with all os debug info about the profile in it."""
    win = ProfileDebugDialog(self)
    win.log_profile_all_os(profile)
    win.exec()

show_log(profile)

Show subwindow with host os debug info about the profile in it.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
265
266
267
268
269
def show_log(self, profile: ComfyLocalProfile) -> None:
    """Show subwindow with host os debug info about the profile in it."""
    win = ProfileDebugDialog(self)
    win.log_profile_current_os(profile)
    win.exec()

ProfileDebugDialog

Bases: QDialog

Dialog for validation of settings.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
class ProfileDebugDialog(QDialog):
    """Dialog for validation of settings."""

    def __init__(self, parent: QWidget | None = None) -> None:
        """Sets up dialog.

        Doesn't add any messages.
        """
        super().__init__(parent=parent)
        self.setStyleSheet(load_stylesheet())
        self.setWindowTitle("Profile debug info")
        self.setMinimumWidth(420)

        layout = QVBoxLayout()

        layout.setAlignment(Qt.AlignmentFlag.AlignTop)

        layout.addWidget(QLabel("Log:"))

        self._lstLogs = QListWidget()
        self._lstLogs.setIconSize(QSize(16, 16))
        self._lstLogs.setSpacing(2)
        layout.addWidget(self._lstLogs)

        self.setLayout(layout)

    def log_profile_current_os(self, profile: ComfyLocalProfile) -> None:
        """Validation for profile (applies to host OS)."""
        validation = profile.validate_profile()
        errors = validation["errors"]
        logs = validation["logs"]

        os = profile.current_os

        self._lstLogs.clear()

        self._lstLogs.addItem(f"{os}, Profile: {profile.name}")

        for error in errors:
            icon = get_pixmap(icon_name="warning")
            list_item = QListWidgetItem(error)
            list_item.setIcon(icon)
            self._lstLogs.addItem(list_item)

        for log in logs:
            icon = get_pixmap(icon_name="create")
            list_item = QListWidgetItem(log)
            list_item.setIcon(icon)
            self._lstLogs.addItem(list_item)

        if not errors:
            icon = get_pixmap(icon_name="success")
            list_item = QListWidgetItem(f"{os}: Validated & usable!")
            list_item.setIcon(icon)
            self._lstLogs.addItem(list_item)

    def log_profile_remote(self, profile: ComfyRemoteProfile) -> None:
        """Validation for profile (applies to remote hosted site)."""
        validation = profile.validate_profile()
        errors = validation["errors"]
        logs = validation["logs"]

        self._lstLogs.clear()

        self._lstLogs.addItem(f"Remote Profile: {profile.name}")

        for error in errors:
            icon = get_pixmap(icon_name="warning")
            list_item = QListWidgetItem(error)
            list_item.setIcon(icon)
            self._lstLogs.addItem(list_item)

        for log in logs:
            icon = get_pixmap(icon_name="create")
            list_item = QListWidgetItem(log)
            list_item.setIcon(icon)
            self._lstLogs.addItem(list_item)

        if not errors:
            icon = get_pixmap(icon_name="success")
            list_item = QListWidgetItem(
                f"{profile.comfy_url}: Validated & usable!"
            )
            list_item.setIcon(icon)
            self._lstLogs.addItem(list_item)

    def log_profile_all_os(self, profile: ComfyLocalProfile) -> None:
        """Validation for profile (applies to all OS')."""
        os_list = ["win", "lin", "osx"]
        self._lstLogs.clear()
        for _os in os_list:
            validation = profile._validate_profile_for_os(_os)  # noqa : SLF001
            errors = validation["errors"]
            logs = validation["logs"]

            os = profile._map_internal_os_name(_os)  # noqa : SLF001

            self._lstLogs.addItem(f"{os}:\n{profile.name}")

            for error in errors:
                icon = get_pixmap(icon_name="warning")
                list_item = QListWidgetItem(error)
                list_item.setIcon(icon)
                self._lstLogs.addItem(list_item)

            for log in logs:
                icon = get_pixmap(icon_name="create")
                list_item = QListWidgetItem(log)
                list_item.setIcon(icon)
                self._lstLogs.addItem(list_item)

            if not errors:
                icon = get_pixmap(icon_name="success")
                list_item = QListWidgetItem(f"{os}: Validated & usable!")
                list_item.setIcon(icon)
                self._lstLogs.addItem(list_item)

__init__(parent=None)

Sets up dialog.

Doesn't add any messages.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
def __init__(self, parent: QWidget | None = None) -> None:
    """Sets up dialog.

    Doesn't add any messages.
    """
    super().__init__(parent=parent)
    self.setStyleSheet(load_stylesheet())
    self.setWindowTitle("Profile debug info")
    self.setMinimumWidth(420)

    layout = QVBoxLayout()

    layout.setAlignment(Qt.AlignmentFlag.AlignTop)

    layout.addWidget(QLabel("Log:"))

    self._lstLogs = QListWidget()
    self._lstLogs.setIconSize(QSize(16, 16))
    self._lstLogs.setSpacing(2)
    layout.addWidget(self._lstLogs)

    self.setLayout(layout)

log_profile_all_os(profile)

Validation for profile (applies to all OS').

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
def log_profile_all_os(self, profile: ComfyLocalProfile) -> None:
    """Validation for profile (applies to all OS')."""
    os_list = ["win", "lin", "osx"]
    self._lstLogs.clear()
    for _os in os_list:
        validation = profile._validate_profile_for_os(_os)  # noqa : SLF001
        errors = validation["errors"]
        logs = validation["logs"]

        os = profile._map_internal_os_name(_os)  # noqa : SLF001

        self._lstLogs.addItem(f"{os}:\n{profile.name}")

        for error in errors:
            icon = get_pixmap(icon_name="warning")
            list_item = QListWidgetItem(error)
            list_item.setIcon(icon)
            self._lstLogs.addItem(list_item)

        for log in logs:
            icon = get_pixmap(icon_name="create")
            list_item = QListWidgetItem(log)
            list_item.setIcon(icon)
            self._lstLogs.addItem(list_item)

        if not errors:
            icon = get_pixmap(icon_name="success")
            list_item = QListWidgetItem(f"{os}: Validated & usable!")
            list_item.setIcon(icon)
            self._lstLogs.addItem(list_item)

log_profile_current_os(profile)

Validation for profile (applies to host OS).

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
def log_profile_current_os(self, profile: ComfyLocalProfile) -> None:
    """Validation for profile (applies to host OS)."""
    validation = profile.validate_profile()
    errors = validation["errors"]
    logs = validation["logs"]

    os = profile.current_os

    self._lstLogs.clear()

    self._lstLogs.addItem(f"{os}, Profile: {profile.name}")

    for error in errors:
        icon = get_pixmap(icon_name="warning")
        list_item = QListWidgetItem(error)
        list_item.setIcon(icon)
        self._lstLogs.addItem(list_item)

    for log in logs:
        icon = get_pixmap(icon_name="create")
        list_item = QListWidgetItem(log)
        list_item.setIcon(icon)
        self._lstLogs.addItem(list_item)

    if not errors:
        icon = get_pixmap(icon_name="success")
        list_item = QListWidgetItem(f"{os}: Validated & usable!")
        list_item.setIcon(icon)
        self._lstLogs.addItem(list_item)

log_profile_remote(profile)

Validation for profile (applies to remote hosted site).

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
def log_profile_remote(self, profile: ComfyRemoteProfile) -> None:
    """Validation for profile (applies to remote hosted site)."""
    validation = profile.validate_profile()
    errors = validation["errors"]
    logs = validation["logs"]

    self._lstLogs.clear()

    self._lstLogs.addItem(f"Remote Profile: {profile.name}")

    for error in errors:
        icon = get_pixmap(icon_name="warning")
        list_item = QListWidgetItem(error)
        list_item.setIcon(icon)
        self._lstLogs.addItem(list_item)

    for log in logs:
        icon = get_pixmap(icon_name="create")
        list_item = QListWidgetItem(log)
        list_item.setIcon(icon)
        self._lstLogs.addItem(list_item)

    if not errors:
        icon = get_pixmap(icon_name="success")
        list_item = QListWidgetItem(
            f"{profile.comfy_url}: Validated & usable!"
        )
        list_item.setIcon(icon)
        self._lstLogs.addItem(list_item)

ProfileDialog

Bases: QDialog

Window that shows a list of profiles.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
class ProfileDialog(QDialog):
    """Window that shows a list of profiles."""

    sig_confirm = Signal()

    def __init__(self, parent: QWidget | None = None):
        """Initialize Local/Remote launch dialog."""
        super().__init__(parent)
        self.setStyleSheet(load_stylesheet())
        self.setWindowTitle("ComfyUI profile")
        self.setMinimumWidth(420)

        # Chosen profile
        self._profile = None
        # keep ref to settings
        self.settings_local = None
        self.settings_remote = None

        mainlayout = QVBoxLayout()

        mainlayout.setAlignment(Qt.AlignmentFlag.AlignTop)

        mainlayout.addWidget(QLabel("Select launch profile..."))

        self.tabs = QTabWidget()

        self.tab_local = LocalSelectionWidget(dialog=self)
        self.tab_remote = RemoteSelectionWidget(dialog=self)
        self.tabs.addTab(self.tab_local, "Local")
        self.tabs.addTab(self.tab_remote, "Remote")
        self.index_to_tab = [self.tab_local, self.tab_remote]

        self.__result = ProfileTypeEnum.UNDECIDED

        # dummy args for function signature related failure prevention
        def _button_confirm(*args: list[Any]) -> None:  # noqa: ARG001
            """Button confirm action."""
            tab: LocalSelectionWidget | RemoteSelectionWidget = (
                self.index_to_tab[self.tab_index]
            )
            profile = tab.lstProfiles.currentItem().data(
                Qt.ItemDataRole.UserRole
            )
            if profile:
                self.confirm_commit_profile(profile)

        self._btnConfirm = QPushButton("Select profile!")
        self._btnConfirm.setDefault(True)
        self._btnConfirm.clicked.connect(partial(_button_confirm))

        self.sig_confirm.connect(partial(_button_confirm))

        mainlayout.addWidget(self.tabs)
        mainlayout.addWidget(self._btnConfirm)
        self.setLayout(mainlayout)

    @property
    def tab_index(self) -> int:
        """Return tab index."""
        return self.tabs.currentIndex()

    @property
    def dialog_result(self) -> ProfileTypeEnum:
        """Return chosen profile."""
        return self.__result

    def populate_list(self, project_name: str | None = None) -> None:
        """Adds profiles to lists from settings, with appropriate icons."""
        self.settings_local = ComfyLocalSettings(project_name=project_name)
        self.settings_remote = ComfyRemoteSettings(project_name=project_name)
        self.tab_local.populate_list(self.settings_local)
        self.tab_remote.populate_list(self.settings_remote)

    @property
    def settings(self) -> ComfyLocalSettings | ComfyRemoteSettings:
        """Returns current relevant settings instance."""
        if self.tab_index == 0:
            return self.settings_local
        return self.settings_remote

    def confirm_profile(
        self,
        profile: ComfyLocalProfile | ComfyRemoteProfile,
    ) -> None:
        """Confirms profile choice, and closes the window."""
        self._profile = profile
        self.__result = ProfileDialog.profile_enum_from_profile(profile)
        self.accept()

    def confirm_commit_profile(
        self,
        profile: ComfyLocalProfile | ComfyRemoteProfile,
    ) -> None:
        """Confirms profile choice, and closes the window.

        Additionally commits the state for later recall.
        """
        self._profile = profile
        self.__result = ProfileDialog.profile_enum_from_profile(profile)

        self.settings.commit(self._profile)
        self.accept()

    @property
    def profile(self) -> ComfyLocalProfile | ComfyRemoteProfile:
        """Returns chosen profile."""
        return self._profile

    @staticmethod
    def profile_enum_from_profile(
        profile: ComfyLocalProfile | ComfyRemoteProfile,
    ) -> ProfileTypeEnum:
        """Return associated profile type with profile."""
        if isinstance(profile, ComfyLocalProfile):
            return ProfileTypeEnum.LOCAL
        if isinstance(profile, ComfyRemoteProfile):
            return ProfileTypeEnum.REMOTE
        return ProfileTypeEnum.UNDECIDED

dialog_result property

Return chosen profile.

profile property

Returns chosen profile.

settings property

Returns current relevant settings instance.

tab_index property

Return tab index.

__init__(parent=None)

Initialize Local/Remote launch dialog.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
def __init__(self, parent: QWidget | None = None):
    """Initialize Local/Remote launch dialog."""
    super().__init__(parent)
    self.setStyleSheet(load_stylesheet())
    self.setWindowTitle("ComfyUI profile")
    self.setMinimumWidth(420)

    # Chosen profile
    self._profile = None
    # keep ref to settings
    self.settings_local = None
    self.settings_remote = None

    mainlayout = QVBoxLayout()

    mainlayout.setAlignment(Qt.AlignmentFlag.AlignTop)

    mainlayout.addWidget(QLabel("Select launch profile..."))

    self.tabs = QTabWidget()

    self.tab_local = LocalSelectionWidget(dialog=self)
    self.tab_remote = RemoteSelectionWidget(dialog=self)
    self.tabs.addTab(self.tab_local, "Local")
    self.tabs.addTab(self.tab_remote, "Remote")
    self.index_to_tab = [self.tab_local, self.tab_remote]

    self.__result = ProfileTypeEnum.UNDECIDED

    # dummy args for function signature related failure prevention
    def _button_confirm(*args: list[Any]) -> None:  # noqa: ARG001
        """Button confirm action."""
        tab: LocalSelectionWidget | RemoteSelectionWidget = (
            self.index_to_tab[self.tab_index]
        )
        profile = tab.lstProfiles.currentItem().data(
            Qt.ItemDataRole.UserRole
        )
        if profile:
            self.confirm_commit_profile(profile)

    self._btnConfirm = QPushButton("Select profile!")
    self._btnConfirm.setDefault(True)
    self._btnConfirm.clicked.connect(partial(_button_confirm))

    self.sig_confirm.connect(partial(_button_confirm))

    mainlayout.addWidget(self.tabs)
    mainlayout.addWidget(self._btnConfirm)
    self.setLayout(mainlayout)

confirm_commit_profile(profile)

Confirms profile choice, and closes the window.

Additionally commits the state for later recall.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
147
148
149
150
151
152
153
154
155
156
157
158
159
def confirm_commit_profile(
    self,
    profile: ComfyLocalProfile | ComfyRemoteProfile,
) -> None:
    """Confirms profile choice, and closes the window.

    Additionally commits the state for later recall.
    """
    self._profile = profile
    self.__result = ProfileDialog.profile_enum_from_profile(profile)

    self.settings.commit(self._profile)
    self.accept()

confirm_profile(profile)

Confirms profile choice, and closes the window.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
138
139
140
141
142
143
144
145
def confirm_profile(
    self,
    profile: ComfyLocalProfile | ComfyRemoteProfile,
) -> None:
    """Confirms profile choice, and closes the window."""
    self._profile = profile
    self.__result = ProfileDialog.profile_enum_from_profile(profile)
    self.accept()

populate_list(project_name=None)

Adds profiles to lists from settings, with appropriate icons.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
124
125
126
127
128
129
def populate_list(self, project_name: str | None = None) -> None:
    """Adds profiles to lists from settings, with appropriate icons."""
    self.settings_local = ComfyLocalSettings(project_name=project_name)
    self.settings_remote = ComfyRemoteSettings(project_name=project_name)
    self.tab_local.populate_list(self.settings_local)
    self.tab_remote.populate_list(self.settings_remote)

profile_enum_from_profile(profile) staticmethod

Return associated profile type with profile.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
166
167
168
169
170
171
172
173
174
175
@staticmethod
def profile_enum_from_profile(
    profile: ComfyLocalProfile | ComfyRemoteProfile,
) -> ProfileTypeEnum:
    """Return associated profile type with profile."""
    if isinstance(profile, ComfyLocalProfile):
        return ProfileTypeEnum.LOCAL
    if isinstance(profile, ComfyRemoteProfile):
        return ProfileTypeEnum.REMOTE
    return ProfileTypeEnum.UNDECIDED

ProfileTypeEnum

Bases: Enum

Enum to pass to result of ProfileDialog for further scheduling.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
50
51
52
53
54
55
class ProfileTypeEnum(Enum):
    """Enum to pass to result of ProfileDialog for further scheduling."""

    UNDECIDED = 0
    LOCAL = 1
    REMOTE = 2

RemoteSelectionWidget

Bases: QWidget

Tab widget for Remote Profile selection.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
class RemoteSelectionWidget(QWidget):
    """Tab widget for Remote Profile selection."""

    def __init__(
        self,
        dialog: ProfileDialog | None = None,
        parent: QWidget | None = None,
    ):
        """Initialize dialog."""
        super().__init__(parent)

        # Chosen profile
        self._profile = None
        # keep ref to settings
        self._settings = None
        self.dialog = dialog

        layout = QVBoxLayout()

        layout.setAlignment(Qt.AlignmentFlag.AlignTop)

        self.lstProfiles = QListWidget()
        self.lstProfiles.setIconSize(QSize(16, 16))
        self.lstProfiles.setSpacing(2)
        self.lstProfiles.setContextMenuPolicy(
            Qt.ContextMenuPolicy.CustomContextMenu
        )
        self.lstProfiles.customContextMenuRequested.connect(
            self._on_profiles_context_menu
        )

        # dummy args for function signature related failure prevention
        def _confirm(*args: list[Any]) -> None:  # noqa: ARG001
            """Button confirm action."""
            self.dialog.sig_confirm.emit()

        self.lstProfiles.itemActivated.connect(_confirm)
        layout.addWidget(self.lstProfiles)

        self.setLayout(layout)

    def populate_list(self, settings: ComfyRemoteSettings) -> None:
        """Adds profiles to list from settings, with appropriate icons."""
        self.lstProfiles.clear()
        self._settings = settings
        for profile_name in settings.profiles:
            self._add_profile_to_list(settings.get(profile_name))

    def _add_profile_to_list(self, item: ComfyRemoteProfile) -> None:
        """Perform sanity check on profile and add it to QListWidget."""
        text = item.name
        icon = None

        icon = get_pixmap(icon_name="create")
        list_item = QListWidgetItem(text)
        list_item.setIcon(icon)

        def _validate() -> None:
            item.validate_profile(rerun=True)
            icon_valid = get_pixmap(icon_name="create")
            icon_err = get_pixmap(icon_name="warning")

            if item.is_valid:
                list_item.setIcon(icon_valid)
            else:
                list_item.setIcon(icon_err)

        Thread(target=_validate).start()

        list_item.setData(Qt.ItemDataRole.UserRole, item)
        self.lstProfiles.addItem(list_item)

    def _on_profiles_context_menu(self, pos: QPoint) -> None:
        """Handle context menu for profiles."""
        item = self.lstProfiles.itemAt(pos)
        if not item:
            return

        profile: ComfyRemoteProfile = item.data(Qt.ItemDataRole.UserRole)

        menu = QMenu(self)
        launch_action = menu.addAction(
            f"Connect to ComfyUI with: {profile.name}"
        )
        launch_action.triggered.connect(
            partial(self.dialog.confirm_commit_profile, profile)
        )

        # Disable diagnosis for now.
        # TODO(@sas): implement validation & diagnosis
        menu.addSeparator()

        ogs_action = menu.addAction("View logs...")
        ogs_action.triggered.connect(partial(self.show_log, profile))

        def _revalidate() -> None:
            profile.validate_profile(rerun=True)
            icon_valid = get_pixmap(icon_name="create")
            icon_err = get_pixmap(icon_name="warning")

            if profile.is_valid:
                item.setIcon(icon_valid)
            else:
                item.setIcon(icon_err)

        def _do_revalidate() -> None:
            Thread(target=_revalidate).start()

        revalidate_action = menu.addAction("Rerun validation...")
        revalidate_action.triggered.connect(_do_revalidate)

        menu.exec(self.lstProfiles.mapToGlobal(pos))

    def show_log(
        self, profile: ComfyRemoteSettings.ComfyRemoteProfile
    ) -> None:
        """Show subwindow with host os debug info about the profile in it."""
        win = ProfileDebugDialog(self)
        win.log_profile_remote(profile)
        win.exec()

__init__(dialog=None, parent=None)

Initialize dialog.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
def __init__(
    self,
    dialog: ProfileDialog | None = None,
    parent: QWidget | None = None,
):
    """Initialize dialog."""
    super().__init__(parent)

    # Chosen profile
    self._profile = None
    # keep ref to settings
    self._settings = None
    self.dialog = dialog

    layout = QVBoxLayout()

    layout.setAlignment(Qt.AlignmentFlag.AlignTop)

    self.lstProfiles = QListWidget()
    self.lstProfiles.setIconSize(QSize(16, 16))
    self.lstProfiles.setSpacing(2)
    self.lstProfiles.setContextMenuPolicy(
        Qt.ContextMenuPolicy.CustomContextMenu
    )
    self.lstProfiles.customContextMenuRequested.connect(
        self._on_profiles_context_menu
    )

    # dummy args for function signature related failure prevention
    def _confirm(*args: list[Any]) -> None:  # noqa: ARG001
        """Button confirm action."""
        self.dialog.sig_confirm.emit()

    self.lstProfiles.itemActivated.connect(_confirm)
    layout.addWidget(self.lstProfiles)

    self.setLayout(layout)

populate_list(settings)

Adds profiles to list from settings, with appropriate icons.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
437
438
439
440
441
442
def populate_list(self, settings: ComfyRemoteSettings) -> None:
    """Adds profiles to list from settings, with appropriate icons."""
    self.lstProfiles.clear()
    self._settings = settings
    for profile_name in settings.profiles:
        self._add_profile_to_list(settings.get(profile_name))

show_log(profile)

Show subwindow with host os debug info about the profile in it.

Source code in client/ayon_comfyui/api/profile_selector/profile_dialog.py
509
510
511
512
513
514
515
def show_log(
    self, profile: ComfyRemoteSettings.ComfyRemoteProfile
) -> None:
    """Show subwindow with host os debug info about the profile in it."""
    win = ProfileDebugDialog(self)
    win.log_profile_remote(profile)
    win.exec()