Skip to content

Commit

Permalink
Updating some more
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 1, 2011
1 parent 544e393 commit 8032989
Show file tree
Hide file tree
Showing 18 changed files with 2,127 additions and 244 deletions.
11 changes: 2 additions & 9 deletions src/REPLACEME.py
@@ -1,13 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Copyright (C) 2007 Christoph Würstle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
"""


import os
import sys
Expand All @@ -19,7 +12,7 @@


import constants
import REPLACEME_gtk
import REPLACEME_qt


if __name__ == "__main__":
Expand All @@ -42,4 +35,4 @@
_moduleLogger.info("Kernel: %s (%s) for %s" % os.uname()[2:])
_moduleLogger.info("Hostname: %s" % os.uname()[1])

REPLACEME_gtk.run()
REPLACEME_qt.run()
62 changes: 43 additions & 19 deletions src/REPLACEME_qt.py
Expand Up @@ -3,7 +3,6 @@

from __future__ import with_statement

import sys
import os
import simplejson
import logging
Expand All @@ -12,24 +11,21 @@
from PyQt4 import QtCore

import constants
import maeqt
from util import qui_utils
from util import misc as misc_utils


_moduleLogger = logging.getLogger(__name__)


IS_MAEMO = True


class REPLACEME(object):

_DATA_PATHS = [
os.path.dirname(__file__),
os.path.join(os.path.dirname(__file__), "../share"),
os.path.join(os.path.dirname(__file__), "../data"),
os.path.join(os.path.dirname(__file__), "../lib"),
'/usr/share/%s' % constants.__app_name__,
'/usr/lib/%s' % constants.__app_name__,
'/opt/%s/share' % constants.__app_name__,
]

def __init__(self, app):
Expand Down Expand Up @@ -67,8 +63,18 @@ def __init__(self, app):
self._quitAction.triggered.connect(self._on_quit)

self._app.lastWindowClosed.connect(self._on_app_quit)
self._mainWindow = MainWindow(None, self)
self._mainWindow.window.destroyed.connect(self._on_child_close)

self.load_settings()

self._mainWindow.show()
self._idleDelay = QtCore.QTimer()
self._idleDelay.setSingleShot(True)
self._idleDelay.setInterval(0)
self._idleDelay.timeout.connect(lambda: self._mainWindow.start())
self._idleDelay.start()

def load_settings(self):
try:
with open(constants._user_settings_, "r") as settingsFile:
Expand Down Expand Up @@ -107,17 +113,22 @@ def quitAction(self):

def _close_windows(self):
if self._mainWindow is not None:
self.save_settings()
self._mainWindow.window.destroyed.disconnect(self._on_child_close)
self._mainWindow.close()
self._mainWindow = None

@misc_utils.log_exception(_moduleLogger)
def _on_app_quit(self, checked = False):
self.save_settings()
if self._mainWindow is not None:
self.save_settings()
self._mainWindow.destroy()

@misc_utils.log_exception(_moduleLogger)
def _on_child_close(self, obj = None):
self._mainWindow = None
if self._mainWindow is not None:
self.save_settings()
self._mainWindow = None

@misc_utils.log_exception(_moduleLogger)
def _on_toggle_fullscreen(self, checked = False):
Expand Down Expand Up @@ -145,24 +156,30 @@ def __init__(self, parent, app):

centralWidget = QtGui.QWidget()
centralWidget.setLayout(self._layout)
centralWidget.setContentsMargins(0, 0, 0, 0)

self._window = QtGui.QMainWindow(parent)
self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
maeqt.set_autorient(self._window, True)
maeqt.set_stackable(self._window, True)
qui_utils.set_autorient(self._window, True)
qui_utils.set_stackable(self._window, True)
self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
self._window.setWindowIcon(QtGui.QIcon(self._app.appIconPath))
self._window.setCentralWidget(centralWidget)

self._aboutAction = QtGui.QAction(None)
self._aboutAction.setText("About")
self._aboutAction.triggered.connect(self._on_about)

self._closeWindowAction = QtGui.QAction(None)
self._closeWindowAction.setText("Close")
self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
self._closeWindowAction.triggered.connect(self._on_close_window)

if IS_MAEMO:
if constants.IS_MAEMO:
fileMenu = self._window.menuBar().addMenu("&File")

viewMenu = self._window.menuBar().addMenu("&View")
viewMenu.addAction(self._aboutAction)

self._window.addAction(self._closeWindowAction)
self._window.addAction(self._app.quitAction)
Expand All @@ -174,6 +191,7 @@ def __init__(self, parent, app):

viewMenu = self._window.menuBar().addMenu("&View")
viewMenu.addAction(self._app.fullscreenAction)
viewMenu.addAction(self._aboutAction)

self._window.addAction(self._app.logAction)

Expand All @@ -187,6 +205,15 @@ def window(self):
def walk_children(self):
return ()

def start(self):
pass
def close(self):
for child in self.walk_children():
child.window.destroyed.disconnect(self._on_child_close)
child.close()
self._window.close()


def show(self):
self._window.show()
for child in self.walk_children():
Expand All @@ -197,12 +224,6 @@ def hide(self):
child.hide()
self._window.hide()

def close(self):
for child in self.walk_children():
child.window.destroyed.disconnect(self._on_child_close)
child.close()
self._window.close()

def set_fullscreen(self, isFullscreen):
if isFullscreen:
self._window.showFullScreen()
Expand All @@ -223,7 +244,10 @@ def run():


if __name__ == "__main__":
logging.basicConfig(level = logging.DEBUG)
import sys

logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
logging.basicConfig(level=logging.DEBUG, format=logFormat)
try:
os.makedirs(constants._data_path_)
except OSError, e:
Expand Down
1 change: 1 addition & 0 deletions src/constants.py
Expand Up @@ -8,3 +8,4 @@
_data_path_ = os.path.join(os.path.expanduser("~"), ".%s" % __app_name__)
_user_settings_ = "%s/settings.ini" % _data_path_
_user_logpath_ = "%s/%s.log" % (_data_path_, __app_name__)
IS_MAEMO = True
122 changes: 0 additions & 122 deletions src/maeqt.py

This file was deleted.

70 changes: 70 additions & 0 deletions src/util/concurrent.py
Expand Up @@ -7,6 +7,76 @@
import time
import functools
import contextlib
import logging

import misc


_moduleLogger = logging.getLogger(__name__)


class AsyncLinearExecution(object):

def __init__(self, pool, func):
self._pool = pool
self._func = func
self._run = None

def start(self, *args, **kwds):
assert self._run is None, "Task already started"
self._run = self._func(*args, **kwds)
trampoline, args, kwds = self._run.send(None) # priming the function
self._pool.add_task(
trampoline,
args,
kwds,
self.on_success,
self.on_error,
)

@misc.log_exception(_moduleLogger)
def on_success(self, result):
_moduleLogger.debug("Processing success for: %r", self._func)
try:
trampoline, args, kwds = self._run.send(result)
except StopIteration, e:
pass
else:
self._pool.add_task(
trampoline,
args,
kwds,
self.on_success,
self.on_error,
)

@misc.log_exception(_moduleLogger)
def on_error(self, error):
_moduleLogger.debug("Processing error for: %r", self._func)
try:
trampoline, args, kwds = self._run.throw(error)
except StopIteration, e:
pass
else:
self._pool.add_task(
trampoline,
args,
kwds,
self.on_success,
self.on_error,
)

def __repr__(self):
return "<async %s at 0x%x>" % (self._func.__name__, id(self))

def __hash__(self):
return hash(self._func)

def __eq__(self, other):
return self._func == other._func

def __ne__(self, other):
return self._func != other._func


def synchronized(lock):
Expand Down

0 comments on commit 8032989

Please sign in to comment.