def __init__(self, block, event, parent, view=None): QMenu.__init__(self, parent) self.setTitle('Block') self.setIcon(icon.get('block')) self.block = block try: self.tracks = parent.tracks except AttributeError: self.tracks = None split_action = QAction(icon.get('split'), 'Split', self) split_action.setStatusTip('Split the block into multiple blocks') split_action.triggered.connect(self.on_split) self.addAction(split_action) join_action = QAction(icon.get('join'), 'Join', self) join_action.setStatusTip('Join selected blocks into one') join_action.triggered.connect(self.on_join) self.addAction(join_action) self.addMenu(HueMenu(self.block.events, self)) delete_action = QAction(icon.get('delete'), 'Delete', self) delete_action.setStatusTip('Delete this block') delete_action.triggered.connect(self.on_delete) self.addAction(delete_action) # disable actions that can't be performed # get all the selected blocks selected = self.get_selected_blocks() # if the block is the only one selected, it can be split split_action.setEnabled((len(selected) == 0) or ((len(selected) == 1) and (self.block in selected))) # if more than one block is selected, they can be joined join_action.setEnabled( (len(selected) == 0) or (self.block in selected))
def __init__(self, target, parent): QMenu.__init__(self, parent) self._target = target self.setTitle('Color') self.setIcon(icon.get('colors')) hues = ( ('None', None), ('Red', 0), ('Orange', 30), ('Yellow', 60), ('Green', 120), ('Cyan', 180), ('Blue', 220), ('Purple', 270), ('Magenta', 330) ) for (name, hue) in hues: action = QAction(name, self) if (hue is not None): hue = (hue / 360.0) color = QColor() color.setHsvF(hue, 1.0, 1.0) action.setIcon(icon.get('color', color)) else: action.setIcon(icon.get('color_none')) action.triggered.connect(functools.partial(self.on_hue, hue)) self.addAction(action)
def __init__(self, unit, event, parent, view=None): QMenu.__init__(self, parent) self.setTitle('MIDI Monitor') self.setIcon(icon.get('data')) self.unit = unit self.style_menu = QMenu(self) self.style_menu.setTitle('Style') styles = (('hex', 'Hexadecimal'), ('decimal', 'Decimal'), ('binary', 'Binary')) for (style, label) in styles: action = QAction(label, self.style_menu) action.setStatusTip( 'Set the display style to %s' % label.lower()) action.triggered.connect(functools.partial(self.on_set_style, style)) if (style == self.unit.style): action.setIcon(icon.get('check')) self.style_menu.addAction(action) self.addMenu(self.style_menu) action = QAction('Show Time', self) action.setStatusTip('Show the times of MIDI events') action.triggered.connect(self.on_toggle_show_time) if (self.unit.show_time): action.setIcon(icon.get('check')) self.addAction(action)
def __init__(self, instrument, event, parent=None, view=None): QMenu.__init__(self, parent) self.setTitle('Instrument') self.setIcon(icon.get('instrument')) self.instrument = instrument self.document = parent.document self.instruments = parent.instruments if (len(self.instrument.path) > 0): (name, ext) = os.path.splitext(os.path.basename(self.instrument.path)) search_dir = os.path.dirname(self.instrument.path) for path in glob.glob(os.path.join(search_dir, '*'+ext)): (name, ext) = os.path.splitext(os.path.basename(path)) action = QAction(name, self) is_current = (path == self.instrument.path) action.setEnabled(not is_current) action.setCheckable(is_current) action.setChecked(is_current) action.triggered.connect(functools.partial(self.on_change_path, path)) self.addAction(action) self.addSeparator() action = QAction(icon.get('instrument'), 'Browse...', self) action.triggered.connect(self.on_browse) self.addAction(action) if (self.instruments): action = QAction(icon.get('delete'), 'Remove', self) action.triggered.connect(self.on_remove) self.addAction(action)
def __init__(self, connection, event, parent, view=None): QMenu.__init__(self, parent) self.setTitle('Connection') self.setIcon(icon.get('connection')) self.connection = connection self.view = view self.addMenu(HueMenu(self.connection, self)) delete_action = QAction(icon.get('delete'), 'Disconnect', self) delete_action.setStatusTip('Remove this connection') delete_action.triggered.connect(self.view.on_delete) self.addAction(delete_action)
def __init__(self, events, number, event, parent, view=None): QMenu.__init__(self, parent) self.setTitle('Controller %d' % number) self.setIcon(icon.get('controller')) self.events = events self.number = number change_action = QAction('Change number', self) change_action.setStatusTip('Change the number of this controller') change_action.triggered.connect(self.on_change) self.addAction(change_action) delete_action = QAction(icon.get('delete'), 'Delete', self) delete_action.setStatusTip( 'Delete all changes on controller %d' % self.number) delete_action.triggered.connect(self.on_delete) self.addAction(delete_action)
def __init__(self, track, event, parent, view=None): QMenu.__init__(self, parent) self.setTitle('Track') self.setIcon(icon.get('track')) self.track = track try: self.tracks = parent.tracks except AttributeError: self.tracks = None try: self.patch_bay = parent.document.patch_bay except AttributeError: self.patch_bay = None delete_action = QAction(icon.get('delete'), 'Delete', self) delete_action.setStatusTip('Delete this track') delete_action.triggered.connect(self.on_delete) self.addAction(delete_action)
def __init__(self, unit, event, parent, view=None): QMenu.__init__(self, parent) self.setTitle('Transport') self.setIcon(icon.get('transport')) self.transport = unit.transport protocols = self.transport.protocols menu = QMenu() menu.setIcon(icon.get('data')) menu.setTitle('MIDI Protocol') for protocol in protocols.iterkeys(): (name, cls) = protocols[protocol] action = QAction(name, menu) if (protocol == self.transport.protocol): action.setIcon(icon.get('check')) action.triggered.connect(functools.partial(self.on_protocol, protocol)) menu.addAction(action) self.addMenu(menu)
def __init__(self, unit, event, parent, view=None): QMenu.__init__(self, parent) self.setTitle('Unit') self.setIcon(icon.get('unit')) self.unit = unit self.view = view selected_units = self.selected_units() if ((self.unit in selected_units) and (len(selected_units) > 1)): action = QAction('Group Selected Units', self) action.setStatusTip('Add the selected units to a group') action.triggered.connect(self.on_group) self.addAction(action) self.addMenu(HueMenu(self.unit, self)) delete_action = QAction(icon.get('delete'), 'Delete', self) delete_action.setStatusTip('Delete %s' % self.unit.name) delete_action.triggered.connect(self.on_delete) self.addAction(delete_action)
def __init__(self, document, event, parent, view=None): QMenu.__init__(self, parent) self.setTitle('Add Unit') self.setIcon(icon.get('workspace')) self.document = document self.units = document.units self.scene_pos = event.scenePos() self.add_action('midi', 'MIDI Inputs', 'Add a MIDI instrument input unit', self.on_add_midi_input) self.add_action('transport', 'Transport', 'Add a transport control unit', self.on_add_transport) self.add_action('tracks', 'Sequencer', 'Add a unit for MIDI recording and playback', self.on_add_sequencer) self.add_action('instrument', 'Sampler Instrument...', 'Add a sampler unit', self.on_add_sampler) self.add_action('speaker', 'Audio Output', 'Add a system audio output unit', self.on_add_audio_output) self.add_action('data', 'MIDI Monitor', 'Add a visual MIDI message monitor', self.on_add_midi_monitor)
def _make_menus(self): menubar = self.menuBar() # file menu file_menu = menubar.addMenu('&File') # new new_action = QAction(QIcon.fromTheme('document-new'), '&New', self) new_action.setShortcut('Ctrl+O') new_action.setStatusTip('Open a document') new_action.triggered.connect(self.file_new) file_menu.addAction(new_action) # open open_action = QAction(QIcon.fromTheme('document-open'), '&Open', self) open_action.setShortcut('Ctrl+O') open_action.setStatusTip('Open a document') open_action.triggered.connect(self.file_open) file_menu.addAction(open_action) # save save_action = QAction(QIcon.fromTheme('document-save'), '&Save', self) save_action.setShortcut('Ctrl+S') save_action.setStatusTip('Save the document') save_action.triggered.connect(self.file_save) file_menu.addAction(save_action) # save as save_as_action = QAction(QIcon.fromTheme('document-save'), 'Save &As', self) save_as_action.setStatusTip('Save the document to a different file') save_as_action.triggered.connect(self.file_save_as) file_menu.addAction(save_as_action) # --- file_menu.addSeparator() # quit quit_action = QAction(QIcon.fromTheme('application-exit'), '&Quit', self) quit_action.setShortcut('Ctrl+Q') quit_action.setStatusTip('Quit application') quit_action.triggered.connect(self.close) file_menu.addAction(quit_action) # edit menu edit_menu = menubar.addMenu('&Edit') # undo self.undo_action = QAction(icon.get('undo'), '&Undo', self) self.undo_action.setShortcut('Ctrl+Z') self.undo_action.setStatusTip('Undo the last action') self.undo_action.triggered.connect(self.edit_undo) edit_menu.addAction(self.undo_action) # redo self.redo_action = QAction(icon.get('redo'), '&Redo', self) self.redo_action.setShortcut('Ctrl+Shift+Z') self.redo_action.setStatusTip('Redo the last action that was undone') self.redo_action.triggered.connect(self.edit_redo) edit_menu.addAction(self.redo_action) # transport menu transport_menu = menubar.addMenu('&Transport') # go to start self.beginning_action = QAction(icon.get('beginning'), 'Jump to &Beginning', self) self.beginning_action.setShortcut('Home') self.beginning_action.setStatusTip('Jump back to the beginning of the project') self.beginning_action.triggered.connect(self.transport_beginning) transport_menu.addAction(self.beginning_action) # go to end self.end_action = QAction(icon.get('ending'), 'Jump to &End', self) self.end_action.setShortcut('End') self.end_action.setStatusTip('Jump forward to the end of the project') self.end_action.triggered.connect(self.transport_end) transport_menu.addAction(self.end_action) # back self.back_action = QAction(icon.get('backward'), 'Bac&k', self) self.back_action.setShortcut('PgUp') self.back_action.setStatusTip('Skip backward in time') self.back_action.triggered.connect(self.transport_back) transport_menu.addAction(self.back_action) # forward self.forward_action = QAction(icon.get('forward'), '&Forward', self) self.forward_action.setShortcut('PgDown') self.forward_action.setStatusTip('Skip forward in time') self.forward_action.triggered.connect(self.transport_forward) transport_menu.addAction(self.forward_action) # --- transport_menu.addSeparator() # previous mark self.previous_mark_action = QAction(icon.get('mark_previous'), 'Previous Mark', self) self.previous_mark_action.setShortcut('Ctrl+PgUp') self.previous_mark_action.setStatusTip('Skip to the previous marked time') self.previous_mark_action.triggered.connect(self.transport_previous_mark) transport_menu.addAction(self.previous_mark_action) # toggle mark self.toggle_mark_action = QAction(icon.get('mark_toggle'), 'Toggle Mark', self) self.toggle_mark_action.setShortcut('Ctrl+\\') self.toggle_mark_action.setStatusTip('Toggle a mark at the current time') self.toggle_mark_action.triggered.connect(self.transport_toggle_mark) transport_menu.addAction(self.toggle_mark_action) # next mark self.next_mark_action = QAction(icon.get('mark_next'), 'Next Mark', self) self.next_mark_action.setShortcut('Ctrl+PgDown') self.next_mark_action.setStatusTip('Skip to the next marked time') self.next_mark_action.triggered.connect(self.transport_next_mark) transport_menu.addAction(self.next_mark_action) # cycle self.toggle_cycle_action = QAction(icon.get('cycle'), 'Cycle', self) self.toggle_cycle_action.setShortcut('Ctrl+L') self.toggle_cycle_action.setStatusTip('Toggle cycling playback mode') self.toggle_cycle_action.setCheckable(True) self.toggle_cycle_action.toggled.connect(self.transport_toggle_cycle) transport_menu.addAction(self.toggle_cycle_action) # --- transport_menu.addSeparator() # stop self.stop_action = QAction(icon.get('stop'), '&Stop', self) self.stop_action.setStatusTip('Stop playback or recording') self.stop_action.triggered.connect(self.transport_stop) transport_menu.addAction(self.stop_action) # play self.play_action = QAction(icon.get('play'), '&Play', self) self.play_action.setStatusTip('Start playback') self.play_action.triggered.connect(self.transport_play) transport_menu.addAction(self.play_action) # record self.record_action = QAction(icon.get('record'), '&Record', self) self.record_action.setStatusTip('Start recording') self.record_action.triggered.connect(self.transport_record) transport_menu.addAction(self.record_action) # --- transport_menu.addSeparator() # zoom in self.zoom_in_action = QAction(icon.get('zoom_in'), 'Zoom &In', self) self.zoom_in_action.setShortcut('Ctrl+Shift+Plus') self.zoom_in_action.setStatusTip('Zoom in') self.zoom_in_action.triggered.connect(self.transport_zoom_in) transport_menu.addAction(self.zoom_in_action) # zoom out self.zoom_out_action = QAction(icon.get('zoom_out'), 'Zoom &Out', self) self.zoom_out_action.setShortcut('Ctrl+Shift+Minus') self.zoom_out_action.setStatusTip('Zoom out') self.zoom_out_action.triggered.connect(self.transport_zoom_out) transport_menu.addAction(self.zoom_out_action) # toolbar self.toolbar = self.addToolBar('Main') self.toolbar.addAction(self.undo_action) self.toolbar.addAction(self.redo_action) self.toolbar.addSeparator() self.toolbar.addAction(self.beginning_action) self.toolbar.addAction(self.back_action) self.toolbar.addAction(self.forward_action) self.toolbar.addAction(self.end_action) self.toolbar.addSeparator() self.toolbar.addAction(self.stop_action) self.toolbar.addAction(self.play_action) self.toolbar.addAction(self.record_action) self.toolbar.addSeparator() self.toolbar.addAction(self.zoom_out_action) self.toolbar.addAction(self.zoom_in_action) # give actions their initial states UndoManager.add_observer(self.update_actions) self.update_actions()
def layout(self): if (not self.scene()): return # make buttons if (not self.begin_button): self.begin_button = self.add_button(icon.get('beginning')) self.begin_button.clicked.connect(self.transport.go_to_beginning) if (not self.back_button): self.back_button = self.add_button(icon.get('backward')) self.back_button.clicked.connect(self.transport.skip_back) if (not self.forward_button): self.forward_button = self.add_button(icon.get('forward')) self.forward_button.clicked.connect(self.transport.skip_forward) if (not self.end_button): self.end_button = self.add_button(icon.get('ending')) self.end_button.clicked.connect(self.transport.go_to_end) if (not self.previous_mark_button): self.previous_mark_button = self.add_button(icon.get('mark_previous')) self.previous_mark_button.clicked.connect(self.transport.previous_mark) if (not self.toggle_mark_button): self.toggle_mark_button = self.add_button(icon.get('mark_toggle')) self.toggle_mark_button.clicked.connect(self.transport.toggle_mark) if (not self.next_mark_button): self.next_mark_button = self.add_button(icon.get('mark_next')) self.next_mark_button.clicked.connect(self.transport.next_mark) if (not self.cycle_button): self.cycle_button = self.add_button(icon.get('cycle')) self.cycle_button.setCheckable(True) self.cycle_button.toggled.connect(self.on_cycle) if (self.cycle_button): self.cycle_button.setChecked(self.transport.cycling) if (not self.stop_button): self.stop_button = self.add_button(icon.get('stop')) self.stop_button.clicked.connect(self.transport.stop) if (not self.play_button): self.play_button = self.add_button(icon.get('play')) self.play_button.clicked.connect(self.transport.play) if (not self.record_button): self.record_button = self.add_button(icon.get('record')) self.record_button.clicked.connect(self.transport.record) # do layout of buttons r = self.rect() width = r.width() height = r.height() size = self.button_size if (len(self.button_proxies) > 0): x = 0.0 y = 0.0 for proxy in self.button_proxies: button = proxy.widget() button.setFixedWidth(size) button.setFixedHeight(size) proxy.setPos(QPointF(x, y)) x += size if (x >= r.width()): x = 0 y += size
def add_action(self, icon_name, name, description, callback): action = QAction(icon.get(icon_name), name, self) action.setStatusTip(description) action.triggered.connect(callback) self.addAction(action)