Guest User

Python

a guest
Oct 2nd, 2013
1,372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.38 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Copyright (C) 2008 Pâris Quentin
  5. # Copyright (C) 2007-2057 PlayOnLinux team
  6.  
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11.  
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16.  
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. encoding = 'utf-8'
  21.  
  22. import os, getopt, sys, urllib, signal, string, time, webbrowser, gettext, locale, sys, shutil, subprocess
  23.  
  24. try :
  25. os.environ["POL_OS"]
  26. except :
  27. print "ERROR ! Please define POL_OS environment var first."
  28. os._exit(1)
  29.  
  30. if(os.environ["POL_OS"] == "Linux"):
  31. import wxversion
  32. wxversion.ensureMinimal('2.8')
  33.  
  34. import wx, wx.aui
  35. import lib.lng as lng
  36. import lib.playonlinux as playonlinux, lib.Variables as Variables
  37. import guiv3 as gui, install, options, wine_versions as wver, sp, configure, threading, debug, gui_server
  38. import irc as ircgui
  39.  
  40. # This thread manage updates
  41. class POLWeb(threading.Thread):
  42. def __init__(self):
  43. threading.Thread.__init__(self)
  44. self.sendToStatusBarStr = ""
  45. self.sendAlertStr = None
  46. self.Gauge = False
  47. self.WebVersion = ""
  48. self.Show = False
  49. self.perc = -1
  50. self.updating = True
  51. def sendToStatusBar(self, message, gauge):
  52. self.sendToStatusBarStr = message
  53. self.Gauge = gauge
  54. self.Show = True
  55.  
  56. def sendPercentage(self, n):
  57. self.perc = n
  58.  
  59. def sendAlert(self, message):
  60. self.sendAlertStr = message
  61.  
  62. def LastVersion(self):
  63. if(os.environ["POL_OS"] == "Mac"):
  64. fichier_online="version_mac"
  65. else:
  66. fichier_online="version2"
  67. return os.popen(os.environ["POL_WGET"]+' "'+os.environ["SITE"]+'/'+fichier_online+'.php?v='+os.environ["VERSION"]+'" -T 30 -O-','r').read()
  68.  
  69. def real_check(self):
  70. self.WebVersion = self.LastVersion()
  71.  
  72. if(self.WebVersion == ""):
  73. self.sendToStatusBar(_('{0} website is unavailable. Please check your connection').format(os.environ["APPLICATION_TITLE"]), False)
  74. else:
  75. self.sendToStatusBar(_("Refreshing {0}").format(os.environ["APPLICATION_TITLE"]), True)
  76. self.sendPercentage(0)
  77. self.updating = True
  78. exe = ['bash',Variables.playonlinux_env+"/bash/pol_update_list"]
  79.  
  80. p = subprocess.Popen(exe, stdout=subprocess.PIPE, bufsize=1, preexec_fn=lambda: os.setpgid(os.getpid(), os.getpid()))
  81.  
  82. for line in iter(p.stdout.readline, ''):
  83. try:
  84. self.sendPercentage(int(line))
  85. except ValueError:
  86. pass
  87.  
  88. self.updating = False
  89. if(playonlinux.VersionLower(os.environ["VERSION"],self.WebVersion)):
  90. self.sendToStatusBar(_('An updated version of {0} is available').format(os.environ["APPLICATION_TITLE"])+" ("+self.WebVersion+")",False)
  91. if(os.environ["DEBIAN_PACKAGE"] == "FALSE"):
  92. self.sendAlert(_('An updated version of {0} is available').format(os.environ["APPLICATION_TITLE"])+" ("+self.WebVersion+")")
  93. os.environ["POL_UPTODATE"] = "FALSE"
  94. else:
  95. self.Show = False
  96. self.perc = -1
  97. os.environ["POL_UPTODATE"] = "TRUE"
  98.  
  99. self.wantcheck = False
  100.  
  101. def check(self):
  102. self.wantcheck = True
  103.  
  104. def run(self):
  105. self.check()
  106. while(1):
  107. if(self.wantcheck == True):
  108. self.real_check()
  109. time.sleep(1)
  110.  
  111. class MainWindow(wx.Frame):
  112. def __init__(self,parent,id,title):
  113.  
  114. wx.Frame.__init__(self, parent, 1000, title, size = (515,450))
  115. self.SetMinSize((400,400))
  116. self.SetIcon(wx.Icon(Variables.playonlinux_env+"/etc/playonlinux.png", wx.BITMAP_TYPE_ANY))
  117.  
  118. self.windowList = {}
  119. self.registeredPid = []
  120. self.windowOpened = 0
  121.  
  122. # Manage updater
  123. self.updater = POLWeb()
  124. self.updater.start()
  125.  
  126. # These lists contain the dock links and images
  127. self.menuElem = {}
  128. self.menuImage = {}
  129.  
  130. # Catch CTRL+C
  131. signal.signal(signal.SIGINT, self.ForceClose)
  132.  
  133. # Window size
  134. try:
  135. self.windowWidth = int(playonlinux.GetSettings("MAINWINDOW_WIDTH"))
  136. self.windowHeight = int(playonlinux.GetSettings("MAINWINDOW_HEIGHT"))
  137. self.SetSize((self.windowWidth,self.windowHeight))
  138. except:
  139. self.windowWidth = 450
  140. self.windowHeight = 450
  141.  
  142. # Window position
  143. try:
  144. self.windowx = int(playonlinux.GetSettings("MAINWINDOW_X"))
  145. self.windowy = int(playonlinux.GetSettings("MAINWINDOW_Y"))
  146. self.screen_width = wx.Display().GetGeometry()[2]
  147. self.screen_height = wx.Display().GetGeometry()[3]
  148.  
  149. if(self.screen_width >= self.windowx and self.screen_height >= self.windowy):
  150. self.SetPosition((self.windowx, self.windowy))
  151. else:
  152. self.Center(wx.BOTH)
  153. except:
  154. self.Center(wx.BOTH)
  155.  
  156.  
  157. try: self.iconSize = int(playonlinux.GetSettings("ICON_SIZE"))
  158. except: self.iconSize = 32
  159.  
  160. self.images = wx.ImageList(self.iconSize, self.iconSize)
  161. self.imagesEmpty = wx.ImageList(1,1)
  162.  
  163.  
  164. self.sendAlertStr = None
  165.  
  166. ## Fonts
  167. if(os.environ["POL_OS"] == "Mac"):
  168. self.fontTitre = wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, "", wx.FONTENCODING_DEFAULT)
  169. self.fontText = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL,False, "", wx.FONTENCODING_DEFAULT)
  170. else :
  171. self.fontTitre = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, "", wx.FONTENCODING_DEFAULT)
  172. self.fontText = wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL,False, "", wx.FONTENCODING_DEFAULT)
  173.  
  174.  
  175. ## List game
  176. self.list_game = wx.TreeCtrl(self, 105, style=wx.TR_HIDE_ROOT|wx.TR_FULL_ROW_HIGHLIGHT)
  177. self.list_game.SetSpacing(0);
  178. self.list_game.SetIndent(5);
  179. self.list_game.SetImageList(self.images)
  180.  
  181. self._mgr = wx.aui.AuiManager(self)
  182. self.menu_gauche = wx.Panel(self,-1)
  183.  
  184.  
  185.  
  186. self._mgr.AddPane(self.list_game, wx.CENTER)
  187.  
  188.  
  189. self.filemenu = wx.Menu()
  190. ### On MacOS X, preference is always on the main menu
  191. if(os.environ["POL_OS"] == "Mac"):
  192. prefItem = self.filemenu.Append(wx.ID_PREFERENCES, text = "&Preferences")
  193. self.Bind(wx.EVT_MENU, self.Options, prefItem)
  194.  
  195. ### File menu
  196. self.filemenu.Append(wx.ID_OPEN, _("Run"))
  197. self.filemenu.Append(wx.ID_ADD, _("Install"))
  198. self.filemenu.Append(wx.ID_DELETE, _("Remove"))
  199. self.filemenu.AppendSeparator()
  200. self.filemenu.Append(216, _("Donate"))
  201. self.filemenu.Append(wx.ID_EXIT, _("Exit"))
  202.  
  203. ### Display menu
  204. self.displaymenu = wx.Menu()
  205. self.icon16 = self.displaymenu.AppendRadioItem(501, _("Small icons"))
  206. self.icon24 = self.displaymenu.AppendRadioItem(502, _("Medium icons"))
  207. self.icon32 = self.displaymenu.AppendRadioItem(503, _("Large icons"))
  208. self.icon48 = self.displaymenu.AppendRadioItem(504, _("Very large icons"))
  209. if(self.iconSize == 16):
  210. self.icon16.Check(True)
  211. if(self.iconSize == 24):
  212. self.icon24.Check(True)
  213. if(self.iconSize == 32):
  214. self.icon32.Check(True)
  215. if(self.iconSize == 48):
  216. self.icon48.Check(True)
  217.  
  218. self.expertmenu = wx.Menu()
  219.  
  220. self.winever_item = wx.MenuItem(self.expertmenu, 107, _("Manage Wine versions"))
  221. self.winever_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/wine.png"))
  222. self.expertmenu.AppendItem(self.winever_item)
  223.  
  224. if(os.environ["POL_OS"] == "Mac"):
  225. self.expertmenu.AppendSeparator()
  226. self.pccd_item = wx.MenuItem(self.expertmenu, 113, _("Read a PC CD-Rom"))
  227. self.pccd_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/cdrom.png"))
  228. self.expertmenu.AppendItem(self.pccd_item)
  229.  
  230. self.expertmenu.AppendSeparator()
  231.  
  232. self.run_item = wx.MenuItem(self.expertmenu, 108, _("Run a local script"))
  233. self.run_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/run.png"))
  234. self.expertmenu.AppendItem(self.run_item)
  235.  
  236. self.wineserv_item = wx.MenuItem(self.expertmenu, 115, _('Close all {0} software').format(os.environ["APPLICATION_TITLE"]))
  237. self.wineserv_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/wineserver.png"))
  238. self.expertmenu.AppendItem(self.wineserv_item)
  239.  
  240. self.polshell_item = wx.MenuItem(self.expertmenu, 109, _('{0} console').format(os.environ["APPLICATION_TITLE"]))
  241. self.polshell_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/polshell.png"))
  242. self.expertmenu.AppendItem(self.polshell_item)
  243.  
  244. self.expertmenu.AppendSeparator()
  245.  
  246. self.pol_online = wx.MenuItem(self.expertmenu, 112, os.environ["APPLICATION_TITLE"]+" online")
  247. self.pol_online.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/playonlinux_online.png"))
  248. self.expertmenu.AppendItem(self.pol_online)
  249.  
  250. self.chat_item = wx.MenuItem(self.expertmenu, 111, _("{0} messenger").format(os.environ["APPLICATION_TITLE"]))
  251. self.chat_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/people.png"))
  252. self.expertmenu.AppendItem(self.chat_item)
  253.  
  254. self.bug_item = wx.MenuItem(self.expertmenu, 110, _("{0} debugger").format(os.environ["APPLICATION_TITLE"]))
  255. self.bug_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/bug.png"))
  256. self.expertmenu.AppendItem(self.bug_item)
  257.  
  258.  
  259. self.optionmenu = wx.Menu()
  260.  
  261.  
  262. self.option_item = wx.MenuItem(self.expertmenu, 211, _("Internet"))
  263. self.option_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/etc/onglet/internet-web-browser.png"))
  264. self.optionmenu.AppendItem(self.option_item)
  265.  
  266. self.option_item = wx.MenuItem(self.expertmenu, 212, _("File associations"))
  267. self.option_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/extensions.png"))
  268. self.optionmenu.AppendItem(self.option_item)
  269.  
  270.  
  271.  
  272. self.help_menu = wx.Menu()
  273. self.help_menu.Append(wx.ID_ABOUT, _('About {0}').format(os.environ["APPLICATION_TITLE"]))
  274. self.pluginsmenu = wx.Menu()
  275.  
  276. files=os.listdir(Variables.playonlinux_rep+"/plugins")
  277. files.sort()
  278. self.plugin_list = []
  279. self.i = 0
  280. self.j = 0
  281. while(self.i < len(files)):
  282. if(os.path.exists(Variables.playonlinux_rep+"/plugins/"+files[self.i]+"/scripts/menu")):
  283. if(os.path.exists(Variables.playonlinux_rep+"/plugins/"+files[self.i]+"/enabled")):
  284. self.plugin_item = wx.MenuItem(self.expertmenu, 300+self.j, files[self.i])
  285.  
  286. self.icon_look_for = Variables.playonlinux_rep+"/plugins/"+files[self.i]+"/icon"
  287. if(os.path.exists(self.icon_look_for)):
  288. self.bitmap = wx.Bitmap(self.icon_look_for)
  289. else:
  290. self.bitmap = wx.Bitmap(Variables.playonlinux_env+"/etc/playonlinux16.png")
  291.  
  292. self.plugin_item.SetBitmap(self.bitmap)
  293. self.pluginsmenu.AppendItem(self.plugin_item)
  294. wx.EVT_MENU(self, 300+self.j, self.run_plugin)
  295. self.plugin_list.append(files[self.i])
  296. self.j += 1
  297. self.i += 1
  298.  
  299. if(self.j > 0):
  300. self.pluginsmenu.AppendSeparator()
  301.  
  302. self.option_item_p = wx.MenuItem(self.expertmenu, 214, _("Plugin manager"))
  303. self.option_item_p.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/etc/onglet/package-x-generic.png"))
  304. self.pluginsmenu.AppendItem(self.option_item_p)
  305.  
  306. self.option_item = wx.MenuItem(self.expertmenu, 214, _("Plugin manager"))
  307. self.option_item.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/etc/onglet/package-x-generic.png"))
  308. self.optionmenu.AppendItem(self.option_item)
  309.  
  310.  
  311. self.last_string = ""
  312.  
  313. self.sb = wx.StatusBar(self, -1 )
  314. self.sb.SetFieldsCount(2)
  315. self.sb.SetStatusWidths([self.GetSize()[0], -1])
  316. self.sb.SetStatusText("", 0)
  317.  
  318. if(os.environ["POL_OS"] == "Mac"):
  319. hauteur = 2;
  320. else:
  321. hauteur = 6;
  322. self.jauge_update = wx.Gauge(self.sb, -1, 100, (self.GetSize()[0]-100, hauteur), size=(100,16))
  323. self.jauge_update.Pulse()
  324. self.jauge_update.Hide()
  325. self.SetStatusBar(self.sb)
  326.  
  327. #self.helpmenu = wx.MenuItem()
  328. #self.helpmenu.Append(wx.ID_ABOUT, _("About"))
  329.  
  330. self.menubar = wx.MenuBar()
  331. self.menubar.Append(self.filemenu, _("File"))
  332. self.menubar.Append(self.displaymenu, _("Display"))
  333. self.menubar.Append(self.expertmenu, _("Tools"))
  334. self.menubar.Append(self.optionmenu, _("Settings"))
  335. self.menubar.Append(self.pluginsmenu, _("Plugins"))
  336. self.menubar.Append(self.help_menu, "&Help")
  337.  
  338. #self.menubar.Append(self.help_menu, _("About"))
  339.  
  340. self.SetMenuBar(self.menubar)
  341. iconSize = (32,32)
  342.  
  343. self.toolbar = self.CreateToolBar(wx.TB_TEXT)
  344. self.toolbar.SetToolBitmapSize(iconSize)
  345. self.searchbox = wx.SearchCtrl( self.toolbar, 124, style=wx.RAISED_BORDER )
  346. self.playTool = self.toolbar.AddLabelTool(wx.ID_OPEN, _("Run"), wx.Bitmap(Variables.playonlinux_env+"/resources/images/toolbar/play.png"))
  347. self.stopTool = self.toolbar.AddLabelTool(123, _("Close"), wx.Bitmap(Variables.playonlinux_env+"/resources/images/toolbar/stop.png"))
  348.  
  349. self.toolbar.AddSeparator()
  350. self.toolbar.AddLabelTool(wx.ID_ADD, _("Install"), wx.Bitmap(Variables.playonlinux_env+"/resources/images/toolbar/install.png"))
  351. self.removeTool = self.toolbar_remove = self.toolbar.AddLabelTool(wx.ID_DELETE, _("Remove"), wx.Bitmap(Variables.playonlinux_env+"/resources/images/toolbar/delete.png"))
  352. self.toolbar.AddSeparator()
  353. self.toolbar.AddLabelTool(121, _("Configure"), wx.Bitmap(Variables.playonlinux_env+"/resources/images/toolbar/configure.png"))
  354.  
  355. try:
  356. self.toolbar.AddStretchableSpace()
  357. self.SpaceHack = False
  358. except:
  359. # wxpython 2.8 does not support AddStretchableSpace(). This is a dirty workaround for this.
  360. self.dirtyHack = wx.StaticText(self.toolbar)
  361. self.SpaceHack = True
  362. self.toolbar.AddControl( self.dirtyHack )
  363. self.UpdateSearchHackSize()
  364.  
  365. try:
  366. self.toolbar.AddControl( self.searchbox , _("Search"))
  367. except:
  368. self.toolbar.AddControl( self.searchbox )
  369. self.searchbox.SetDescriptiveText(_("Search"))
  370.  
  371.  
  372. self.toolbar.Realize()
  373. self.Reload(self)
  374. wx.EVT_MENU(self, wx.ID_OPEN, self.Run)
  375. wx.EVT_MENU(self, 123, self.RKill)
  376.  
  377. wx.EVT_MENU(self, wx.ID_ADD, self.InstallMenu)
  378. wx.EVT_MENU(self, wx.ID_ABOUT, self.About)
  379. wx.EVT_MENU(self, wx.ID_EXIT, self.ClosePol)
  380. wx.EVT_MENU(self, wx.ID_DELETE, self.UninstallGame)
  381.  
  382. # Display
  383. wx.EVT_MENU(self, 501, self.iconDisplay)
  384. wx.EVT_MENU(self, 502, self.iconDisplay)
  385. wx.EVT_MENU(self, 503, self.iconDisplay)
  386. wx.EVT_MENU(self, 504, self.iconDisplay)
  387. wx.EVT_MENU(self, 505, self.displayMen)
  388.  
  389. # Expert
  390. wx.EVT_MENU(self, 101, self.Reload)
  391. wx.EVT_MENU(self, 107, self.WineVersion)
  392. wx.EVT_MENU(self, 108, self.Executer)
  393. wx.EVT_MENU(self, 109, self.PolShell)
  394. wx.EVT_MENU(self, 110, self.BugReport)
  395. wx.EVT_MENU(self, 111, self.OpenIrc)
  396. wx.EVT_MENU(self, 112, self.POLOnline)
  397. wx.EVT_MENU(self, 113, self.PCCd)
  398. wx.EVT_MENU(self, 115, self.killall)
  399. wx.EVT_MENU(self, 121, self.Configure)
  400. wx.EVT_MENU(self, 122, self.Package)
  401. wx.EVT_TEXT(self, 124, self.Reload)
  402.  
  403. #Options
  404. wx.EVT_MENU(self, 210, self.Options)
  405. wx.EVT_MENU(self, 211, self.Options)
  406. wx.EVT_MENU(self, 212, self.Options)
  407. wx.EVT_MENU(self, 213, self.Options)
  408. wx.EVT_MENU(self, 214, self.Options)
  409. wx.EVT_MENU(self, 215, self.Options)
  410.  
  411. wx.EVT_MENU(self, 216, self.donate)
  412.  
  413. wx.EVT_CLOSE(self, self.ClosePol)
  414. wx.EVT_TREE_ITEM_ACTIVATED(self, 105, self.Run)
  415. wx.EVT_TREE_SEL_CHANGED(self, 105, self.Select)
  416.  
  417.  
  418. # PlayOnLinux main timer
  419. self.timer = wx.Timer(self, 1)
  420. self.Bind(wx.EVT_TIMER, self.TimerAction, self.timer)
  421. self.timer.Start(1000)
  422. self.Timer_LastShortcutList = None
  423. self.Timer_LastIconList = None
  424.  
  425. # SetupWindow timer. The server is in another thread and GUI must be run from the main thread
  426. self.SetupWindowTimer = wx.Timer(self, 2)
  427. self.Bind(wx.EVT_TIMER, self.SetupWindowAction, self.SetupWindowTimer)
  428. self.SetupWindowTimer_action = None
  429. self.SetupWindowTimer.Start(100)
  430. self.SetupWindowTimer_delay = 100
  431.  
  432. #Pop-up menu for game list: beginning
  433. wx.EVT_TREE_ITEM_MENU(self, 105, self.RMBInGameList)
  434. wx.EVT_MENU(self, 230, self.RWineConfigurator)
  435. wx.EVT_MENU(self, 231, self.RRegistryEditor)
  436. wx.EVT_MENU(self, 232, self.GoToAppDir)
  437. wx.EVT_MENU(self, 233, self.ChangeIcon)
  438. wx.EVT_MENU(self, 234, self.UninstallGame)
  439. wx.EVT_MENU(self, 235, self.RKill)
  440. wx.EVT_MENU(self, 236, self.ReadMe)
  441. self.Bind(wx.EVT_SIZE, self.ResizeWindow)
  442.  
  443. self.MgrAddPage()
  444.  
  445. def ResizeWindow(self, e):
  446. self.UpdateGaugePos()
  447. self.UpdateSearchHackSize()
  448.  
  449. def UpdateSearchHackSize(self):
  450. if(self.SpaceHack == True):
  451. self.dirtyHack.SetLabel("")
  452. self.dirtyHack.SetSize((50,1))
  453.  
  454. def UpdateGaugePos(self):
  455. if(os.environ["POL_OS"] == "Mac"):
  456. hauteur = 2;
  457. else:
  458. hauteur = 6;
  459. self.jauge_update.SetPosition((self.GetSize()[0]-100, hauteur))
  460.  
  461. def SetupWindowTimer_SendToGui(self, recvData):
  462. recvData = recvData.split("\t")
  463. while(self.SetupWindowTimer_action != None):
  464. time.sleep(0.1)
  465. self.SetupWindowTimer_action = recvData
  466.  
  467. def SetupWindow_TimerRestart(self, time):
  468. if(time != self.SetupWindowTimer_delay):
  469. self.SetupWindowTimer.Stop()
  470. self.SetupWindowTimer.Start(time)
  471. self.SetupWindowTimer_delay = time
  472.  
  473. def SetupWindowAction(self, event):
  474.  
  475. if(self.windowOpened == 0):
  476. self.SetupWindow_TimerRestart(100)
  477. else:
  478. self.SetupWindow_TimerRestart(10)
  479.  
  480. if(self.SetupWindowTimer_action != None):
  481. return gui_server.readAction(self)
  482.  
  483.  
  484. def TimerAction(self, event):
  485. self.StatusRead()
  486.  
  487. # We read shortcut folder to see if it has to be rescanned
  488. currentShortcuts = os.path.getmtime(Variables.playonlinux_rep+"/shortcuts")
  489. currentIcons = os.path.getmtime(Variables.playonlinux_rep+"/icones/32")
  490. if(currentShortcuts != self.Timer_LastShortcutList or currentIcons != self.Timer_LastIconList):
  491. self.Reload(self)
  492. self.Timer_LastShortcutList = currentShortcuts
  493. self.Timer_LastIconList = currentIcons
  494.  
  495. def MgrAddPage(self):
  496. try:
  497. self.LoadSize = int(playonlinux.GetSettings("PANEL_SIZE"))
  498. except:
  499. self.LoadSize = 150
  500.  
  501. try:
  502. self.LoadPosition = playonlinux.GetSettings("PANEL_POSITION")
  503. except:
  504. self.LoadPosition = "LEFT"
  505.  
  506. if(self.LoadSize < 20):
  507. self.LoadSize = 20
  508. if(self.LoadSize > 1000):
  509. self.LoadSize = 1000
  510.  
  511.  
  512. if(self.LoadPosition == "LEFT"):
  513. self._mgr.AddPane(self.menu_gauche, wx.aui.AuiPaneInfo().Name('Actions').Caption('Actions').Left().BestSize((self.LoadSize,400)).Floatable(True).CloseButton(False).TopDockable(False).BottomDockable(False))
  514. else:
  515. self._mgr.AddPane(self.menu_gauche, wx.aui.AuiPaneInfo().Name('Actions').Caption('Actions').Right().BestSize((self.LoadSize,400)).Floatable(True).CloseButton(False).TopDockable(False).BottomDockable(False))
  516. self.menu_gauche.Show()
  517.  
  518. self._mgr.Update()
  519.  
  520. def displayMen(self, event):
  521. playonlinux.SetSettings("PANEL_POSITION","LEFT")
  522. if(self.panDisplay.IsChecked()):
  523. self.MgrAddPage()
  524.  
  525. def StatusRead(self):
  526. self.sb.SetStatusText(self.updater.sendToStatusBarStr, 0)
  527. if(self.updater.Gauge == True):
  528. perc = self.updater.perc
  529. if(perc == -1):
  530. self.jauge_update.Pulse()
  531. else:
  532. try:
  533. self.installFrame.percentageText.SetLabel(str(perc)+" %")
  534. except:
  535. pass
  536. self.jauge_update.SetValue(perc)
  537. self.jauge_update.Show()
  538. else:
  539. self.jauge_update.Hide()
  540.  
  541. if(self.updater.updating == True):
  542. self.sb.Show()
  543. try:
  544. self.installFrame.panelItems.Hide()
  545. self.installFrame.panelManual.Hide()
  546. self.installFrame.panelWait.Show()
  547. try:
  548. if(self.playing == False):
  549. self.installFrame.animation_wait.Play()
  550. self.playing = True
  551. except:
  552. self.playing = False
  553. except:
  554. pass
  555. else:
  556. self.sb.Hide()
  557. try:
  558. if(self.installFrame.currentPanel == 1):
  559. self.installFrame.panelManual.Show()
  560. else:
  561. self.installFrame.panelItems.Show()
  562. self.installFrame.panelWait.Hide()
  563. self.installFrame.animation_wait.Stop()
  564. self.playing = False
  565. self.installFrame.Refresh()
  566. except:
  567. pass
  568.  
  569. if(self.updater.sendAlertStr != self.sendAlertStr):
  570. wx.MessageBox(self.updater.sendAlertStr, os.environ["APPLICATION_TITLE"])
  571. self.sendAlertStr = self.updater.sendAlertStr
  572.  
  573. def RMBInGameList(self, event):
  574. self.GameListPopUpMenu = wx.Menu()
  575.  
  576. self.ConfigureWine = wx.MenuItem(self.GameListPopUpMenu, 230, _("Configure Wine"))
  577. self.ConfigureWine.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/run.png"))
  578. self.GameListPopUpMenu.AppendItem(self.ConfigureWine)
  579.  
  580. self.RegistryEditor = wx.MenuItem(self.GameListPopUpMenu, 231, _("Registry Editor"))
  581. self.RegistryEditor.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/regedit.png"))
  582. self.GameListPopUpMenu.AppendItem(self.RegistryEditor)
  583.  
  584. self.GotoAppDir = wx.MenuItem(self.GameListPopUpMenu, 232, _("Open the application's directory"))
  585. self.GotoAppDir.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/folder-wine.png"))
  586. self.GameListPopUpMenu.AppendItem(self.GotoAppDir)
  587.  
  588. self.ChangeIcon = wx.MenuItem(self.GameListPopUpMenu, 236, _("Read the manual"))
  589. self.ChangeIcon.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/manual.png"))
  590. self.GameListPopUpMenu.AppendItem(self.ChangeIcon)
  591.  
  592. self.ChangeIcon = wx.MenuItem(self.GameListPopUpMenu, 233, _("Set the icon"))
  593. self.ChangeIcon.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/change_icon.png"))
  594. self.GameListPopUpMenu.AppendItem(self.ChangeIcon)
  595.  
  596. self.ChangeIcon = wx.MenuItem(self.GameListPopUpMenu, 234, _("Remove"))
  597. self.ChangeIcon.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/delete.png"))
  598. self.GameListPopUpMenu.AppendItem(self.ChangeIcon)
  599.  
  600. self.ChangeIcon = wx.MenuItem(self.GameListPopUpMenu, 235, _("Close this application"))
  601. self.ChangeIcon.SetBitmap(wx.Bitmap(Variables.playonlinux_env+"/resources/images/menu/media-playback-stop.png"))
  602. self.GameListPopUpMenu.AppendItem(self.ChangeIcon)
  603.  
  604. self.PopupMenu(self.GameListPopUpMenu, event.GetPoint())
  605.  
  606.  
  607. def RWineConfigurator(self, event):
  608. self.RConfigure(_("Configure Wine"), "nothing")
  609.  
  610. def RKill(self, event):
  611. self.RConfigure(_("KillApp"), "nothing")
  612.  
  613. def ReadMe(self, event):
  614. game_exec = self.GetSelectedProgram()
  615. if(os.path.exists(os.environ["POL_USER_ROOT"]+"/configurations/manuals/"+game_exec)):
  616. playonlinux.POL_Open(os.environ["POL_USER_ROOT"]+"/configurations/manuals/"+game_exec)
  617. else:
  618. wx.MessageBox(_("No manual found for {0}").format(game_exec), os.environ["APPLICATION_TITLE"])
  619.  
  620. def RRegistryEditor(self, event):
  621. self.RConfigure(_("Registry Editor"), "nothing")
  622.  
  623. def run_plugin(self, event):
  624. game_exec = self.GetSelectedProgram()
  625. plugin=self.plugin_list[event.GetId()-300]
  626. try :
  627. os.system("bash \""+Variables.playonlinux_rep+"/plugins/"+plugin+"/scripts/menu\" \""+game_exec+"\"&")
  628. except :
  629. pass
  630.  
  631. def iconDisplay(self, event):
  632. iconEvent=event.GetId()
  633.  
  634. if(iconEvent == 501):
  635. self.iconSize = 16
  636. if(iconEvent == 502):
  637. self.iconSize = 24
  638. if(iconEvent == 503):
  639. self.iconSize = 32
  640. if(iconEvent == 504):
  641. self.iconSize = 48
  642.  
  643. playonlinux.SetSettings("ICON_SIZE",str(self.iconSize))
  644. self.list_game.SetImageList(self.imagesEmpty)
  645. self.images.Destroy()
  646. self.images = wx.ImageList(self.iconSize, self.iconSize)
  647. self.list_game.SetImageList(self.images)
  648.  
  649.  
  650. self.Reload(self)
  651.  
  652. def OpenIrc(self, event):
  653. self.irc = ircgui.IrcClient(self)
  654. self.irc.Center(wx.BOTH)
  655. self.irc.Show(True)
  656.  
  657. def UpdateGIT(self, event):
  658. os.system("bash \""+Variables.playonlinux_env+"/bash/update_git\"&")
  659.  
  660.  
  661. def GoToAppDir(self, event):
  662. self.game_exec = self.GetSelectedProgram()
  663. playonlinux.open_folder(self.game_exec)
  664.  
  665. def ChangeIcon(self, event):
  666. self.IconDir = Variables.homedir+"/.local/share/icons/"
  667. self.SupprotedIconExt = "All|*.xpm;*.XPM;*.png;*.PNG;*.ico;*.ICO;*.jpg;*.JPG;*.jpeg;*.JPEG;*.bmp;*.BMP\
  668. \|XPM (*.xpm)|*.xpm;*.XPM\
  669. \|PNG (*.png)|*.png;*.PNG\
  670. \|ICO (*.ico)|*.ico;*.ICO\
  671. \|JPG (*.jpg)|*.jpg;*.JPG\
  672. \|BMP (*.bmp)|*.bmp;*.BMP\
  673. \|JPEG (*.jpeg)|*.jpeg;*JPEG"
  674. self.IconDialog = wx.FileDialog(self, "Choose a icon file", self.IconDir, "", self.SupprotedIconExt, wx.OPEN | wx.FD_PREVIEW)
  675. if self.IconDialog.ShowModal() == wx.ID_OK:
  676. self.IconFilename=self.IconDialog.GetFilename()
  677. self.IconDirname=self.IconDialog.GetDirectory()
  678. IconFile=os.path.join(self.IconDirname,self.IconFilename)
  679. self.RConfigure("IconChange", IconFile)
  680. self.IconDialog.Destroy()
  681. #Pop-up menu for game list: ending
  682.  
  683. def Select(self, event):
  684. game_exec = self.GetSelectedProgram()
  685. self.read = open(Variables.playonlinux_rep+"shortcuts/"+game_exec,"r").readlines()
  686. self.i = 0;
  687. self.wine_present = False;
  688. while(self.i < len(self.read)):
  689. if("wine " in self.read[self.i]):
  690. self.wine_present = True;
  691. self.i += 1
  692.  
  693. self.generate_menu(game_exec)
  694. self.playTool.Enable(True)
  695. self.stopTool.Enable(True)
  696. self.removeTool.Enable(True)
  697.  
  698. def generate_menu(self, shortcut=None):
  699. for c in self.menuElem:
  700. self.menuElem[c].Destroy()
  701.  
  702. for c in self.menuImage:
  703. self.menuImage[c].Destroy()
  704. try:
  705. self.menuBitmap.Destroy()
  706. except:
  707. pass
  708.  
  709. self.menuElem = {}
  710. self.menuImage = {}
  711.  
  712. i = 0;
  713. self.menuGaucheAddTitle("pol_title", os.environ["APPLICATION_TITLE"], i)
  714. i+=1
  715. self.menuGaucheAddLink("pol_prgm_install", _("Install a program"), i,Variables.playonlinux_env+"/resources/images/menu/add.png",self.InstallMenu)
  716. i+=1
  717. self.menuGaucheAddLink("pol_prgm_settings", _("Settings"), i,Variables.playonlinux_env+"/resources/images/menu/settings.png",self.Options)
  718. i+=1
  719. self.menuGaucheAddLink("pol_prgm_messenger", _("Messenger"), i,Variables.playonlinux_env+"/resources/images/menu/people.png",self.OpenIrc)
  720. if(os.path.exists(os.environ["PLAYONLINUX"]+"/.git/")):
  721. i+=1
  722. self.menuGaucheAddLink("pol_git", _("Update GIT"), i,Variables.playonlinux_env+"/resources/images/menu/update_git.png",self.UpdateGIT)
  723.  
  724. if(shortcut != None):
  725. i+=2
  726. self.menuGaucheAddTitle("prgm_title", shortcut, i)
  727. i+=1
  728. self.menuGaucheAddLink("pol_prgm_run", _("Run"), i,Variables.playonlinux_env+"/resources/images/menu/media-playback-start.png",self.Run)
  729. i+=1
  730. self.menuGaucheAddLink("pol_prgm_kill", _("Close"), i,Variables.playonlinux_env+"/resources/images/menu/media-playback-stop.png",self.RKill)
  731. i+=1
  732. self.menuGaucheAddLink("pol_prgm_rundebug", _("Debug"), i,Variables.playonlinux_env+"/resources/images/menu/bug.png",self.RunDebug)
  733. i+=1
  734. self.menuGaucheAddLink("pol_prgm_reportproblem", _("Report a problem"), i,Variables.playonlinux_env+"/resources/images/menu/bug.png",self.ReportProblem)
  735. i+=1
  736. self.menuGaucheAddLink("pol_prgm_configure", _("Configure"), i,Variables.playonlinux_env+"/resources/images/menu/run.png",self.Configure)
  737. i+=1
  738. self.menuGaucheAddLink("pol_prgm_shortcut", _("Create a shortcut"), i,Variables.playonlinux_env+"/resources/images/menu/shortcut.png",self.Package)
  739. i+=1
  740. self.menuGaucheAddLink("pol_prgm_adddir", _("Open the directory"), i,Variables.playonlinux_env+"/resources/images/menu/folder-wine.png",self.GoToAppDir)
  741.  
  742. if(os.path.exists(os.environ["POL_USER_ROOT"]+"/configurations/manuals/"+shortcut)):
  743. i+=1
  744. self.menuGaucheAddLink("pol_prgm_readme", _("Read the manual"), i,Variables.playonlinux_env+"/resources/images/menu/manual.png",self.ReadMe)
  745.  
  746. i+=1
  747. self.menuGaucheAddLink("pol_prgm_uninstall", _("Uninstall"), i,Variables.playonlinux_env+"/resources/images/menu/window-close.png",self.UninstallGame)
  748.  
  749.  
  750. self.linksfile = os.environ["POL_USER_ROOT"]+"/configurations/links/"+shortcut
  751. if(os.path.exists(self.linksfile)):
  752. self.linksc = open(self.linksfile,"r").read().split("\n")
  753. for line in self.linksc:
  754. if("|" in line):
  755. line = line.split("|")
  756. i+=1
  757. if("PROFILEBUTTON/" in line[0]):
  758. line[0] = line[0].replace("PROFILEBUTTON/","")
  759.  
  760. self.menuGaucheAddLink("url_"+str(i), line[0], i,Variables.playonlinux_env+"/resources/images/menu/star.png",None,line[1])
  761.  
  762. icon = os.environ["POL_USER_ROOT"]+"/icones/full_size/"+shortcut
  763.  
  764. self.perspective = self._mgr.SavePerspective().split("|")
  765. self.perspective = self.perspective[len(self.perspective) - 2].split("=")
  766.  
  767. left_pos = (int(self.perspective[1]) - 50)/2
  768. if(left_pos <= 0):
  769. left_pos = (200-48)/2
  770.  
  771. if(os.path.exists(icon)):
  772. try:
  773. self.bitmap = wx.Image(icon)
  774. if(self.bitmap.GetWidth() >= 48):
  775. self.bitmap.Rescale(48,48,wx.IMAGE_QUALITY_HIGH)
  776. self.bitmap = self.bitmap.ConvertToBitmap()
  777. self.menuBitmap = wx.StaticBitmap(self.menu_gauche, id=-1, bitmap=self.bitmap, pos=(left_pos,20+(i+2)*20))
  778. except:
  779. pass
  780.  
  781. def menuGaucheAddTitle(self,id,text,pos):
  782. self.menuElem[id] = wx.StaticText(self.menu_gauche, -1, text,pos=(5,5+pos*20))
  783. self.menuElem[id].SetForegroundColour((0,0,0)) # For dark themes
  784. self.menuElem[id].SetFont(self.fontTitre)
  785.  
  786.  
  787. def menuGaucheAddLink(self,id,text,pos,image,evt,url=None):
  788. if(os.path.exists(image)):
  789. menu_icone = image
  790. else:
  791. menu_icone = Variables.playonlinux_env+"/etc/playonlinux.png"
  792.  
  793. try:
  794. self.bitmap = wx.Image(menu_icone)
  795. self.bitmap.Rescale(16,16,wx.IMAGE_QUALITY_HIGH)
  796. self.bitmap = self.bitmap.ConvertToBitmap()
  797. self.menuImage[id] = wx.StaticBitmap(self.menu_gauche, id=-1, bitmap=self.bitmap, pos=(10,15+pos*20))
  798.  
  799. except:
  800. pass
  801.  
  802. if(url == None):
  803. self.menuElem[id] = wx.HyperlinkCtrl(self.menu_gauche, 10000+pos, text, "", pos=(35,15+pos*20))
  804. else:
  805. self.menuElem[id] = wx.HyperlinkCtrl(self.menu_gauche, 10000+pos, text, url, pos=(35,15+pos*20))
  806.  
  807. self.menuElem[id].SetNormalColour(wx.Colour(0,0,0))
  808. self.menuElem[id].SetVisitedColour(wx.Colour(0,0,0))
  809. self.menuElem[id].SetHoverColour(wx.Colour(100,100,100))
  810.  
  811. if(evt != None):
  812. wx.EVT_HYPERLINK(self, 10000+pos, evt)
  813.  
  814. def donate(self, event):
  815. if(os.environ["POL_OS"] == "Mac"):
  816. webbrowser.open("http://www.playonmac.com/en/donate.html")
  817. else:
  818. webbrowser.open("http://www.playonlinux.com/en/donate.html")
  819.  
  820. def Reload(self, event):
  821. self.games = os.listdir(Variables.playonlinux_rep+"shortcuts/")
  822. self.games.sort(key=str.upper)
  823.  
  824. try:
  825. self.games.remove(".DS_Store")
  826. except:
  827. pass
  828.  
  829. self.list_game.DeleteAllItems()
  830. self.images.RemoveAll()
  831. root = self.list_game.AddRoot("")
  832. self.i = 0
  833. if(self.iconSize <= 32):
  834. self.iconFolder = "32";
  835. else:
  836. self.iconFolder = "full_size";
  837. for game in self.games: #METTRE EN 32x32
  838. if(self.searchbox.GetValue().encode("utf-8","replace").lower() in game.lower()):
  839. if(not os.path.isdir(Variables.playonlinux_rep+"/shortcuts/"+game)):
  840. if(os.path.exists(Variables.playonlinux_rep+"/icones/"+self.iconFolder+"/"+game)):
  841. file_icone = Variables.playonlinux_rep+"/icones/"+self.iconFolder+"/"+game
  842. else:
  843. file_icone = Variables.playonlinux_env+"/etc/playonlinux.png"
  844.  
  845. try:
  846. self.bitmap = wx.Image(file_icone)
  847. self.bitmap.Rescale(self.iconSize,self.iconSize,wx.IMAGE_QUALITY_HIGH)
  848. self.bitmap = self.bitmap.ConvertToBitmap()
  849. self.images.Add(self.bitmap)
  850. except:
  851. pass
  852.  
  853. item = self.list_game.AppendItem(root, game, self.i)
  854. self.i += 1
  855. self.generate_menu(None)
  856.  
  857. if(os.environ["POL_OS"] == "Mac"):
  858. self.playTool.Enable(False)
  859. self.stopTool.Enable(False)
  860. self.removeTool.Enable(False)
  861.  
  862.  
  863. def RConfigure(self, function_to_run, firstargument):
  864. """Starts polconfigurator remotely."""
  865. game_exec = self.GetSelectedProgram()
  866. if(game_exec != ""):
  867. os.system("bash \""+Variables.playonlinux_env+"/bash/polconfigurator\" \""+game_exec+"\" \""+function_to_run+"\" \""+firstargument+"\"&")
  868. else:
  869. wx.MessageBox(_("Please select a program."), os.environ["APPLICATION_TITLE"])
  870.  
  871.  
  872. def Options(self, event):
  873. onglet=event.GetId()
  874. try:
  875. self.optionFrame.SetFocus()
  876. except:
  877. self.optionFrame = options.MainWindow(self, -1, _("{0} settings").format(os.environ["APPLICATION_TITLE"]), 2)
  878. if(onglet == 211):
  879. self.optionFrame = options.MainWindow(self, -1, _("{0} settings").format(os.environ["APPLICATION_TITLE"]), 0)
  880. if(onglet == 214):
  881. self.optionFrame = options.MainWindow(self, -1, _("{0} settings").format(os.environ["APPLICATION_TITLE"]), 1)
  882. self.optionFrame.Center(wx.BOTH)
  883. self.optionFrame.Show(True)
  884.  
  885. def killall(self, event):
  886. os.system("bash \""+Variables.playonlinux_env+"/bash/killall\"&")
  887.  
  888. def Executer(self, event):
  889. os.system("bash \""+Variables.playonlinux_env+"/bash/expert/Executer\"&")
  890.  
  891. def BugReport(self, event):
  892. try:
  893. self.debugFrame.Show()
  894. self.debugFrame.SetFocus()
  895. except:
  896. self.debugFrame = debug.MainWindow(None, -1, _("{0} debugger").format(os.environ["APPLICATION_TITLE"]))
  897. self.debugFrame.Center(wx.BOTH)
  898. self.debugFrame.Show()
  899.  
  900.  
  901. def POLOnline(self, event):
  902. os.system("bash \""+Variables.playonlinux_env+"/bash/playonlinux_online\" &")
  903.  
  904. def PCCd(self, event):
  905. os.system("bash \""+Variables.playonlinux_env+"/bash/read_pc_cd\" &")
  906.  
  907. def PolShell(self, event):
  908. #Variables.run_x_server()
  909. os.system("bash \""+Variables.playonlinux_env+"/bash/expert/PolShell\"&")
  910.  
  911. def Configure(self, event):
  912. game_exec = self.GetSelectedProgram()
  913. try:
  914. self.configureFrame.Show(True)
  915. self.configureFrame.SetFocus()
  916. if(game_exec != ""):
  917. self.configureFrame.change_program(game_exec,False)
  918.  
  919. except:
  920. if(game_exec == ""):
  921. self.configureFrame = configure.MainWindow(self, -1, _("{0} configuration").format(os.environ["APPLICATION_TITLE"]),"default",True)
  922. else:
  923. self.configureFrame = configure.MainWindow(self, -1, _("{0} configuration").format(os.environ["APPLICATION_TITLE"]),game_exec.decode("utf-8","replace"),False)
  924.  
  925.  
  926. self.configureFrame.Center(wx.BOTH)
  927. self.configureFrame.Show(True)
  928.  
  929. #os.system("bash \""+Variables.playonlinux_env+"/bash/polconfigurator\" \""+game_exec+"\"&")
  930.  
  931. def Package(self, event):
  932. game_exec = self.GetSelectedProgram()
  933. os.system("bash \""+Variables.playonlinux_env+"/bash/make_shortcut\" \""+game_exec.encode("utf-8","replace")+"\"&")
  934.  
  935. def UninstallGame(self, event):
  936. game_exec = self.GetSelectedProgram()
  937. if(game_exec != ""):
  938. os.system("bash \""+Variables.playonlinux_env+"/bash/uninstall\" \""+game_exec.encode("utf-8","replace")+"\"&")
  939. else:
  940. wx.MessageBox(_("Please select a program."), os.environ["APPLICATION_TITLE"])
  941.  
  942. def InstallMenu(self, event):
  943. try:
  944. self.installFrame.Show(True)
  945. self.installFrame.SetFocus()
  946. except:
  947. self.installFrame = install.InstallWindow(self, -1, _('{0} install menu').format(os.environ["APPLICATION_TITLE"]))
  948. self.installFrame.Center(wx.BOTH)
  949. self.installFrame.Show(True)
  950.  
  951. def WineVersion(self, event):
  952. try:
  953. self.wversion.Show()
  954. self.wversion.SetFocus()
  955. except:
  956. self.wversion = wver.MainWindow(None, -1, _('{0} wine versions manager').format(os.environ["APPLICATION_TITLE"]))
  957. self.wversion.Center(wx.BOTH)
  958. self.wversion.Show(True)
  959.  
  960. def GetSelectedProgram(self):
  961. return self.list_game.GetItemText(self.list_game.GetSelection()).encode("utf-8","replace")
  962.  
  963. def Run(self, event, s_debug=False):
  964.  
  965. game_exec = self.GetSelectedProgram()
  966. game_prefix = playonlinux.getPrefix(game_exec)
  967.  
  968. if(s_debug == False):
  969. playonlinux.SetDebugState(game_exec, game_prefix, False)
  970.  
  971. if(os.path.exists(os.environ["POL_USER_ROOT"]+"/wineprefix/"+game_prefix)):
  972. if(game_exec != ""):
  973. if(playonlinux.GetDebugState(game_exec)):
  974. try:
  975. self.debugFrame.analyseReal(0, game_prefix)
  976. self.debugFrame.Show()
  977. self.debugFrame.SetFocus()
  978. except:
  979. self.debugFrame = debug.MainWindow(None, -1, _("{0} debugger").format(os.environ["APPLICATION_TITLE"]),game_prefix,0)
  980. self.debugFrame.Center(wx.BOTH)
  981. self.debugFrame.Show()
  982.  
  983. os.system("bash "+Variables.playonlinux_env+"/bash/run_app \""+game_exec+"\"&")
  984. else:
  985. wx.MessageBox(_("Please select a program."), os.environ["APPLICATION_TITLE"])
  986. else:
  987. wx.MessageBox(_("The virtual drive associated with {0} ({1}) does no longer exists.").format(game_exec, game_prefix), os.environ["APPLICATION_TITLE"])
  988.  
  989. def RunDebug(self, event):
  990. game_exec = self.GetSelectedProgram()
  991. game_prefix = playonlinux.getPrefix(game_exec)
  992. playonlinux.SetDebugState(game_exec, game_prefix, True)
  993. self.Run(self, True)
  994.  
  995. def ReportProblem(self, event):
  996. game_exec = self.GetSelectedProgram()
  997. game_log = playonlinux.getLog(game_exec)
  998. if game_log:
  999. os.system('env LOGTITLE="'+game_log+'" bash "'+os.environ["PLAYONLINUX"]+'/bash/bug_report" &')
  1000.  
  1001. def POLDie(self):
  1002. for pid in self.registeredPid:
  1003. os.system("kill -9 -%d 2> /dev/null" % pid)
  1004. os.system("kill -9 %d 2> /dev/null" % pid)
  1005. app.POLServer.closeServer()
  1006. os._exit(0)
  1007.  
  1008. def POLRestart(self):
  1009. for pid in self.registeredPid:
  1010. os.system("kill -9 -%d 2> /dev/null" % pid)
  1011. os.system("kill -9 %d 2> /dev/null" % pid)
  1012. app.POLServer.closeServer()
  1013. os._exit(63) # Restart code
  1014.  
  1015. def ForceClose(self, signal, frame): # Catch SIGINT
  1016. print "\nCtrl+C pressed. Killing all processes..."
  1017. self.POLDie()
  1018.  
  1019. def ClosePol(self, event):
  1020. pids = []
  1021. for pid in self.registeredPid:
  1022. try:
  1023. os.kill(pid, 0)
  1024. pid_exists = True
  1025. pids.append(pid)
  1026. except OSError:
  1027. pid_exists = False
  1028. print "Registered PID: %d (%s)" % (pid, 'Present' if pid_exists else 'Missing')
  1029. self.registeredPid = pids
  1030.  
  1031. if(playonlinux.GetSettings("DONT_ASK_BEFORE_CLOSING") == "TRUE" or self.registeredPid == [] or wx.YES == wx.MessageBox(_('Are you sure you want to close all {0} Windows?').format(os.environ["APPLICATION_TITLE"]).decode("utf-8","replace"),os.environ["APPLICATION_TITLE"], style=wx.YES_NO | wx.ICON_QUESTION)):
  1032. self.SizeToSave = self.GetSize();
  1033. self.PositionToSave = self.GetPosition();
  1034. # Save size and position
  1035. playonlinux.SetSettings("MAINWINDOW_WIDTH",str(self.SizeToSave[0]))
  1036. playonlinux.SetSettings("MAINWINDOW_HEIGHT",str(self.SizeToSave[1]-Variables.windows_add_playonmac*56))
  1037. playonlinux.SetSettings("MAINWINDOW_X",str(self.PositionToSave[0]))
  1038. playonlinux.SetSettings("MAINWINDOW_Y",str(self.PositionToSave[1]))
  1039. self._mgr.UnInit()
  1040. # I know, that's very ugly, but I have no choice for the moment
  1041. self.perspective = self._mgr.SavePerspective().split("|")
  1042. self.perspective = self.perspective[len(self.perspective) - 2].split("=")
  1043.  
  1044. self.DockType = self.perspective[0]
  1045. self.mySize = 200
  1046. self.myPosition = "LEFT"
  1047.  
  1048. if(self.DockType == "dock_size(4,0,0)"):
  1049. self.mySize = int(self.perspective[1]) - 2
  1050. self.myPosition = "LEFT"
  1051.  
  1052. if(self.DockType == "dock_size(2,0,1)" or self.DockType == "dock_size(2,0,0)" or "dock_size(2," in self.DockType):
  1053. self.mySize = int(self.perspective[1]) - 2
  1054. self.myPosition = "RIGHT"
  1055.  
  1056. playonlinux.SetSettings("PANEL_SIZE",str(self.mySize))
  1057. playonlinux.SetSettings("PANEL_POSITION",str(self.myPosition))
  1058.  
  1059. self.POLDie()
  1060. return None
  1061.  
  1062. def About(self, event):
  1063. self.aboutBox = wx.AboutDialogInfo()
  1064. if(os.environ["POL_OS"] == "Linux"):
  1065. self.aboutBox.SetIcon(wx.Icon(Variables.playonlinux_env+"/etc/playonlinux.png", wx.BITMAP_TYPE_ANY))
  1066.  
  1067.  
  1068. self.aboutBox.SetName(os.environ["APPLICATION_TITLE"])
  1069. self.aboutBox.SetVersion(Variables.version)
  1070. self.aboutBox.SetDescription(_("Run your Windows programs on "+os.environ["POL_OS"]+" !"))
  1071. self.aboutBox.SetCopyright("© 2007-2013 "+_("PlayOnLinux and PlayOnMac team\nUnder GPL licence version 3"))
  1072. self.aboutBox.AddDeveloper(_("Developer and Website: ")+"Tinou (Pâris Quentin), MulX (Petit Aymeric)")
  1073. self.aboutBox.AddDeveloper(_("Scriptors: ")+"GNU_Raziel")
  1074. self.aboutBox.AddDeveloper(_("Packager: ")+"MulX (Petit Aymeric), Tinou (Pâris Quentin)")
  1075. self.aboutBox.AddDeveloper(_("Icons:")+"Faenza-Icons http://tiheum.deviantart.com/art/Faenza-Icons-173323228")
  1076. self.aboutBox.AddDeveloper(_("The following people contributed to this program: ")+"kiplantt, Salvatos, Minchul")
  1077. self.aboutBox.AddTranslator(_("Translations:"))
  1078. self.aboutBox.AddTranslator(_("Read TRANSLATORS file"))
  1079.  
  1080. if(os.environ["POL_OS"] == "Mac"):
  1081. self.aboutBox.SetWebSite("http://www.playonmac.com")
  1082. else:
  1083. self.aboutBox.SetWebSite("http://www.playonlinux.com")
  1084. wx.AboutBox(self.aboutBox)
  1085.  
  1086. class PlayOnLinuxApp(wx.App):
  1087. def OnInit(self):
  1088. lng.iLang()
  1089. close = False
  1090. exe_present = False
  1091.  
  1092. os.system("bash "+Variables.playonlinux_env+"/bash/startup")
  1093. self.systemCheck()
  1094.  
  1095. for f in sys.argv[1:]:
  1096. self.MacOpenFile(f)
  1097. if(".exe" in f or ".EXE" in f):
  1098. exe_present = True
  1099. close = True
  1100.  
  1101. if(close == True and exe_present == False):
  1102. os._exit(0)
  1103.  
  1104. self.SetClassName(os.environ["APPLICATION_TITLE"])
  1105. self.SetAppName(os.environ["APPLICATION_TITLE"])
  1106.  
  1107.  
  1108. self.frame = MainWindow(None, -1, os.environ["APPLICATION_TITLE"])
  1109. # Gui Server
  1110. self.POLServer = gui_server.gui_server(self.frame)
  1111. self.POLServer.start()
  1112.  
  1113. i = 0
  1114. while(os.environ["POL_PORT"] == "0"):
  1115. time.sleep(0.01)
  1116. if(i >= 300):
  1117. wx.MessageBox(_("{0} is not able to start PlayOnLinux Setup Window server.").format(os.environ["APPLICATION_TITLE"]),_("Error"))
  1118. os._exit(0)
  1119. break
  1120. i+=1
  1121. os.system("bash \"$PLAYONLINUX/bash/startup_after_server\" &")
  1122.  
  1123. self.SetTopWindow(self.frame)
  1124. self.frame.Show(True)
  1125.  
  1126. return True
  1127.  
  1128. def _executableFound(self, executable):
  1129. devnull = open('/dev/null', 'wb')
  1130. try:
  1131. returncode = subprocess.call(["which",executable],stdout=devnull)
  1132. return (returncode == 0)
  1133. except:
  1134. return False
  1135.  
  1136. def _singleCheck(self, executable, package, fatal):
  1137. if not self._executableFound(executable):
  1138. message = _("{0} cannot find {1}")
  1139. if package is not None:
  1140. message += _(" (from {2})")
  1141.  
  1142. if fatal:
  1143. verdict = _("You need to install it to continue")
  1144. else:
  1145. verdict = _("You should install it to use {0}")
  1146.  
  1147. wx.MessageBox(("%s\n\n%s" % (message, verdict)).format(os.environ["APPLICATION_TITLE"], executable, package), _("Error"))
  1148.  
  1149. if fatal:
  1150. os._exit(0)
  1151.  
  1152. def singleCheck(self, executable, package=None):
  1153. self._singleCheck(executable, package, False)
  1154.  
  1155. def singleCheckFatal(self, executable, package=None):
  1156. self._singleCheck(executable, package, True)
  1157.  
  1158. def systemCheck(self):
  1159. #### Root uid check
  1160. # if(os.popen("id -u").read() == "0\n" or os.popen("id -u").read() == "0"):
  1161. # wx.MessageBox(_("{0} is not supposed to be run as root. Sorry").format(os.environ["APPLICATION_TITLE"]),_("Error"))
  1162. #os._exit(0)
  1163.  
  1164. #### 32 bits OpenGL check
  1165. try:
  1166. returncode=subprocess.call([os.environ["PLAYONLINUX"]+"/bash/check_gl","x86"])
  1167. except:
  1168. returncode=255
  1169. if(os.environ["POL_OS"] == "Linux" and returncode != 0):
  1170. wx.MessageBox(_("{0} is unable to find 32bits OpenGL libraries.\n\nYou might encounter problem with your games").format(os.environ["APPLICATION_TITLE"]),_("Error"))
  1171. os.environ["OpenGL32"] = "0"
  1172. else:
  1173. os.environ["OpenGL32"] = "1"
  1174.  
  1175. #### 64 bits OpenGL check
  1176. if(os.environ["AMD64_COMPATIBLE"] == "True"):
  1177. try:
  1178. returncode=subprocess.call([os.environ["PLAYONLINUX"]+"/bash/check_gl","amd64"])
  1179. except:
  1180. returncode=255
  1181. if(os.environ["AMD64_COMPATIBLE"] == "True" and os.environ["POL_OS"] == "Linux" and returncode != 0):
  1182. wx.MessageBox(_("{0} is unable to find 64bits OpenGL libraries.\n\nYou might encounter problem with your games").format(os.environ["APPLICATION_TITLE"]),_("Error"))
  1183. os.environ["OpenGL64"] = "0"
  1184. else:
  1185. os.environ["OpenGL64"] = "1"
  1186.  
  1187. #### Filesystem check
  1188. if(os.environ["POL_OS"] == "Linux"):
  1189. try:
  1190. returncode=subprocess.call([os.environ["PLAYONLINUX"]+"/bash/check_fs"])
  1191. except:
  1192. returncode=255
  1193. if(os.environ["POL_OS"] == "Linux" and returncode != 0):
  1194. wx.MessageBox(_("Your filesystem might prevent {0} from running correctly.\n\nPlease open {0} in a terminal to get more details").format(os.environ["APPLICATION_TITLE"]),_("Error"))
  1195.  
  1196. if(os.environ["DEBIAN_PACKAGE"] == "FALSE"):
  1197. if(playonlinux.GetSettings("SEND_REPORT") == ""):
  1198. if(wx.YES == wx.MessageBox(_('Do you want to help {0} to make a compatibility database?\n\nIf you click yes, the following things will be sent to us anonymously the first time you run a Windows program:\n\n- You graphic card model\n- Your OS version\n- If graphic drivers are installed or not.\n\n\nThese information will be very precious for us to help people.').format(os.environ["APPLICATION_TITLE"]).decode("utf-8","replace"), os.environ["APPLICATION_TITLE"],style=wx.YES_NO | wx.ICON_QUESTION)):
  1199. playonlinux.SetSettings("SEND_REPORT","TRUE")
  1200. else:
  1201. playonlinux.SetSettings("SEND_REPORT","FALSE")
  1202.  
  1203. #### Other import checks
  1204. self.singleCheckFatal("nc", package="Netcat")
  1205. self.singleCheckFatal("tar")
  1206. self.singleCheckFatal("cabextract")
  1207. self.singleCheckFatal("convert", package="ImageMagick")
  1208. self.singleCheckFatal("wget", package="Wget")
  1209. self.singleCheckFatal("curl", package="cURL")
  1210.  
  1211. self.singleCheckFatal("gpg", package="GnuPG")
  1212.  
  1213. if(os.environ["DEBIAN_PACKAGE"] == "FALSE"):
  1214. self.singleCheck("xterm")
  1215. self.singleCheck("gettext.sh", package="gettext") # gettext-base on Debian
  1216. self.singleCheck("icotool", package="icoutils")
  1217. self.singleCheck("wrestool", package="icoutils")
  1218. self.singleCheck("wine", package="Wine")
  1219. self.singleCheck("unzip", package="InfoZIP")
  1220. self.singleCheck("7z", package="P7ZIP full") # p7zip-full on Debian
  1221.  
  1222. def BringWindowToFront(self):
  1223. try: # it's possible for this event to come when the frame is closed
  1224. self.GetTopWindow().Raise()
  1225. except:
  1226. pass
  1227.  
  1228. def MacOpenFile(self, filename):
  1229. file_extension = string.split(filename,".")
  1230. file_extension = file_extension[len(file_extension) - 1]
  1231. if(file_extension == "desktop"): # Un raccourcis Linux
  1232. content = open(filename,"r").readlines()
  1233. i = 0
  1234. while(i < len(content)):
  1235. #wx.MessageBox(content[i], "PlayOnLinux", wx.OK)
  1236.  
  1237. if("Path=" in content[i]):
  1238. cd_app = content[i].replace("Path=","").replace("\n","")
  1239. if("Exec=" in content[i]):
  1240. exec_app = content[i].replace("Exec=","").replace("\n","")
  1241. i += 1
  1242. if(":\\\\\\\\" in exec_app):
  1243. exec_app = exec_app.replace("\\\\","\\")
  1244. try:
  1245. os.system("cd \""+cd_app+"\" && "+exec_app+" &")
  1246. except:
  1247. pass
  1248.  
  1249. elif(file_extension == "exe" or file_extension == "EXE"):
  1250. os.system("bash \"$PLAYONLINUX/bash/run_exe\" \""+filename+"\" &")
  1251.  
  1252. elif(file_extension == "pol" or file_extension == "POL"):
  1253. if(wx.YES == wx.MessageBox(_('Are you sure you want to want to install {0} package?').format(filename).decode("utf-8","replace"), os.environ["APPLICATION_TITLE"],style=wx.YES_NO | wx.ICON_QUESTION)):
  1254. os.system("bash \"$PLAYONLINUX/bash/playonlinux-pkg\" -i \""+filename+"\" &")
  1255. else:
  1256. playonlinux.open_document(filename,file_extension.lower())
  1257.  
  1258. def MacOpenURL(self, url):
  1259. if(os.environ["POL_OS"] == "Mac" and "playonlinux://" in url):
  1260. wx.MessageBox(_("You are trying to open a script design for {0}! It might not work as expected").format("PlayOnLinux"), os.environ["APPLICATION_TITLE"])
  1261. if(os.environ["POL_OS"] == "Linux" and "playonmac://" in url):
  1262. wx.MessageBox(_("You are trying to open a script design for {0}! It might not work as expected").format("PlayOnMac"), os.environ["APPLICATION_TITLE"])
  1263.  
  1264. os.system("bash \"$PLAYONLINUX/bash/playonlinux-url_handler\" \""+url+"\" &")
  1265.  
  1266. def MacReopenApp(self):
  1267. #sys.exit()
  1268. self.BringWindowToFront()
  1269.  
  1270. # Idea taken from flacon
  1271. def setSigchldHandler():
  1272. signal.signal(signal.SIGCHLD, handleSigchld)
  1273. if hasattr(signal, 'siginterrupt'):
  1274. signal.siginterrupt(signal.SIGCHLD, False)
  1275.  
  1276. def handleSigchld(number, frame):
  1277. # Apparently some UNIX systems automatically resent the SIGCHLD
  1278. # handler to SIG_DFL. Reset it just in case.
  1279. setSigchldHandler()
  1280.  
  1281. setSigchldHandler()
  1282. lng.Lang()
  1283.  
  1284. app = PlayOnLinuxApp(redirect=False)
  1285. app.MainLoop()
  1286. #sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment