Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __init__(self, parent):
recentFile.SetSubMenu(RecentFileMenu(parent))
AppendItem(recentFile)
self.AppendSeparator()

AppendItem(saveModel)
AppendItem(saveAsModel)

Expand Down
10 changes: 4 additions & 6 deletions Reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,11 @@ def __init__(self, message):
self.ShowModal()

def DoLayout(self):
"""
Layout the dialog and prepare it to be shown


**Note:**
""" Layout the dialog and prepare it to be shown

**Note:**

* Do not call this method in your code
* Do not call this method in your code
"""

# Objects
Expand Down
47 changes: 26 additions & 21 deletions Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def updatePackageWithPiP():
"""

updatePiP()

if pip.__version__ > '10.0.1':
import pkg_resources
packages = [dist.project_name for dist in pkg_resources.working_set if 'PyPubSub' not in dist.project_name]
Expand All @@ -194,26 +194,31 @@ def updatePackageWithPiP():
NotificationMessage(_('Information'), 'All pip packages have been updated!', None, timeout=5)

def install_and_import(package):
try:
importlib.import_module(package)
installed = True
except:

if pip.main(['search', package]) != 23:
dial = wx.MessageDialog(None, _('We find that the package %s is missing. \n\n Do you want to install him using pip?'%(package)), _('Install Package'), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)

if dial.ShowModal() == wx.ID_YES:
pip.main(['install', package])
installed = True
dial.Destroy()
else:
installed = False
dial.Destroy()
finally:
if installed : globals()[package] = importlib.import_module(package)

return installed

""" Install and import the package
"""
installed = install(package)
if installed and package not in sys.modules: globals()[package] = importlib.import_module(package)
return installed

def install(package):
""" Install the package
"""
try:
importlib.import_module(package)
installed = True
except ImportError:
if pip.main(['search', package]) != 23:
dial = wx.MessageDialog(None, _('We find that the package %s is missing. \n\n Do you want to install him using pip?'%(package)), _('Install Package'), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)

if dial.ShowModal() == wx.ID_YES:
installed = not pip.main(['install', '--user', package])
dial.Destroy()
else:
installed = False
dial.Destroy()

return installed

def getObjectFromString(scriptlet):
"""
"""
Expand Down
69 changes: 40 additions & 29 deletions devsimpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
from PreferencesGUI import PreferencesGUI
from pluginmanager import load_plugins, enable_plugin
from which import which
from Utilities import GetUserConfigDir, install_and_import, updatePackageWithPiP
from Utilities import GetUserConfigDir, install, install_and_import, updatePackageWithPiP, NotificationMessage
from Decorators import redirectStdout, BuzyCursorNotification, ProgressNotification, cond_decorator
from DetachedFrame import DetachedFrame
from LibraryTree import LibraryTree
Expand Down Expand Up @@ -1165,38 +1165,49 @@ def OnScreenCapture(self, event):
""" Print preview of current diagram
"""

### gi is in the pyobject package
try:
import gtk.gdk
import gi
package_installed = True
except ImportError:
id = event.GetId()
menu = self.GetMenuBar().FindItemById(id).GetMenu()
menuItem = menu.FindItemById(id)
### enable the menu
menuItem.Enable(False)
sys.stdout.write(_("Unable to import gtk module.\n"))
else:
### dfault filename
fn = "screenshot.png"
package = "pygobject"
package_installed = install(package)

if package_installed:
import gi
gi.require_version("Gdk", "3.0")
import gi.repository.Gdk as gdk

#### filename dialog request
dlg = wx.TextEntryDialog(self, _('Enter a new name:'),_('ScreenShot Filename'), fn)
if dlg.ShowModal() == wx.ID_OK:
fn = dlg.GetValue()
dlg.Destroy()
currentPage = self.nb2.GetCurrentPage()
currentPage.deselect()
diagram = currentPage.GetDiagram()

### options building
wcd = _("PNG files (*.png)|*.png|All files (*)|*)")
home = self.home or os.path.dirname(getattr(diagram,'last_name_saved', False)) or HOME_PATH if self.openFileList == ['']*NB_OPENED_FILE else self.home or os.path.dirname(self.openFileList[0])
save_dlg = wx.FileDialog(self, message=_('Save file as...'), defaultDir=home, defaultFile='screenshot.png', wildcard=wcd, style=wx.SAVE | wx.OVERWRITE_PROMPT)

if save_dlg.ShowModal() == wx.ID_OK:
save_dlg.Destroy()

### wait to avoid the message box that appear when a png already existe and ask to replace it !
time.sleep(2)

### screenshot for the whole window w
w = gdk.get_default_root_window()
pb = gdk.pixbuf_get_from_window(w, 0,0, w.get_width(), w.get_height())
### saving
if (pb != None):
path = os.path.normpath(save_dlg.GetPath())
ext = os.path.splitext(path)[-1][1:]
pb.savev(path, ext, ["quality"], ["100"])

NotificationMessage(_('Information'), _("Screenshot saved in %s.")%path, parent=self, timeout=5)
else:
NotificationMessage(_('Error'), _("Unable to get the screenshot. \n Check the trace in background for more informations."), parent=self, flag=wx.ICON_ERROR, timeout=5)
else:
NotificationMessage(_('Error'), _('%s is not installed. \n Check the trace in background for more informations.'%(package)), parent=self, flag=wx.ICON_ERROR, timeout=5)

### screenshot
w = gtk.gdk.get_default_root_window()
sz = w.get_size()
### "The size of the window is %d x %d" % sz
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, sz[0], sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(), 0, 0, 0, 0, sz[0], sz[1])
### saving
if (pb != None):
ext = os.path.splitext(fn)[-1][1:]
pb.save(fn, ext)
wx.MessageBox(_("Screenshot saved in %s.")%fn, _("Success"), wx.OK|wx.ICON_INFORMATION)
else:
wx.MessageBox(_("Unable to get the screenshot."), _("Error"), wx.OK|wx.ICON_ERROR)
###
def OnUndo(self, event):
""" Undo the diagram
Expand Down