3
# Copyright (C) 2010 Canonical Ltd
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License version 2 as
7
# published by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
# Copyright (C) 2010 Ken VanDine <ken.vandine@canonical.com>
19
# A poster for Gwibber
23
######################################################################
25
from os.path import join, dirname, exists, realpath, abspath
28
LAUNCH_DIR = abspath(sys.path[0])
29
SOURCE_DIR = join(LAUNCH_DIR, "..", "gwibber")
31
# If we were invoked from a Gwibber source directory add that as the
32
# preferred module path ...
33
if exists(join(SOURCE_DIR, "client.py")):
34
sys.path.insert(0, realpath(dirname(SOURCE_DIR)))
36
from gwibber.microblog.util import log
37
log.logger.name = "Gwibber Poster"
38
log.logger.info("Running from the source tree")
39
from gwibber import client
43
from gwibber.microblog.util import log
44
log.logger.name = "Gwibber Poster"
45
log.logger.info("Running from the source tree")
46
from gwibber import client
47
######################################################################
49
from gwibber.lib.gtk import widgets
51
import gwibber.gwui, gwibber.util, gwibber.microblog.util.resources
53
from gettext import lgettext as _
55
######################################################################
57
from optparse import OptionParser
58
parser = OptionParser()
59
parser.add_option("-p", "--persist", action="store_true",
60
dest="persist", default=False,
61
help=_("Don't exit after posting"))
62
parser.add_option("-w", "--window", action="store_true",
63
dest="window", default=False,
64
help=_("Don't exit when the window loses focus, also implies -d"))
65
parser.add_option("--decorate", action="store_true",
66
dest="decorate", default=False,
67
help=_("Display window decorations"))
68
parser.add_option("-d", "--debug", action="store_true",
69
dest="debug", default=False,
70
help=_("Log debug messages"))
71
parser.add_option("-m", "--message", dest="message",
72
help=_("Message to post"))
73
(options, args) = parser.parse_args()
75
log.logger.setLevel(log.logging.DEBUG)
77
log.logger.setLevel(log.logging.INFO)
78
######################################################################
80
class GwibberPosterWindow(gtk.Window):
82
gtk.Window.__init__(self)
83
self.set_default_size(420,140)
84
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
85
self.set_title(_("Gwibber Poster"))
86
self.set_icon_from_file(gwibber.microblog.util.resources.get_ui_asset("gwibber.svg"))
88
self.connect("delete-event", self.on_window_close)
90
if not options.decorate and not options.window:
91
self.set_decorated(False)
93
if not options.window:
94
self.connect("focus-out-event", self.on_window_close)
97
self.poster = widgets.GwibberPosterVBox(content=options.message)
99
self.poster = widgets.GwibberPosterVBox()
101
self.poster.input.connect("submit", self.on_input_activate)
102
self.poster.button_send.connect("clicked", self.on_button_send_clicked)
105
self.add(self.poster)
108
def on_input_activate(self, *args):
109
if not options.persist:
110
self.on_window_close()
112
def on_button_send_clicked(self, *args):
113
if not options.persist:
114
self.on_window_close()
116
def on_window_close(self, *args):
120
w = GwibberPosterWindow()