Skip to content

Commit

Permalink
large update
Browse files Browse the repository at this point in the history
renamed the project from nclock to uberqt as the maintainer of nclock seems not interested
implemented theme switching
added license file
large updates
  • Loading branch information
poelzi committed Aug 9, 2010
1 parent 5715bcc commit d77abd9
Show file tree
Hide file tree
Showing 10 changed files with 636 additions and 103 deletions.
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

27 changes: 17 additions & 10 deletions src/ui/Ui_clock.py
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'src/ui/clock.ui'
#
# Created: Fri Aug 6 04:42:30 2010
# Created: Mon Aug 9 16:17:45 2010
# by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!
Expand All @@ -23,14 +23,14 @@ def setupUi(self, MainWindow):
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.clockContainer = ClockContainer(self.centralwidget)
self.clock = ClockContainer(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.clockContainer.sizePolicy().hasHeightForWidth())
self.clockContainer.setSizePolicy(sizePolicy)
self.clockContainer.setObjectName("clockContainer")
self.horizontalLayout.addWidget(self.clockContainer)
sizePolicy.setHeightForWidth(self.clock.sizePolicy().hasHeightForWidth())
self.clock.setSizePolicy(sizePolicy)
self.clock.setObjectName("clock")
self.horizontalLayout.addWidget(self.clock)
self.optionsFrame = QtGui.QFrame(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(1)
Expand Down Expand Up @@ -77,9 +77,9 @@ def setupUi(self, MainWindow):
self.boxAlarm.setObjectName("boxAlarm")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.boxAlarm)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.listView = QtGui.QListView(self.boxAlarm)
self.listView.setObjectName("listView")
self.verticalLayout_2.addWidget(self.listView)
self.ucList = QtGui.QListView(self.boxAlarm)
self.ucList.setObjectName("ucList")
self.verticalLayout_2.addWidget(self.ucList)
self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setMargin(5)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
Expand Down Expand Up @@ -123,6 +123,11 @@ def setupUi(self, MainWindow):
self.boxThemes = QtGui.QWidget()
self.boxThemes.setGeometry(QtCore.QRect(0, 0, 374, 356))
self.boxThemes.setObjectName("boxThemes")
self.horizontalLayout_5 = QtGui.QHBoxLayout(self.boxThemes)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.listThemes = QtGui.QListWidget(self.boxThemes)
self.listThemes.setObjectName("listThemes")
self.horizontalLayout_5.addWidget(self.listThemes)
self.tools.addItem(self.boxThemes, "")
self.verticalLayout.addWidget(self.tools)
self.preferences = QtGui.QPushButton(self.optionsFrame)
Expand All @@ -134,10 +139,12 @@ def setupUi(self, MainWindow):
MainWindow.setCentralWidget(self.centralwidget)

self.retranslateUi(MainWindow)
self.tools.setCurrentIndex(0)
QtCore.QObject.connect(self.listThemes, QtCore.SIGNAL("itemActivated(QListWidgetItem*)"), MainWindow.on_listThemes_itemactivated)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "uberqt", None, QtGui.QApplication.UnicodeUTF8))
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "UberQT", None, QtGui.QApplication.UnicodeUTF8))
self.exit.setText(QtGui.QApplication.translate("MainWindow", "Quit", None, QtGui.QApplication.UnicodeUTF8))
self.fullscreen.setText(QtGui.QApplication.translate("MainWindow", "Fullscreen", None, QtGui.QApplication.UnicodeUTF8))
self.zoomIn.setText(QtGui.QApplication.translate("MainWindow", "Zoom In", None, QtGui.QApplication.UnicodeUTF8))
Expand Down
19 changes: 18 additions & 1 deletion src/ui/Ui_config.py
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'src/ui/config.ui'
#
# Created: Wed Aug 4 22:02:31 2010
# Created: Mon Aug 9 14:51:50 2010
# by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!
Expand Down Expand Up @@ -70,6 +70,7 @@ def setupUi(self, configWindow):
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.dirLabel = QtGui.QLabel(self.general)
self.dirLabel.setMinimumSize(QtCore.QSize(150, 0))
self.dirLabel.setObjectName("dirLabel")
self.horizontalLayout_2.addWidget(self.dirLabel)
self.dirInput = QtGui.QLineEdit(self.general)
Expand All @@ -80,6 +81,20 @@ def setupUi(self, configWindow):
self.loadButton.setObjectName("loadButton")
self.horizontalLayout_2.addWidget(self.loadButton)
self.verticalLayout_3.addLayout(self.horizontalLayout_2)
self.horizontalLayout_6 = QtGui.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.bgLabel = QtGui.QLabel(self.general)
self.bgLabel.setMinimumSize(QtCore.QSize(150, 0))
self.bgLabel.setObjectName("bgLabel")
self.horizontalLayout_6.addWidget(self.bgLabel)
self.bgInput = QtGui.QLineEdit(self.general)
self.bgInput.setObjectName("bgInput")
self.horizontalLayout_6.addWidget(self.bgInput)
self.bgButton = QtGui.QPushButton(self.general)
self.bgButton.setFlat(False)
self.bgButton.setObjectName("bgButton")
self.horizontalLayout_6.addWidget(self.bgButton)
self.verticalLayout_3.addLayout(self.horizontalLayout_6)
self.tabWidget.addTab(self.general, "")
self.alarm = QtGui.QWidget()
self.alarm.setObjectName("alarm")
Expand Down Expand Up @@ -162,6 +177,8 @@ def retranslateUi(self, configWindow):
self.halfButton.setText(QtGui.QApplication.translate("configWindow", "Eco after 30 minutes", None, QtGui.QApplication.UnicodeUTF8))
self.dirLabel.setText(QtGui.QApplication.translate("configWindow", "Theme Directory", None, QtGui.QApplication.UnicodeUTF8))
self.loadButton.setText(QtGui.QApplication.translate("configWindow", "Browse", None, QtGui.QApplication.UnicodeUTF8))
self.bgLabel.setText(QtGui.QApplication.translate("configWindow", "Background Image", None, QtGui.QApplication.UnicodeUTF8))
self.bgButton.setText(QtGui.QApplication.translate("configWindow", "Browse", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.general), QtGui.QApplication.translate("configWindow", "General", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("configWindow", "Backend", None, QtGui.QApplication.UnicodeUTF8))
self.alarmSelect.setItemText(0, QtGui.QApplication.translate("configWindow", "Disabled", None, QtGui.QApplication.UnicodeUTF8))
Expand Down
10 changes: 10 additions & 0 deletions src/ui/__init__.py
@@ -0,0 +1,10 @@
import os

def get_default_theme_dir():
import platform
import re
# it is actually the hostname, but it should match normally :-)
if re.match("Nokia-N[0-9]{3}.*", platform.node()):
return os.path.join(os.path.expanduser("~"), "MyDocs", "Uberqt-themes")
# default linux path
return os.path.join(os.path.expanduser("~"), ".config", "uberclock", "uberqt-themes")
138 changes: 79 additions & 59 deletions src/ui/clock.py
Expand Up @@ -3,25 +3,25 @@
"""
Module implementing MainWindow.
"""
from PyQt4.QtCore import QSettings, SIGNAL, QBasicTimer, QTimer,QTime, QRect, QPoint
from PyQt4.QtGui import QMainWindow, QGraphicsScene, QTransform, QMessageBox, QSizePolicy
from PyQt4.QtCore import QSettings, Qt, QAbstractListModel, QModelIndex, QVariant, SIGNAL, QBasicTimer, QTimer,QTime, QRect, QPoint
from PyQt4.QtGui import QMainWindow, QSpinBox, QGraphicsScene, QTransform, QMessageBox, QSizePolicy, QListWidgetItem
from PyQt4.QtSvg import QGraphicsSvgItem
from Ui_clock import Ui_MainWindow
from config import configWindow
from PyQt4.QtCore import pyqtSignature
from __init__ import get_default_theme_dir

from .analog import AnalogClock

import os.path

def get_default_theme_dir():
import platform
import re
# it is actually the hostname, but it should match normally :-)
if re.match("Nokia-N[0-9]{3}.*", platform.node()):
return os.path.join(os.path.expanduser("~"), "MyDocs", "Nclocktheme")
# default linux path
return os.path.join(os.path.expanduser("~"), ".config", "nclock", "themes")
class ThemesItem(QListWidgetItem):
def __init__(self, path, name, **kwargs):
self.path = path
self.name = name
super(ThemesItem, self).__init__(name, **kwargs)



class MainWindow(QMainWindow, Ui_MainWindow):
"""
Expand All @@ -35,17 +35,30 @@ def __init__(self, parent=None, fullscreen="AUTO"):

self.clock_class = AnalogClock

self.fullScreen=0

self.settings=QSettings("uberclock", "uberqt")
self.config={}

self.setupUi(self)


self.configWin=configWindow(self, self.settings, self.config)

#self.model = MyListModel([1,2,3], self)
#self.listThemes.setModel(self.model)
#self.listThemes.setIndexWidget (self, QModelIndex index, QWidget widget)

#self.clock = self.grView
self.clock = AnalogClock(self)
self.clockContainer.addWidget(self.clock)
#self.tools.setCurrentIndex(1)
#self.horizontalLayout.addWidget(self.clock)

#self.setDefaults()
self.readConfig()
self._update_clock()
#self.readConfig()
self.updateBG()
self.clock.updateClock(self.config)

self.update_themes_list(True)
if fullscreen == "AUTO":
self.set_fullscreen(self.settings.value("fullscreen", False).toBool())
#self.loadTheme()
Expand All @@ -54,9 +67,8 @@ def __init__(self, parent=None, fullscreen="AUTO"):
#self.setClockType()

self.hideOptions()
self.configWin=configWindow(self, self.settings)
self.connect(self.configWin, SIGNAL("window closed"), self.config_window_closed)
self.connect(self.clockContainer, SIGNAL("clicked"), self.toggle_options)
self.connect(self.clock, SIGNAL("clicked"), self.toggle_options)


@pyqtSignature("")
Expand All @@ -74,25 +86,21 @@ def on_zoomOut_clicked(self):
#Sets the seconds hand to Automatic smooth style
def on_exit_clicked(self):
self.saveConfig()
self.configWin.writeConfig()
self.close()


def closeEvent(self, *args, **kwargs):
self.on_exit_clicked()
super(MainWindow, self).closeEvent(*args, **kwargs)

def config_window_closed(self, value):
#handle config window closed custom signals
self.config["clockType"]=value["clockType"]
self.config["ecoTimeout"]=value["ecoTimeout"]
self._update_clock()

def _update_clock(self):
self.clock.setClockType(self.config["clockType"])
if self.config["ecoTimeout"] == "quaterly":
timeout = 15
elif self.config["ecoTimeout"] == "half":
timeout = 30
else:
timeout = 0
self.clock.setEcoTimeout(timeout)
#self.config["clockType"]=value["clockType"]
#self.config["ecoTimeout"]=value["ecoTimeout"]
#self.config["backgroundPath"]=value["backgroundPath"]
self.updateBG()
self.clock.updateClock(self.config)


@pyqtSignature("")
def on_preferences_clicked(self):
#shows the config menu
Expand All @@ -102,7 +110,33 @@ def on_preferences_clicked(self):
@pyqtSignature("")
def on_fullscreen_clicked(self):
self.set_fullscreen(not self.isFullScreen())


def update_themes_list(self, load_theme=False):
self.listThemes.clear()
# add default items
pt = os.path.join(os.path.dirname(__file__), os.path.pardir, "theme")
self.listThemes.addItem(ThemesItem(pt, "default: analog"))

# add real entries
pt = os.path.expanduser(self.config["themePath"])
try:
for entry in os.listdir(pt):
item = ThemesItem(os.path.join(pt, entry), entry)
self.listThemes.addItem(item)
if self.config["themeName"] == entry:
self.listThemes.setItemSelected(item, True)
if load_theme:
self.clock.loadTheme(os.path.join(pt, entry))
except OSError:
pass

@pyqtSignature("(QListWidgetItem)")
def on_listThemes_itemactivated(self, item, **kwargs):
#shows the config menu
self.clock.loadTheme(item.path)
self.config["themeName"] = item.name


def set_fullscreen(self, do):
if do:
self.config["zoom"] = self.clock.getZoom()
Expand Down Expand Up @@ -133,6 +167,18 @@ def toggle_options(self, event):
self.hideOptions()
event.accept()

def updateBG(self):
if self.config.get("backgroundPath", None):
self.centralwidget.setStyleSheet("QWidget#centralwidget {\n"
" background-image: url(%s);\n"
"}" %self.config["backgroundPath"])
else:
self.centralwidget.setStyleSheet("QWidget#centralwidget {\n"
" background-image: url(:/background/theme/background.svg);\n"
" background-color: qradialgradient(spread:pad, cx:0.48, cy:0.533884, radius:0.597, fx:0.237, fy:0.213029, stop:0.14375 rgba(2, 28, 72, 255), stop:0.638535 rgba(1, 13, 34, 255), stop:1 rgba(0, 0, 0, 255))\n"
"}")


def saveConfig(self):
if self.config.get("zoom", None):
self.settings.setValue("zoom", self.config["zoom"])
Expand All @@ -141,29 +187,3 @@ def saveConfig(self):
self.settings.setValue("fullscreen", self.isFullScreen())
self.settings.sync()

def readConfig(self):
#read the config file from QSettings
self.settings=QSettings("nclock", "nclock")

def sd(key, default):
self.config[key] = val = unicode(self.settings.value(key, default).toString())
if not self.settings.contains(key):
self.settings.setValue(key, val)

sd("themeName", "")
sd("clockType", "Auto")
sd("themeDir", get_default_theme_dir())
sd("ecoTimeout", "15")
sd("alarmBackend", "none")
sd("uberclockHost", "localhost:1799")
sd("uberclockUser", "user")
sd("uberclockPassword", "user")

rv = self.settings.value("zoom", None).toFloat()
if rv[1]:
self.config["zoom"] = rv[0]

rv = self.settings.value("zoomFullscreen", None).toFloat()
if rv[1]:
self.config["zoomFullscreen"] = rv[0]

0 comments on commit d77abd9

Please sign in to comment.