def __init__(self, filename=None, fullscreen=False, hidemenu=False): self.filename = None self.encoding = 'utf-8' self.is_fullscreen = False self.prev_geometry = (0, 0) self.properties = Properties() #self.properties.read_properties(config_file) self.bookmarks = Bookmarks() #self.main_properties = MainProperties() #self.main_properties = read_config_file() ##from pprint import pprint; pprint(self.main_properties) #self.books_manager = None self.create_widgets() if filename: gobject.idle_add(self.open_file, filename) elif self.properties.recent_files: gobject.idle_add(self.open_file, self.properties.recent_files[-1][0]) if fullscreen and gtk.pygtk_version >= (2, 2): self.on_fullscreen_activate() self.prev_geometry = (self.properties.main_window_width, self.properties.main_window_height) if hidemenu: self.main_menubar.hide() OpenFileDialog.file_select_path = self.properties.file_select_path #self.timeout_cb() gobject.idle_add(lambda : self.timeout_cb() and False) gobject.timeout_add(10000, self.timeout_cb) #self.window.connect('key-release-event', self.key_press_event_cb) self.window.connect('key-press-event', self.key_press_event_cb)
class OrnamentBookMain: def __init__(self, filename=None, fullscreen=False, hidemenu=False): self.filename = None self.encoding = 'utf-8' self.is_fullscreen = False self.prev_geometry = (0, 0) self.properties = Properties() #self.properties.read_properties(config_file) self.bookmarks = Bookmarks() #self.main_properties = MainProperties() #self.main_properties = read_config_file() ##from pprint import pprint; pprint(self.main_properties) #self.books_manager = None self.create_widgets() if filename: gobject.idle_add(self.open_file, filename) elif self.properties.recent_files: gobject.idle_add(self.open_file, self.properties.recent_files[-1][0]) if fullscreen and gtk.pygtk_version >= (2, 2): self.on_fullscreen_activate() self.prev_geometry = (self.properties.main_window_width, self.properties.main_window_height) if hidemenu: self.main_menubar.hide() OpenFileDialog.file_select_path = self.properties.file_select_path #self.timeout_cb() gobject.idle_add(lambda : self.timeout_cb() and False) gobject.timeout_add(10000, self.timeout_cb) #self.window.connect('key-release-event', self.key_press_event_cb) self.window.connect('key-press-event', self.key_press_event_cb) def create_widgets(self): gf = None for d in sys.path: f = os.path.join(d, CONFIG_PREFIX, glade_file) if os.path.exists(f): gf = f break if not gf: sys.exit('ERROR: can\'t find glade file') self.glade_file = gf pgf = None for d in sys.path: f = os.path.join(d, CONFIG_PREFIX, propsdialog_glade_file) if os.path.exists(f): pgf = f break if not pgf: sys.exit('ERROR: can\'t find glade file') self.propsdialog_glade_file = pgf wTree = glade.XML(gf, 'main_window') wTree.signal_autoconnect(self) self.window = wTree.get_widget('main_window') top_vbox = wTree.get_widget('top_vbox') self.main_menubar = wTree.get_widget('main_menubar') # (un)fullscreen available in PyGTK 2.2 and above if gtk.pygtk_version < (2, 2): wTree.get_widget('fullscreen_menu').set_sensitive(False) self.open_recent_file_menu = wTree.get_widget('open_recent_file_menu') self.content_menu = wTree.get_widget('content_menu') self.background_menu = wTree.get_widget('background_menu') self.skins_menu = wTree.get_widget('skins_menu') self.hyphenation_menu = wTree.get_widget('hyphenation_menu') self.text_widget = ornamentbook.OrnamentBook(self) top_vbox.pack_start( self.text_widget ) self.text_widget.realize() #text_widget.connect('position-changed', self.position_changed_cb) #self.text_widget = text_widget self.properties.read_properties(show_warning=True) self.window.resize(self.properties.main_window_width, self.properties.main_window_height) self.update_background_menu() self.update_skins_menu() self.update_hyphenation_menu() self.window.show_all() self.text_widget.initialize() #text_widget.grab_focus() ## def position_changed_cb(self, w, pos): ## self.percent_label.set_text('%d %%' % int(pos*100)) def open_file(self, filename): #print 'open_file', filename try: open(filename) except IOError, err: #sys.stderr.write('ERROR: can\'t open file: %s: %s\n' # % (filename, err[1])) error_dialog(self.window, "Can't open file %s: %s" % (fix_filename(filename), err[1])) self.update_recent_files_menu() return if self.filename: # save previous file #print 'save previous file', self.text_widget.current_page_line_index self.add_file_to_recent(self.filename, self.text_widget.current_page_line_index, self.text_widget.current_page_char_index, self.text_widget.content.encoding, self.text_widget.content.lang) rf = [f for f in self.properties.recent_files if f[0] == filename] if rf: rf = rf[0] ret = self.text_widget.open_file(filename, rf[3], rf[1], rf[2], rf[4]) else: ret = self.text_widget.open_file(filename) if ret: # success self.filename = filename self.add_file_to_recent(self.filename, self.text_widget.current_page_line_index, self.text_widget.current_page_char_index, self.text_widget.content.encoding, self.text_widget.content.lang) self.update_recent_files_menu()