24 sys.stderr.write(
"No wxPython installation detected!"
26 "Please ensure that you have wxPython installed "
27 "before running RIDE. "
28 "You can obtain wxPython from "
29 "https://wxpython.org/pages/downloads/\n"
30 "or pip install wxPython")
33 from os.path
import exists, join
37 Usage: python ride_postinstall.py [options] <-install|-remove>
38 or python -m robotide.postinstall [options] <-install|-remove>
39 -install - Installs a Desktop Shortcut to RIDE.
40 -remove - [TODO] Removes a Desktop Shortcut to RIDE.
41 options: -q - Quiet, don't ask user for confirmation.
50 from wx
import version
52 sys.stderr.write(
"No wxPython installation detected!"
54 "Please ensure that you have wxPython installed "
55 "before running RIDE. "
56 "You can obtain wxPython from "
57 "https://wxpython.org/pages/downloads/\n"
58 "or pip install wxPython")
61 sys.stderr.write(
"wxPython is installed.\n%s\n" %
version())
66 def __init__(self, parent, message, title, ttl=10):
67 RIDEDialog.__init__(self, title=title, parent=parent, size=(300, 200))
69 self.CenterOnScreen(wx.BOTH)
72 st_msg = wx.StaticText(self, -1, message)
74 vbox = wx.BoxSizer(wx.VERTICAL)
75 vbox.Add(st_msg, 0, wx.ALIGN_CENTER | wx.TOP, 40)
76 vbox.Add(self.
settimetolivemsgsettimetolivemsg, 0, wx.ALIGN_CENTER | wx.TOP, 10)
78 self.SetAffirmativeId(wx.ID_OK)
80 self.SetBackgroundColour(Colour(self.color_background))
81 self.SetForegroundColour(Colour(self.color_foreground))
82 self.
timertimer = wx.Timer(self)
83 self.
timertimer.Start(1000)
84 self.Bind(wx.EVT_CLOSE, self.
OnCloseOnClose)
85 self.Bind(wx.EVT_TIMER, self.
onTimeronTimer, self.
timertimer)
86 self.Bind(wx.EVT_BUTTON, self.
OnCancelOnCancel, id=wx.ID_CANCEL)
87 self.Bind(wx.EVT_BUTTON, self.
OnNoOnNo, id=wx.ID_NO)
88 self.Bind(wx.EVT_CHAR_HOOK, self.
OnKeyPressedOnKeyPressed)
91 key_code = event.GetKeyCode()
92 if key_code == wx.WXK_ESCAPE:
93 self.EndModal(wx.ID_NO)
97 self.EndModal(wx.ID_NO)
100 self.EndModal(wx.ID_NO)
103 self.EndModal(wx.ID_NO)
110 self.
timertimer.Stop()
111 self.EndModal(wx.ID_NO)
114 buttons = self.CreateStdDialogButtonSizer(wx.OK|wx.CANCEL)
115 self.SetBackgroundColour(Colour(self.color_background))
116 self.SetForegroundColour(Colour(self.color_foreground))
117 for item
in self.GetChildren():
118 if isinstance(item, (wx.Button, wx.BitmapButton)):
119 item.SetBackgroundColour(Colour(self.color_secondary_background))
120 item.SetOwnBackgroundColour(Colour(self.color_secondary_background))
121 item.SetForegroundColour(Colour(self.color_secondary_foreground))
122 item.SetOwnForegroundColour(Colour(self.color_secondary_foreground))
123 self.Sizer.Add(buttons, flag=wx.ALIGN_CENTER | wx.ALL, border=5)
132 parent = wx.Frame(
None, size=(0, 0))
134 parent = wx.Frame(frame, size=(0, 0))
135 parent.CenterOnScreen()
137 result = dlg.ShowModal()
in [ wx.ID_YES, wx.ID_OK]
138 print(
"Result %s" % result)
152 parent = wx.Frame(
None, size=(0, 0))
154 parent = wx.Frame(frame, size=(0, 0))
155 parent.CenterOnScreen()
156 dlg = wx.DirDialog(parent, title, initialdir, style=wx.DD_DIR_MUST_EXIST)
157 if dlg.ShowModal() == wx.ID_OK:
158 result = dlg.GetPath()
167 from os.path
import expanduser
168 from os
import environ, chmod, chown
172 DEFAULT_LANGUAGE = environ.get(
'LANG',
'').split(
':')
174 desktop = {
"de":
"Desktop",
"en":
"Desktop",
"es":
"Escritorio",
175 "fi":
r"Työpöytä",
"fr":
"Bureau",
"it":
"Scrivania",
176 "pt":
r"Área de Trabalho"}
177 user = str(subprocess.check_output([
'logname']).strip(), encoding=
'utf-8')
179 ndesktop = desktop[DEFAULT_LANGUAGE[0][:2]]
180 directory = join(
"/home", user, ndesktop)
181 defaultdir = join(
"/home", user,
"Desktop")
182 if not exists(directory):
183 if exists(defaultdir):
184 directory = defaultdir
188 initialdir=join(expanduser(
'~')),
195 initialdir=join(expanduser(
'~')),
199 if directory
is None:
200 sys.stderr.write(
"Desktop shortcut creation aborted!\n")
203 link = join(directory,
"RIDE.desktop")
205 link = join(directory.encode(
'utf-8'),
"RIDE.desktop")
206 if not exists(link)
or option_f:
207 if not option_q
and not option_f:
208 if not _askyesno(
"Setup",
"Create desktop shortcut?", frame):
210 roboticon = join(sysconfig.get_paths()[
"purelib"],
"robotide",
"widgets",
"robot.ico")
211 if not exists(roboticon):
214 roboticon = join(_.__path__[0],
"widgets",
"robot.ico")
217 if not exists(roboticon):
218 roboticon = join(
"FIXME: find correct path to: .../site-packages/",
"robotide",
"widgets",
"robot.ico")
219 with open(link,
"w+")
as shortcut:
220 shortcut.write(f
"#!/usr/bin/env xdg-open\n[Desktop Entry]\n"
221 f
"Exec={sys.executable} -m robotide.__init__\n"
222 f
"Comment=A Robot Framework IDE\nGenericName=RIDE\n"
223 f
"Icon={roboticon}\n"
224 f
"Name=RIDE\nStartupNotify=true\nTerminal=false\n"
225 "Type=Application\nX-KDE-SubstituteUID=false\n")
226 uid = pwd.getpwnam(user).pw_uid
235 ride_app_name =
'RIDE.app'
236 application_path =
'/Applications'
237 ride_app_pc_path = os.path.join(application_path, ride_app_name)
238 ride_app_module_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), ride_app_name)
240 if not exists(ride_app_pc_path)
or option_f:
241 if not option_q
and not option_f
and not _askyesno(
"Setup",
"Create application shortcut?", frame):
243 app_script = os.path.join(ride_app_module_path,
'Contents',
'MacOS',
'RIDE')
244 with open(app_script,
'w+')
as shortcut:
245 shortcut.write(
"#!/bin/sh\nPAL=$PATH\nfor i in `cat /etc/paths`\n do\n PAL=\"$PAL:$i\"\n"
246 " done\nPATH=$PAL\nexport $PATH\n{} -m robotide.__init__ $* 2>"
247 " /dev/null &\n".format(sys.executable))
248 if exists(ride_app_pc_path):
249 shutil.rmtree(ride_app_pc_path,
True)
250 shutil.copytree(ride_app_module_path, ride_app_pc_path)
251 user = str(subprocess.check_output([
'logname']).strip(), encoding=
'utf-8')
252 user_desktop_link =
'/Users/' + user +
'/Desktop/' + ride_app_name
253 if exists(user_desktop_link):
254 os.remove(user_desktop_link)
256 os.symlink(ride_app_pc_path, user_desktop_link)
266 from win32com.shell
import shell, shellcon
268 sys.stderr.write(
"Cannot create desktop shortcut.\nPlease install"
269 " pywin32 from https://github.com/mhammond/pywin32\n"
270 "or pip install pywin32")
272 desktop = shell.SHGetFolderPath(0, shellcon.CSIDL_DESKTOP,
None, 0)
273 link = os.path.join(desktop,
'RIDE.lnk')
274 public_link = os.path.join(os.getenv(
'PUBLIC'),
'Desktop',
'RIDE.lnk')
275 icon = os.path.join(sys.prefix,
'Lib',
'site-packages',
'robotide',
276 'widgets',
'robot.ico')
277 if not (exists(public_link)
or exists(link))
or option_f:
278 if not option_q
and not option_f:
279 if not _askyesno(
"Setup",
"Create desktop shortcut?", frame):
280 sys.stderr.write(
"Users can create a Desktop shortcut to RIDE "
281 "with:\n%s -m robotide.postinstall -install\n"
285 shortcut = pythoncom.CoCreateInstance(shell.CLSID_ShellLink,
None,
286 pythoncom.CLSCTX_INPROC_SERVER,
287 shell.IID_IShellLink)
288 command_args =
" -c \"from robotide import main; main()\""
289 shortcut.SetPath(sys.executable.replace(
'python.exe',
'pythonw.exe'))
290 shortcut.SetArguments(command_args)
291 shortcut.SetDescription(
"Robot Framework testdata editor")
292 shortcut.SetIconLocation(icon, 0)
293 persist_file = shortcut.QueryInterface(pythoncom.IID_IPersistFile)
294 from pywintypes
import com_error
296 persist_file.Save(public_link, 0)
297 sys.stderr.write(f
"Desktop shortcut created for all users.")
299 persist_file.Save(link, 0)
303 if platform.startswith(
"linux"):
305 elif platform.startswith(
"darwin"):
307 elif platform.startswith(
"win"):
310 sys.stderr.write(
"Unknown platform {0}: Failed to create desktop short"
311 "cut.".format(platform))
320 option_f = frame
is not None
329 option_q = option_f =
None
330 option_q = next((x
for x
in args
if x ==
"-q"),
None)
331 if option_q
is not None:
332 del args[args.index(option_q)]
334 option_f = next((x
for x
in args
if x ==
"-f"),
None)
335 if option_f
is not None:
336 del args[args.index(option_f)]
338 arg = args[-1]
if len(args) == 1
and args[-1]
in [
'-install',
'-remove',
340 if arg ==
'-install':
342 platform = sys.platform.lower()
346 elif arg ==
'-remove':
347 sys.stderr.write(
"Sorry, -remove is not implemented yet.\n")
349 sys.stderr.write(__doc__)
350 sys.stderr.write(
"\n")
353 if __name__ ==
'__main__':
def __init__(self, parent, message, title, ttl=10)
def _create_buttons(self)
def OnKeyPressed(self, event)
def _create_desktop_shortcut_windows(frame=None)
def caller(frame, platform)
def _create_desktop_shortcut_mac(frame=None)
def _askdirectory(title, initialdir, frame=None)
def create_desktop_shortcut(platform, frame=None)
def _askyesno(title, message, frame=None)
def _create_desktop_shortcut_linux(frame=None)