Skip to content

Commit c0367b3

Browse files
committed
Some cleanups on the plugin code fix for gtk+2.20
1 parent 16190fa commit c0367b3

File tree

7 files changed

+106
-12
lines changed

7 files changed

+106
-12
lines changed

pyazan/options.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Options(object):
99
def __init__(self):
1010
self.filename = paths.CONFIGPATH
11-
defaults = {"timeout":0, "events": ",".join(PRAYER_NAMES), "enabled": True, "text":"It's time to pray"}
11+
defaults = {"timeout":0, "events": ",".join(PRAYER_NAMES), "text":"It's time to pray"}
1212
self.options = ConfigParser(defaults)
1313
self.options.read(self.filename)
1414

@@ -24,7 +24,7 @@ def getNotifications(self):
2424

2525
def getEnabledPlugins(self):
2626
if self.options.has_section("main"):
27-
return self.options.get("main", "plugins").split(",")
27+
return [ x.strip() for x in self.options.get("main", "plugins").split(",") ]
2828
return list()
2929

3030
def setEnabledPlugins(self, plugins):
@@ -78,9 +78,3 @@ def setNotificationText(self, text):
7878
def save(self):
7979
fd = open(self.filename, "w")
8080
self.options.write(fd)
81-
82-
def enableNotifications(self, flag):
83-
self.setValue("notification", "enabled", flag)
84-
85-
def isNotificationEnabled(self):
86-
return self.getOption("notification", "enabled", True, True)

pyazan/plugins/notification/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
class Plugin(plugin.Plugin):
77
def __init__(self):
8+
self.name = "notification"
89
self.notify = pynotify.Notification("Praying Time")
910

1011
def load(self, pyazangui):

pyazan/plugins/plugin.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import logging
1+
import logging, os
2+
from pyazan.paths import XML
23

34
class Plugin(object):
45
def __init__(self):
5-
pass
6+
self.name = None
67

78
def load(self, *args):
89
raise NotImplementedError
@@ -14,6 +15,13 @@ def getDescription(self):
1415
return "No description"
1516

1617
def getUiWidget(self):
18+
import gtk
19+
ui_config = os.path.join(XML, "%s.xml" % self.name)
20+
logging.info("Reading %s from ui", ui_config)
21+
if os.path.exists(ui_config):
22+
self.builder = gtk.Builder()
23+
self.builder.add_from_file(ui_config)
24+
return self.builder.get_object("plugin")
1725
return None
1826

1927
def save(self):

pyazan/pyazan_gui_handler.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
from paths import *
88
from stopwatch import getTimeDiff
99

10+
class UiDict(dict):
11+
def __init__(self, builder):
12+
self.builder = builder
13+
self.cache = dict()
14+
15+
def __getitem__(self, name):
16+
if name not in self.cache:
17+
self.cache[name] = self.builder.get_object(name)
18+
return self.cache[name]
19+
1020
class PyazanGTK(object):
1121
def __init__(self):
1222
self.mainloop = gobject.MainLoop()
@@ -19,7 +29,7 @@ def __init__(self):
1929
self.build = gtk.Builder()
2030
self.build.add_from_file(os.path.join(XML, 'pyazan_ui.xml'))
2131

22-
self.ui = dict(((x.get_name(), x) for x in self.build.get_objects() if hasattr(x, 'get_name')))
32+
self.ui = UiDict(self.build)
2333
self.attachSignals()
2434

2535
self.loadOptions()

pyazangtk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging, os
33
from pyazan.pyazan_gui_handler import PyazanGTK
44

5-
65
if __name__ == "__main__":
76
loglevel = logging.WARNING
87
if os.environ.get("DEBUG"):

ui/audiohandler.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<property name="visible">True</property>
77
<property name="n_rows">5</property>
88
<property name="n_columns">2</property>
9+
<property name="row_spacing">5</property>
910
<child>
1011
<object class="GtkLabel" id="lbl_volume">
1112
<property name="visible">True</property>

ui/notification.xml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0"?>
2+
<interface>
3+
<requires lib="gtk+" version="2.16"/>
4+
<!-- interface-naming-policy project-wide -->
5+
<object class="GtkTable" id="plugin">
6+
<property name="visible">True</property>
7+
<property name="n_rows">4</property>
8+
<property name="n_columns">2</property>
9+
<property name="row_spacing">5</property>
10+
<child>
11+
<object class="GtkHSeparator" id="hseparator1">
12+
<property name="height_request">20</property>
13+
<property name="visible">True</property>
14+
</object>
15+
<packing>
16+
<property name="right_attach">2</property>
17+
<property name="y_options">GTK_FILL</property>
18+
</packing>
19+
</child>
20+
<child>
21+
<object class="GtkLabel" id="lbl_txt">
22+
<property name="visible">True</property>
23+
<property name="xalign">0</property>
24+
<property name="xpad">10</property>
25+
<property name="label" translatable="yes">Notification text</property>
26+
</object>
27+
<packing>
28+
<property name="top_attach">1</property>
29+
<property name="bottom_attach">2</property>
30+
<property name="y_options"></property>
31+
</packing>
32+
</child>
33+
<child>
34+
<object class="GtkEntry" id="txtbx">
35+
<property name="visible">True</property>
36+
<property name="can_focus">True</property>
37+
<property name="invisible_char">&#x25CF;</property>
38+
</object>
39+
<packing>
40+
<property name="left_attach">1</property>
41+
<property name="right_attach">2</property>
42+
<property name="top_attach">1</property>
43+
<property name="bottom_attach">2</property>
44+
<property name="y_options">GTK_FILL</property>
45+
</packing>
46+
</child>
47+
<child>
48+
<object class="GtkLabel" id="lbl_timeout">
49+
<property name="visible">True</property>
50+
<property name="xalign">0</property>
51+
<property name="xpad">10</property>
52+
<property name="label" translatable="yes">TimeOut</property>
53+
</object>
54+
<packing>
55+
<property name="top_attach">2</property>
56+
<property name="bottom_attach">3</property>
57+
<property name="y_options"></property>
58+
</packing>
59+
</child>
60+
<child>
61+
<object class="GtkSpinButton" id="spinbutton1">
62+
<property name="visible">True</property>
63+
<property name="can_focus">True</property>
64+
<property name="invisible_char">&#x25CF;</property>
65+
</object>
66+
<packing>
67+
<property name="left_attach">1</property>
68+
<property name="right_attach">2</property>
69+
<property name="top_attach">2</property>
70+
<property name="bottom_attach">3</property>
71+
<property name="y_options"></property>
72+
</packing>
73+
</child>
74+
<child>
75+
<placeholder/>
76+
</child>
77+
<child>
78+
<placeholder/>
79+
</child>
80+
</object>
81+
</interface>

0 commit comments

Comments
 (0)