コード例 #1
0
    def __init__(self, parent):
        super(TemplateManager, self).__init__(parent)
        self.template_panel = TemplatePanel(self.tp_holder)
        self.movable_list = MovableListPanel(self, self.movable_list_holder)

        self.tp_holder.Sizer.Add(self.template_panel,
                                 1,
                                 wx.GROW | wx.ALL,
                                 border=5)
        self.movable_list_holder.Sizer.Add(self.movable_list,
                                           1,
                                           wx.GROW | wx.ALL,
                                           border=5)

        self.tp_holder.Fit()
        self.movable_list_holder.Fit()
        self.Fit()
        self.MinSize = self.Size

        for a in [
                wx.EVT_KILL_FOCUS,
        ]:
            for item in self.template_panel.fields:
                item.Bind(a, self.change_field)

        self.movable_list.gui_templates.Bind(wx.EVT_LISTBOX_DCLICK,
                                             lambda x: self.EndModal(wx.ID_OK))

        self.read_templates()
        self.movable_list.init()
コード例 #2
0
class PathManagerPanel(wx.Panel):
    def __init__(self, parent):
        super(PathManagerPanel, self).__init__(parent)

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.panel = MovableListPanel(parent=self,
                                      gui_parent=self,
                                      copy_text=_("New"))

        sizer.Add(self.panel, 1, wx.GROW)
        s = wx.StdDialogButtonSizer()
        s.AddButton(wx.Button(self, id=wx.ID_OK))
        s.AddButton(wx.Button(self, id=wx.ID_CANCEL))

        s.Realize()
        sizer.Add(s, 0, wx.GROW)

        self.Sizer = sizer

        self.templates = self.read_templates()

        self.panel.init()

    def read_templates(self):
        return [PathItem(x) for x in biblemgr.load_paths()]

    def normalize_path(self, path):
        dir = os.getcwd()
        return os.path.normpath(path)

    def get_unique_name(self, name="", template=None, overwrite=False):
        if not name:
            name = os.getcwd()

        dlg = wx.DirDialog(self,
                           _("Choose a directory:"),
                           style=wx.DD_DEFAULT_STYLE,
                           defaultPath=name)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it.
        ansa = dlg.ShowModal()
        if ansa == wx.ID_OK:
            path = dlg.Path
            return path

    def on_template_change(self, selection):
        pass

    def save(self):
        busy = wx.BusyInfo(_("Reading books..."))
        biblemgr.set_new_paths([str(a.name) for a in self.templates])
コード例 #3
0
ファイル: pathmanager.py プロジェクト: cvillaluz81/bpbible
class PathManagerPanel(wx.Panel):
	def __init__(self, parent):
		super(PathManagerPanel, self).__init__(parent)
		
		sizer = wx.BoxSizer(wx.VERTICAL)
		self.panel = MovableListPanel(parent=self, gui_parent=self,
			copy_text=_("New"))
		
		sizer.Add(self.panel, 1, wx.GROW)
		s = wx.StdDialogButtonSizer()
		s.AddButton(wx.Button(self, id=wx.ID_OK))
		s.AddButton(wx.Button(self, id=wx.ID_CANCEL))
		
		s.Realize()
		sizer.Add(s, 0, wx.GROW)
		
		self.Sizer = sizer


		self.templates = self.read_templates()
		
		self.panel.init()
	
	def read_templates(self):
		return [PathItem(x) for x in biblemgr.load_paths()]
	
	def normalize_path(self, path):
		dir = os.getcwd()
		return os.path.normpath(path)
	
	def get_unique_name(self, name="", template=None, overwrite=False):
		if not name:
			name=os.getcwd()

		dlg = wx.DirDialog(self, _("Choose a directory:"),
						  style=wx.DD_DEFAULT_STYLE, defaultPath=name)

		# If the user selects OK, then we process the dialog's data.
		# This is done by getting the path data from the dialog - BEFORE
		# we destroy it. 
		ansa = dlg.ShowModal() 
		if ansa == wx.ID_OK:
			path = dlg.Path
			return path

	def on_template_change(self, selection): pass

	def save(self):
		busy = wx.BusyInfo(_("Reading books..."))
		biblemgr.set_new_paths([str(a.name) for a in self.templates])
