Merge branch 'notecolours' into dev
This commit is contained in:
commit
0ae5a99346
12
.idea/dataSources.xml
Normal file
12
.idea/dataSources.xml
Normal 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>
|
||||||
@ -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
6
.idea/sqldialects.xml
Normal 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>
|
||||||
@ -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
|
||||||
|
|||||||
51
app/model.py
51
app/model.py
@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
|
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -38,6 +40,54 @@ 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=True)
|
||||||
|
is_regex = Column(Boolean, default=False, index=False)
|
||||||
|
is_casesensitive = Column(Boolean, default=False, index=False)
|
||||||
|
order = Column(Integer, index=True)
|
||||||
|
|
||||||
|
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)
|
||||||
|
.filter(NoteColours.enabled == True)
|
||||||
|
.order_by(NoteColours.order)
|
||||||
|
.all()
|
||||||
|
):
|
||||||
|
if rec.is_regex:
|
||||||
|
if rec.is_casesensitive:
|
||||||
|
p = re.compile(rec.substring)
|
||||||
|
else:
|
||||||
|
p = re.compile(rec.substring, re.IGNORECASE)
|
||||||
|
if p.match(text):
|
||||||
|
return '#' + rec.hexcolour
|
||||||
|
else:
|
||||||
|
if rec.is_casesensitive:
|
||||||
|
if rec.substring in text:
|
||||||
|
return '#' + rec.hexcolour
|
||||||
|
else:
|
||||||
|
if rec.substring.lower() in text.lower():
|
||||||
|
return '#' + rec.hexcolour
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Notes(Base):
|
class Notes(Base):
|
||||||
__tablename__ = 'notes'
|
__tablename__ = 'notes'
|
||||||
|
|
||||||
@ -451,6 +501,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):
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
@ -1041,11 +1041,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)
|
||||||
)
|
)
|
||||||
|
|||||||
36
migrations/versions/a5aada49f2fc_add_notecolours_table.py
Normal file
36
migrations/versions/a5aada49f2fc_add_notecolours_table.py
Normal 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 ###
|
||||||
Loading…
Reference in New Issue
Block a user