~khurshid-alam/gwibber/gwibber-hack

« back to all changes in this revision

Viewing changes to bin/gwibber-poster

  • Committer: Khurshid Alam
  • Date: 2012-04-06 14:38:38 UTC
  • Revision ID: khurshid.alam@linuxmail.org-20120406143838-nz7hjg8vtzi2wl7i
initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# Copyright (C) 2010 Canonical Ltd
 
4
#
 
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.
 
8
#
 
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.
 
13
#
 
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/>.
 
16
#
 
17
# Copyright (C) 2010 Ken VanDine <ken.vandine@canonical.com>
 
18
#
 
19
# A poster for Gwibber
 
20
#
 
21
 
 
22
 
 
23
######################################################################
 
24
# Setup path
 
25
from os.path import join, dirname, exists, realpath, abspath
 
26
import sys
 
27
 
 
28
LAUNCH_DIR = abspath(sys.path[0])
 
29
SOURCE_DIR = join(LAUNCH_DIR, "..", "gwibber")
 
30
 
 
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)))
 
35
    try:
 
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
 
40
    finally:
 
41
        del sys.path[0]
 
42
else:
 
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
######################################################################
 
48
 
 
49
from gwibber.lib.gtk import widgets
 
50
import gtk
 
51
import gwibber.gwui, gwibber.util, gwibber.microblog.util.resources
 
52
import gettext
 
53
from gettext import lgettext as _
 
54
 
 
55
######################################################################
 
56
# Options 
 
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()
 
74
if options.debug:
 
75
  log.logger.setLevel(log.logging.DEBUG)
 
76
else:
 
77
  log.logger.setLevel(log.logging.INFO)
 
78
######################################################################
 
79
 
 
80
class GwibberPosterWindow(gtk.Window):
 
81
  def __init__(self):
 
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"))
 
87
 
 
88
    self.connect("delete-event", self.on_window_close)
 
89
 
 
90
    if not options.decorate and not options.window:
 
91
      self.set_decorated(False)
 
92
 
 
93
    if not options.window:
 
94
      self.connect("focus-out-event", self.on_window_close)
 
95
 
 
96
    if options.message:
 
97
      self.poster = widgets.GwibberPosterVBox(content=options.message)
 
98
    else:
 
99
      self.poster = widgets.GwibberPosterVBox()
 
100
 
 
101
    self.poster.input.connect("submit", self.on_input_activate)
 
102
    self.poster.button_send.connect("clicked", self.on_button_send_clicked)
 
103
 
 
104
 
 
105
    self.add(self.poster)
 
106
    self.show_all()
 
107
 
 
108
  def on_input_activate(self, *args):
 
109
    if not options.persist:
 
110
      self.on_window_close()
 
111
 
 
112
  def on_button_send_clicked(self, *args):
 
113
    if not options.persist:
 
114
      self.on_window_close()
 
115
 
 
116
  def on_window_close(self, *args):
 
117
    gtk.main_quit()
 
118
 
 
119
 
 
120
w = GwibberPosterWindow()
 
121
gtk.main()