コード例 #4
0
	def __init__(self, parent):
		super(TemplateManager, self).__init__(parent)
		self.template_panel = TemplatePanel(self.tp_holder)
		self.movable_list = MovableListPanel(self, self.movable_list_holder)

		self.tp_holder.Sizer.Add(self.template_panel, 1, wx.GROW|wx.ALL,
			border=5)
		self.movable_list_holder.Sizer.Add(self.movable_list, 1, 
			wx.GROW|wx.ALL,	border=5)
			
		self.tp_holder.Fit()
		self.movable_list_holder.Fit()
		self.Fit()
		self.MinSize = self.Size
		

		for a in [wx.EVT_KILL_FOCUS,]:
			for item in self.template_panel.fields:
				item.Bind(a, self.change_field)
		
		
		self.movable_list.gui_templates.Bind(wx.EVT_LISTBOX_DCLICK, 
			lambda x:self.EndModal(wx.ID_OK))
			
		self.read_templates()
		self.movable_list.init()
コード例 #5
0
    def __init__(self, parent):
        super(PathManagerPanel, self).__init__(parent)

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.panel = MovableListPanel(parent=self,
                                      gui_parent=self,
                                      copy_text=_("New"))

        sizer.Add(self.panel, 1, wx.GROW)
        s = wx.StdDialogButtonSizer()
        s.AddButton(wx.Button(self, id=wx.ID_OK))
        s.AddButton(wx.Button(self, id=wx.ID_CANCEL))

        s.Realize()
        sizer.Add(s, 0, wx.GROW)

        self.Sizer = sizer

        self.templates = self.read_templates()

        self.panel.init()
コード例 #6
0
ファイル: pathmanager.py プロジェクト: cvillaluz81/bpbible
	def __init__(self, parent):
		super(PathManagerPanel, self).__init__(parent)
		
		sizer = wx.BoxSizer(wx.VERTICAL)
		self.panel = MovableListPanel(parent=self, gui_parent=self,
			copy_text=_("New"))
		
		sizer.Add(self.panel, 1, wx.GROW)
		s = wx.StdDialogButtonSizer()
		s.AddButton(wx.Button(self, id=wx.ID_OK))
		s.AddButton(wx.Button(self, id=wx.ID_CANCEL))
		
		s.Realize()
		sizer.Add(s, 0, wx.GROW)
		
		self.Sizer = sizer


		self.templates = self.read_templates()
		
		self.panel.init()
コード例 #7
0
class TemplateManager(xrcTemplateManager):
    def __init__(self, parent):
        super(TemplateManager, self).__init__(parent)
        self.template_panel = TemplatePanel(self.tp_holder)
        self.movable_list = MovableListPanel(self, self.movable_list_holder)

        self.tp_holder.Sizer.Add(self.template_panel,
                                 1,
                                 wx.GROW | wx.ALL,
                                 border=5)
        self.movable_list_holder.Sizer.Add(self.movable_list,
                                           1,
                                           wx.GROW | wx.ALL,
                                           border=5)

        self.tp_holder.Fit()
        self.movable_list_holder.Fit()
        self.Fit()
        self.MinSize = self.Size

        for a in [
                wx.EVT_KILL_FOCUS,
        ]:
            for item in self.template_panel.fields:
                item.Bind(a, self.change_field)

        self.movable_list.gui_templates.Bind(wx.EVT_LISTBOX_DCLICK,
                                             lambda x: self.EndModal(wx.ID_OK))

        self.read_templates()
        self.movable_list.init()

    def template_exists(self, name, excluded=None):
        for item in self.templates:
            if item is not excluded and item.name == name:
                return True
        return False

    def save(self):
        if not os.path.exists(config.data_path):
            os.makedirs(config.data_path)

        f = open(template_file, "wb")
        pickle.dump(self.templates, f)

    def change_field(self, event):
        event.Skip()
        if self.movable_list.template.readonly: return
        assert not self.movable_list.template.readonly

        item = event.EventObject

        self.movable_list.template[item.field] = item.Text
        self.update_preview()

    @property
    def template(self):
        """Delegate this to the movable list"""
        return self.movable_list.template

    def get_template(self, name):
        for item in self.templates:
            if item.name == name:
                return item

    def get_unique_name(self, name="", template=None, overwrite=False):
        original_name = name
        while True:
            te = wx.TextEntryDialog(self,
                                    "New name for template...",
                                    "Rename",
                                    defaultValue=name)
            if te.ShowModal() == wx.ID_OK:
                name = te.GetValue()
                if overwrite and self.template_exists(name):
                    if self.get_template(name).readonly:
                        wx.MessageBox(
                            _("Template '%s' is read only. Try a "
                              "different name.") % name, _("Error"),
                            wx.OK | wx.ICON_ERROR)
                    elif name == original_name:
                        return name
                    else:
                        ansa = wx.MessageBox(
                            _("Template '%s' already exists. Overwrite?") %
                            name, _("Overwrite?"),
                            wx.YES_NO | wx.ICON_QUESTION)
                        if ansa == wx.YES:
                            return name
                elif self.template_exists(name, template):
                    wx.MessageBox(
                        _("Template name is already in use. Try a different name."
                          ), _("Error"), wx.OK | wx.ICON_ERROR)

                else:
                    return name

            else:
                return

    def read_templates(self):
        try:
            f = open(template_file, "rb")
            self.templates = pickle.load(f)
            for template in self.templates:
                # If we are loading a pickled template from 0.4.x, the
                # preverse template will not be present.
                # If it is not, then we give it a default so it doesn't
                # crash.
                if not hasattr(template, "preverse"):
                    from backend.verse_template import str_template
                    template.preverse = str_template("")
        except Exception, e:
            dprint(WARNING, "Template loading exception", e)
            self.templates = default_templates[:]
