PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/components/desktop/os-welcome/files/os-next-steps.py

https://bitbucket.org/dilos/userland-gate
Python | 241 lines | 172 code | 42 blank | 27 comment | 5 complexity | ff9821cfba0c9fa79fa0c1d802e682e2 MD5 | raw file
Possible License(s): CPL-1.0, AGPL-3.0, IPL-1.0, Apache-2.0, MPL-2.0-no-copyleft-exception, Unlicense, CC-BY-SA-4.0, AGPL-1.0, GPL-3.0, LGPL-2.0, LGPL-2.1, CC-BY-3.0, MIT, ISC, EPL-1.0, GPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, BSD-3-Clause, LGPL-3.0, BSD-2-Clause, 0BSD, JSON
  1. #!/usr/bin/python2.7
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. import locale
  20. import gettext
  21. from gettext import gettext as _
  22. import os
  23. import socket
  24. import string
  25. import subprocess
  26. import re
  27. import gi
  28. gi.require_version('Gtk', '3.0')
  29. from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, Gio
  30. def N_(message): return message
  31. PACKAGE = "os-next-steps"
  32. VERSION = "12"
  33. GETTEXT_PACKAGE = "os-welcome"
  34. LOCALEDIR = "/usr/share/locale"
  35. release_string = "Oracle Solaris 12"
  36. # There's probably a nicer way of including UTF-8 strings than this
  37. bullet_point = u'\u2022'
  38. default_link_color = Gdk.Color (0, 0, 65535)
  39. # This needs to stay in sync with the method in /lib/svc/method/svc-webui-server
  40. # for generating the hostname used in the site certificate to avoid TLS errors.
  41. def get_solaris_dashboard_url():
  42. hostname = socket.gethostname()
  43. if hostname != '':
  44. p = subprocess.Popen(["/usr/sbin/host", hostname],
  45. stdin=None, stdout=subprocess.PIPE,
  46. stderr=None, shell=False, close_fds=True,
  47. bufsize=-1)
  48. (stdoutdata, stderrdata) = p.communicate()
  49. if p.returncode == 0:
  50. hostname = stdoutdata.split(' ', 1)[0]
  51. if hostname == '':
  52. hostname = "localhost"
  53. return "https://%s:6787/" % hostname
  54. help_link= {
  55. 'header' : N_("Learn More about Oracle Solaris"),
  56. 'icon' : "resources.png",
  57. 'url_links' : [ ["http://docs.oracle.com/cd/E53394_01/pdf/E54847.pdf", N_("##What's new## with <b>Oracle Solaris 11.3</b>")], ["http://www.oracle.com/us/support/systems/index.html", N_("##Get world class support## with <b>Oracle Premier Support</b>")], [get_solaris_dashboard_url(), N_("##Explore## the <b>Oracle Solaris Dashboard</b> with system analytics and more")] ],
  58. }
  59. personalize_link= {
  60. 'header' : N_("Use the GNOME Desktop"),
  61. 'icon' : "gnome.png",
  62. 'program_links' : [ ["yelp.desktop", N_("##Get Help## using the <b>GNOME Desktop</b>")], ["gnome-control-center.desktop", N_("##Change desktop settings## with <b>GNOME Control Center</b>")], ["gnome-universal-access-panel.desktop", N_("##Enable Accessibility## with <b>Settings > Universal Access</b>")] ],
  63. }
  64. participate_link= {
  65. 'header' : N_("Participate"),
  66. 'icon' : "participate.png",
  67. 'url_links' : [ ["https://community.oracle.com/community/server_%26_storage_systems/solaris", N_("##Join in on the discussion## of the <b>Oracle Solaris Forums</b>")], ["http://www.oracle.com/technetwork/server-storage/solaris11/community/index.html", N_("##Catch the latest## from the <b>Oracle Solaris Community</b>")] ],
  68. }
  69. ICON_PATH = "/usr/share/os-about/"
  70. DESKTOP_ITEM_PATH = "/usr/share/applications/"
  71. class DialogOSNextSteps(Gtk.Dialog):
  72. def __init__(self, parent=None):
  73. Gtk.Dialog.__init__(self, self.__class__.__name__, parent, 0, None)
  74. self.connect('destroy', lambda *w: Gtk.main_quit())
  75. Gtk.Window.set_default_icon_from_file ("/usr/share/os-about/about-os-window-icon.png")
  76. self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('white'))
  77. # Set the dialog default spacing for about
  78. self.set_title(_("Start here with Oracle Solaris 12"))
  79. self.set_border_width(5)
  80. self.set_resizable(False)
  81. self.vbox.set_border_width(2)
  82. self.action_area.set_border_width(5)
  83. vbox = Gtk.VBox(False, 8)
  84. vbox.set_border_width(5)
  85. self.vbox.pack_start(vbox, False, False, 0)
  86. # Logo
  87. logo = Gtk.Image()
  88. pixbuf = GdkPixbuf.Pixbuf.new_from_file (ICON_PATH + "about-os-logo.png")
  89. # scale = 48.0 / pixbuf.get_height()
  90. # width_scale = pixbuf.get_width() * scale
  91. # height_scale = pixbuf.get_height() * scale
  92. # pixbuf = pixbuf.scale_simple (int(width_scale), int(height_scale), GdkPixbuf.InterpType.BILINEAR)
  93. logo.set_from_pixbuf (pixbuf)
  94. logo_hbox = Gtk.HBox(True, 0)
  95. logo_hbox.pack_start(logo, False, False, 0)
  96. vbox.pack_start(logo_hbox, False, False, 0)
  97. close_button=self.add_button(Gtk.STOCK_CLOSE,Gtk.ResponseType.CANCEL)
  98. self.set_default_response (Gtk.ResponseType.CANCEL)
  99. close_button.grab_default()
  100. close_button.grab_focus()
  101. close_button.connect('clicked', lambda *w: Gtk.main_quit())
  102. self.create_section(help_link, vbox)
  103. self.create_section(personalize_link, vbox)
  104. self.create_section(participate_link, vbox)
  105. self.show_all()
  106. def create_section(self, section_link, vbox):
  107. section_hbox = Gtk.HBox(False, 10)
  108. vbox.pack_start(section_hbox, True, True, 10)
  109. header = Gtk.Image()
  110. header.set_from_file (ICON_PATH + section_link['icon'])
  111. section_hbox.pack_start(header, False, False, 2)
  112. header_vbox = Gtk.VBox(False, 0)
  113. section_hbox.pack_start(header_vbox, False, False, 0)
  114. label = Gtk.Label()
  115. label.set_alignment(0, 0)
  116. label.set_markup("<span><b>%s</b></span>" % _(section_link['header']))
  117. label.set_justify(Gtk.Justification.LEFT)
  118. header_vbox.pack_start(label, False, False, 2)
  119. detail_vbox = Gtk.VBox(False, 0)
  120. detail_vbox.set_spacing(2)
  121. header_vbox.pack_start(detail_vbox, False, False, 0)
  122. self.fill_section(section_link, detail_vbox)
  123. def launch_app(self,label,uri):
  124. try:
  125. ditem = Gio.DesktopAppInfo.new (uri)
  126. ditem.launch ([])
  127. except Exception, e:
  128. print '''Warning: could not execute file "%s" : %s''' % (uri, e)
  129. return True
  130. def fill_section (self, section_link, vbox):
  131. if 'program_links' in section_link:
  132. for i in section_link['program_links']:
  133. hbox = Gtk.HBox(False, 0)
  134. label = Gtk.Label()
  135. label.set_markup(bullet_point + " ")
  136. label.set_justify(Gtk.Justification.LEFT)
  137. hbox.pack_start(label, False, False, 0)
  138. tmp = _(i[1]).split('##')
  139. label = Gtk.Label()
  140. label.set_markup(tmp[0])
  141. hbox.pack_start(label, False, False, 0)
  142. link_button = Gtk.Label()
  143. link_button.connect("activate-link", self.launch_app)
  144. markup = "<b><a href='%s'>%s</a></b>" % (i[0],tmp[1])
  145. link_button.set_markup(markup)
  146. hbox.pack_start(link_button, False, False, 0)
  147. label = Gtk.Label()
  148. label.set_markup(tmp[2])
  149. hbox.pack_start(label, False, False, 0)
  150. vbox.pack_start(hbox, False, False, 0)
  151. if 'url_links' in section_link:
  152. for i in section_link['url_links']:
  153. hbox = Gtk.HBox(False, 0)
  154. label = Gtk.Label()
  155. label.set_markup(bullet_point + " ")
  156. label.set_justify(Gtk.Justification.LEFT)
  157. hbox.pack_start(label, False, False, 0)
  158. tmp = _(i[1]).split('##')
  159. label = Gtk.Label()
  160. label.set_markup(tmp[0])
  161. hbox.pack_start(label, False, False, 0)
  162. link_button = Gtk.Label()
  163. markup = "<b><a href='%s'>%s</a></b>" % (i[0],tmp[1])
  164. link_button.set_markup(markup)
  165. hbox.pack_start(link_button, False, False, 0)
  166. label = Gtk.Label()
  167. label.set_markup(tmp[2])
  168. hbox.pack_start(label, False, False, 0)
  169. vbox.pack_start(hbox, False, False, 0)
  170. def main():
  171. locale.setlocale (locale.LC_ALL, "")
  172. gettext.textdomain (GETTEXT_PACKAGE)
  173. gettext.install (GETTEXT_PACKAGE, LOCALEDIR)
  174. style_provider = Gtk.CssProvider()
  175. css = """
  176. GtkDialog {
  177. background-image: url('/usr/share/os-about/about-os-background.jpg');
  178. background-position: left top;
  179. }
  180. """
  181. style_provider.load_from_data(css)
  182. Gtk.StyleContext.add_provider_for_screen(
  183. Gdk.Screen.get_default(),
  184. style_provider,
  185. Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
  186. )
  187. DialogOSNextSteps()
  188. Gtk.main()
  189. if __name__ == '__main__':
  190. main()