def get_base_dir(return_this_dir=False):
    if getattr(sys, "frozen", False):
        # If this is running in the context of a frozen (executable) file,
        # we return the path of the main application executable
        return os.path.dirname(os.path.abspath(sys.executable))
    else:
        # If we are running in script or debug mode, we need
        # to inspect the currently executing frame. This enable us to always
        # derive the directory of main.py no matter from where this function
        # is being called
        thisdir = os.path.dirname(inspect.getfile(inspect.currentframe()))
        parent = os.path.abspath(os.path.join(thisdir, os.pardir))
        if return_this_dir:
            return thisdir
        else:
            return parent def parseStyle(stylesheet, theme, theme_folder):
    results = []
    for line in stylesheet:
        cleaned_line = cleanPath(line)
        themed_path = parseThemePath(cleaned_line, theme_folder)
        finished_path = parseIconPath(themed_path, theme)
        results.append(finished_path)
    return "".join(results) def postProcessLines(lines):
    return_val = lines.replace('\\', '/')
    return return_val def merge_instruments(instrument_list):
    return ", ".join([instrument["name"] for instrument in instrument_list]) def merge_clefs_and_keys(clef_or_key_dict):
    result = ''
    for instrument in clef_or_key_dict:
        result += ", ".join(clef_or_key_dict[instrument])
    return result def fit_columns_to_widget(widget, columns):
    for column in range(columns):
        widget.setColumnWidth(column, widget.width() / (columns - 1)) class ThemedWindow(object):
    def __init__(self, theme, themes_folder):
    def applyTheme(self):
    def setTheme(self, theme): class Window(QtGui.QWidget):
class Scorebook(Window):
class PlaylistWidget(Window):
class MyPlaylists(PlaylistWidget):
class AutoPlaylists(PlaylistWidget):
class PieceInfo(Window):
class FeaturedIn(PlaylistWidget):
class PlaylistBrowser(Window):
class SearchTree(QtGui.QTreeWidget):
    def __init__(self, parent, file, title, design_folder):
    def loadPiece(self, current_item):
    def __init__(self, parent, design_folder):
    def onSortChange(self):
    def onScoresReady(self, pieces):
    def __init__(self, parent, file, title, design_folder, data_set="mine"):
    def onPlaylistsReady(self, myPlaylists):
    def create_widgets(self, data):
    def loadPlaylists(self, select_method="all"):
    def load_data(self):
    def loadPlaylist(self, current_item):
    def __init__(self, parent, design_folder):
    def addClicked(self):
    def delete(self):
    def __init__(self, parent, design_folder):
    def sortMethodChanged(self):
    def onPlaylistsReady(self, playlist_summaries):
    def __init__(self, parent, design_folder):
    def loadInfo(self):
    def __init__(self, parent, design_folder):
    def loadPlaylists(self):
    def __init__(self, parent, design_folder):
    def load(self):
    def __init__(self, parent, design_folder):
    def leaveEvent(self, QFocusEvent):
    def clicked(self, current_item):
    def clear(self):
    def group_children(self, root):
    def remove_children(self, location_type, children, root):
    def load(self, results): class AppThread(QThread):
class mythread(AppThread):
class QueryThread(AppThread):
class RenderThread(AppThread):
class DownloadThread(AppThread):
    def __init__(self, parent, method, args, **kwargs):
    def __init__(self, parent, method, args, **kwargs):
    def run(self):
    def __init__(self, parent, method, args, online):
    def run(self):
    def __init__(self, parent, method, args, filename):
    def run(self):
    def __init__(self, parent, method, args):
    def run(self): class MultistandWidget(QtGui.QWidget, themedWindow.ThemedWindow):

    def __init__(self, file, theme_folder, theme):
        QtGui.QWidget.__init__(self)
        themedWindow.ThemedWindow.__init__(self, theme, theme_folder)
        self.pages = 2
        self.file = file
        self.load()
        self.viewer = pdfViewer.PDFViewer(width=None)
        self.loadPdfToGraphicsWidget(file)
        self.move(0, 0)

    def load(self):
        design_file = os.path.join(
            get_base_dir(True), "designer_files", "MultiStandWidget.ui")
        uic.loadUi(design_file, self)
        self.setWindowTitle("MuseLib Multistand View: " + self.file)
        self.pageValue.valueChanged.connect(self.pageValChanged)
        self.zoomInBtn.clicked.connect(self.zoomIn)
        self.zoomOutBtn.clicked.connect(self.zoomOut)

    def zoomIn(self):
        self.scoreWindow.scale(1.1, 1.1)

    def zoomOut(self):
        self.scoreWindow.scale(0.9, 0.9)

    def loadPdfToGraphicsWidget(self, filename):
        """
        sets up the graphics view with pairs of pages
        :param filename: pdf file to load
        :return:
        """
        self.viewer.setPDF(filename)
        scene = self.scoreWindow.scene()
        if scene is not None:
            scene.clear()
        scene = self.viewer.getScene()
        self.scoreWindow.setScene(scene)

    def pageValChanged(self, pageVal):
        self.pages = pageVal
        width = self.viewer.getPageWidth(0) * self.pages
        self.scoreWindow.setFixedWidth(width)
        self.setFixedWidth(width) class PDFViewer(object):
    def __init__(self, width=None, pages=None):
    def setPDF(self, pdf):
    def getNumPages(self):
    def getPageWidth(self, number):
    def getNumGroups(self):
    def getPageLabel(self, number):
    def getPageSize(self, number):
    def setGroupLength(self, number):
    def getScene(self):
from PyQt4 import QtGui, QtCore, uic
from sys import platform
    from popplerqt4 import Poppler
from implementation.primaries.GUI.helpers import get_base_dir, parseStyle, postProcessLines, merge_instruments, merge_clefs_and_keys, fit_columns_to_widget
from implementation.primaries.GUI import themedWindow, Widgets, qt_threading, MultistandWidget, pdfViewer
import sip
import os
import difflib
import time
if platform != 'win32':


class MainWindow(QtGui.QMainWindow, themedWindow.ThemedWindow):
    widgets = {}
    frames = {}
    colors = {}

    def __init__(self, app, theme, theme_folder, design_folder):
        QtGui.QMainWindow.__init__(self)
        themedWindow.ThemedWindow.__init__(self, theme, theme_folder)
        self.qApp = app
        self.theme = theme
        self.theme_folder = theme_folder
        self.design_folder = design_folder
        self.loaded = ""
        self.current_piece = ""
        self.playlist = None
        self.index = None
        self.themeSet = False

    def resizeEvent(self, QResizeEvent):
        if hasattr(self, "scoreWindow"):
            self.resizeScoreWindow()
        if hasattr(self, "playlistTable"):
            self.resizePlaylistTable()
        if hasattr(self, "searchBar"):
            self.resizeSearchbar()
        QResizeEvent.accept()

    def resizeScoreWindow(self):
        if not self.scoreWindow.isHidden():
            widgetSize = (
                self.scoreWindow.width(), self.scoreWindow.height())
            self.resizeCenterWidget(self.scoreWindow)
            self.resizePages(widgetSize)

    def resizePlaylistTable(self):
        if not self.playlistTable.isHidden():
            self.resizeCenterWidget(self.playlistTable)

            fit_columns_to_widget(self.playlistTable, 10)