-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPySSB.py
158 lines (127 loc) · 4.73 KB
/
PySSB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
import gtk, webkit, sys, getopt, argparse
import os.path
###
#
### Thanks go to
#
# Eugene for the argparse hint, it helped me out. (13/03/2016)
# Namechange from messenger.py to PySSB.py (16/03/2016)
# Added simple support for custom app icon png files ->
# Window name now reflects the website visited. (19/03/2016)
#
###
#INIT
class Go():
def __init__(self):
#Defaults for the app
webpage = 'http://www.messenger.com/login'
siteicon = 'messenger'
#Get metrics
width = gtk.gdk.screen_width() /3
height = gtk.gdk.screen_height()
print width, height
#Don't show the Browser UI
showBrowser = False
#Arguments, before window creation
#Eugene inspired this monstrosity...
parser = argparse.ArgumentParser(description='A SSB Python script.')
parser.add_argument('-s','--site', help='The website to load.',required=False)
parser.add_argument('-w','--width',help='The display width.', required=False)
parser.add_argument('-e','--height',help='The display height.', required=False)
parser.add_argument('-b','--browser',help='Show the Browser UI.', required=False)
args = parser.parse_args()
## show values ##
if args.site is not None:
#check for http/s, if not found, add.
#moved this to the args, less work down the line.
webpage = args.site
if webpage.startswith('http://') or webpage.startswith('https://'):
self._webview.open(webpage)
else:
webpage = 'http://' + webpage
#extract the general website name
#used for the useicon ad the window title
siteicon = webpage.split('//', 1)
print 'website: '+siteicon[1]
print siteicon[1].split('.',1)
print siteicon[1].split('.',2)
siteicon=siteicon[1].split('.',1)
siteicon=siteicon[1].split('.',2)
#get check for site name as an icon.png file
useicon=siteicon[0]+'.png'
print 'using icon: '+useicon
#check for a special width
if args.width is not None:
width = int(args.width)
print width
#check for a special height
if args.height is not None:
height = int(args.height)
print height
#check to show BrowserUI
if args.browser is not None:
showBrowser == True
# Create window
self._window = gtk.Window()
if os.path.exists('icons/'+useicon):
self._window.set_icon_from_file('icons/'+useicon)
else:
self._window.set_icon_from_file('icons/icon.png')
self._window.connect('destroy', lambda w: gtk.main_quit())
self._window.set_default_size(width, height)
# Create navigation bar
self._navigation = gtk.HBox()
#add in code for showing the Browser UI here .. from the command line.
#default = off
#This is NOT the right way to do this... but i am tired.
#Will fix soon.
if args.browser is not None:
self._back = gtk.ToolButton(gtk.STOCK_GO_BACK)
self._forward = gtk.ToolButton(gtk.STOCK_GO_FORWARD)
self._refresh = gtk.ToolButton(gtk.STOCK_REFRESH)
self._address_bar = gtk.Entry()
self._back.connect('clicked', self.go_back)
self._forward.connect('clicked', self.go_forward)
self._refresh.connect('clicked', self.refresh_page)
self._address_bar.connect('activate', self.load_page)
self._navigation.pack_start(self._back, False)
self._navigation.pack_start(self._forward, False)
self._navigation.pack_start(self._refresh, False)
self._navigation.pack_start(self._address_bar)
# Create view for webpage
self._view = gtk.ScrolledWindow()
self._webview = webkit.WebView()
self._webview.open(webpage)
print 'requested site: ',webpage
self._webview.connect('title-changed', self.change_title)
self._webview.connect('load-committed', self.change_url)
self._view.add(self._webview)
# Add everything and initialize
self._container = gtk.VBox()
self._container.pack_start(self._navigation, False)
self._container.pack_start(self._view)
self._window.add(self._container)
self._window.show_all()
self._window.set_title(siteicon[0].capitalize())
gtk.main()
def load_page(self, widget):
_add = self._address_bar.get_text()
if _add.startswith('http://') or _add.startswith('https://'):
self._webview.open(_add)
else:
_add = 'http://' + _add
self._address_bar.set_text(_add)
self._webview.open(_add)
def change_title(self, widget, frame, title):
self._window.set_title(title)
def change_url(self, widget, frame):
uri = frame.get_uri()
self._address_bar.set_text(uri)
def go_back(self, widget):
self._webview.go_back()
def go_forward(self, widget):
self._webview.go_forward()
def refresh_page(self, widget):
self._webview.reload()
init = Go()