Skip to content

Commit

Permalink
docs: Examples & docs for diff, image viewers
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jul 21, 2023
1 parent 5173e2d commit 694bc3c
Show file tree
Hide file tree
Showing 30 changed files with 1,305 additions and 242 deletions.
128 changes: 128 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[email protected].
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
45 changes: 29 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
# CONTRIBUTING
Thank you for considering to contribute to Cupcake! To keep the code clean and for understanding our naming conventions, here are some guidelines and a list of coding tools used.
<h1 align="center">CONTRIBUTING</h1>

## Dependencies
For package management and dependencies this project uses [**poetry**](https://python-poetry.org/docs/#installation)
## Cupcake Developer Guide
Welcome to the Contributing Guidelines for Cupcake. Your contributions and support are greatly appreciated! 🧡
> **Note**
> You will need [Git](https://git-scm.com/) installed to follow the steps below!
After installation of poetry, you will be able to install all dependencies of cupcake with the following command
```
poetry install
```
## Fixing an issue/adding a feature
Here are the basic steps needed to get set up and contribute a patch.

## Running Tests
Cupcake uses [**pytest**](https://docs.pytest.org/) to run tests. After installation of poetry, you will be able to run the following command
```
poetry run pytest
```
Otherwise, you can also run pytest directly
```
pytest tests
1. [**Fork**](https://docs.github.com/en/get-started/quickstart/fork-a-repo) the Cupcake repository to your GitHub account and get the source code using:

```bash
git clone https://github.com/<your_username>/Cupcake.git
cd Cupcake
```
2. We appreciate using a [**Release of Biscuit**](https://github.com/billyeatcookies/Biscuit/releases) itself for development, but you can use your preferred editor. Open the project directory in your preferred environment.
3. **Open an issue** report in the [issue tracker](https://github.com/billyeatcookies/Cupcake/issues) if the issue has not been reported/proposed yet.

4. Switch to a new local branch where your work for the issue will go (format it `fix-#` or `feat-#` if you are having trouble naming)
```
git checkout -b fix-123 main
```
5. Once you fixed the issue, try running the related examples, and check no errors are occuring, if everything is ok, commit with a proper message regarding what has been fixed.
6. You can run the changelog command (not mandatory, requires `pip install git-changelog`):
```
git-changelog -o CHANGELOG.md
```
This will update the changelog, and now commit the changes.
7. Push the branch on your fork on GitHub and create a pull request. Include `fix: #` in the description
```
fix: #123, Fix x bug in y module
```
13 changes: 13 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Security Policy

## Supported Versions

The following versions of Cupcakes are currently being supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| 0.20.x | :white_check_mark: |

## Reporting a Vulnerability

Go the discussions tab of the repo and you can open a discussion there, and we will look into it! you can expect to get an update on the reported vulnerability within a few days, we will try to fix it quickly if its accepted.
70 changes: 50 additions & 20 deletions cupcake/__init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
__version__ = '0.15.0'
__version__ = '0.25.0'
__version_info__ = tuple([ int(num) for num in __version__.split('.')])

__all__ = ["Editor", "get_editor", "DiffEditor", "ImageViewer", "TextEditor", "Config"]
__all__ = ["Editor", "get_editor", "DiffEditor", "ImageViewer", "TextEditor", "Config", "Languages"]


import os
import tkinter as tk
from .config import Config
from tkinter.font import Font

from .config import Config
from .languages import Languages
from .utils import FileType, Frame
from .breadcrumbs import BreadCrumbs

from .breadcrumbs import BreadCrumbs
from .diffeditor import DiffEditor
from .imageviewer import ImageViewer
from .texteditor import TextEditor

def get_editor(base, path=None, path2=None, diff=False):
def get_editor(base, path=None, path2=None, diff=False, language=None):
"picks the right editor for the given values"
if diff:
return DiffEditor(base, path, path2)
return DiffEditor(base, path, path2, language=language)

if path and os.path.isfile(path):
if FileType.is_image(path):
return ImageViewer()
return ImageViewer(base, path)

return TextEditor(base, path)
return TextEditor(base, path, language=language)

return TextEditor(base)
return TextEditor(base, language=language)


class Editor(Frame):
"""
Editor class
Picks the right editor based on the path, path2 & exists values passed. Supports showing diff, images, text files.
If nothing is passed, empty text editor is opened.
Picks the right editor based on the path, path2, diff values passed. Supports showing diff, images, text files.
If nothing is passed, empty text editor is opened.
Attributes
----------
path : str
Expand All @@ -43,31 +45,59 @@ class Editor(Frame):
path of file to be opened in diff, required if diff=True is passed
diff : bool
whether this is to be opened in diff editor
language : str
Use the `Languages` enum provided (eg. Languages.PYTHON, Languages.TYPESCRIPT)
This is given priority while picking suitable highlighter. If not passed, guesses from file extension.
dark_mode : str
Sets the editor theme to cupcake dark if True, or cupcake light by default
This is ignored if custom config_file path is passed
config_file : str
path to the custom config (TOML) file, uses theme defaults if not passed
showpath : bool
whether to show the breadcrumbs for editor or not
font : str | Font
Font used in line numbers, text editor, autocomplete. defaults to Consolas(11)
uifont : str | Font
Font used for other UI components (breadcrumbs, trees)
preview_file_callback : function(path)
called when files in breadcrumbs-pathview are single clicked. MUST take an argument (path)
open_file_callback : function(path)
called when files in breadcrumbs-pathview are double clicked. MUST take an argument (path)
NOTE: All the *tk.Text* methods are available under *Editor.content* (eg. Editor.content.insert, Editor.content.get)
Methods
-------
save(path: str=None)
If the content is editable writes to the specified path.
focus()
Gives focus to the content.
"""
def __init__(self, master, path: str=None, path2: str=None, diff: bool=False, showpath: bool=True, config_file: str=None, dark_mode=True, *args, **kwargs):
def __init__(self, master,
path: str=None, path2: str=None, diff: bool=False, language: str=None,
darkmode=True, config_file: str=None, showpath: bool=True,
font: str|Font=None, uifont: str|Font=None,
preview_file_callback=None, open_file_callback=None,
*args, **kwargs) -> None:
super().__init__(master, *args, **kwargs)
self.settings = Config(self, config_file)
self.theme = self.settings.theme
self.config(bg=self.theme.border)

self.path = path
self.path2 = path2
self.diff = diff
self.showpath = showpath
self.filename = os.path.basename(self.path) if path else None

self.darkmode = darkmode
self.config_file = config_file
self.preview_file_callback = preview_file_callback
self.open_file_callback = open_file_callback

self.settings = Config(self, config_file, darkmode, font, uifont)
self.theme = self.settings.theme

self.config(bg=self.theme.border)
self.grid_columnconfigure(0, weight=1)
self.content = get_editor(self, path, path2, diff)

self.content = get_editor(self, path, path2, diff, language)
self.filename = os.path.basename(self.path) if path else None
if path and self.showpath and not diff:
self.breadcrumbs = BreadCrumbs(self, path)
self.grid_rowconfigure(1, weight=1)
Expand Down
7 changes: 3 additions & 4 deletions cupcake/breadcrumbs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

class Item(Menubutton):
def __init__(self, master, path, *args, **kwargs):
super().__init__(master, font=("Segoe UI", 10), *args, **kwargs)
super().__init__(master, *args, **kwargs)
self.path = path
self.config(height=1, pady=2, padx=1, **self.base.theme.breadcrumbs)

self.config(pady=3, padx=3, font=self.base.settings.uifont, **self.base.theme.breadcrumbs)

class BreadCrumbs(Frame):
def __init__(self, master, path=None, *args, **kwargs):
super().__init__(master, *args, **kwargs)
self.config(padx=10, **self.base.theme.breadcrumbs["background"])
self.config(padx=20, bg=self.base.theme.breadcrumbs["background"])

self.pathview = PathView(self)
path = os.path.abspath(path).split('\\')
Expand Down
7 changes: 5 additions & 2 deletions cupcake/breadcrumbs/pathview.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
class PathView(Toplevel):
def __init__(self, master, width=150, *args, **kwargs):
super().__init__(master, *args, **kwargs)
self.width = round(width * self.base.scale)
self.width = round(width)

self.tree = DirectoryTree(self, width=width, observe_changes=False, itembar=False)
self.tree = DirectoryTree(self, width=width)
self.tree.pack()

self.config(pady=1, padx=1, bg=self.base.theme.border)
Expand Down Expand Up @@ -36,7 +36,10 @@ def show(self, e):
x = w.winfo_rootx()
y = w.winfo_rooty() + w.winfo_height()

if not w.path:
return
self.tree.change_path(w.path)

self.geometry(f"+{x}+{y}")
self.deiconify()
self.focus_set()
16 changes: 9 additions & 7 deletions cupcake/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import toml, os
from tkinter import font
from tkinter.font import Font
from types import SimpleNamespace

from .styles import Style

class Config:
def __init__(self, master, config_file=None, darkmode=True):
def __init__(self, master, config_file=None, darkmode=True, font=None, uifont=None):
self.base = master
self.dir = os.path.dirname(__file__)

self.stipple = os.path.join(self.dir, 'stipple.xbm')
if not config_file:
config_file = 'dark.toml' if darkmode else 'light.toml'
config_file = os.path.join(self.dir, 'dark.toml') if darkmode else os.path.join(self.dir, 'light.toml')

self.dir = os.path.dirname(__file__)
self.font = font.Font(family="Consolas", size=11)
self.font = font or Font(family="Consolas", size=11)
self.uifont = uifont or Font(family="Segoi UI", size=10)
self.load_from(config_file)

def load_from(self, config_file: str):
self.theme = SimpleNamespace(**toml.load(os.path.join(self.dir, config_file)))
self.theme = SimpleNamespace(**toml.load(config_file))
self.theme.editor = SimpleNamespace(**self.theme.editor)
self.theme.diffeditor = SimpleNamespace(**self.theme.diffeditor)
self.syntax = self.theme.syntax

self.style = Style(self.base, self.theme)
self.style = Style(self.base, self)
Loading

0 comments on commit 694bc3c

Please sign in to comment.