コード例 #8
0
class TemplateManager(xrcTemplateManager):
	def __init__(self, parent):
		super(TemplateManager, self).__init__(parent)
		self.template_panel = TemplatePanel(self.tp_holder)
		self.movable_list = MovableListPanel(self, self.movable_list_holder)

		self.tp_holder.Sizer.Add(self.template_panel, 1, wx.GROW|wx.ALL,
			border=5)
		self.movable_list_holder.Sizer.Add(self.movable_list, 1, 
			wx.GROW|wx.ALL,	border=5)
			
		self.tp_holder.Fit()
		self.movable_list_holder.Fit()
		self.Fit()
		self.MinSize = self.Size
		

		for a in [wx.EVT_KILL_FOCUS,]:
			for item in self.template_panel.fields:
				item.Bind(a, self.change_field)
		
		
		self.movable_list.gui_templates.Bind(wx.EVT_LISTBOX_DCLICK, 
			lambda x:self.EndModal(wx.ID_OK))
			
		self.read_templates()
		self.movable_list.init()
		
	
	def template_exists(self, name, excluded=None):
		for item in self.templates:
			if item is not excluded and item.name == name:
				return True
		return False
	
	def save(self):
		if not os.path.exists(config.data_path):
			os.makedirs(config.data_path)
	
		f = open(template_file, "wb")
		pickle.dump(self.templates, f)
		
		
	
	def change_field(self, event):
		event.Skip()
		if self.movable_list.template.readonly: return
		assert not self.movable_list.template.readonly
	
		item = event.EventObject

		self.movable_list.template[item.field] = item.Text
		self.update_preview()
			
	@property
	def template(self):
		"""Delegate this to the movable list"""
		return self.movable_list.template

	def get_template(self, name):
		for item in self.templates:
			if item.name == name:
				return item
			
	def get_unique_name(self, name="", template=None, overwrite=False):
		original_name = name
		while True:
			te = wx.TextEntryDialog(self, "New name for template...", 
				"Rename", defaultValue=name)
			if te.ShowModal() == wx.ID_OK:
				name = te.GetValue()
				if overwrite and self.template_exists(name):
					if self.get_template(name).readonly:
						wx.MessageBox(_("Template '%s' is read only. Try a "
						"different name.") % name, _("Error"), 
							wx.OK|wx.ICON_ERROR)
					elif name == original_name:
						return name
					else:
						ansa = wx.MessageBox(
						_("Template '%s' already exists. Overwrite?") % name,
						_("Overwrite?") , wx.YES_NO|wx.ICON_QUESTION)
						if ansa == wx.YES:
							return name
				elif self.template_exists(name, template):
					wx.MessageBox(
					_("Template name is already in use. Try a different name."),
					_("Error"), wx.OK|wx.ICON_ERROR)		
												
				else: 
					return name
					
			else:
				return
			
	
	
	def read_templates(self):
		try:
			f = open(template_file, "rb")
			self.templates = pickle.load(f)
			for template in self.templates:
				# If we are loading a pickled template from 0.4.x, the
				# preverse template will not be present.
				# If it is not, then we give it a default so it doesn't
				# crash.
				if not hasattr(template, "preverse"):
					from backend.verse_template import str_template
					template.preverse = str_template("")
		except Exception, e:
			dprint(WARNING, "Template loading exception", e)
			self.templates = default_templates[:]