def __init__(self, parent, notebook):
     wx.Panel.__init__(self, notebook)
     self._parent = parent
     main_sizer = wx.BoxSizer(wx.VERTICAL)
     self.SetSizer(main_sizer)
     self._format = parent.format
     self.__view = None
     self._printing = Printing(self)
     box = wx.BoxSizer(wx.HORIZONTAL)
     box.Add(self._chooser())
     box.Add(self._print_button(), 1, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
     self.Sizer.Add(box)
     notebook.AddPage(self, "Preview")
示例#2
0
文件: preview.py 项目: IlfirinPL/RIDE
 def __init__(self, parent, notebook):
     wx.Panel.__init__(self, notebook)
     self._parent = parent
     main_sizer = wx.BoxSizer(wx.VERTICAL)
     self.SetSizer(main_sizer)
     self._format = parent.format
     self.__view = None
     self._printing = Printing(self)
     box = wx.BoxSizer(wx.HORIZONTAL)
     box.Add(self._chooser())
     box.Add(self._print_button(), 1, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
     self.Sizer.Add(box)
     notebook.AddPage(self, "Preview")
示例#3
0
文件: preview.py 项目: yvdhi/RIDE
class PreviewPanel(wx.Panel):
    _formats = ['HTML', 'Text (Spaces)', 'Text (Pipes)']

    def __init__(self, parent, notebook):
        wx.Panel.__init__(self, notebook)
        self._parent = parent
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(main_sizer)
        self._format = parent.format
        self.__view = None
        self._printing = Printing(self)
        box = wx.BoxSizer(wx.HORIZONTAL)
        box.Add(self._chooser())
        if wx.VERSION < (4, 1, 0):
            box.Add(self._print_button(), 1, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
        else:
            box.Add(self._print_button(), 1, wx.EXPAND)
        self.Sizer.Add(box)
        notebook.AddPage(self, "Preview")

    def OnPrint(self, evt):
        self._printing.preview_text(self._get_content())

    @property
    def _file_format(self):
        if self._format == 'HTML':
            return self._format.lower()
        return 'txt'

    @property
    def _pipe_separated(self):
        return 'Pipes' in self._format

    def _chooser(self):
        chooser = wx.RadioBox(self, label='Format', choices=self._formats)
        chooser.SetStringSelection(self._format)
        self.Bind(wx.EVT_RADIOBOX, self.OnTypeChanged, chooser)
        return chooser

    def _print_button(self):
        return ButtonWithHandler(self, 'Print')

    @property
    def _view(self):
        view_class = HtmlView if self._file_format == 'html' else TxtView
        if isinstance(self.__view, view_class):
            return self.__view
        self._remove_current_view()
        self.__view = self._create_view(view_class)
        return self.__view

    def _remove_current_view(self):
        if self.__view:
            self.Sizer.Remove(self.__view)
            self.__view.Destroy()

    def _create_view(self, view_class):
        view = view_class(self)
        self.Sizer.Add(view, 1, wx.EXPAND|wx.ALL, border=8)
        self.Sizer.Layout()
        return view

    def tree_node_selected(self, item):
        self.update_preview()
        self._view.scroll_to_subitem(item)

    def update_preview(self):
        self._view.set_content(self._get_content())

    def _get_content(self):
        datafile = self._parent.datafile
        if not datafile:
            return ''
        output = StringIO()
        try:
            datafile.save(
                output=output,
                format=self._file_format,
                pipe_separated=self._pipe_separated,
                txt_separating_spaces=self._parent.global_settings['txt number of spaces']
            )
        except Exception as e:
            return "Creating preview of '%s' failed: %s" % (datafile.name, e)
        else:
            return output.getvalue()

    def OnTypeChanged(self, event):
        self._format = event.String
        self.update_preview()
        self._parent.save_setting('format', self._format)
示例#4
0
文件: preview.py 项目: IlfirinPL/RIDE
class PreviewPanel(wx.Panel):
    _formats = ['HTML', 'Text (Spaces)', 'Text (Pipes)']

    def __init__(self, parent, notebook):
        wx.Panel.__init__(self, notebook)
        self._parent = parent
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(main_sizer)
        self._format = parent.format
        self.__view = None
        self._printing = Printing(self)
        box = wx.BoxSizer(wx.HORIZONTAL)
        box.Add(self._chooser())
        box.Add(self._print_button(), 1, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
        self.Sizer.Add(box)
        notebook.AddPage(self, "Preview")

    def OnPrint(self, evt):
        self._printing.preview_text(self._get_content())

    @property
    def _file_format(self):
        if self._format == 'HTML':
            return self._format.lower()
        return 'txt'

    @property
    def _pipe_separated(self):
        return 'Pipes' in self._format

    def _chooser(self):
        chooser = wx.RadioBox(self, label='Format', choices=self._formats)
        chooser.SetStringSelection(self._format)
        self.Bind(wx.EVT_RADIOBOX, self.OnTypeChanged, chooser)
        return chooser

    def _print_button(self):
        return ButtonWithHandler(self, 'Print')

    @property
    def _view(self):
        view_class = HtmlView if self._file_format == 'html' else TxtView
        if isinstance(self.__view, view_class):
            return self.__view
        self._remove_current_view()
        self.__view = self._create_view(view_class)
        return self.__view

    def _remove_current_view(self):
        if self.__view:
            self.Sizer.Remove(self.__view)
            self.__view.Destroy()

    def _create_view(self, view_class):
        view = view_class(self)
        self.Sizer.Add(view, 1, wx.EXPAND|wx.ALL, border=8)
        self.Sizer.Layout()
        return view

    def tree_node_selected(self, item):
        self.update_preview()
        self._view.scroll_to_subitem(item)

    def update_preview(self):
        self._view.set_content(self._get_content())

    def _get_content(self):
        datafile = self._parent.datafile
        if not datafile:
            return ''
        output = StringIO()
        try:
            datafile.save(output=output, format=self._file_format,
                          pipe_separated=self._pipe_separated)
        except Exception, e:
            return "Creating preview of '%s' failed: %s" % (datafile.name, e)
        else: