def about_clicked (self, arg): about_dialog = gtk.AboutDialog () about_dialog.set_name ("Labyrinth") about_dialog.set_version (__version__) if os.name != 'nt': try: about_dialog.set_logo_icon_name("labyrinth") except: pass else: about_dialog.set_logo (gtk.gdk.pixbuf_new_from_file( utils.get_data_file_name("labyrinth-32.png"))) about_dialog.set_license ( "Labyrinth is free software; you can redistribute it and/or modify " "it under the terms of the GNU General Public Licence as published by " "the Free Software Foundation; either version 2 of the Licence, or " "(at your option) any later version." "\n\n" "Labyrinth is distributed in the hope that it will be useful, " "but WITHOUT ANY WARRANTY; without even the implied warranty of " "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " "GNU General Public Licence for more details." "\n\n" "You should have received a copy of the GNU General Public Licence " "along with Labyrinth; if not, write to the Free Software Foundation, Inc., " "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA") about_dialog.set_wrap_license (True) about_dialog.set_copyright ("2006-2008 Don Scorgie et. al") about_dialog.set_authors (AUTHORS) about_dialog.set_website ("http://code.google.com/p/labyrinth") about_dialog.set_translator_credits (_("Translation by Don Scorgie")) about_dialog.run () about_dialog.hide () del (about_dialog) return
def _load(file_name): file_name = get_data_file_name(file_name) # Go down the right path data = pd.read_csv(file_name, header=None) data = data[[1, 2]] data.columns = ['labels', 'news'] data['news'] = data['news'].map(lambda x: x.lower().translate( dict((ord(char), None) for char in string.punctuation if char != '\'' and char != '-'))) data['news'] = data['news'].map(lambda x: x.replace('\n', ' ')) return data
def __init__ (self, coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color): super (ResourceThought, self).__init__(coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color, "res_thought") self.uri = "" # TODO: we should handle such things with a singleton self.glade = gtk.glade.XML(utils.get_data_file_name('labyrinth.glade')) self.dialog = self.glade.get_widget('ResourceChooserDialog') self.dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK) if not loading: self.process_uri_dialog() self.all_okay = True
def __init__(self, start_hidden, tray_icon): super(Browser, self).__init__() self.glade=Gtk.glade.XML(utils.get_data_file_name('labyrinth.glade')) self.view = self.glade.get_widget ('MainView') self.populate_view () self.view.connect ('row-activated', self.open_row_cb) self.view.connect ('cursor-changed', self.cursor_change_cb) self.view_dependants = [] self.open_button = self.glade.get_widget('OpenButton') self.delete_button = self.glade.get_widget('DeleteButton') self.open_menu = self.glade.get_widget('open1') self.delete_menu = self.glade.get_widget('delete1') self.view_dependants.append (self.open_button) self.view_dependants.append (self.delete_button) self.view_dependants.append (self.open_menu) self.view_dependants.append (self.delete_menu) self.open_button.connect ('clicked', self.open_clicked) self.glade.get_widget('NewButton').connect ('clicked', self.new_clicked) self.delete_button.connect ('clicked', self.delete_clicked) self.open_menu.connect ('activate', self.open_clicked) self.glade.get_widget('new1').connect ('activate', self.new_clicked) self.delete_menu.connect ('activate', self.delete_clicked) self.glade.get_widget('import1').connect ('activate', self.import_clicked) self.glade.get_widget('quit1').connect ('activate', self.quit_clicked) self.glade.get_widget('about1').connect ('activate', self.about_clicked) self.glade.get_widget('showhelp').connect ('activate', self.show_help_clicked) map(lambda x : x.set_sensitive(False), self.view_dependants) props = { gnome.PARAM_APP_DATADIR : '/usr/share' } prog = gnome.program_init('labyrinth', '0.5', properties=props) self.main_window = self.glade.get_widget ('MapBrowser') # set remembered size if os.name != 'nt': self.config_client = GConf.Client.get_default() self.config_client.add_dir ("/apps/labyrinth", GConf.ClientPreloadType.PRELOAD_NONE) width = self.config_client.get_int ('/apps/labyrinth/width') height = self.config_client.get_int ('/apps/labyrinth/height') utils.use_bezier_curves = self.config_client.get_bool ('/apps/labyrinth/curves') if width == 0 or height == 0: width = 400 height = 300 else: width = 400 height = 300 view_sortable = self.view.get_model () view_sortable.connect ('sort-column-changed', self.sort_column_changed_cb) if os.name != 'nt': sort_order = self.config_client.get_int('/apps/labyrinth/map_sort_order') column_id = self.config_client.get_int('/apps/labyrinth/map_sort_order_column') view_sortable.set_sort_column_id (column_id, sort_order) self.main_window.resize (width, height) if os.name != 'nt': try: self.main_window.set_icon_name ('labyrinth') except: self.main_window.set_icon_from_file(utils.get_data_file_name('labyrinth.svg')) else: self.main_window.set_icon_from_file('images\\labyrinth-24.png') if tray_icon: self.main_window.connect ('delete_event', self.toggle_main_window, None) traymenu = Gtk.Menu() quit_item = Gtk.MenuItem("Quit") quit_item.connect("activate",self.quit_clicked) traymenu.add(quit_item) traymenu.show_all() self.traymenu = traymenu self.trayicon = TrayIcon.TrayIcon( icon_name="labyrinth", menu=traymenu, activate=self.toggle_main_window) else: self.main_window.connect('delete_event', self.quit_clicked, None) if start_hidden: self.main_window.hide () else: self.main_window.show_all ()
def export_cb (self, event): maxx, maxy = self.MainArea.get_max_area () x, y, width, height, bitdepth = self.MainArea.window.get_geometry () glade = gtk.glade.XML (utils.get_data_file_name('labyrinth.glade')) dialog = glade.get_widget ('ExportImageDialog') box = glade.get_widget ('dialog_insertion') fc = gtk.FileChooserWidget(gtk.FILE_CHOOSER_ACTION_SAVE) box.pack_end (fc) filter_mapping = [ (_('All Files'), ['*']), (_('PNG Image (*.png)'), ['*.png']), (_('JPEG Image (*.jpg, *.jpeg)'), ['*.jpeg', '*.jpg']), (_('SVG Vector Image (*.svg)'), ['*.svg']), (_('PDF Portable Document (*.pdf)'), ['*.pdf']) ] for (filter_name, filter_patterns) in filter_mapping: fil = gtk.FileFilter () fil.set_name(filter_name) for pattern in filter_patterns: fil.add_pattern(pattern) fc.add_filter(fil) fc.set_current_name ("%s.png" % self.main_window.title) rad = glade.get_widget ('rb_complete_map') rad2 = glade.get_widget ('rb_visible_area') self.spin_width = glade.get_widget ('width_spin') self.spin_height = glade.get_widget ('height_spin') self.spin_width.set_value (maxx) self.spin_height.set_value (maxy) self.spin_width.set_sensitive (False) self.spin_height.set_sensitive (False) rad.connect ('toggled', self.toggle_range, width, height,maxx,maxy) fc.show () while 1: # Cheesy loop. Break out as needed. response = dialog.run() if response == gtk.RESPONSE_OK: ext_mime_mapping = { 'png':'png', 'jpg':'jpeg', 'jpeg':'jpeg', \ 'svg':'svg', 'pdf':'pdf' } filename = fc.get_filename() if filename is None: continue # No file selected ext = filename[filename.rfind('.')+1:] try: mime = ext_mime_mapping[ext] break except KeyError: msg = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, \ _("Unknown file format")) msg.format_secondary_text (_("The file type '%s' is unsupported. Please use the suffix '.png',"\ " '.jpg' or '.svg'." % ext)) msg.run () msg.destroy () else: dialog.destroy () return true_width = int (self.spin_width.get_value ()) true_height = int (self.spin_height.get_value ()) native = not rad.get_active () dialog.destroy () if mime in ['png', 'jpeg']: self.save_as_pixmap(filename, mime, true_width, true_height, bitdepth, native) else: surface = None if mime == 'svg': surface = cairo.SVGSurface(filename, true_width, true_height) elif mime == 'pdf': surface = cairo.PDFSurface(filename, true_width, true_height) self.save_surface(surface, true_width, true_height, native)
def __init__ (self, filename, imported=False): super(LabyrinthWindow, self).__init__() # First, construct the MainArea and connect it all up self.undo = UndoManager.UndoManager (self) self.undo.block () self.MainArea = MMapArea.MMapArea (self.undo) self.MainArea.connect ("title_changed", self.title_changed_cb) self.MainArea.connect ("doc_save", self.doc_save_cb) self.MainArea.connect ("doc_delete", self.doc_del_cb) self.MainArea.connect ("change_mode", self.mode_request_cb) self.MainArea.connect ("button-press-event", self.main_area_focus_cb) self.MainArea.connect ("change_buffer", self.switch_buffer_cb) self.MainArea.connect ("thought_selection_changed", self.thought_selected_cb) self.MainArea.connect ("set_focus", self.main_area_focus_cb) self.MainArea.connect ("set_attrs", self.attrs_cb) if os.name != 'nt': self.MainArea.connect ("text_selection_changed", self.selection_changed_cb) self.config_client = gconf.client_get_default() glade = gtk.glade.XML(utils.get_data_file_name('labyrinth.glade')) self.main_window = glade.get_widget ('MapWindow') self.main_window.set_focus_child (self.MainArea) if os.name != 'nt': try: self.main_window.set_icon_name ('labyrinth') except: self.main_window.set_icon_from_file(utils.get_data_file_name('labyrinth.svg')) else: self.main_window.set_icon_from_file(utils.get_data_file_name('labyrinth-32.png')) # insert menu, toolbar and map self.create_menu() glade.get_widget ('main_area_insertion').pack_start(self.MainArea) vbox = glade.get_widget ('map_window_vbox') menubar = self.ui.get_widget('/MenuBar') menubar.show_all() vbox.pack_start(menubar) vbox.reorder_child(menubar, 0) vbox.set_child_packing(menubar, 0, 0, 0, gtk.PACK_START) toolbar = self.ui.get_widget('/ToolBar') toolbar.show_all() vbox.pack_start(toolbar) vbox.reorder_child(toolbar, 1) vbox.set_child_packing(toolbar, 0, 0, 0, gtk.PACK_START) # TODO: Bold, Italics etc. self.bold_widget = glade.get_widget('tool_bold') self.bold_widget.connect('toggled', self.bold_toggled) self.bold_block = False self.bold_state = False self.italic_widget = glade.get_widget('tool_italic') self.italic_widget.connect('toggled', self.italic_toggled) self.italic_block = False self.italic_state = False self.underline_widget = glade.get_widget('tool_underline') self.underline_widget.connect('toggled', self.underline_toggled) self.underline_block = False self.underline_state = False self.font_widget = glade.get_widget('font_button') self.font_widget.connect ("font-set", self.font_change_cb) self.background_widget = glade.get_widget('background_color_button') self.background_widget.connect ("color-set", self.background_change_cb) self.foreground_widget = glade.get_widget('foreground_color_button') self.foreground_widget.connect ("color-set", self.foreground_change_cb) self.thickness_widget = glade.get_widget('thickness_button') self.thickness_widget.connect("value_changed", self.thickness_change_cb) self.thickness_widget.set_numeric(True) self.thickness_widget.set_range(1, 10) self.thickness_widget.set_increments(1, 0.5) self.thickness_widget.set_value(utils.thickness) self.cut = self.ui.get_widget ('/MenuBar/EditMenu/Cut') self.copy = self.ui.get_widget ('/MenuBar/EditMenu/Copy') self.paste = self.ui.get_widget ('/MenuBar/EditMenu/Paste') self.link = self.ui.get_widget ('/MenuBar/EditMenu/LinkThoughts') self.delete = self.ui.get_widget ('/MenuBar/EditMenu/DeleteNodes') self.ui.get_widget('/MenuBar/EditMenu').connect ('activate', self.edit_activated_cb) self.cut.set_sensitive (False) self.copy.set_sensitive (False) # get toolbars and activate corresponding menu entries self.main_toolbar = self.ui.get_widget ('/ToolBar') self.format_toolbar = glade.get_widget ('format_toolbar') self.ui.get_widget('/MenuBar/ViewMenu/ShowToolbars/ShowMainToolbar').set_active(True) self.ui.get_widget('/MenuBar/ViewMenu/ShowToolbars/ShowFormatToolbar').set_active(True) self.ui.get_widget('/MenuBar/ViewMenu/UseBezier').set_active(utils.use_bezier_curves) self.ui.get_widget('/MenuBar/ViewMenu/ShowArrowheads').set_active(utils.use_arrowheads) # Add in the extended info view self.extended_window = glade.get_widget('extended_window') self.extended = glade.get_widget('extended') self.invisible_buffer = gtk.TextBuffer () # Connect all our signals self.main_window.connect ("configure_event", self.configure_cb) self.main_window.connect ("window-state-event", self.window_state_cb) self.main_window.connect ("destroy", self.close_window_cb) # Deal with loading the map if not filename: self.MainArea.set_size_request (400, 400) # TODO: This shouldn't be set to a hard-coded number. Fix. self.pane_pos = 500 self.title_cp = _("Untitled Map") self.mode = MMapArea.MODE_EDITING self.extended_visible = False else: self.parse_file (filename) up_box = glade.get_widget('up_box') up_box.connect("button-press-event", self.translate, "Up") up_box.connect("button-release-event", self.finish_translate) down_box = glade.get_widget('down_box') down_box.connect("button-press-event", self.translate, "Down") down_box.connect("button-release-event", self.finish_translate) right_box = glade.get_widget('right_box') right_box.connect("button-press-event", self.translate, "Right") right_box.connect("button-release-event", self.finish_translate) left_box = glade.get_widget('left_box') left_box.connect("button-press-event", self.translate, "Left") left_box.connect("button-release-event", self.finish_translate) panes = glade.get_widget('vpaned1') panes.connect ("button-release-event", self.pos_changed) panes.set_position (self.pane_pos) # Other stuff self.width, self.height = self.main_window.get_size () # if we import, we dump the old filename to create a new hashed one self.save_file = None if not imported: self.save_file = filename self.maximised = False self.view_type = 0 self.act.set_current_value (self.mode) self.undo.unblock () self.start_timer ()
def create_menu (self): actions = [ ('FileMenu', None, _('File')), ('Export', None, _('Export as Image'), None, _("Export your map as an image"), self.export_cb), ('ExportMap', gtk.STOCK_SAVE_AS, _('Export Map...'), '<control>S', _("Export your map as XML"), self.export_map_cb), ('Close', gtk.STOCK_CLOSE, None, '<control>W', _('Close the current window'), self.close_window_cb), ('EditMenu', None, _('_Edit')), ('ViewMenu', None, _('_View')), ('ShowToolbars', None, _('_Toolbar')), ('Undo', gtk.STOCK_UNDO, None, '<control>Z', None), ('Redo', gtk.STOCK_REDO, None, '<control><shift>Z', None), ('Cut', gtk.STOCK_CUT, None, '<control>X', None, self.cut_text_cb), ('Copy', gtk.STOCK_COPY, None, '<control>C', None, self.copy_text_cb), ('Paste', gtk.STOCK_PASTE, None, '<control>V', None, self.paste_text_cb), ('LinkThoughts', None, _("Link Thoughts"), '<control>L', _("Link the selected thoughts"), self.link_thoughts_cb), ('ModeMenu', None, _('_Mode')), ('ZoomIn', gtk.STOCK_ZOOM_IN, None, '<control>plus', None, self.zoomin_cb), ('ZoomOut', gtk.STOCK_ZOOM_OUT, None, '<control>minus', None, self.zoomout_cb), ('Zoom100', gtk.STOCK_ZOOM_100, None, '<control>0', None, self.zoom100_cb)] self.radio_actions = [ ('Edit', gtk.STOCK_EDIT, _('_Edit Mode'), '<control>E', _('Turn on edit mode'), MMapArea.MODE_EDITING), ('AddImage', gtk.STOCK_ADD, _('_Add Image'), '<control>I', _('Add an image to selected thought'), MMapArea.MODE_IMAGE), ('Drawing', gtk.STOCK_COLOR_PICKER, _('_Drawing Mode'), '<control>D', _('Make a pretty drawing'), MMapArea.MODE_DRAW)] self.view_radio_actions = [ ('UseBezier', None, _('Use _Curves'), None, _('Use curves as links'), MMapArea.VIEW_BEZIER), ('UseLines', None, _('Use _Lines'), None, _('Use straight lines as links'), MMapArea.VIEW_LINES)] self.toggle_actions = [ ('ViewExtend', None, _('_Extended Information'), None, _('Show extended information for thoughts'), self.view_extend_cb), ('ShowMainToolbar', None, _('_Main'), None, _('Show main toolbar'), self.show_main_toolbar_cb), ('ShowFormatToolbar', None, _('_Format'), None, _('Show format toolbar'), self.show_format_toolbar_cb), ('ShowArrowheads', None, _('_Arrowheads'), None, _('Show arrowheads'), self.use_arrowheads_cb)] ag = gtk.ActionGroup ('WindowActions') ag.set_translation_domain(gettext.textdomain()) ag.add_actions (actions) ag.add_radio_actions (self.radio_actions) ag.add_radio_actions (self.view_radio_actions) ag.add_toggle_actions (self.toggle_actions) self.act = ag.get_action ('Edit') self.ext_act = ag.get_action ('ViewExtend') self.act.connect ("changed", self.mode_change_cb) self.undo.set_widgets (ag.get_action ('Undo'), ag.get_action ('Redo')) self.view_action = ag.get_action('UseBezier') self.view_action.connect ("changed", self.view_change_cb) self.ui = gtk.UIManager () self.ui.insert_action_group (ag, 0) self.ui.add_ui_from_file (utils.get_data_file_name('labyrinth-ui.xml')) self.main_window.add_accel_group (self.ui.get_accel_group ())
def __init__(self, start_hidden, tray_icon): super(Browser, self).__init__() self.glade=gtk.glade.XML(utils.get_data_file_name('labyrinth.glade')) self.view = self.glade.get_widget ('MainView') self.populate_view () self.view.connect ('row-activated', self.open_row_cb) self.view.connect ('cursor-changed', self.cursor_change_cb) self.view_dependants = [] self.open_button = self.glade.get_widget('OpenButton') self.delete_button = self.glade.get_widget('DeleteButton') self.open_menu = self.glade.get_widget('open1') self.delete_menu = self.glade.get_widget('delete1') self.view_dependants.append (self.open_button) self.view_dependants.append (self.delete_button) self.view_dependants.append (self.open_menu) self.view_dependants.append (self.delete_menu) self.open_button.connect ('clicked', self.open_clicked) self.glade.get_widget('NewButton').connect ('clicked', self.new_clicked) self.delete_button.connect ('clicked', self.delete_clicked) self.open_menu.connect ('activate', self.open_clicked) self.glade.get_widget('new1').connect ('activate', self.new_clicked) self.delete_menu.connect ('activate', self.delete_clicked) self.glade.get_widget('import1').connect ('activate', self.import_clicked) self.glade.get_widget('quit1').connect ('activate', self.quit_clicked) self.glade.get_widget('about1').connect ('activate', self.about_clicked) self.glade.get_widget('showhelp').connect ('activate', self.show_help_clicked) for x in self.view_dependants: x.set_sensitive(False) self.main_window = self.glade.get_widget ('MapBrowser') # set remembered size if os.name != 'nt': self.config_client = gconf.client_get_default() self.config_client.add_dir ("/apps/labyrinth", gconf.CLIENT_PRELOAD_NONE) width = self.config_client.get_int ('/apps/labyrinth/width') height = self.config_client.get_int ('/apps/labyrinth/height') utils.use_bezier_curves = self.config_client.get_bool ('/apps/labyrinth/curves') if width == 0 or height == 0: width = 400 height = 300 else: width = 400 height = 300 view_sortable = self.view.get_model () view_sortable.connect ('sort-column-changed', self.sort_column_changed_cb) if os.name != 'nt': sort_order = self.config_client.get_int('/apps/labyrinth/map_sort_order') column_id = self.config_client.get_int('/apps/labyrinth/map_sort_order_column') view_sortable.set_sort_column_id (column_id, sort_order) self.main_window.resize (width, height) if os.name != 'nt': try: self.main_window.set_icon_name ('labyrinth') except: self.main_window.set_icon_from_file(utils.get_data_file_name('labyrinth.svg')) else: self.main_window.set_icon_from_file('images\\labyrinth-24.png') if tray_icon: self.main_window.connect ('delete_event', self.toggle_main_window, None) traymenu = gtk.Menu() quit_item = gtk.MenuItem("Quit") quit_item.connect("activate",self.quit_clicked) traymenu.add(quit_item) traymenu.show_all() self.traymenu = traymenu self.trayicon = TrayIcon.TrayIcon( icon_name="labyrinth", menu=traymenu, activate=self.toggle_main_window) else: self.main_window.connect('delete_event', self.quit_clicked, None) if start_hidden: self.main_window.hide () else: self.main_window.show_all ()
def export_cb(self, event): maxx, maxy = self.MainArea.get_max_area() x, y, width, height, bitdepth = self.MainArea.window.get_geometry() glade = gtk.glade.XML(utils.get_data_file_name('labyrinth.glade')) dialog = glade.get_widget('ExportImageDialog') box = glade.get_widget('dialog_insertion') fc = gtk.FileChooserWidget(gtk.FILE_CHOOSER_ACTION_SAVE) box.pack_end(fc) filter_mapping = [(_('All Files'), ['*']), (_('PNG Image (*.png)'), ['*.png']), (_('JPEG Image (*.jpg, *.jpeg)'), ['*.jpeg', '*.jpg']), (_('SVG Vector Image (*.svg)'), ['*.svg']), (_('PDF Portable Document (*.pdf)'), ['*.pdf'])] for (filter_name, filter_patterns) in filter_mapping: fil = gtk.FileFilter() fil.set_name(filter_name) for pattern in filter_patterns: fil.add_pattern(pattern) fc.add_filter(fil) fc.set_current_name("%s.png" % self.main_window.title) rad = glade.get_widget('rb_complete_map') rad2 = glade.get_widget('rb_visible_area') self.spin_width = glade.get_widget('width_spin') self.spin_height = glade.get_widget('height_spin') self.spin_width.set_value(maxx) self.spin_height.set_value(maxy) self.spin_width.set_sensitive(False) self.spin_height.set_sensitive(False) rad.connect('toggled', self.toggle_range, width, height, maxx, maxy) fc.show() while 1: # Cheesy loop. Break out as needed. response = dialog.run() if response == gtk.RESPONSE_OK: ext_mime_mapping = { 'png':'png', 'jpg':'jpeg', 'jpeg':'jpeg', \ 'svg':'svg', 'pdf':'pdf' } filename = fc.get_filename() ext = filename[filename.rfind('.') + 1:] try: mime = ext_mime_mapping[ext] break except KeyError: msg = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, \ _("Unknown file format")) msg.format_secondary_text (_("The file type '%s' is unsupported. Please use the suffix '.png',"\ " '.jpg' or '.svg'." % ext)) msg.run() msg.destroy() else: dialog.destroy() return true_width = int(self.spin_width.get_value()) true_height = int(self.spin_height.get_value()) native = not rad.get_active() dialog.destroy() if mime in ['png', 'jpg']: self.save_as_pixmap(filename, mime, true_width, true_height, bitdepth, native) else: surface = None if mime == 'svg': surface = cairo.SVGSurface(filename, true_width, true_height) elif mime == 'pdf': surface = cairo.PDFSurface(filename, true_width, true_height) self.save_surface(surface, true_width, true_height, native)
def __init__(self, filename, imported=False): super(LabyrinthWindow, self).__init__() # FIXME: This can go when we move entirely to gtk 2.10 # pygtk 2.8 doesn't have the correct function :( self.set_val = gtk.gtk_version[1] > 8 # First, construct the MainArea and connect it all up self.undo = UndoManager.UndoManager(self) self.undo.block() self.MainArea = MMapArea.MMapArea(self.undo) self.MainArea.connect("title_changed", self.title_changed_cb) self.MainArea.connect("doc_save", self.doc_save_cb) self.MainArea.connect("doc_delete", self.doc_del_cb) self.MainArea.connect("change_mode", self.mode_request_cb) self.MainArea.connect("button-press-event", self.main_area_focus_cb) self.MainArea.connect("change_buffer", self.switch_buffer_cb) self.MainArea.connect("thought_selection_changed", self.thought_selected_cb) self.MainArea.connect("set_focus", self.main_area_focus_cb) self.MainArea.connect("set_attrs", self.attrs_cb) if os.name != 'nt': self.MainArea.connect("text_selection_changed", self.selection_changed_cb) self.config_client = gconf.client_get_default() glade = gtk.glade.XML(utils.get_data_file_name('labyrinth.glade')) self.main_window = glade.get_widget('MapWindow') self.main_window.set_focus_child(self.MainArea) if os.name != 'nt': try: self.main_window.set_icon_name('labyrinth') except: self.main_window.set_icon_from_file( utils.get_data_file_name('labyrinth.svg')) else: self.main_window.set_icon_from_file('images\\labyrinth-24.png') # insert menu, toolbar and map self.create_menu() glade.get_widget('main_area_insertion').pack_start(self.MainArea) vbox = glade.get_widget('map_window_vbox') menubar = self.ui.get_widget('/MenuBar') menubar.show_all() vbox.pack_start(menubar) vbox.reorder_child(menubar, 0) vbox.set_child_packing(menubar, 0, 0, 0, gtk.PACK_START) toolbar = self.ui.get_widget('/ToolBar') toolbar.show_all() vbox.pack_start(toolbar) vbox.reorder_child(toolbar, 1) vbox.set_child_packing(toolbar, 0, 0, 0, gtk.PACK_START) # TODO: Bold, Italics etc. self.bold_widget = glade.get_widget('tool_bold') self.bold_widget.connect('toggled', self.bold_toggled) self.bold_block = False self.bold_state = False self.italic_widget = glade.get_widget('tool_italic') self.italic_widget.connect('toggled', self.italic_toggled) self.italic_block = False self.italic_state = False self.underline_widget = glade.get_widget('tool_underline') self.underline_widget.connect('toggled', self.underline_toggled) self.underline_block = False self.underline_state = False self.font_widget = glade.get_widget('font_button') self.font_widget.connect("font-set", self.font_change_cb) self.background_widget = glade.get_widget('background_color_button') self.background_widget.connect("color-set", self.background_change_cb) self.foreground_widget = glade.get_widget('foreground_color_button') self.foreground_widget.connect("color-set", self.foreground_change_cb) self.cut = self.ui.get_widget('/MenuBar/EditMenu/Cut') self.copy = self.ui.get_widget('/MenuBar/EditMenu/Copy') self.paste = self.ui.get_widget('/MenuBar/EditMenu/Paste') self.link = self.ui.get_widget('/MenuBar/EditMenu/LinkThoughts') self.delete = self.ui.get_widget('/MenuBar/EditMenu/DeleteNodes') self.ui.get_widget('/MenuBar/EditMenu').connect( 'activate', self.edit_activated_cb) self.cut.set_sensitive(False) self.copy.set_sensitive(False) # get toolbars and activate corresponding menu entries self.main_toolbar = self.ui.get_widget('/ToolBar') self.format_toolbar = glade.get_widget('format_toolbar') self.ui.get_widget( '/MenuBar/ViewMenu/ShowToolbars/ShowMainToolbar').set_active(True) self.ui.get_widget('/MenuBar/ViewMenu/ShowToolbars/ShowFormatToolbar' ).set_active(True) self.ui.get_widget('/MenuBar/ViewMenu/UseBezier').set_active( utils.use_bezier_curves) # Add in the extended info view self.extended_window = glade.get_widget('extended_window') self.extended = glade.get_widget('extended') self.invisible_buffer = gtk.TextBuffer() # Connect all our signals self.main_window.connect("configure_event", self.configure_cb) self.main_window.connect("window-state-event", self.window_state_cb) self.main_window.connect("destroy", self.close_window_cb) # Deal with loading the map if not filename: self.MainArea.set_size_request(400, 400) # TODO: This shouldn't be set to a hard-coded number. Fix. self.pane_pos = 500 self.title_cp = _("Untitled Map") self.mode = MMapArea.MODE_EDITING self.extended_visible = False else: self.parse_file(filename) up_box = glade.get_widget('up_box') up_box.connect("button-press-event", self.translate, "Up") up_box.connect("button-release-event", self.finish_translate) down_box = glade.get_widget('down_box') down_box.connect("button-press-event", self.translate, "Down") down_box.connect("button-release-event", self.finish_translate) right_box = glade.get_widget('right_box') right_box.connect("button-press-event", self.translate, "Right") right_box.connect("button-release-event", self.finish_translate) left_box = glade.get_widget('left_box') left_box.connect("button-press-event", self.translate, "Left") left_box.connect("button-release-event", self.finish_translate) panes = glade.get_widget('vpaned1') panes.connect("button-release-event", self.pos_changed) panes.set_position(self.pane_pos) # Other stuff self.width, self.height = self.main_window.get_size() # if we import, we dump the old filename to create a new hashed one self.save_file = None if not imported: self.save_file = filename self.maximised = False self.view_type = 0 if self.set_val: self.act.set_current_value(self.mode) self.undo.unblock() self.start_timer()
def create_menu(self): actions = [ ('FileMenu', None, _('File')), ('Export', None, _('Export as Image'), None, _("Export your map as an image"), self.export_cb), ('ExportMap', gtk.STOCK_SAVE_AS, _('Export Map...'), '<control>S', _("Export your map as XML"), self.export_map_cb), ('Close', gtk.STOCK_CLOSE, None, '<control>W', _('Close the current window'), self.close_window_cb), ('EditMenu', None, _('_Edit')), ('ViewMenu', None, _('_View')), ('ShowToolbars', None, _('_Toolbar')), ('Undo', gtk.STOCK_UNDO, None, '<control>Z', None), ('Redo', gtk.STOCK_REDO, None, '<control><shift>Z', None), ('Cut', gtk.STOCK_CUT, None, '<control>X', None, self.cut_text_cb), ('Copy', gtk.STOCK_COPY, None, '<control>C', None, self.copy_text_cb), ('Paste', gtk.STOCK_PASTE, None, '<control>V', None, self.paste_text_cb), ('LinkThoughts', None, _("Link Thoughts"), '<control>L', _("Link the selected thoughts"), self.link_thoughts_cb), ('ModeMenu', None, _('_Mode')), ('ZoomIn', gtk.STOCK_ZOOM_IN, None, '<control>plus', None, self.zoomin_cb), ('ZoomOut', gtk.STOCK_ZOOM_OUT, None, '<control>minus', None, self.zoomout_cb), ('ZoomFit', gtk.STOCK_ZOOM_FIT, None, None, None, self.zoomfit_cb) ] self.radio_actions = [ ('Edit', gtk.STOCK_EDIT, _('_Edit Mode'), '<control>E', _('Turn on edit mode'), MMapArea.MODE_EDITING), ('AddImage', gtk.STOCK_ADD, _('_Add Image'), None, _('Add an image to selected thought'), MMapArea.MODE_IMAGE), ('Drawing', gtk.STOCK_COLOR_PICKER, _('_Drawing Mode'), None, _('Make a pretty drawing'), MMapArea.MODE_DRAW) ] self.view_radio_actions = [ ('UseBezier', None, _('Use _Curves'), None, _('Use curves as links'), MMapArea.VIEW_BEZIER), ('UseLines', None, _('Use _Lines'), None, _('Use straight lines as links'), MMapArea.VIEW_LINES) ] self.toggle_actions = [ ('ViewExtend', None, _('_Extended Information'), None, _('Show extended information for thoughts'), self.view_extend_cb), ('ShowMainToolbar', None, _('_Main'), None, _('Show main toolbar'), self.show_main_toolbar_cb), ('ShowFormatToolbar', None, _('_Format'), None, _('Show format toolbar'), self.show_format_toolbar_cb) ] ag = gtk.ActionGroup('WindowActions') ag.set_translation_domain(gettext.textdomain()) ag.add_actions(actions) ag.add_radio_actions(self.radio_actions) ag.add_radio_actions(self.view_radio_actions) ag.add_toggle_actions(self.toggle_actions) self.act = ag.get_action('Edit') self.ext_act = ag.get_action('ViewExtend') self.act.connect("changed", self.mode_change_cb) self.undo.set_widgets(ag.get_action('Undo'), ag.get_action('Redo')) self.view_action = ag.get_action('UseBezier') self.view_action.connect("changed", self.view_change_cb) self.ui = gtk.UIManager() self.ui.insert_action_group(ag, 0) self.ui.add_ui_from_file(utils.get_data_file_name('labyrinth-ui.xml')) self.main_window.add_accel_group(self.ui.get_accel_group())
import utils utils.crear_screen() try: data2 = open("rna_codon_table.txt", "r") except FileNotFoundError: print("rna_codon_table.txt") print("ending execution.....") quit() text2 = data2.read() text2 = text2.split("\n") data = open(utils.get_data_file_name(__file__), "r") text = data.read() codon_list = [] protein_list = [] for i in range(len(text2)): codon_list.append(text2[i].split(" ")[0]) protein_list.append(text2[i].split(" ")[1]) rna_codon_dict = dict(zip(codon_list, protein_list)) #print (rna_codon_dict) protein = "" for i in range(0, len(text) - 3, 3): sub = text[i:i + 3] if (rna_codon_dict[sub].lower() == "stop"): break protein += rna_codon_dict[sub] print(rna_codon_dict) print(protein)
def create_menu(self): actions = [ ("FileMenu", None, _("File")), ("Export", None, _("Export as Image"), None, _("Export your map as an image"), self.export_cb), ( "ExportMap", gtk.STOCK_SAVE_AS, _("Export Map..."), "<control>S", _("Export your map as XML"), self.export_map_cb, ), ("Close", gtk.STOCK_CLOSE, None, "<control>W", _("Close the current window"), self.close_window_cb), ("EditMenu", None, _("_Edit")), ("ViewMenu", None, _("_View")), ("ShowToolbars", None, _("_Toolbar")), ("Undo", gtk.STOCK_UNDO, None, "<control>Z", None), ("Redo", gtk.STOCK_REDO, None, "<control><shift>Z", None), ("Cut", gtk.STOCK_CUT, None, "<control>X", None, self.cut_text_cb), ("Copy", gtk.STOCK_COPY, None, "<control>C", None, self.copy_text_cb), ("Paste", gtk.STOCK_PASTE, None, "<control>V", None, self.paste_text_cb), ( "LinkThoughts", None, _("Link Thoughts"), "<control>L", _("Link the selected thoughts"), self.link_thoughts_cb, ), ("ModeMenu", None, _("_Mode")), ("ZoomIn", gtk.STOCK_ZOOM_IN, None, "<control>plus", None, self.zoomin_cb), ("ZoomOut", gtk.STOCK_ZOOM_OUT, None, "<control>minus", None, self.zoomout_cb), ("Zoom100", gtk.STOCK_ZOOM_100, None, "<control>0", None, self.zoom100_cb), ] self.radio_actions = [ ("Edit", gtk.STOCK_EDIT, _("_Edit Mode"), "<control>E", _("Turn on edit mode"), MMapArea.MODE_EDITING), ( "AddImage", gtk.STOCK_ADD, _("_Add Image"), None, _("Add an image to selected thought"), MMapArea.MODE_IMAGE, ), ( "Drawing", gtk.STOCK_COLOR_PICKER, _("_Drawing Mode"), None, _("Make a pretty drawing"), MMapArea.MODE_DRAW, ), ] self.view_radio_actions = [ ("UseBezier", None, _("Use _Curves"), None, _("Use curves as links"), MMapArea.VIEW_BEZIER), ("UseLines", None, _("Use _Lines"), None, _("Use straight lines as links"), MMapArea.VIEW_LINES), ] self.toggle_actions = [ ( "ViewExtend", None, _("_Extended Information"), None, _("Show extended information for thoughts"), self.view_extend_cb, ), ("ShowMainToolbar", None, _("_Main"), None, _("Show main toolbar"), self.show_main_toolbar_cb), ("ShowFormatToolbar", None, _("_Format"), None, _("Show format toolbar"), self.show_format_toolbar_cb), ] ag = gtk.ActionGroup("WindowActions") ag.set_translation_domain(gettext.textdomain()) ag.add_actions(actions) ag.add_radio_actions(self.radio_actions) ag.add_radio_actions(self.view_radio_actions) ag.add_toggle_actions(self.toggle_actions) self.act = ag.get_action("Edit") self.ext_act = ag.get_action("ViewExtend") self.act.connect("changed", self.mode_change_cb) self.undo.set_widgets(ag.get_action("Undo"), ag.get_action("Redo")) self.view_action = ag.get_action("UseBezier") self.view_action.connect("changed", self.view_change_cb) self.ui = gtk.UIManager() self.ui.insert_action_group(ag, 0) self.ui.add_ui_from_file(utils.get_data_file_name("labyrinth-ui.xml")) self.main_window.add_accel_group(self.ui.get_accel_group())