Skip to content

Commit

Permalink
Remember Editor layout on close (if set in config)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaurizioB committed Mar 17, 2017
1 parent 252575f commit f7904cd
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 88 deletions.
32 changes: 18 additions & 14 deletions bigglesworth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def __init__(self, app, args):
self.librarian.aboutQtAction.triggered.connect(lambda: QtGui.QMessageBox.aboutQt(self.librarian, 'About Qt'))
self.device_event.connect(lambda event: self.device_response(event, self.librarian))
self.loader.loaded.connect(self.librarian.create_proxy)
# self.loader.loaded.connect(self.librarian.create_proxy)
self.loading_win = LoadingWindow(self.librarian)
self.librarian.shown.connect(self.loading_win.show)
self.loading_win.shown.connect(self.loader_thread.start)
Expand All @@ -116,13 +115,10 @@ def __init__(self, app, args):
self.dump_bulk_timer = QtCore.QTimer()
self.dump_bulk_timer.setInterval(500)
self.dump_bulk_timer.setSingleShot(True)
# self.dump_detect_dialog = QtGui.QMessageBox(QtGui.QMessageBox.Information, 'Dump receiving', 'Receiving dump from Blofeld, please wait', parent=self.librarian)
# self.dump_detect_dialog.setStandardButtons(QtGui.QMessageBox.NoButton)

self.dump_timer = QtCore.QTimer()
self.dump_timer.setInterval(100)
self.dump_timer.setSingleShot(True)
# self.dump_timer.timeout.connect(lambda: self.dump_waiter.emit())

self.dump_active = False
self.dump_pause = False
Expand Down Expand Up @@ -154,6 +150,13 @@ def __init__(self, app, args):

#EDITOR
self.editor = Editor(self)
if self.editor_appearance_efx_arp & 1:
self.editor.efx_arp_toggle_btn.clicked.emit(1)
self.editor.efx_arp_toggle_state.connect(lambda state: setattr(self, 'editor_appearance_efx_arp', 2|state) if self.editor_appearance_efx_arp&2 else None)
if self.editor_appearance_filter_matrix & 1:
self.editor.filter_matrix_toggle_btn.clicked.emit(1)
self.editor.filter_matrix_toggle_state.connect(lambda state: setattr(self, 'editor_appearance_filter_matrix', 2|state) if self.editor_appearance_filter_matrix&2 else None)


self.editor_dump_state = False
self.editor_dump_timer = QtCore.QTimer()
Expand Down Expand Up @@ -214,7 +217,8 @@ def __init__(self, app, args):
self.settingsAction.triggered.connect(self.show_settings)
self.output_conn_state_change.connect(lambda conn: self.settings_dialog.detect_connections(OUTPUT, conn))
self.input_conn_state_change.connect(lambda conn: self.settings_dialog.detect_connections(INPUT, conn))
# self.settings_dialog.show()
self.editor.filter_matrix_toggle_state.connect(lambda state: setattr(self, 'editor_appearance_filter_matrix_latest', state))
self.editor.efx_arp_toggle_state.connect(lambda state: setattr(self, 'editor_appearance_efx_arp_latest', state))

self.midi_connect()
# self.dump_win.show()
Expand Down Expand Up @@ -334,24 +338,24 @@ def editor_remember_states(self, value):
self._editor_remember_states = value

@property
def editor_appearance_remember(self):
def editor_appearance_efx_arp(self):
try:
return self._editor_appearance_remember
return self._editor_appearance_efx_arp
except:
self._editor_appearance_remember = self.settings.gEditor.get_Remember_Appearance(True, True)
return self._editor_appearance_remember
self._editor_appearance_efx_arp = self.settings.gEditor.get_Remember_Appearance_EfxArp(2, True)
return self._editor_appearance_efx_arp

@editor_appearance_remember.setter
def editor_appearance_remember(self, value):
self._editor_appearance_remember = self.settings.gEditor.set_Remember_Appearance(value)
self._editor_appearance_remember = value
@editor_appearance_efx_arp.setter
def editor_appearance_efx_arp(self, value):
self._editor_appearance_efx_arp = self.settings.gEditor.set_Remember_Appearance_EfxArp(value)
self._editor_appearance_efx_arp = value

@property
def editor_appearance_filter_matrix(self):
try:
return self._editor_appearance_filter_matrix
except:
self._editor_appearance_filter_matrix = self.settings.gEditor.get_Remember_Appearance_FilterMatrix(0, True)
self._editor_appearance_filter_matrix = self.settings.gEditor.get_Remember_Appearance_FilterMatrix(2, True)
return self._editor_appearance_filter_matrix

@editor_appearance_filter_matrix.setter
Expand Down
46 changes: 40 additions & 6 deletions bigglesworth/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,18 @@ def __init__(self, main, parent):

self.preset_group.buttonClicked.connect(self.set_preset_labels)

self.previous = 0
self.editor_appearance_filter_matrix_group.setId(self.adv_filter_radio, 0)
self.editor_appearance_filter_matrix_group.setId(self.adv_matrix_radio, 1)
self.editor_appearance_filter_matrix_group.setId(self.adv_last_radio, 2)
self.editor_appearance_efx_arp_group.setId(self.arp_efx_radio, 0)
self.editor_appearance_efx_arp_group.setId(self.arp_arp_radio, 1)
self.editor_appearance_efx_arp_group.setId(self.arp_last_radio, 2)
self.editor_appearance_efx_arp_group.buttonClicked.connect(self.editor_appearance_groups_check)
self.editor_appearance_filter_matrix_group.buttonClicked.connect(self.editor_appearance_groups_check)
self.editor_appearance_remember_last_chk.toggled.connect(self.editor_appearance_groups_check)
self.editor_appearance_efx_arp_latest = self.editor_appearance_filter_matrix_latest = 0

self.previous_id = 0
self.connections = {INPUT: None, OUTPUT: None}
self.deviceID_spin.valueChanged.connect(lambda value: self.deviceID_hex_lbl.setText('({:02X}h)'.format(value)))
self.deviceID_spin.valueChanged.connect(self.check_broadcast)
Expand All @@ -274,6 +285,12 @@ def __init__(self, main, parent):

self.no_response_msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, 'No response', 'We got no response from the Blofeld.\nPlease check MIDI connections or try to switch it off and on again.', QtGui.QMessageBox.Ok, self)

def editor_appearance_groups_check(self, btn):
if all([self.adv_last_radio.isChecked(), self.arp_last_radio.isChecked()]):
self.editor_appearance_remember_last_chk.setChecked(True)
else:
self.editor_appearance_remember_last_chk.setChecked(False)

def set_preset_labels(self, btn):
self.preset_desc_lbl.setText(self.preset_texts[str(btn.objectName())[7:-6]])

Expand All @@ -292,7 +309,7 @@ def detect_response(self, data):
self.detect_msgbox.accept()
self.no_response_msgbox.accept()
id = data[42]
self.previous = id
self.previous_id = id
if id == 127:
self.broadcast_chk.setChecked(True)
self.broadcast_chk.toggled.emit(True)
Expand All @@ -312,13 +329,13 @@ def detect_connections(self, dir, conn):

def set_broadcast(self, state):
if state:
self.previous = self.deviceID_spin.value()
self.previous_id = self.deviceID_spin.value()
self.deviceID_spin.blockSignals(True)
self.deviceID_spin.setValue(127)
self.deviceID_hex_lbl.setText('({:02X}h)'.format(127))
self.deviceID_spin.blockSignals(False)
else:
self.deviceID_spin.setValue(self.previous)
self.deviceID_spin.setValue(self.previous_id)

def check_broadcast(self, value):
if value == 127:
Expand All @@ -331,35 +348,52 @@ def check_broadcast(self, value):
self.broadcast_chk.setEnabled(True)

def exec_(self):
#Library
self.library_doubleclick_combo.setCurrentIndex(self.main.library_doubleclick)
preset_btn = getattr(self, 'preset_{}_radio'.format(self.settings.gGeneral.get_Source_Library('personal')))
preset_btn.setChecked(True)

#Editor
self.editor_appearance_filter_matrix_group.button(min(2, self.main.editor_appearance_filter_matrix)).click()
self.editor_appearance_efx_arp_group.button(min(2, self.main.editor_appearance_efx_arp)).click()
self.editor_pgm_send_combo.setCurrentIndex(self.main.editor_remember_states[PGMSEND])
self.editor_midi_send_combo.setCurrentIndex(self.main.editor_remember_states[MIDISEND])
self.editor_remember_chk.setChecked(self.main.editor_remember)

#MIDI
self.midi_groupbox.layout().addWidget(self.main.midiwidget)

id = self.main.blofeld_id
if id == 127:
self.broadcast_chk.setChecked(True)
self.broadcast_chk.toggled.emit(True)
else:
self.previous = id
self.previous_id = id
self.deviceID_spin.setValue(id)
self.broadcast_chk.setChecked(False)
self.broadcast_chk.toggled.emit(False)

self.blofeld_autoconnect_chk.setChecked(self.main.blofeld_autoconnect)
self.remember_connections_chk.setChecked(self.main.remember_connections)

#EXEC
res = QtGui.QDialog.exec_(self)
if not res: return

self.main.library_doubleclick = self.library_doubleclick_combo.currentIndex()
# if self.preset_group.checkedButton() != self.preset_personal_radio and not self.settings.gGeneral.get_Source_Library(False):
self.settings.gGeneral.set_Source_Library(str(self.preset_group.checkedButton().objectName())[7:-6])


if self.editor_appearance_filter_matrix_group.checkedId() > 1:
if not self.main.editor_appearance_filter_matrix & 2:
self.main.editor_appearance_filter_matrix = self.editor_appearance_filter_matrix_latest+2
else:
self.main.editor_appearance_filter_matrix = self.editor_appearance_filter_matrix_group.checkedId()
if self.editor_appearance_efx_arp_group.checkedId() > 1:
if not self.main.editor_appearance_efx_arp & 2:
self.main.editor_appearance_efx_arp = self.editor_appearance_efx_arp_latest+2
else:
self.main.editor_appearance_efx_arp = self.editor_appearance_efx_arp_group.checkedId()
self.main.editor_remember = self.editor_remember_chk.isChecked()
if self.editor_remember_chk.isChecked():
self.main.editor_remember_states = [
Expand Down
74 changes: 17 additions & 57 deletions bigglesworth/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,9 @@ class Editor(QtGui.QMainWindow):
show_midi_dialog = QtCore.pyqtSignal()
show_librarian = QtCore.pyqtSignal()

filter_matrix_toggle_state = QtCore.pyqtSignal(bool)
efx_arp_toggle_state = QtCore.pyqtSignal(bool)

object_dict = {attr:ParamObject(param_tuple) for attr, param_tuple in Params.param_names.items()}
with open(local_path('blofeld_efx'), 'rb') as _fx:
efx_params = pickle.load(_fx)
Expand Down Expand Up @@ -2336,8 +2339,8 @@ def create_layout(self):

btn_layout = QtGui.QHBoxLayout()
filter_matrix_btn_layout.addLayout(btn_layout, 1, 0)
open_mod = SquareButton(self, color=QtCore.Qt.darkGreen, size=(20, 16), name='Mod Matrix Editor', label_pos=RIGHT, text_align=QtCore.Qt.AlignLeft)
btn_layout.addWidget(open_mod)
self.filter_matrix_toggle_btn = SquareButton(self, color=QtCore.Qt.darkGreen, size=(20, 16), name='Mod Matrix Editor', label_pos=RIGHT, text_align=QtCore.Qt.AlignLeft)
btn_layout.addWidget(self.filter_matrix_toggle_btn)
# filter_matrix_lbl = Label(self, 'Mod Matrix Editor', QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
# btn_layout.addWidget(filter_matrix_lbl)
filter_matrix_cycle = cycle((0, 1))
Expand All @@ -2358,8 +2361,8 @@ def create_layout(self):
matrix_opacity_anim.setDuration(200)
filter_matrix_tuple = (filter_widget, filter_opacity_anim), (matrix_widget, matrix_opacity_anim)

def filter_matrix_set(cycler):
id = cycler.next()
def filter_matrix_set():
id = filter_matrix_cycle.next()
for i, (w, a) in enumerate(filter_matrix_tuple):
if i == id:
a.setStartValue(0)
Expand All @@ -2370,12 +2373,13 @@ def filter_matrix_set(cycler):
a.setStartValue(1)
a.setEndValue(0)
a.start()
open_mod.setText(filter_matrix_labels[id])
self.filter_matrix_toggle_state.emit(id)
self.filter_matrix_toggle_btn.setText(filter_matrix_labels[id])

open_mod.clicked.connect(lambda state, cycler=filter_matrix_cycle: filter_matrix_set(cycler))
self.filter_matrix_toggle_btn.clicked.connect(lambda state: filter_matrix_set())

open_arp = SquareButton(self, color=QtCore.Qt.darkGreen, size=(20, 16), name='Arpeggiator Pattern Editor', label_pos=RIGHT, text_align=QtCore.Qt.AlignLeft)
btn_layout.addWidget(open_arp)
self.efx_arp_toggle_btn = SquareButton(self, color=QtCore.Qt.darkGreen, size=(20, 16), name='Arpeggiator Pattern Editor', label_pos=RIGHT, text_align=QtCore.Qt.AlignLeft)
btn_layout.addWidget(self.efx_arp_toggle_btn)
# adv_arp_lbl = Label(self, 'Arpeggiator Pattern Editor', QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
# btn_layout.addWidget(adv_arp_lbl)

Expand Down Expand Up @@ -2420,8 +2424,8 @@ def filter_matrix_set(cycler):
arp_opacity_anim.setDuration(200)
adv_arp_tuple = (adv_widget, adv_opacity_anim), (arp_widget, arp_opacity_anim)

def adv_arp_set(cycler):
id = cycler.next()
def adv_arp_set():
id = adv_arp_cycle.next()
for i, (w, a) in enumerate(adv_arp_tuple):
if i == id:
a.setStartValue(0)
Expand All @@ -2432,9 +2436,10 @@ def adv_arp_set(cycler):
a.setStartValue(1)
a.setEndValue(0)
a.start()
open_arp.setText(adv_arp_labels[id])
self.efx_arp_toggle_state.emit(id)
self.efx_arp_toggle_btn.setText(adv_arp_labels[id])

open_arp.clicked.connect(lambda state, cycler=adv_arp_cycle: adv_arp_set(cycler))
self.efx_arp_toggle_btn.clicked.connect(lambda state: adv_arp_set())

lower_layout = QtGui.QGridLayout()
self.grid.addLayout(lower_layout, 4, 0, 1, 5)
Expand Down Expand Up @@ -2664,51 +2669,6 @@ def create_arp(self):

return frame

# def create_sorted_library(self):
# sorted_library = SortedLibrary(self.blofeld_library)
# del self.sorted_library_menu
# menu = QtGui.QMenu()
# by_bank = QtGui.QMenu('By bank', menu)
# menu.addMenu(by_bank)
# for id, bank in enumerate(sorted_library.by_bank):
# if not any(bank): continue
# bank_menu = QtGui.QMenu(uppercase[id], by_bank)
# by_bank.addMenu(bank_menu)
# for sound in bank:
# if sound is None: continue
# item = QtGui.QAction('{:03} {}'.format(sound.prog+1, sound.name), bank_menu)
# item.setData((sound.bank, sound.prog))
# bank_menu.addAction(item)
# by_cat = QtGui.QMenu('By category', menu)
# menu.addMenu(by_cat)
# for cid, cat in enumerate(categories):
# cat_menu = QtGui.QMenu(by_cat)
# by_cat.addMenu(cat_menu)
# cat_len = 0
# for sound in sorted_library.by_cat[cid]:
# cat_len += 1
# item = QtGui.QAction(sound.name, cat_menu)
# item.setData((sound.bank, sound.prog))
# cat_menu.addAction(item)
# if not len(cat_menu.actions()):
# cat_menu.setEnabled(False)
# cat_menu.setTitle('{} ({})'.format(cat, cat_len))
# by_alpha = QtGui.QMenu('Alphabetical', menu)
# menu.addMenu(by_alpha)
# for alpha in sorted(sorted_library.by_alpha.keys()):
# alpha_menu = QtGui.QMenu(by_alpha)
# by_alpha.addMenu(alpha_menu)
# alpha_len = 0
# for sound in sorted_library.by_alpha[alpha]:
# alpha_len += 1
# item = QtGui.QAction(sound.name, alpha_menu)
# item.setData((sound.bank, sound.prog))
# alpha_menu.addAction(item)
# if not len(alpha_menu.actions()):
# alpha_menu.setEnabled(False)
# alpha_menu.setTitle('{} ({})'.format(alpha, alpha_len))
# self.sorted_library_menu = menu
# self.sorted_library = sorted_library

def autosave_set(self, state):
self.save = state
Expand Down
Loading

0 comments on commit f7904cd

Please sign in to comment.