Ejemplo n.º 1
0
    def open(self, doc_file=''):
        if not doc_file:
            doc_file = dialogs.get_open_file_name(self.mw, self,
                                                  config.open_dir)

        if os.path.lexists(doc_file) and os.path.isfile(doc_file):
            try:
                msg = _('Model creation for') + ' "%s" ' % (doc_file)
                uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.JOB, msg)

                doc = SW_Presenter(self, doc_file)
            except:
                details = sys.exc_info()[1].__str__(
                ) + '\n' + traceback.format_tb(sys.exc_info()[2])[0]
                msg = _('Cannot open file')
                msg = "%s '%s'" % (msg, doc_file)
                sec = _('The file may be corrupted or not supported format')

                uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.STOP, msg)

                dialogs.msg_dialog(self.mw, self.appdata.app_name, msg, sec,
                                   details)
                return
            self.docs.append(doc)
            self.set_current_doc(doc)
            config.open_dir = os.path.dirname(doc_file)
            events.emit(events.APP_STATUS, _('Document opened'))
Ejemplo n.º 2
0
    def save(self, doc=''):
        if not doc:
            doc = self.current_doc
        if not doc.doc_file:
            return self.save_as()
        ext = os.path.splitext(self.current_doc.doc_file)[1]
        if not ext[1:]:
            return self.save_as()
        if not os.path.lexists(os.path.dirname(self.current_doc.doc_file)):
            return self.save_as()

        try:
            msg = _('Model saving for') + ' "%s" ' % (doc.doc_file)
            uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.JOB, msg)

            doc.save()
            events.emit(events.DOC_SAVED, doc)
        except:
            details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
            msg = _('Cannot save file')
            msg = "%s '%s'" % (msg, self.current_doc.doc_file)
            sec = _('Please check file write permissions')

            uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.STOP, msg)

            dialogs.msg_dialog(self.mw, self.appdata.app_name, msg, sec,
                               details)
            return False
        events.emit(events.APP_STATUS, _('Document saved'))
        return True
Ejemplo n.º 3
0
	def save_as(self):
		doc_file = self.current_doc.doc_file
		if not doc_file:
			doc_file = self.current_doc.doc_name
		if not os.path.lexists(os.path.dirname(doc_file)):
			doc_file = os.path.join(config.save_dir,
								os.path.basename(doc_file))
		doc_file = dialogs.get_save_file_name(self.mw, self, doc_file)
		if doc_file:
			old_file = self.current_doc.doc_file
			old_name = self.current_doc.doc_name
			self.current_doc.set_doc_file(doc_file)
			try:
				msg = _('Model saving for') + ' "%s" ' % (doc_file)
				uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.JOB, msg)

				self.current_doc.save()
			except IOError:
				self.current_doc.set_doc_file(old_file, old_name)
				details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
				first = _('Cannot save document')
				sec = _('Please check file name and write permissions')
				msg = ("%s '%s'.") % (first, self.current_doc.doc_name)

				uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.STOP, msg)

				dialogs.msg_dialog(self.mw, self.appdata.app_name, msg, sec, details)

				return False
			config.save_dir = os.path.dirname(doc_file)
			events.emit(events.APP_STATUS, _('Document saved'))
			return True
		else:
			return False
Ejemplo n.º 4
0
 def check_selection(self, *args):
     self.set_ascii_selection()
     if self.tb.get_has_selection():
         rng = self.tb.get_selection_bounds()
         self.set_ascii_selection(rng)
         if rng:
             events.emit(events.BIN_SELECTION, self.tb.get_text(*rng))
             return
     events.emit(events.BIN_SELECTION, '')
Ejemplo n.º 5
0
 def edit_object(self, *args):
     obj = self.app.current_doc.docarea.objectbrowser.visualizer.viewer.current_obj
     filename = 'chunk[%s]' % (str(obj).split(' at ')[1][:-1])
     filename = os.path.join(self.app.appdata.app_temp_dir, filename)
     file = open(filename, 'wb')
     file.write(obj.chunk)
     file.close()
     self.app.external_bineditor_open(filename)
     eventloop = self.app.current_doc.eventloop
     selection = self.app.current_doc.selection
     eventloop.emit(eventloop.SELECTION_CHANGED, selection.selected)
     events.emit(events.SELECTION_CHANGED, selection.selected)
Ejemplo n.º 6
0
 def update_object(self, *args):
     obj = self.app.current_doc.docarea.objectbrowser.visualizer.viewer.current_obj
     filename = 'chunk[%s]' % (str(obj).split(' at ')[1][:-1])
     filename = os.path.join(self.app.appdata.app_temp_dir, filename)
     if os.path.lexists(filename):
         try:
             file = open(filename, 'rb')
             obj.chunk = file.read()
             file.close()
             os.remove(filename)
         except:
             pass
     eventloop = self.app.current_doc.eventloop
     selection = self.app.current_doc.selection
     eventloop.emit(eventloop.SELECTION_CHANGED, selection.selected)
     events.emit(events.SELECTION_CHANGED, selection.selected)
Ejemplo n.º 7
0
	def close(self, doc=None):
		if not self.docs:
			return
		if doc is None:
			doc = self.current_doc

		if not self.mw.nb.page_num(doc.docarea) == self.mw.nb.get_current_page():
			self.mw.set_active_tab(doc.docarea)
		if doc in self.docs:
			self.docs.remove(doc)
			doc.close()
			events.emit(events.DOC_CLOSED)
			if not len(self.docs):
				self.current_doc = None
				events.emit(events.NO_DOCS)
				msg = _('To start, create new document or open existing')
				events.emit(events.APP_STATUS, msg)
		return True
Ejemplo n.º 8
0
 def reflect_saving(self):
     self.saved = True
     self.set_title()
     events.emit(events.DOC_SAVED, self)
Ejemplo n.º 9
0
 def modified(self, *args):
     self.saved = False
     self.set_title()
     events.emit(events.DOC_MODIFIED, self)
Ejemplo n.º 10
0
 def run(self):
     events.emit(events.NO_DOCS)
     events.emit(events.APP_STATUS,
                 _('To start create new or open existing document'))
     gtk.main()
Ejemplo n.º 11
0
 def set_current_doc(self, doc):
     self.current_doc = doc
     events.emit(events.DOC_CHANGED, doc)
Ejemplo n.º 12
0
 def refresh_object(self, *args):
     eventloop = self.app.current_doc.eventloop
     selection = self.app.current_doc.selection
     eventloop.emit(eventloop.SELECTION_CHANGED, selection.selected)
     events.emit(events.SELECTION_CHANGED, selection.selected)
Ejemplo n.º 13
0
 def _send_event(self):
     self.eventloop.emit(self.eventloop.SELECTION_CHANGED, self.selected)
     events.emit(events.SELECTION_CHANGED, self.selected)
Ejemplo n.º 14
0
 def __setattr__(self, attr, value):
     if not hasattr(self, attr) or getattr(self, attr) != value:
         self.__dict__[attr] = value
         events.emit(events.CONFIG_MODIFIED, attr, value)