Start configurable note colours

This commit is contained in:
Keith Edmunds 2022-02-05 18:42:35 +00:00
parent eb1dc4c07d
commit 1de7cefe72
7 changed files with 103 additions and 19 deletions

12
.idea/dataSources.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="musicmuster_dev@localhost" uuid="49514dbe-26ec-4cb2-b457-06666d93ac47">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://localhost:3306/musicmuster_dev</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -1,5 +1,6 @@
<component name="InspectionProjectProfileManager"> <component name="InspectionProjectProfileManager">
<settings> <settings>
<option name="PROJECT_PROFILE" value="Default" />
<option name="USE_PROJECT_PROFILE" value="false" /> <option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" /> <version value="1.0" />
</settings> </settings>

6
.idea/sqldialects.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="PROJECT" dialect="MariaDB" />
</component>
</project>

View File

@ -39,8 +39,7 @@ prepend_sys_path = .
# are written from script.py.mako # are written from script.py.mako
# output_encoding = utf-8 # output_encoding = utf-8
sqlalchemy.url = mysql+mysqldb://songdb:songdb@localhost/musicmuster sqlalchemy.url = mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_dev
[post_write_hooks] [post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run # post_write_hooks defines scripts or Python functions that are run

View File

@ -38,6 +38,36 @@ Session = sessionmaker(bind=engine)
# Database classes # Database classes
class NoteColours(Base):
__tablename__ = 'notecolours'
id = Column(Integer, primary_key=True, autoincrement=True)
substring = Column(String(256), index=False)
hexcolour = Column(String(6), index=False)
enabled = Column(Boolean, default=True, index=False)
is_regex = Column(Boolean, default=False, index=False)
is_casesensitive = Column(Boolean, default=False, index=False)
def __repr__(self):
return (
f"<NoteColour(id={self.id}, substring={self.substring}, colour={self.hexcolour}>"
)
@staticmethod
def get_colour(session, text):
"""
Parse text and return colour string if match, else None
Currently ignore is_regex and is_casesensitive
"""
for rec in session.query(NoteColours).all():
if rec.substring in text:
return '#' + rec.hexcolour
return None
class Notes(Base): class Notes(Base):
__tablename__ = 'notes' __tablename__ = 'notes'
@ -454,6 +484,7 @@ class Tracks(Base):
f"<Track(id={self.id}, title={self.title}, " f"<Track(id={self.id}, title={self.title}, "
f"artist={self.artist}, path={self.path}>" f"artist={self.artist}, path={self.path}>"
) )
# Not currently used 1 June 2021 # Not currently used 1 June 2021
# @staticmethod # @staticmethod
# def get_note(session, id): # def get_note(session, id):

View File

@ -20,7 +20,7 @@ from datetime import datetime, timedelta
from helpers import get_relative_date, open_in_audacity from helpers import get_relative_date, open_in_audacity
from log import DEBUG, ERROR from log import DEBUG, ERROR
from model import ( from model import (
Notes, Playdates, Playlists, PlaylistTracks, Session, Settings, Tracks Notes, Playdates, Playlists, PlaylistTracks, Session, Settings, Tracks, NoteColours
) )
from songdb import create_track_from_file, update_meta from songdb import create_track_from_file, update_meta
@ -1040,11 +1040,10 @@ class PlaylistTab(QTableWidget):
if row_time: if row_time:
next_start_time = row_time next_start_time = row_time
# Set colour # Set colour
note_colour = Config.COLOUR_NOTES_PLAYLIST
note_text = self.item(row, self.COL_TITLE).text() note_text = self.item(row, self.COL_TITLE).text()
for colour_token in Config.NOTE_COLOURS.keys(): note_colour = NoteColours.get_colour(session, note_text)
if note_text.lower().startswith(colour_token.lower()): if not note_colour:
note_colour = Config.NOTE_COLOURS[colour_token] note_colour = Config.COLOUR_NOTES_PLAYLIST
self._set_row_colour( self._set_row_colour(
row, QColor(note_colour) row, QColor(note_colour)
) )

View File

@ -0,0 +1,36 @@
"""Add NoteColours table
Revision ID: a5aada49f2fc
Revises: 2cc37d3cf07f
Create Date: 2022-02-05 17:34:54.880473
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'a5aada49f2fc'
down_revision = '2cc37d3cf07f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('notecolours',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('substring', sa.String(length=256), nullable=True),
sa.Column('hexcolour', sa.String(length=6), nullable=True),
sa.Column('enabled', sa.Boolean(), nullable=True),
sa.Column('is_regex', sa.Boolean(), nullable=True),
sa.Column('is_casesensitive', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('notecolours')
# ### end Alembic commands ###