Example #1
0
    def __init__(self, network, width, height, font, frameRate, logFile, config):
        if getattr(sys, 'frozen', False):
            # In a bundle
            self.exeDir = os.path.dirname(sys.executable)
        else:
            # In normal python
            self.exeDir = ""
        self.logFile = logFile
        Log.__init__(self, logFile=logFile)

        KeyPress.__init__(self)

        self.network = network
        self.width = width
        self.height = height
        self.font = font
        self.frameRate = frameRate
        self.config = config

        #self.backgroundColour = (150, 150, 150)
        self.backgroundColour = (230, 230, 230)
        #self.backgroundColour = (255, 255, 255)

        self.button_reloadBells = Button("Reload Bells", (0, 0), font=self.font, active=True, border=True, fontSize="small")
        self.button_options = Button("Options", (self.button_reloadBells.rect.x+self.button_reloadBells.rect.w, 0), font=self.font, border=True, fontSize="small")
        self.button_help = Button("Help", (self.button_options.rect.x+self.button_options.rect.w, 0), font=self.font, border=True, fontSize="small")
        self.button_about = Button("About", (self.button_help.rect.x+self.button_help.rect.w, 0), font=self.font, border=True, fontSize="small")
        self.button_back = Button("Back", (self.button_about.rect.x+self.button_about.rect.w, 0), font=self.font, border=True, fontSize="small")
        self.button_quit = Button("Quit", (self.button_back.rect.x+self.button_back.rect.w, 0), font=self.font, border=True, fontSize="small")
        self.button_blankSpace = Button("", (self.button_quit.rect.x+self.button_quit.rect.w, 0), font=self.font, border=True, fontSize="small", buttonColour=(self.button_options.borderColour))
        self.button_blankSpace.rect.w = self.width - self.button_blankSpace.rect.x
        self.buttons = [self.button_reloadBells, self.button_options, self.button_help, self.button_about, self.button_back, self.button_quit, self.button_blankSpace]

        self.initialised = False
Example #2
0
    def __init__(self, logFile, frameRate=30):

        self.logFile = logFile

        Log.__init__(self, logFile=logFile)

        self.frameRate = frameRate

        self._lock = threading.Lock()
        self.clientThread = threading.Thread(target=self.start,
                                             args=(),
                                             daemon=True)
        self.incomingMessagesThread = threading.Thread(
            target=self.incomingMessages, args=(), daemon=True)
        self.outgoingMessagesThread = threading.Thread(
            target=self.outgoingMessages, args=(), daemon=True)

        self.disconnecting = False

        self.dataSize = 128
        self.ringing = False
        self.bellsRung = []

        self.messageEnd = bytes("/", "utf-8")

        self.connected = False
        self.gotNumberOfBells = False
        self.numberOfBells = []
Example #3
0
 def __init__(self, socket_type=_BROADCAST, tcp_host="0.0.0.0", port=PORT):
     super(_BaseClient, self).__init__(name=self.__class__.__name__,
                                           target=self._task)
     Log.__init__(self) # duh
     self.s = None
     self.setup(socket_type, tcp_host, port)
     self.port = port
     self.host = socket.gethostbyname(socket.gethostname())
     self.port = PORT  # Reserve a port for your service. TODO...
Example #4
0
 def __init__(self, port):
   Log.__init__(self, self._title)
   self._logger.debug(u"command host: init")
   self._silence = join(dirname(realpath(__file__)), 'data/silence.mp3')
   self._silence_size = getsize(self._silence)
   self._logger.info(u"command host: silence at %s" % self._silence)
   self._port = port
   Thread.__init__(self)
   self._queue = Queue()
Example #5
0
File: config.py Project: pscn/ads
 def __init__(self, filename, schema=None):
   Log.__init__(self, self._title)
   self._config = SafeConfigParser()
   if not isdir(self._configdir):
     self._logger.info(u"creating configuration directory %s" % self._configdir)
     makedirs(self._configdir)
   self._configfile = join(self._configdir, filename)
   self._schema = schema
   self.load()
Example #6
0
File: worker.py Project: pscn/ads
 def __init__(self, lifo=True, queue_timeout=5):
   Log.__init__(self, self._title)
   self._logger.debug(u"worker(init)")
   Thread.__init__(self)
   self._queue_timeout = queue_timeout
   if lifo:
     self._queue = LifoQueue()
   else:
     self._queue = Queue()
   self._queue_low = Queue(100)
Example #7
0
File: audio.py Project: sw104/ReBel
    def __init__(self, numberOfBells, mixer, config, logFile):
        if getattr(sys, 'frozen', False):
            # In a bundle
            self.exeDir = os.path.dirname(sys.executable)
        else:
            # In normal python
            self.exeDir = ""

        Log.__init__(self, logFile=logFile)
        Error.__init__(self)

        self.numberOfBells = numberOfBells
        self.config = config
        self.mixer = mixer

        self.bellSemitones = []
        self.bells = {}
        # Major scale formula: t t s t t t s
        self.majorScale = [0, 2, 4, 5, 7, 9, 11, 12]
        # Natural minor scale: t s t t s t t
        self.naturalMinorScale = [0, 2, 3, 5, 7, 8, 10, 12]
        # Harmonic minor scale: t s t t 1.5t s
        self.harmonicMinorScale = [0, 2, 3, 5, 7, 8, 11, 12]
        # Melodic minor scale: t s t t t t s
        self.melodicMinorScale = [0, 2, 3, 5, 7, 9, 11, 12]
        if self.config.get('scale') == "major":
            self.scale = self.majorScale
        elif self.config.get('scale') == "naturalMinor":
            self.scale = self.naturalMinorScale
        elif self.config.get('scale') == "harmonicMinor":
            self.scale = self.harmonicMinorScale
        elif self.config.get('scale') == "melodicMinor":
            self.scale = self.melodicMinorScale

        self.regenerateBells = True
        self.checkGeneratedBells()
        if self.regenerateBells == True:
            self.generateBells()
        if self.config.get('regenerateBells') == True:
            self.log("[INFO] Config regenerate bells option is True")
            self.generateBells()

        self.loadBells()
Example #8
0
    def __init__(self, serverLocalIP, serverPort):
        if getattr(sys, 'frozen', False):
            # In a bundle
            self.exeDir = os.path.dirname(sys.executable)
        else:
            # In normal python
            self.exeDir = ""
        Log.__init__(self,
                     logFile=os.path.join(self.exeDir, "..", "log",
                                          "serverLog.txt"))
        self.clearLog()

        self.reBelServerVersion = "v1.0.1"
        self.log("[INFO] Running ReBel server {}".format(
            self.reBelServerVersion))

        self.serverLocalIP = serverLocalIP
        self.serverPublicIP = None
        self.serverPort = serverPort

        self.connections = 0
        self.maxConnections = 12

        self.dataSize = 128

        self.clients = {}

        self.messageEnd = bytes("/", "utf-8")

        self.frameRate = 1000

        self.incomingMessagesThread = threading.Thread(
            target=self.incomingMessages, args=(), daemon=True)
        self.outgoingMessagesThread = threading.Thread(
            target=self.outgoingMessages, args=(), daemon=True)
        self.backgroundTasksThread = threading.Thread(
            target=self.backgroundTasks, args=(), daemon=True)

        self.numberOfBells = 8
        self.bellStrokeList = ['B'] * self.numberOfBells
Example #9
0
    def __init__(self,
                 menuWidth,
                 menuHeight,
                 mainWidth,
                 mainHeight,
                 configFile=os.path.join("..", "config", "config.txt")):

        # initialize
        pygame.init()
        pygame.mixer.pre_init(frequency=44100, size=16, channels=1)
        pygame.mixer.init()
        pygame.font.init()

        if getattr(sys, 'frozen', False):
            # In a bundle
            self.exeDir = os.path.dirname(sys.executable)
        else:
            # In normal python
            self.exeDir = ""

        self.font = Font(directory=os.path.join(self.exeDir, "..", "fonts"))

        self.logFile = os.path.join(self.exeDir, "..", "log", "log.txt")
        Log.__init__(self, logFile=self.logFile)
        self.clearLog()

        self.reBelClientVersion = "v1.0.1"
        self.log("[INFO] Running ReBel client {}".format(
            self.reBelClientVersion))

        self.menuWidth = menuWidth
        self.menuHeight = menuHeight

        self.mainWidth = mainWidth
        self.mainHeight = mainHeight

        self.configFile = os.path.join(self.exeDir, configFile)

        self.win = pygame.display.set_mode((self.menuWidth, self.menuHeight))
        pygame.display.set_caption("ReBel")
        self.gameIcon = pygame.image.load(
            os.path.join(self.exeDir, "..", "img", "ReBel_Icon.png"))
        pygame.display.set_icon(self.gameIcon)

        self.config = Config(fileName=self.configFile)

        self.frameRate = self.config.get('frameRate')
        self.log("[INFO] FrameRate set to {}".format(self.frameRate))

        self.network = Network(self.logFile, frameRate=self.frameRate)
        self.aboutScreen = AboutScreen(self.win,
                                       font=self.font,
                                       frameRate=self.frameRate,
                                       version=self.reBelClientVersion)
        self.helpScreen = HelpScreen(self.win,
                                     font=self.font,
                                     frameRate=self.frameRate)
        self.menuScreen = MenuScreen(win=self.win,
                                     font=self.font,
                                     network=self.network,
                                     frameRate=self.frameRate,
                                     logFile=self.logFile,
                                     config=self.config)
        self.optionsScreen = OptionsScreen(win=self.win,
                                           font=self.font,
                                           config=self.config,
                                           frameRate=self.frameRate)
        self.ringingScreen = RingingScreen(network=self.network,
                                           width=self.mainWidth,
                                           height=self.mainHeight,
                                           font=self.font,
                                           frameRate=self.frameRate,
                                           logFile=self.logFile,
                                           config=self.config)

        self.screen = 'menuScreen'
Example #10
0
    def __init__(self, win, network, frameRate, logFile, config, font):
        if getattr(sys, 'frozen', False):
            # In a bundle
            self.exeDir = os.path.dirname(sys.executable)
        else:
            # In normal python
            self.exeDir = ""

        self.win = win
        self.network = network
        self.frameRate = frameRate
        self.logFile = logFile
        self.config = config
        self.font = font

        Log.__init__(self, logFile=logFile)

        self.width = self.win.get_width()
        self.height = self.win.get_height()

        self.backgroundColour = (255, 255, 255)
        self.rebelLogo = pygame.image.load(
            os.path.join(self.exeDir, "..", "img", "logo.png"))

        self.offlineMessage = self.font.smallFont.render(
            "Server offline...", 1, (255, 0, 0))
        self.connectingMessage = self.font.smallFont.render(
            "Connecting to server...", 1, (50, 50, 50))
        self.connectedMessage = self.font.smallFont.render(
            "Connected to server!", 1, (0, 255, 0))
        self.blankMessage = self.font.smallFont.render("", 1, (255, 255, 255))

        self.userName = ""
        self.serverIP = ""
        self.serverPort = None

        self.offline = None
        self.connection = None

        self.connectionActive = False

        self.button_quit = Button("Quit", (20, self.height - 20),
                                  font=self.font)
        self.button_quit.rect.y -= self.button_quit.rect.h
        #
        self.button_about = Button("About", (20, self.button_quit.rect.y - 10),
                                   font=self.font,
                                   active=True)
        self.button_about.rect.y -= self.button_about.rect.h
        #
        self.button_help = Button("Help Info",
                                  (20, self.button_about.rect.y - 10),
                                  font=self.font,
                                  active=True)
        self.button_help.rect.y -= self.button_help.rect.h
        #
        self.button_startRinging = Button("Start ringing",
                                          (20, self.button_help.rect.y - 10),
                                          font=self.font,
                                          active=False)
        self.button_startRinging.rect.y -= self.button_startRinging.rect.h
        #
        self.button_serverConnect = Button(
            "Connect to server", (20, self.button_startRinging.rect.y - 10),
            font=self.font)
        self.button_serverConnect.rect.y -= self.button_serverConnect.rect.h
        #
        self.buttons = [
            self.button_serverConnect, self.button_startRinging,
            self.button_help, self.button_about, self.button_quit
        ]

        self.inputBox_serverPort = TitledInputBox(
            "Server Port:",
            160,
            self.button_serverConnect.rect.y - 85,
            200,
            32,
            font=self.font,
            text='35555')
        self.inputBox_serverIP = TitledInputBox("Server IP:",
                                                160,
                                                self.inputBox_serverPort.y -
                                                50,
                                                200,
                                                32,
                                                font=self.font)
        self.inputBox_userName = TitledInputBox("Your Name:",
                                                160,
                                                self.inputBox_serverIP.y - 50,
                                                200,
                                                32,
                                                font=self.font)
        self.input_boxes = [
            self.inputBox_userName, self.inputBox_serverIP,
            self.inputBox_serverPort
        ]
        self.activeBox = None

        self.connectionRectWhite = pygame.Rect(
            self.button_serverConnect.width + 25,
            self.button_serverConnect.rect.y + 5,
            self.connectingMessage.get_width(),
            self.connectingMessage.get_height())

        self.connectionActive = False
Example #11
0
 def __init__(self):
     self._r_env = _create_shared_env()
     Log.__init__(self)
     self.collector = None
     self.trigger = None
Example #12
0
 def __init__(self):
     self._r_env = _create_shared_env()
     Log.__init__(self)
     self.collector = None
     self.trigger = None
 def __init__(self, town="town01"):
     self.classes = read_class_names(cfg.YOLO.CLASSES)
     Log.__init__(self, "carla_dataset", town)
Example #14
0
File: library.py Project: pscn/ads
  def __init__(self, config):
    Log.__init__(self, self._title)
    self._logger.info(u"init")
    Worker.__init__(self, lifo=False)
    self._config = config
    self._library_filename = self._config.get('Library', 'path',
        join(self._config.configdir(), 'library.pkl'))
    Factories.clear()
    Logger.set_logger(self._logger)

    if self._config.get('TrackRelation', 'use_db', True):
      TrackRelationFactory.use_db()
      TrackRelationFactory.set_path(self._config.get('TrackRelation',
          'path', join(self._config.configdir(), '')))
    else:
      TrackRelationFactory.use_fs()
      TrackRelationFactory.set_path(self._config.get('TrackRelation',
          'path', join(self._config.configdir(), 'track')))
    TrackRelationFactory.set_maxentries(
        self._config.get('TrackRelation', 'maxentries', 500))

    if self._config.get('ArtistRelation', 'use_db', True):
      ArtistRelationFactory.use_db()
      ArtistRelationFactory.set_path(self._config.get('ArtistRelation',
          'path', join(self._config.configdir(), '')))
    else:
      ArtistRelationFactory.use_fs()
      ArtistRelationFactory.set_path(self._config.get('ArtistRelation',
          'path', join(self._config.configdir(), 'artist')))
    ArtistRelationFactory.set_maxentries(
        self._config.get('ArtistRelation', 'maxentries', 500))

    if self._config.get('Lookup', 'QueueResults', 'False') == 'True':
      self._queue_lookup_results = True
    else:
      self._queue_lookup_results = False

    # FIXME:  log if one of those libs is not present
    if self._config.get('Lookup', 'UseLastFM', 'True') == 'True':
      self._lastfm = LastFM(config)
      self._lastfm.start()
      self._thres_lastfm_lookup = self._config.getint('Lookup',
          'ThresholdLastFM', self._thres_lastfm_lookup)

    if self._config.get('Lookup', 'UseEchoNest', 'True') == 'True':
      self._echonest = EchoNest(config)
      self._echonest.start()
      self._thres_echonest_lookup = self._config.getint('Lookup',
          'ThresholdEchoNest', self._thres_echonest_lookup)

    # read, normalize and update ranking factors
    factor = 0.0
    for k in self._factor_ranking.keys():
      self._factor_ranking[k] = self._config.getfloat('Ranking',
          "factor%s" % k, self._factor_ranking[k])
      factor += self._factor_ranking[k]
    for k in self._factor_ranking.keys():
      self._factor_ranking[k] /= factor
      self._config.set('Ranking', "factor%s" % k, self._factor_ranking[k])

    self._relation_decay = self._config.getfloat('Ranking', 'RelationDecay',
        self._relation_decay)

    self._queue_update_factor = self._config.getfloat('Rating',
        'QueueUpdateFactor', self._queue_update_factor)

    self._unplayed_rating = self._config.getfloat('Ranking',
        'UnplayedRating', self._unplayed_rating)

    self._thres_track_lastplayed = self._config.getint('Ranking',
        'ThresholdTrackLastPlayed', self._thres_track_lastplayed)
    self._thres_track_laststarted= self._config.getint('Ranking',
        'ThresholdTrackLastStarted', self._thres_track_laststarted)
    self._thres_track_lastqueued= self._config.getint('Ranking',
        'ThresholdTrackLastQueued', self._thres_track_lastqueued)
    self._thres_artist_lastplayed = self._config.getint('Ranking',
        'ThresholdArtistLastPlayed', self._thres_artist_lastplayed)
    self._thres_artist_laststarted= self._config.getint('Ranking',
        'ThresholdArtistLastStarted', self._thres_artist_laststarted)
    self._thres_artist_lastqueued= self._config.getint('Ranking',
        'ThresholdArtistLastQueued', self._thres_artist_lastqueued)