Ejemplo n.º 1
0
 def __init__(self, notebook):
     Observable.__init__(self)
     self.kernel = None
     self.notebook = notebook
     self.continue_fetching = True
     self.result_factory = ServiceLocator.get_result_factory()
     self.fetch_func_id = GObject.timeout_add(50, self.fetch_results)
Ejemplo n.º 2
0
    def __init__(self, pathname):
        Observable.__init__(self)

        self.pathname = pathname
        self.kernelname = None
        self.cells = []
        self.active_cell = None
        self.busy_cells = set()
        self.modified_cells = set()
        self.kernel_state = None
        self.result_factory = ServiceLocator.get_result_factory()

        self.save_state = 'saved'
        try: self.last_saved = datetime.datetime.fromtimestamp(os.path.getmtime(pathname))
        except FileNotFoundError:
            self.last_saved = datetime.datetime.fromtimestamp(0)
        
        # set source language for syntax highlighting
        self.source_language_manager = GtkSource.LanguageManager()
        self.source_language_manager.set_search_path((os.path.dirname(__file__) + '/../resources/gtksourceview/language-specs',))
        self.source_language_code = self.source_language_manager.get_language('sage')
        self.source_language_markdown = self.source_language_manager.get_language('markdown')
        
        self.source_style_scheme_manager = GtkSource.StyleSchemeManager()
        self.source_style_scheme_manager.set_search_path((os.path.dirname(__file__) + '/../resources/gtksourceview/styles',))
        self.source_style_scheme = self.source_style_scheme_manager.get_scheme('sage')

        self.cursor_position = {'cell': None, 'cell_position': None, 'cell_size': None, 'position': None}

        self.list_item = list_item_model.NotebookListItem(self)
        self.view = notebook_viewgtk.NotebookView()
        self.presenter = notebook_presenter.NotebookPresenter(self, self.view)
        self.controller = notebook_controller.NotebookController(self, self.view)
        self.evaluator = notebook_evaluator.NotebookEvaluator(self)
        self.headerbar_controls = headerbar_controls.HeaderbarControls(self)
Ejemplo n.º 3
0
    def __init__(self, notebook):
        GtkSource.Buffer.__init__(self)
        Observable.__init__(self)

        self.notebook = notebook
        self.notebook_position = None

        self.set_modified(False)
        self.set_highlight_matching_brackets(False)
    def __init__(self, workspace):
        Observable.__init__(self)

        self.workspace = workspace
        self.pathname = os.path.expanduser('~') + '/.porto'
        self.items = dict()

        self.presenter = ro_presenter.RecentlyOpenedNotebooksListPresenter(
            workspace, self)
        self.controller = ro_controller.RecentlyOpenedNotebooksListController(
            workspace, self)
Ejemplo n.º 5
0
    def __init__(self, workspace):
        Observable.__init__(self)
        self.workspace = workspace

        self.sb_items = dict()
        self.hb_items = dict()

        self.sb_view = onb_view.OpenNotebooksListView()
        self.hb_view = onb_view.OpenNotebooksListView()
        self.presenter = onb_presenter.OpenNotebooksListPresenter(
            workspace, self, self.sb_view, self.hb_view)
        self.controller = onb_controller.OpenNotebooksListController(
            workspace, self.sb_view, self.hb_view)
Ejemplo n.º 6
0
    def __init__(self, notebook):
        Observable.__init__(self)
        self.notebook = notebook
        self.kernelspecs = ServiceLocator.get_kernelspecs()

        self.sb_view = nbli_view.OpenNotebookListViewItem(
            notebook, notebook.get_last_saved())
        self.hb_view = nbli_view.OpenNotebookListViewItem(
            notebook, notebook.get_last_saved())
        self.presenter = nbli_presenter.NotebookListItemPresenter(
            notebook, self, self.sb_view, self.hb_view)
        self.controller = nbli_controller.NotebookListItemController(
            notebook, self, self.sb_view, self.hb_view)

        self.set_kernel(notebook.get_kernelname())
Ejemplo n.º 7
0
    def __init__(self, workspace):
        Observable.__init__(self)
        self.workspace = workspace
        self.main_window = ServiceLocator.get_main_window()

        self.window_mode = None
        self.activate_welcome_page_mode()

        self.main_window.paned.set_position(self.workspace.sidebar_position)
        if self.workspace.show_sidebar:
            self.on_show_sidebar()
        else:
            self.on_hide_sidebar()

        self.workspace.register_observer(self)
Ejemplo n.º 8
0
 def __init__(self, timeout):
     self._timeout = timeout
     self._task = asyncio.ensure_future(self._job())
     self._running = True
     self._was_completed = False
     self._wait_event: Event = Event()
     self.on_timer_finish: Observable = Observable()
Ejemplo n.º 9
0
    def __init__(self):
        Observable.__init__(self)

        self.recently_opened_notebooks = ro_notebooks_list.RecentlyOpenedNotebooksList(self)
        self.open_notebooks_list = open_notebooks_list.OpenNotebooksList(self)
        self.open_notebooks = dict()
        self.active_notebook = None

        self.settings = ServiceLocator.get_settings()
        self.show_sidebar = self.settings.get_value('window_state', 'sidebar_visible')
        self.sidebar_position = self.settings.get_value('window_state', 'paned_position')
        self.presenter = workspace_presenter.WorkspacePresenter(self)
        self.controller = workspace_controller.WorkspaceController(self)
        self.headerbar = headerbar_model.Headerbar(self)
        self.shortcuts = shortcuts.Shortcuts(self)

        self.set_pretty_print(self.settings.get_value('preferences', 'pretty_print'))
