Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:log warning/error in status bar
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 88afc776d35169e430417d979cbcdf220875be7dfbeb75b1bed8f53253a5bc62
User & Date: jmcclure 2019-09-08 18:56:38
Context
2019-09-09
01:32
logging revisions; adjustable eraser size check-in: 8550c6eb3d user: jmcclure tags: trunk
2019-09-08
18:56
log warning/error in status bar check-in: 88afc776d3 user: jmcclure tags: trunk
17:33
basic logging implemented ... need better file location check-in: ec4628377a user: jmcclure tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to tweetypy/__init__.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23

import os, sys, time, logging
from PyQt5.QtWidgets import QApplication
from logging.handlers import RotatingFileHandler
from tweetypy.config import configure
from tweetypy.mainwin import MainWin

def main():
   logging.basicConfig(
      level=logging.INFO,
      format='%(created)f <%(levelno)s> %(module)12s(%(lineno)3d): %(message)s',
      handlers = [
         logging.StreamHandler(),
         RotatingFileHandler('tweetypy.log', maxBytes=(4 * 1024 * 1024), backupCount=255)
      ]
   )

   log = logging.getLogger()
   log.info('---------------------------------------------')
   log.info(f'TweetyPy started on {time.asctime(time.localtime())}')
   log.info('Version 1.0.0 "Ain\'t She Tweet"')
   log.info('Copyright 2017 Jesse McClure')
   log.info('License: MIT')
   log.info('---------------------------------------------')










|





>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

import os, sys, time, logging
from PyQt5.QtWidgets import QApplication
from logging.handlers import RotatingFileHandler
from tweetypy.config import configure
from tweetypy.mainwin import MainWin

def main():
   logging.basicConfig(
      level=logging.INFO,
      format='%(created)f <%(levelno)s> %(module)12s(%(lineno)03d): %(message)s',
      handlers = [
         logging.StreamHandler(),
         RotatingFileHandler('tweetypy.log', maxBytes=(4 * 1024 * 1024), backupCount=255)
      ]
   )
   logging.addLevelName(25, 'DATA')
   log = logging.getLogger()
   log.info('---------------------------------------------')
   log.info(f'TweetyPy started on {time.asctime(time.localtime())}')
   log.info('Version 1.0.0 "Ain\'t She Tweet"')
   log.info('Copyright 2017 Jesse McClure')
   log.info('License: MIT')
   log.info('---------------------------------------------')

Changes to tweetypy/mainwin.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

import logging
from logging import Handler
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QIcon, QPalette, QPixmap
from PyQt5.QtWidgets import qApp, QAction, QFileDialog, QLabel, QMenuBar, QMainWindow, QWidget
from tweetypy.spectrogram import Spectrogram

log = logging.getLogger()

class RequestHandler(Handler):
   def __init__(self, text):
      super().__init__()
      self.text = text

   def emit(self, record):

      self.text.setText(self.format(record))

class MainWin(QMainWindow):
   def __init__(self, files, config):
      super().__init__()

      self.files = files
      self.data = []
      self.saved = True
      self.config = config
      #self.setGeometry(0, 0, 800, 600)
      self.setWindowTitle("TweetyPy")
      self.setWindowIcon(QIcon('web.png'))   # TODO FIXME
      if self.config['main-window']['maximized']:
         self.setWindowState(Qt.WindowMaximized)
      self.init_calls()
      self.init_actions()
      self.init_menubar()
      self.init_toolbar()
      self.init_statusbar()

      self.slog = RequestHandler(self.statusbar.text2)
      log.addHandler(self.slog)

      self.init_body()
      self.show()
      self.spect = None
      # Spectrograms are sized relative to parent window.  The timer allows
      # the window manager to adjust the parent window prior to this sizing.











|

|


>
|




















|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

import logging
from logging import Handler
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QIcon, QPalette, QPixmap
from PyQt5.QtWidgets import qApp, QAction, QFileDialog, QLabel, QMenuBar, QMainWindow, QWidget
from tweetypy.spectrogram import Spectrogram

log = logging.getLogger()

class RequestHandler(Handler):
   def __init__(self, sbar):
      super().__init__()
      self.sbar = sbar

   def emit(self, record):
      if record.levelno > 25:
         self.sbar.showMessage(self.format(record), 5000)

