Skip to content

toolbar

Classes:

SceningToolbar

SceningToolbar(main: MainWindow)

Bases: AbstractToolbar

Methods:

Attributes:

Source code
53
54
55
56
57
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
def __init__(self, main: MainWindow) -> None:
    super().__init__(main, SceningSettings(self))
    self.setup_ui()

    self.lists = SceningLists()

    self.first_frame: Frame | None = None
    self.second_frame: Frame | None = None
    self.export_template_pattern = re.compile(r'.*(?:{start}|{end}|{label}).*')
    self.export_template_scenes_pattern = re.compile(r'.+')

    self.items_combobox.setModel(self.lists)
    self.scening_update_status_label()
    self.scening_list_dialog = SceningListDialog(self.main)

    self.items_combobox.valueChanged.connect(self.on_current_list_changed)
    self.add_list_button.clicked.connect(self.on_add_list_clicked)
    self.remove_list_button.clicked.connect(self.on_remove_list_clicked)
    self.view_list_button.clicked.connect(self.on_view_list_clicked)
    self.import_file_button.clicked.connect(self.on_import_file_clicked)
    self.seek_to_prev_button.clicked.connect(self.on_seek_to_prev_clicked)
    self.seek_to_next_button.clicked.connect(self.on_seek_to_next_clicked)

    self.add_single_frame_button.clicked.connect(self.on_add_single_frame_clicked)
    self.toggle_first_frame_button.clicked.connect(self.on_first_frame_clicked)
    self.toggle_second_frame_button.clicked.connect(self.on_second_frame_clicked)
    self.add_to_list_button.clicked.connect(self.on_add_to_list_clicked)
    self.remove_last_from_list_button.clicked.connect(self.on_remove_last_from_list_clicked)
    self.remove_at_current_frame_button.clicked.connect(self.on_remove_at_current_frame_clicked)
    self.export_template_lineedit.textChanged.connect(self.check_remove_export_possibility)
    self.export_button.clicked.connect(self.export)

    # FIXME: get rid of workaround
    self._on_list_items_changed = lambda *arg: self.on_list_items_changed(*arg)

    self.set_qobject_names()

class_storable_attrs class-attribute instance-attribute

class_storable_attrs = tuple[str, ...](('settings', 'visibility'))

current_list property

current_list: SceningList | None

current_list_index property writable

current_list_index: int

export_template_pattern instance-attribute

export_template_pattern = compile('.*(?:{start}|{end}|{label}).*')

export_template_scenes_pattern instance-attribute

export_template_scenes_pattern = compile('.+')

first_frame instance-attribute

first_frame: Frame | None = None

hlayout instance-attribute

hlayout: HBoxLayout

is_notches_visible property

is_notches_visible: bool

lists instance-attribute

lists = SceningLists()

main instance-attribute

main: MainWindow = main

name instance-attribute

name: str = __name__[:-7]

notches_changed class-attribute instance-attribute

notches_changed = pyqtSignal(ExtendedWidget)

num_keys class-attribute instance-attribute

num_keys = [
    Key_1,
    Key_2,
    Key_3,
    Key_4,
    Key_5,
    Key_6,
    Key_7,
    Key_8,
    Key_9,
    Key_0,
]

scening_list_dialog instance-attribute

scening_list_dialog: SceningListDialog = SceningListDialog(main)

second_frame instance-attribute

second_frame: Frame | None = None

settings instance-attribute

settings: SceningSettings

storable_attrs class-attribute instance-attribute

storable_attrs = ('current_list_index', 'lists', 'first_frame', 'second_frame')

toggle_button instance-attribute

toggle_button = PushButton(name, self, checkable=True, clicked=on_toggle)

visibility instance-attribute

visibility = False

vlayout instance-attribute

vlayout: VBoxLayout

check_add_to_list_possibility

check_add_to_list_possibility() -> None
Source code
398
399
400
401
402
403
404
def check_add_to_list_possibility(self) -> None:
    self.add_to_list_button.setEnabled(False)

    if not (self.current_list_index != -1 and (self.first_frame is not None or self.second_frame is not None)):
        return

    self.add_to_list_button.setEnabled(True)

check_remove_export_possibility

check_remove_export_possibility(checked: bool | None = None) -> None
Source code
406
407
408
409
410
411
412
413
414
415
416
417
418
419
def check_remove_export_possibility(self, checked: bool | None = None) -> None:
    is_enabled = self.current_list is not None and len(self.current_list) > 0
    self.remove_last_from_list_button.setEnabled(is_enabled)
    self.seek_to_next_button.setEnabled(is_enabled)
    self.seek_to_prev_button.setEnabled(is_enabled)

    curr = self.main.current_output.last_showed_frame

    is_enabled = self.current_list is not None and curr in self.current_list
    self.add_single_frame_button.setEnabled(not is_enabled)
    self.remove_at_current_frame_button.setEnabled(is_enabled)

    is_enabled = self.export_template_pattern.fullmatch(self.export_template_lineedit.text()) is not None
    self.export_button.setEnabled(is_enabled)

export

export(checked: bool | None = None) -> None
Source code
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
def export(self, checked: bool | None = None) -> None:
    if self.current_list is None:
        return

    template = self.export_template_lineedit.text()
    export_str = str()

    try:
        for scene in self.current_list:
            export_str += template.format(
                start=scene.start, end=scene.end, label=scene.label, script_name=self.main.script_path.stem
            ) + ('\n' if self.settings.export_multiline else '')
    except KeyError:
        logging.warning('Scening: export template contains invalid placeholders.')
        self.main.show_message('Export template contains invalid placeholders.')
        return

    if self.main.clipboard:
        self.main.clipboard.setText(export_str)

    self.main.show_message('Scening data exported to the clipboard')

get_notches

get_notches() -> Notches
Source code
183
184
185
186
187
188
189
190
191
192
def get_notches(self) -> Notches:
    marks = Notches()

    if self.current_list is None:
        return marks

    for scene in self.current_list:
        marks.add(scene, cast(QColor, Qt.GlobalColor.green))

    return marks

get_separator

get_separator(horizontal: bool = False) -> QFrame
Source code
318
319
320
321
322
def get_separator(self, horizontal: bool = False) -> QFrame:
    separator = QFrame(self)
    separator.setFrameShape(QFrame.Shape.HLine if horizontal else QFrame.Shape.VLine)
    separator.setFrameShadow(QFrame.Shadow.Sunken)
    return separator

import_file

import_file(
    import_func: Callable[[Path, SceningList], int], path: Path
) -> None
Source code
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
@fire_and_forget
@set_status_label('Importing scening list')
def import_file(self, import_func: Callable[[Path, SceningList], int], path: Path) -> None:
    scening_list, scening_list_index = self.lists.add(path.stem)

    out_of_range_count = import_func(path, scening_list)

    if out_of_range_count > 0:
        logging.warning(
            f'Scening import: {out_of_range_count} scenes were out of range of output, so they were dropped.')
    if len(scening_list) == 0:
        logging.warning(f"Scening import: nothing was imported from '{path.name}'.")
        self.lists.remove(scening_list_index)
    else:
        self.current_list_index = scening_list_index

init_notches

init_notches(main: MainWindow = ...) -> None
Source code
402
403
def init_notches(self, main: MainWindow = ...) -> None:
    self.notches_changed.connect(main.timeline.update_notches)

on_add_list_clicked

on_add_list_clicked(checked: bool | None = None) -> None
Source code
212
213
def on_add_list_clicked(self, checked: bool | None = None) -> None:
    _, self.current_list_index = self.lists.add()

on_add_single_frame_clicked

on_add_single_frame_clicked(checked: bool | None = None) -> None
Source code
279
280
281
282
283
284
285
286
287
def on_add_single_frame_clicked(self, checked: bool | None = None) -> None:
    if self.current_list is None:
        self.on_add_list_clicked()

    assert self.current_list is not None

    self.current_list.add(self.main.current_output.last_showed_frame, label=self.label_lineedit.text())

    self.check_remove_export_possibility()

on_add_to_list_clicked

on_add_to_list_clicked(checked: bool | None = None) -> None
Source code
289
290
291
292
293
294
295
296
297
298
299
def on_add_to_list_clicked(self, checked: bool | None = None) -> None:
    self.current_list.add(self.first_frame, self.second_frame, self.label_lineedit.text())  # type: ignore

    if self.toggle_first_frame_button.isChecked():
        self.toggle_first_frame_button.click()
    if self.toggle_second_frame_button.isChecked():
        self.toggle_second_frame_button.click()
    self.add_to_list_button.setEnabled(False)
    self.label_lineedit.setText('')

    self.check_remove_export_possibility()

on_current_frame_changed

on_current_frame_changed(frame: Frame) -> None
Source code
179
180
181
def on_current_frame_changed(self, frame: Frame) -> None:
    self.check_remove_export_possibility()
    self.scening_list_dialog.on_current_frame_changed(frame, Time(frame))

on_current_list_changed

on_current_list_changed(
    new_value: SceningList | None, old_value: SceningList
) -> None
Source code
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
def on_current_list_changed(self, new_value: SceningList | None, old_value: SceningList) -> None:
    if new_value is not None:
        self.remove_list_button.setEnabled(True)
        self.view_list_button.setEnabled(True)
        new_value.rowsInserted.connect(self._on_list_items_changed)
        new_value.rowsRemoved.connect(self._on_list_items_changed)
        new_value.dataChanged.connect(self._on_list_items_changed)
        self.scening_list_dialog.on_current_list_changed(new_value)
    else:
        self.remove_list_button.setEnabled(False)
        self.view_list_button.setEnabled(False)

    self.scening_list_dialog.adjustSize()

    if old_value is not None:
        try:
            old_value.rowsInserted.disconnect(self._on_list_items_changed)
            old_value.rowsRemoved.disconnect(self._on_list_items_changed)
            old_value.dataChanged.disconnect(self._on_list_items_changed)
        except (IndexError, TypeError):
            pass

    self.check_add_to_list_possibility()
    self.check_remove_export_possibility()
    self.notches_changed.emit(self)

on_current_output_changed

on_current_output_changed(index: int, prev_index: int) -> None
Source code
176
177
def on_current_output_changed(self, index: int, prev_index: int) -> None:
    self.scening_list_dialog.on_current_output_changed(index, prev_index)

on_first_frame_clicked

on_first_frame_clicked(checked: bool, frame: Frame | None = None) -> None
Source code
301
302
303
304
305
306
307
308
309
310
def on_first_frame_clicked(self, checked: bool, frame: Frame | None = None) -> None:
    if frame is None:
        frame = self.main.current_output.last_showed_frame

    if checked:
        self.first_frame = frame
    else:
        self.first_frame = None
    self.scening_update_status_label()
    self.check_add_to_list_possibility()

on_import_file_clicked

on_import_file_clicked(checked: bool | None = None) -> None
Source code
350
351
352
353
354
355
356
357
358
def on_import_file_clicked(self, checked: bool | None = None) -> None:
    filter_str = ';;'.join(supported_file_types.keys())
    path_strs, file_type = QFileDialog.getOpenFileNames(
        self.main, caption='Open chapters file', filter=filter_str
    )

    paths = [Path(path_str) for path_str in path_strs]
    for path in paths:
        self.import_file(supported_file_types[file_type], path)

on_list_items_changed

on_list_items_changed(parent: QModelIndex, first: int, last: int) -> None
Source code
241
242
def on_list_items_changed(self, parent: QModelIndex, first: int, last: int) -> None:
    self.notches_changed.emit(self)

on_remove_at_current_frame_clicked

on_remove_at_current_frame_clicked(checked: bool | None = None) -> None
Source code
312
313
314
315
316
317
318
319
320
321
322
323
def on_remove_at_current_frame_clicked(self, checked: bool | None = None) -> None:
    if self.current_list is None:
        return

    curr = self.main.current_output.last_showed_frame

    for scene in self.current_list:
        if (scene.start == curr or scene.end == curr):
            self.current_list.remove(scene)

    self.remove_at_current_frame_button.clearFocus()
    self.check_remove_export_possibility()

on_remove_last_from_list_clicked

on_remove_last_from_list_clicked(checked: bool | None = None) -> None
Source code
325
326
327
328
329
330
331
def on_remove_last_from_list_clicked(self, checked: bool | None = None) -> None:
    if self.current_list is None:
        return

    self.current_list.remove(self.current_list[-1])
    self.remove_last_from_list_button.clearFocus()
    self.check_remove_export_possibility()

on_remove_list_clicked

on_remove_list_clicked(checked: bool | None = None) -> None
Source code
244
245
246
247
248
249
def on_remove_list_clicked(self, checked: bool | None = None) -> None:
    self.lists.remove(self.current_list_index)

    if len(self.lists) == 0:
        self.remove_list_button.setEnabled(False)
        self.view_list_button.setEnabled(False)

on_second_frame_clicked

on_second_frame_clicked(checked: bool, frame: Frame | None = None) -> None
Source code
333
334
335
336
337
338
339
340
341
342
def on_second_frame_clicked(self, checked: bool, frame: Frame | None = None) -> None:
    if frame is None:
        frame = self.main.current_output.last_showed_frame

    if checked:
        self.second_frame = frame
    else:
        self.second_frame = None
    self.scening_update_status_label()
    self.check_add_to_list_possibility()

on_seek_to_next_clicked

on_seek_to_next_clicked(checked: bool | None = None) -> None
Source code
270
271
272
273
274
275
276
277
def on_seek_to_next_clicked(self, checked: bool | None = None) -> None:
    if self.current_list is None:
        return

    new_pos = self.current_list.get_next_frame(self.main.current_output.last_showed_frame)
    if new_pos is None:
        return
    self.main.switch_frame(new_pos)

on_seek_to_prev_clicked

on_seek_to_prev_clicked(checked: bool | None = None) -> None
Source code
261
262
263
264
265
266
267
268
def on_seek_to_prev_clicked(self, checked: bool | None = None) -> None:
    if self.current_list is None:
        return

    new_pos = self.current_list.get_prev_frame(self.main.current_output.last_showed_frame)
    if new_pos is None:
        return
    self.main.switch_frame(new_pos)

on_toggle

on_toggle(new_state: bool) -> None
Source code
167
168
169
170
171
172
173
174
def on_toggle(self, new_state: bool) -> None:
    if new_state is True:
        self.check_add_to_list_possibility()
        self.check_remove_export_possibility()

    self.status_label.setVisible(self.is_notches_visible)

    super().on_toggle(new_state)

on_toggle_single_frame

on_toggle_single_frame() -> None
Source code
344
345
346
347
348
def on_toggle_single_frame(self) -> None:
    if self.add_single_frame_button.isEnabled():
        self.add_single_frame_button.click()
    elif self.remove_at_current_frame_button.isEnabled():
        self.remove_at_current_frame_button.click()

on_view_list_clicked

on_view_list_clicked(checked: bool | None = None) -> None
Source code
251
252
253
def on_view_list_clicked(self, checked: bool | None = None) -> None:
    self.scening_list_dialog.adjustSize()
    self.scening_list_dialog.show()

resize_main_window

resize_main_window(expanding: bool) -> None
Source code
481
482
483
484
485
486
487
488
489
def resize_main_window(self, expanding: bool) -> None:
    if self.main.windowState() in {Qt.WindowState.WindowMaximized, Qt.WindowState.WindowFullScreen}:
        return

    if expanding:
        self.main.resize(self.main.width(), self.main.height() + self.height() + round(6 * self.main.display_scale))
    if not expanding:
        self.main.resize(self.main.width(), self.main.height() - self.height() - round(6 * self.main.display_scale))
        self.main.timeline.update()