Ejemplo n.º 10
0
    def __init__(self, stream_type='stdout'):
        Gtk.HBox.__init__(self)
        Observable.__init__(self)

        self.get_style_context().add_class('resultview')

        self.innerwrap = Gtk.HBox()
        self.innerwrap.set_margin_left(9)
        self.innerwrap.set_margin_right(9)

        self.scrolled_window = Gtk.ScrolledWindow()
        self.scrolled_window.set_margin_top(11)
        self.scrolled_window.set_margin_bottom(9)
        self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                        Gtk.PolicyType.NEVER)

        self.centerbox = Gtk.HBox()
        self.scrolled_window.add(self.centerbox)
        self.scrolled_window.set_size_request(750, -1)

        self.innerwrap.set_center_widget(self.scrolled_window)
        self.set_center_widget(self.innerwrap)
        self.set_hexpand(True)

        self.get_style_context().add_class('resultstreamview')

        self.result_text = ''
        self.stream_type = stream_type

        self.label = Gtk.Label()
        self.label.set_single_line_mode(False)
        self.label.set_line_wrap_mode(Pango.WrapMode.CHAR)
        self.label.set_line_wrap(True)
        self.label.set_selectable(True)
        self.label.set_justify(Gtk.Justification.LEFT)
        self.label.set_xalign(0)
        self.label.set_markup('')

        self.size_box = Gtk.VBox()
        self.size_box.pack_start(self.label, False, False, 0)
        self.centerbox.pack_start(self.size_box, False, False, 0)
Ejemplo n.º 11
0
    def __init__(self, workspace):
        Observable.__init__(self)

        self.workspace = workspace
        self.presenter = headerbar_presenter.HeaderbarPresenter(workspace)
        self.controller = headerbar_controller.HeaderbarController(workspace)
Ejemplo n.º 12
0
    def __init__(self):
        Observable.__init__(self)

        self.result = None
Ejemplo n.º 13
0
    def __init__(self, db: PostgreSQL, user_id: int):
        super().__init__(db, 'users', dict(id=user_id))
        self.id = user_id
        self.member = None
        self._tutorial_stage: DictRef[int] = DictRef(self._data, 'tutorial')
        if utils.is_test():
            self._tutorial_stage.set(-1)
        self.upgrades_row = Row(db, 'user_upgrades', dict(user_id=user_id))
        self.upgrades = {
            'bank':
            upgrades.UpgradeLink(upgrades.BANK_LIMIT,
                                 DictRef(self.upgrades_row._data, 'bank'),
                                 before=self._update_bank_limit),
            'money':
            upgrades.UpgradeLink(upgrades.MONEY_LIMIT,
                                 DictRef(self.upgrades_row._data, 'money')),
            'garden':
            upgrades.UpgradeLink(upgrades.GARDEN_PROD,
                                 DictRef(self.upgrades_row._data, 'garden'),
                                 after=self._update_bank_increment),
            'inventory':
            upgrades.UpgradeLink(upgrades.INVENTORY_LIMIT,
                                 DictRef(self.upgrades_row._data, 'inventory'),
                                 after=self._update_inventory_limit),
        }
        self._bank = Incremental(
            DictRef(self._data, 'bank'), DictRef(self._data, 'bank_time'),
            TimeSlot(TimeMetric.HOUR, self.upgrades['garden'].get_value()))
        self._tokens = Incremental(DictRef(self._data, 'tokens'),
                                   DictRef(self._data, 'tokens_time'),
                                   TimeSlot(TimeMetric.HOUR, 2))
        self._adventure: Optional[Adventure] = None
        self._lang: DictRef[str] = DictRef(self._data, 'lang')

        # User entity
        self.user_entity: UserEntity = UserEntity(
            DictRef(self._data, 'last_name'))
        self._user_class: DictRef[int] = DictRef(self._data, 'class')
        if utils.is_test():
            self._user_class.set(UserClass.WARRIOR.get_id())
        self._persistent_stats: dict[StatInstance, int] = {}
        if self._user_class.get() != -1:
            uc: UserClass = UserClass.get_from_id(self._user_class.get())
            self.user_entity.set_class(uc)
            self._persistent_stats: dict[StatInstance, int] = {
                stat: value
                for stat, value in uc.get_stats().items()
                if stat.is_persistent()
            }

        # Fill inventory
        items_data = self._db.start_join('users', dict(id=self.id), columns=['slot', 'item_id'], limit=30) \
            .join('user_items', field_matches=[('user_id', 'id')]) \
            .execute()
        self.inventory: Inventory = Inventory(
            self._db, items_data, self.upgrades['inventory'].get_value(), 1,
            self.id, self.user_entity)
        # for is_info in item_slots:
        #     slot: str = is_info['slot']
        #     item_dict: dict[str, Any] = self._db.get_row_data('items', dict(id=is_info['item_id']))
        #
        # slots = self.upgrades['inventory'].get_value()
        # inv_items: list[Optional[Item]] = [None] * slots
        # item_slots = self._db.start_join('users', dict(id=self.id), columns=['slot', 'item_id'],
        #                                  limit=self.upgrades['inventory'].get_value()) \
        #     .join('user_items', field_matches=[('user_id', 'id')]) \
        #     .execute()
        # for is_info in item_slots:
        #     item_dict: dict[str, Any] = self._db.get_row_data('items', dict(id=is_info['item_id']))
        #     item: Item = item_utils.from_dict(item_dict['data'])
        #     item.id = item_dict['id']
        #     inv_items[is_info['slot']] = item
        # if len(item_slots) > slots:
        #     # Too many item_data... log
        #     print(f"{user_id} exceeded {slots} items: {len(item_slots)}!")
        # self.inventory: Inventory = Inventory(self._db, DictRef(self._data, 'equipment'), slots, inv_items,
        #                                       self.user_entity, self.id)

        # Observables
        self.on_money_changed: Observable[int] = Observable()