class MainWin(QMainWindow):
   def __init__(self, files, config):
      super().__init__()

      self.files = files
      self.data = []
      self.saved = True
      self.config = config
      #self.setGeometry(0, 0, 800, 600)
      self.setWindowTitle("TweetyPy")
      self.setWindowIcon(QIcon('web.png'))   # TODO FIXME
      if self.config['main-window']['maximized']:
         self.setWindowState(Qt.WindowMaximized)
      self.init_calls()
      self.init_actions()
      self.init_menubar()
      self.init_toolbar()
      self.init_statusbar()

      self.slog = RequestHandler(self.statusbar)
      log.addHandler(self.slog)

      self.init_body()
      self.show()
      self.spect = None
      # Spectrograms are sized relative to parent window.  The timer allows
      # the window manager to adjust the parent window prior to this sizing.
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
      conf = self.config['main-window']
      if 'menu' in conf and type(conf['menu']) is list:
         bar = self.menuBar()
         add_menu(bar, conf['menu'])

   def init_statusbar(self):
      self.statusbar = self.statusBar()
      self.statusbar.text1 = QLabel()
      self.statusbar.text2 = QLabel()
      self.statusBar().addPermanentWidget(self.statusbar.text2)
      self.statusBar().addPermanentWidget(self.statusbar.text1)

   def init_toolbar(self):
      for bar in self.config['main-window']['toolbars']:
         toolbar = self.addToolBar(bar['name'])
         toolbar.setVisible(bar['visible'])
         toolbar.setToolButtonStyle(bar['style'])
         for item in bar['items']:
            if item == 'bar':
               toolbar.addSeparator()
            elif item in self.actions:
               toolbar.addAction(self.actions[item])
            else:
               log.warning(f'Unknown toolbar item "{item}"')

   def closeEvent(self, e):
      if self.spect and not self.spect.stored:
         log.info('fex: ' + ' '.join(map(str, self.spect.data.values())))
         self.data.append(self.spect.data)
         self.saved = False
      if not self.saved:
         self.action_save()

   def next_spectrogram(self):
      if self.spect and not self.spect.stored:
         log.info('fex: ' + ' '.join(map(str, self.spect.data.values())))
         self.data.append(self.spect.data)
         self.spect.close()
         self.saved = False
      if self.files:
         self.fname = self.files.pop(0)
         self.spect = Spectrogram(self.fname, self.body, self.config['spectrogram'])
         self.spect.mouseOver.connect(self.update_status)
         title = f'TweetyPy: {self.spect.data["name"]}'
         if self.files:
            title += f' [+{len(self.files)} more]'
         self.setWindowTitle(title)
      else:
         self.fname = None
         self.spect = None

   def update_status(self, x, y):
      self.statusbar.text1.setText(f'FEX: {self.spect.data["fex"]:.3}   {x:0.3}s {y:0.1}KHz')








|
<
|
<
















|







|
















|

123
124
125
126
127
128
129
130

131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
      conf = self.config['main-window']
      if 'menu' in conf and type(conf['menu']) is list:
         bar = self.menuBar()
         add_menu(bar, conf['menu'])

   def init_statusbar(self):
      self.statusbar = self.statusBar()
      self.statusbar.text = QLabel()

      self.statusBar().addPermanentWidget(self.statusbar.text)


   def init_toolbar(self):
      for bar in self.config['main-window']['toolbars']:
         toolbar = self.addToolBar(bar['name'])
         toolbar.setVisible(bar['visible'])
         toolbar.setToolButtonStyle(bar['style'])
         for item in bar['items']:
            if item == 'bar':
               toolbar.addSeparator()
            elif item in self.actions:
               toolbar.addAction(self.actions[item])
            else:
               log.warning(f'Unknown toolbar item "{item}"')

   def closeEvent(self, e):
      if self.spect and not self.spect.stored:
         log.log(25,' '.join(map(str, self.spect.data.values())))
         self.data.append(self.spect.data)
         self.saved = False
      if not self.saved:
         self.action_save()

   def next_spectrogram(self):
      if self.spect and not self.spect.stored:
         log.log(25,' '.join(map(str, self.spect.data.values())))
         self.data.append(self.spect.data)
         self.spect.close()
         self.saved = False
      if self.files:
         self.fname = self.files.pop(0)
         self.spect = Spectrogram(self.fname, self.body, self.config['spectrogram'])
         self.spect.mouseOver.connect(self.update_status)
         title = f'TweetyPy: {self.spect.data["name"]}'
         if self.files:
            title += f' [+{len(self.files)} more]'
         self.setWindowTitle(title)
      else:
         self.fname = None
         self.spect = None

   def update_status(self, x, y):
      self.statusbar.text.setText(f'FEX: {self.spect.data["fex"]:.3}   {x:0.3}s {y:0.1}KHz')