scening_update_status_label

scening_update_status_label() -> None
Source code
421
422
423
424
def scening_update_status_label(self) -> None:
    first_frame_text = str(self.first_frame) if self.first_frame is not None else ''
    second_frame_text = str(self.second_frame) if self.second_frame is not None else ''
    self.status_label.setText(f'Scening: {first_frame_text} - {second_frame_text} ')

set_qobject_names

set_qobject_names() -> None
Source code
279
280
281
282
283
284
285
286
287
288
289
290
291
292
def set_qobject_names(self) -> None:
    if not hasattr(self, '__slots__'):
        return

    slots = list(self.__slots__)

    if isinstance(self, AbstractToolbar) and 'main' in slots:
        slots.remove('main')

    for attr_name in slots:
        attr = getattr(self, attr_name)
        if not isinstance(attr, QObject):
            continue
        attr.setObjectName(type(self).__name__ + '.' + attr_name)

setup_ui

setup_ui() -> None
Source code
 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
def setup_ui(self) -> None:
    super().setup_ui()

    self.items_combobox = ComboBox[SceningList](duplicatesEnabled=True, minimumContentsLength=4)

    self.add_list_button = PushButton('Add List')

    self.remove_list_button = PushButton('Remove List', enabled=False)

    self.view_list_button = PushButton('View List', enabled=False)

    self.import_file_button = PushButton('Import List')

    self.seek_to_prev_button = PushButton('⏪', enabled=False)

    self.seek_to_next_button = PushButton('⏩', enabled=False)

    self.always_show_scene_marks_checkbox = CheckBox(
        'Always show scene marks in the timeline',
        checked=self.settings.always_show_scene_marks
    )

    self.add_single_frame_button = PushButton('🆎', tooltip='Add Single Frame Scene')

    self.toggle_first_frame_button = PushButton('🅰️', tooltip='Toggle Start of New Scene', checkable=True)

    self.toggle_second_frame_button = PushButton('🅱️', tooltip='Toggle End of New Scene', checkable=True)

    self.label_lineedit = LineEdit('New Scene Label')

    self.add_to_list_button = PushButton('Add to List', enabled=False)

    self.remove_last_from_list_button = PushButton('Remove Last', enabled=False)

    self.remove_at_current_frame_button = PushButton('Remove at Current Frame', enabled=False)

    self.export_template_lineedit = LineEdit(
        'Export Template',
        text=self.settings.default_export_template,
        tooltip=(
            r'Use {start} and {end} as placeholders.'
            r'Both are valid for single frame scenes. '
            r'{label} is available, too. '
        )
    )

    self.export_button = PushButton('Export', enabled=False)

    HBoxLayout(self.vlayout, [
        self.items_combobox,
        self.add_list_button,
        self.remove_list_button,
        self.view_list_button,
        self.import_file_button,
        self.get_separator(),
        self.seek_to_prev_button,
        self.seek_to_next_button,
        self.always_show_scene_marks_checkbox
    ]).addStretch()

    HBoxLayout(self.vlayout, [
        self.add_single_frame_button,
        self.toggle_first_frame_button,
        self.toggle_second_frame_button,
        self.label_lineedit,
        self.add_to_list_button,
        self.remove_last_from_list_button,
        self.remove_at_current_frame_button,
        self.get_separator(),
        self.export_template_lineedit,
        self.export_button
    ]).addStretch(2)

    self.status_label = QLabel(self)
    self.status_label.setVisible(False)
    self.main.statusbar.addPermanentWidget(self.status_label)

switch_list

switch_list(index: int) -> None
Source code
255
256
257
258
259
def switch_list(self, index: int) -> None:
    try:
        self.current_list_index = index
    except IndexError:
        pass