Commit a8f8dd7c authored by Pado's avatar Pado
Browse files

initial commit of ASYST project to public repository

parents
MIT License
Copyright (c) 2022 Larissa Kirschner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
# coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Code is originally from https://github.com/nlpyang/pytorch-transformers/blob/master/examples/run_glue.py
# Adapted to the SAG task by Ulrike Pado, HFT Stuttgart: Run a fine-tuned model on given input data to predict short-answer grades.
from __future__ import absolute_import, division, print_function
import argparse
import os
import random
import sys
import numpy as np
import torch
from torch.utils.data import DataLoader, SequentialSampler, TensorDataset
from sklearn.metrics import f1_score, accuracy_score
from transformers import (
BertConfig,
BertForSequenceClassification,
BertTokenizer,
)
from transformers import glue_compute_metrics as compute_metrics
from transformers import (
glue_convert_examples_to_features as convert_examples_to_features,
)
from transformers.data.processors.utils import (
DataProcessor,
InputExample,
)
#logger = logging.getLogger(__name__)
MODEL_CLASSES = {
"bert": (BertConfig, BertForSequenceClassification, BertTokenizer),
}
def set_seed():
random.seed(42)
np.random.seed(42)
torch.manual_seed(42)
def evaluate(args, model, tokenizer, prefix=""):
# Loop to handle MNLI double evaluation (matched, mis-matched)
# and SemEval evaluation (unseen questions, unseen answers, unseen domains)
eval_task_names = ("sag",
)
eval_outputs_dirs = (
(args.output_dir, )
)
results = {}
for eval_task, eval_output_dir in zip(eval_task_names, eval_outputs_dirs):
eval_dataset = load_and_cache_examples(
args, eval_task, tokenizer
)
if not os.path.exists(eval_output_dir):
os.makedirs(eval_output_dir)
args.eval_batch_size = 8
# Note that DistributedSampler samples randomly
eval_sampler = SequentialSampler(eval_dataset)
eval_dataloader = DataLoader(
eval_dataset, sampler=eval_sampler, batch_size=args.eval_batch_size
)
# Eval!
#logger.info("***** Running evaluation {} *****".format(prefix))
#logger.info(" Task name = {}".format(eval_task))
#logger.info(" Num examples = %d", len(eval_dataset))
#logger.info(" Batch size = %d", args.eval_batch_size)
eval_loss = 0.0
nb_eval_steps = 0
preds = None
out_label_ids = None
for batch in eval_dataloader:
#logger.info(" Starting eval for batch")
model.eval()
batch = tuple(t.to(args.device) for t in batch)
#logger.info(" Batch converted to tuple")
with torch.no_grad():
inputs = {
"input_ids": batch[0],
"attention_mask": batch[1],
"token_type_ids": batch[2],
"labels": batch[3],
}
outputs = model(**inputs)
tmp_eval_loss, logits = outputs[:2]
eval_loss += tmp_eval_loss.mean().item()
#logger.info("Eval loss: %d", eval_loss)
nb_eval_steps += 1
if preds is None:
preds = logits.detach().cpu().numpy()
out_label_ids = inputs["labels"].detach().cpu().numpy()
else:
preds = np.append(preds, logits.detach().cpu().numpy(), axis=0)
out_label_ids = np.append(
out_label_ids, inputs["labels"].detach().cpu().numpy(), axis=0
)
#logger.info("Prediction generation done")
# classification task; choose maximum label
preds = np.argmax(preds, axis=1)
# if evaluating SAG, return both accuracy and F1
task = "sag"
# logger.info("starting to compute metrics")
result = my_compute_metrics(task, preds, out_label_ids)
results.update(result)
# print predictions made by the current model
if args.do_print_predictions:
print_predictions(args, preds)
output_eval_file = os.path.join(
eval_output_dir, prefix + "-eval_results.txt")
#logger.info("sending output to "+str(output_eval_file));
with open(output_eval_file, "w") as writer:
#logger.info("***** Eval results {} *****".format(prefix))
for key in sorted(result.keys()):
#logger.info(" %s = %s", key, str(result[key]))
writer.write("%s = %s\n" % (key, str(result[key])))
return results
def load_and_cache_examples(args, task, tokenizer):
examples = []
# choose the correct processor to read the data
processor = (
SemEvalProcessor()
)
output_mode = "classification"
#logger.info("Creating features from dataset file at %s", args.data_dir)
label_list = processor.get_labels()
examples = (
processor.get_test_examples(args.data_dir)
)
# We are continuing to train mnli models, so task = mnli to create
# the correct type of features
feature_task = "mnli" if task.startswith("sag") else task
features = convert_examples_to_features(
examples,
tokenizer,
label_list=label_list,
max_length=args.max_seq_length,
output_mode=output_mode,
task=feature_task
)
# Convert to Tensors and build dataset
all_input_ids = torch.tensor(
[f.input_ids for f in features], dtype=torch.long)
all_attention_mask = torch.tensor(
[f.attention_mask for f in features], dtype=torch.long
)
all_token_type_ids = torch.tensor(
[f.token_type_ids for f in features], dtype=torch.long
)
# do classification setup
all_labels = torch.tensor(
[f.label for f in features], dtype=torch.long)
dataset = TensorDataset(
all_input_ids, all_attention_mask, all_token_type_ids, all_labels
)
return dataset
def main():
# Where are we?
location=".";
if getattr(sys, 'frozen', False):
# running in a bundle
location = sys._MEIPASS
# open a log file next to the executable with line buffering
#out = open("log.txt", "a", buffering=1);
#print("Started English processing in", location, file=out);
parser = argparse.ArgumentParser()
# Required parameters - adapt to current directory
parser.add_argument(
"--data_dir",
# default=None,
default=location+"\\Skript\\outputs\\",
type=str,
# required=True,
required=False,
help="The input data dir. Should contain the .tsv files (or other data files) for the task.",
)
parser.add_argument(
"--model_type",
# default=None,
default="bert",
type=str,
# required=True,
required=False,
help="Model type selected in the list: " + ", ".join(MODEL_CLASSES),
)
parser.add_argument(
"--model_name_or_path",
# default=None,
#default= "textattack/bert-base-uncased-MNLI",
default=location+"\\Skript\\english\\seb-bert-mnli",
type=str,
# required=True,
required=False,
help="Path to pre-trained model",
)
parser.add_argument(
"--tokenizer_name",
default="textattack/bert-base-uncased-MNLI",
type=str,
help="Pretrained tokenizer name or path if not the same as model_name",
)
parser.add_argument(
"--output_dir",
# default=None,
default=location+"\\Skript\\english\\seb-bert-mnli",
type=str,
# required=True,
required=False,
help="The output directory where checkpoints will be written.",
)
parser.add_argument(
"--config_name",
default=location+"\\Skript\\english\\seb-bert-mnli\\config.json",
type=str,
help="Pretrained config name or path if not the same as model_name",
)
parser.add_argument(
"--cache_dir",
default="",
type=str,
help="Where do you want to store the pre-trained models downloaded from s3",
)
parser.add_argument(
"--max_seq_length",
# default=128,
default=256,
type=int,
help="The maximum total input sequence length after tokenization. Sequences longer "
"than this will be truncated, sequences shorter will be padded.",
)
parser.add_argument(
# "--do_test", action="store_true", help="Whether to run eval on the test set."
"--do_test", action="store_false", help="Whether to run eval on the test set."
),
parser.add_argument(
#"--do_print_predictions",action="store_true",help="Whether to print the model predictions for manual inspection.",
"--do_print_predictions",
action="store_false",
help="Whether to print the model predictions for manual inspection.",
),
parser.add_argument(
"--do_lower_case",
# action="store_true",
action="store_false",
help="Set this flag if you are using an uncased model.",
)
parser.add_argument(
"--overwrite_output_dir",
# action="store_true",
action="store_false",
help="Overwrite the content of the output directory",
)
args = parser.parse_args()
if (
os.path.exists(args.output_dir)
and os.listdir(args.output_dir)
and not args.overwrite_output_dir
):
raise ValueError(
"Output directory ({}) already exists and is not empty. Use --overwrite_output_dir to overcome.".format(
args.output_dir
)
)
# Setup CPU processing
device = torch.device("cpu")
args.device = device
# Setup logging
#logging.basicConfig(
# format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
# datefmt="%m/%d/%Y %H:%M:%S",
# filename='log.txt',
# filemode='a',
# level=logging.INFO,
#)
#logger.warning(
# "Device: %s",
# device
#)
# Set seed to 42
set_seed()
processor = (
SemEvalProcessor()
)
args.output_mode = (
"classification"
)
label_list = processor.get_labels()
num_labels = len(label_list)
args.model_type = args.model_type.lower()
#logger.info("Model %s", args.model_type)
config_class, model_class, tokenizer_class = MODEL_CLASSES[args.model_type]
config = config_class.from_pretrained(
args.config_name if args.config_name else args.model_name_or_path,
num_labels=num_labels,
cache_dir=args.cache_dir if args.cache_dir else None,
)
tokenizer = tokenizer_class.from_pretrained(
args.tokenizer_name if args.tokenizer_name else
args.model_name_or_path,
do_lower_case=args.do_lower_case,
cache_dir=args.cache_dir if args.cache_dir else None,
)
model = model_class.from_pretrained(
args.model_name_or_path,
from_tf=bool(".ckpt" in args.model_name_or_path),
config=config,
cache_dir=args.cache_dir if args.cache_dir else None,
)
model.to(args.device)
#logger.info("Training/evaluation parameters %s", args)
# Evaluation
results = {}
if args.do_test:
tokenizer = tokenizer_class.from_pretrained(
args.tokenizer_name if args.tokenizer_name else
args.model_name_or_path,
do_lower_case=args.do_lower_case,
)
checkpoints = [args.output_dir]
#logger.info("Evaluate the following checkpoints: %s", checkpoints)
for checkpoint in checkpoints:
global_step = checkpoint.split(
"-")[-1] if len(checkpoints) > 1 else ""
prefix = str(global_step)
model = model_class.from_pretrained(checkpoint)
model.to(args.device)
result = evaluate(args, model, tokenizer, prefix=prefix)
result = dict((k + "_{}".format(global_step), v)
for k, v in result.items())
results.update(result)
else: # use currently active model
result = evaluate(args, model, tokenizer, prefix="test")
#results.update(result)
return results
# define a new data processor for the SemEval data/SAG task
class SemEvalProcessor(DataProcessor):
def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "train.tsv")), "train"
)
def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev"
)
def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "test.tsv")), "test"
)
def get_labels(self):
"""See base class."""
return ["correct", "incorrect", "NONE"]
def _create_examples(self, lines, set_type):
"""Creates examples for the test set."""
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = line[0]
text_a = line[1]
text_b = line[2]
label = line[-1]
examples.append(
InputExample(guid=guid, text_a=text_a,
text_b=text_b, label=label)
)
return examples
# custom metrics for SAG: F1 and Accuracy
def my_compute_metrics(eval_task, preds, labels):
result = {}
if eval_task == "sag":
acc = accuracy_score(y_pred=preds, y_true=labels)
f1_weighted = f1_score(y_pred=preds, y_true=labels, average="weighted")
f1_macro = f1_score(y_pred=preds, y_true=labels, average="macro")
result = {"f1-weighted": f1_weighted,
"f1-macro": f1_macro, "accuracy": acc}
else:
result = compute_metrics(eval_task, preds, labels)
return result
def print_predictions(args, preds):
# generate data set part of output path
dir_name = (""
)
# get examples
processor = (
SemEvalProcessor()
)
examples = (
processor.get_test_examples(args.data_dir)
)
with open(args.data_dir + "/" + dir_name + "/predictions.txt", "w", encoding="utf8") as writer:
# print("# examples: " + str(len(examples)))
# print("# labels: " + str(len(labels)))
# print("# preds: " + str(len(preds)))
writer.write(
"question\treferenceAnswer\tstudentAnswer\tsuggested grade\tobserved grade\n")
for i in range(len(examples)):
# iterate over data
# print prediction as a text-based label
hrpred = "incorrect"
if preds[i] == 0:
hrpred = "correct"
# get guid, text, from inputExample
writer.write(
str(examples[i].guid)
+ "\t"
+ examples[i].text_a
+ "\t"
+ examples[i].text_b
+ "\t"
+ hrpred
+ "\t"
+ examples[i].label
+ "\n"
)
# else: print("Labels don't match! "+str(i)+": "+str(examples[i].label)+" "+str(labels[i]))
if __name__ == "__main__":
main()
{
"_name_or_path": "textattack/bert-base-uncased-MNLI",
"architectures": [
"BertForSequenceClassification"
],
"attention_probs_dropout_prob": 0.1,
"finetuning_task": "sag-seb",
"gradient_checkpointing": false,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"id2label": {
"0": "LABEL_0",
"1": "LABEL_1",
"2": "LABEL_2"
},
"initializer_range": 0.02,
"intermediate_size": 3072,
"label2id": {
"LABEL_0": 0,
"LABEL_1": 1,
"LABEL_2": 2
},
"layer_norm_eps": 1e-12,
"max_position_embeddings": 512,
"model_type": "bert",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"pad_token_id": 0,
"position_embedding_type": "absolute",
"transformers_version": "4.2.2",
"type_vocab_size": 2,
"use_cache": true,
"vocab_size": 30522
}
MIT License
Copyright (c) 2022 Yunus Eryilmaz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
MIT License
Copyright (c) 2022 Yunus Eryilmaz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
import os
import sys
import time
import numpy as np
import pandas as pd
# UP
import pickle
import argparse
from sklearn import metrics
from sentence_transformers import models, SentenceTransformer
from sklearn.linear_model import LogisticRegression, Perceptron
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import cross_validate, cross_val_predict
__author__ = "Yunus Eryilmaz"
__version__ = "1.0"
__date__ = "21.07.2021"
__source__ = "https://pypi.org/project/sentence-transformers/0.3.0/"
def main():
parser = argparse.ArgumentParser()
# Where are we?
location = ".";
if getattr(sys, 'frozen', False):
# running in a bundle
location = sys._MEIPASS
# Required parameters
parser.add_argument(
"--data",
#default=None,
default=location+"\\Skript\\outputs\\test.tsv",
type=str,
# required=True,
required=False,
help="The input data file for the task.",
)
parser.add_argument(
"--output_dir",
# default=None,
default=location+"\\Skript\\outputs\\",
type=str,
# required=True,
required=False,
help="The output directory where predictions will be written.",
)
parser.add_argument(
"--model_dir",
# default=None,
default=location+"\\Skript\\german\\models",
type=str,
# required=True,
required=False,
help="The directory where the ML models are stored.",
)
args = parser.parse_args()
# open a log file next to the executable with line buffering
# out = open("log.txt", "a",buffering=1);
# print("Started German processing in",location,file=out);
# import SentenceTransformer-model
start_time = time.time()
# print("Reading from",args.data, file=out);
with open(os.path.join(location,args.data)) as ft:
dft = pd.read_csv(ft, delimiter='\t')
# Sentences we want sentence embeddings for
sentences1_test = dft['referenceAnswer'].values.tolist()
sentences2_test = dft['studentAnswer'].values.tolist()
# print("Input read:",sentences2_test, file=out);
# Use BERT for mapping tokens to embeddings
word_embedding_model = models.Transformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
# pooling operation can choose by setting true (Apply mean pooling to get one fixed sized sentence vector)
pooling_model = models.Pooling(word_embedding_model.get_word_embedding_dimension(),
pooling_mode_mean_tokens=True,
pooling_mode_cls_token=False,
pooling_mode_max_tokens=False)
# compute the sentence embeddings for both sentences
model = SentenceTransformer(modules=[word_embedding_model, pooling_model])
# print("Model loaded", file=out);
sentence_embeddings1_test = model.encode(sentences1_test, convert_to_tensor=True, show_progress_bar=False)
# print("Embeddings RefA:",sentence_embeddings1_test,file=out);
sentence_embeddings2_test = model.encode(sentences2_test, convert_to_tensor=True, show_progress_bar=False)
# print("Embeddings found", file=out);
# Possible concatenations from the embedded sentences can be selected
def similarity(sentence_embeddings1, sentence_embeddings2):
# I2=(|u − v| + u ∗ v)
simi = abs(np.subtract(sentence_embeddings1, sentence_embeddings2)) + np.multiply(sentence_embeddings1,
sentence_embeddings2)
return simi
# calls the similarity function and get the concatenated values between the sentence embeddings
computed_simis_test = similarity(sentence_embeddings1_test, sentence_embeddings2_test)
# get the sentence embeddings and the labels fpr train and test
X_test = computed_simis_test
# Y_test = np.array(dft['label'])
# UP: read pre-trained LR model
clf_log = pickle.load(open(args.model_dir + "\\clf_BERT.pickle", "rb"))
# print('--------Evaluate on Testset------- ', file=out)
predictions = clf_log.predict(X_test)
# UP print results
with open(args.output_dir + "\\predictions.txt", "w") as writer:
writer.write("question\treferenceAnswer\tstudentAnswer\tsuggested grade\tobserved grade\n")
for i in range(len(dft)):
hrpred = "incorrect"
if predictions[i] == 1:
hrpred = "correct"
writer.write(
str(dft.iloc[i][0])
+ "\t"
+ str(dft.iloc[i][1])
+ "\t"
+ str(dft.iloc[i][2])
+ "\t"
+ str(hrpred)
+ "\t"
+ str(dft.iloc[i][3])
+ "\n"
)
# print('\nExecution time:', time.strftime("%H:%M:%S", time.gmtime(time.time() - start_time)),file=out)
if __name__ == "__main__":
main()
# Copyright © 2021 rdbende <rdbende@gmail.com>
# MIT License
#
# Copyright (c) 2021 rdbende
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
source [file join [file dirname [info script]] theme light.tcl]
source [file join [file dirname [info script]] theme dark.tcl]
option add *tearOff 0
proc set_theme {mode} {
if {$mode == "dark"} {
ttk::style theme use "azure-dark"
array set colors {
-fg "#ffffff"
-bg "#333333"
-disabledfg "#ffffff"
-disabledbg "#737373"
-selectfg "#ffffff"
-selectbg "#007fff"
}
ttk::style configure . \
-background $colors(-bg) \
-foreground $colors(-fg) \
-troughcolor $colors(-bg) \
-focuscolor $colors(-selectbg) \
-selectbackground $colors(-selectbg) \
-selectforeground $colors(-selectfg) \
-insertcolor $colors(-fg) \
-insertwidth 1 \
-fieldbackground $colors(-selectbg) \
-font {"Segoe Ui" 10} \
-borderwidth 1 \
-relief flat
tk_setPalette background [ttk::style lookup . -background] \
foreground [ttk::style lookup . -foreground] \
highlightColor [ttk::style lookup . -focuscolor] \
selectBackground [ttk::style lookup . -selectbackground] \
selectForeground [ttk::style lookup . -selectforeground] \
activeBackground [ttk::style lookup . -selectbackground] \
activeForeground [ttk::style lookup . -selectforeground]
ttk::style map . -foreground [list disabled $colors(-disabledfg)]
option add *font [ttk::style lookup . -font]
option add *Menu.selectcolor $colors(-fg)
} elseif {$mode == "light"} {
ttk::style theme use "azure-light"
array set colors {
-fg "#000000"
-bg "#ffffff"
-disabledfg "#737373"
-disabledbg "#ffffff"
-selectfg "#ffffff"
-selectbg "#007fff"
}
ttk::style configure . \
-background $colors(-bg) \
-foreground $colors(-fg) \
-troughcolor $colors(-bg) \
-focuscolor $colors(-selectbg) \
-selectbackground $colors(-selectbg) \
-selectforeground $colors(-selectfg) \
-insertcolor $colors(-fg) \
-insertwidth 1 \
-fieldbackground $colors(-selectbg) \
-font {"Segoe Ui" 10} \
-borderwidth 1 \
-relief flat
tk_setPalette background [ttk::style lookup . -background] \
foreground [ttk::style lookup . -foreground] \
highlightColor [ttk::style lookup . -focuscolor] \
selectBackground [ttk::style lookup . -selectbackground] \
selectForeground [ttk::style lookup . -selectforeground] \
activeBackground [ttk::style lookup . -selectbackground] \
activeForeground [ttk::style lookup . -selectforeground]
ttk::style map . -foreground [list disabled $colors(-disabledfg)]
option add *font [ttk::style lookup . -font]
option add *Menu.selectcolor $colors(-fg)
}
}
import tkinter as tk
from tkinter import BOTTOM, RIDGE, RIGHT, Label, Menu, Toplevel, ttk
from tkinter.messagebox import showwarning
from tkinter.font import NORMAL
from tkinter.messagebox import showinfo
from tkinter.filedialog import askopenfilename
from tkinter import DISABLED
import csv
import xlsxwriter
import tkinter
##import sentence_transformers
import pandas as pd
import sys
import os
from Skript.english.run_SAG_mnli import main as english_backend
from Skript.german.run_LR_SBERT import main as german_backend
class App(ttk.Frame):
def __init__(self, parent):
ttk.Frame.__init__(self)
# Make the app responsive
for index in [0, 1, 2]:
self.columnconfigure(index=index, weight=1)
self.rowconfigure(index=index, weight=1)
# Create value list
self.combo_list = ["Choose language of input data", "English", "German"]
# Create a Frame for input widgets
self.widgets_frame = ttk.Frame(self)
self.widgets_frame.grid(
row=1, column=1, sticky="nsew", rowspan=8
)
self.widgets_frame.columnconfigure(index=0, weight=1)
root.lift(self.widgets_frame)
# Set Menu list
self.menubar = Menu(root)
root.configure(menu=self.menubar)
self.options_menu = Menu(self.menubar)
self.options_menu.add_command(label='Fenster schließen', command=root.destroy)
self.options_menu.add_cascade(label='Optionen', menu=self.options_menu)
# create labelframe for the file names read in
labelframe = tk.LabelFrame(self.widgets_frame, text="Input File", height=80, width=300, font=("Segoeui 10"))
labelframe.grid(row=25, column=0, padx=1, pady=15, sticky="nsew")
text = tk.Label(labelframe, text="", font=("Segoeui 10"))
text.pack()
labelframe.update()
# open filechooser for .csv-files, set the state for the "Start" button1 and show infoboxes
self.csv_file_path = ""
def import_csv_data():
csv_file_path = askopenfilename(
title="Open .csv file", initialdir='Dokumente', filetypes=(
("Excel files", "*.xlsx"), ("csv files", "*.csv"), ("tsv files", "*.tsv"), ("all files", "*.*")))
# update the labelframe with the file cut down to only filename w/o path
text.configure(text=os.path.basename(csv_file_path))
# windows path:
csv_file_path = csv_file_path.replace("/", "\\")
indexIdent = csv_file_path
# Set environment for output.csv files
output_str = 'Skript\\outputs\\test.tsv'
# Windows path:
output_str = resource_path(output_str)
# Excel files are parsed into csv files
if (indexIdent.endswith('.xlsx')):
# Check if file exists
if (os.path.exists(csv_file_path)):
# showinfo(title="debug_info", message=output_str + "\n" + indexIdent)
read_file = pd.read_excel(indexIdent)
read_file.to_csv(output_str, index=None, header=True, quoting=csv.QUOTE_NONE, escapechar="\t", sep='\t')
# when the input data has been loaded, highlight the Start button to indicate that
# grading can now commence
self.style = ttk.Style(self)
self.style.configure('Wild.TButton',font=('Helvetica', 14, 'bold'),
foreground='green')
self.button1.config(state=NORMAL,style='Wild.TButton')
print(self.button1.winfo_class())
labelframe.update()
root.update()
print(self.button1.winfo_class())
else:
showinfo(
title="Information",
message="File " + csv_file_path + " could not be found."
# message="Please choose a file"
)
else:
showinfo(
title="Information",
message="File " + csv_file_path + " could not be opened. Is it an Excel Sheet?"
# message="Please choose a file"
)
# New outputwinodow for showing the content of a csv file
def open_new_window():
new_window = Toplevel(root)
new_window.protocol("WM_DELETE_WINDOW", new_window.destroy)
new_window.title("ASYST Evaluated Results")
#new_window.geometry("1920x1080")
new_window.iconbitmap(resource_path("icon.ico"))
lab = Label(new_window, text="Results", font=("Segoeui 20 bold"))
lab.pack(padx=0, pady=35)
container = ttk.Frame(new_window)
canvas = tk.Canvas(container)
scrollbary = ttk.Scrollbar(container, orient='vertical', command=canvas.yview)
scrollbar = ttk.Scrollbar(container, orient="horizontal", command=canvas.xview)
scrollable_frame = ttk.Frame(canvas)
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion=canvas.bbox("all")
)
)
canvas.configure(scrollregion=canvas.bbox("all"))
canvas.create_window((4, 4), window=scrollable_frame)
csv_file_path = resource_path("Skript\\outputs\\predictions.txt");
# Read the csv file and parse it into the table
with open((csv_file_path), "r", newline="", encoding="utf8") as f:
reader = csv.reader(f, delimiter="\t")
r = 0
for col in reader:
c = 0
for row in col:
# variable column width
col_width = 65
anch= 'center'
match c:
case 0:
col_width = 10 # ID is short
anch='w'
case 3:
col_width = 20 # label is short
anch='w'
case 4:
col_width = 20 # label is short
anch = 'w'
label = Label(scrollable_frame, width=col_width, height=4, text=row, wraplength=500, anchor=anch, relief=RIDGE,
font=("Segoeui 10"))
label.grid(row=r + 1, column=c + 1)
string_c = "incorrect"
if string_c in row:
label.config(bg="red")
c += 1
r += 1
canvas.config(height=500, width=1500, xscrollcommand=scrollbar.set, yscrollcommand=scrollbary.set)
canvas.configure(xscrollcommand=scrollbar.set, yscrollcommand=scrollbary.set)
scrollbary.pack(side=RIGHT, fill=tk.Y)
scrollbar.pack(side=BOTTOM, fill=tk.X)
save_button = ttk.Button(new_window, text="Save as ...", command=save_as_excel)
save_button.pack(side=BOTTOM, expand=True)
container.pack(padx=30, pady=15,fill="both", expand=True)
canvas.pack(fill="both", expand=True)
def save_as_excel():
csvfile = "Skript\\outputs\\predictions.txt"
name = "predictions.xlsx"
# for Windows:
csvfile = resource_path(csvfile)
t = tkinter.filedialog.asksaveasfile(initialfile=name, mode='w',
filetypes=[("All Files", "*.*"), ("Excel Files", "*.xlsx")],
defaultextension=".xlsx")
workbook = xlsxwriter.Workbook(t.name)
worksheet = workbook.add_worksheet()
with open(csvfile, 'rt', encoding='utf8') as f:
reader = csv.reader(f, delimiter="\t")
for r, row in enumerate(reader):
for c, col in enumerate(row):
worksheet.write(r, c, col)
workbook.close()
t.close()
def start_progress():
# Initializing busy state for cursor
root.config(cursor="wait")
self.button1.config(state=DISABLED)
self.button2.config(state=DISABLED)
root.update()
# start the correct backend pipeline
if (self.combobox.get() == 'English'):
showinfo(
title="Information",
message="Generating grade suggestions for English student answers. This may take a little while.")
# run English backend
english_backend()
elif (self.combobox.get() == 'German'):
showinfo(
title="Information",
message="Generating grade suggestions for German student answers. This may take a little while.")
# run German/multilingual backend
german_backend()
self.button1.config(state=NORMAL)
self.button2.config(state=NORMAL)
root.update()
root.config(cursor="")
# Evaluation window
open_new_window()
self.button2 = ttk.Button(self.widgets_frame, text="Input file", command=import_csv_data, state=DISABLED)
self.button2.grid(row=9, column=0, padx=5, pady=10, sticky="nsew")
# select language, "Choose language" as default
self.combobox = ttk.Combobox(
self.widgets_frame, values=self.combo_list)
self.combobox.current(0)
self.combobox.grid(row=5, column=0, padx=5, pady=10, sticky="ew")
# set state for button2("Input"-button) and if 'Spanish' is chosen in the combobox disable both buttons
def set_buttons_state(event):
self.button2.config(state="normal")
# print('State changed')
if (self.combobox.get() == 'Spanish'):
showwarning(title="Information", message="Not available")
self.button1.config(state="disabled")
self.button2.config(state="disabled")
# get events from changing combobox
self.combobox.bind('<<ComboboxSelected>>', set_buttons_state)
self.button1 = ttk.Button(self.widgets_frame, text="Start",
command=start_progress,
state=tk.DISABLED)
self.button1.grid(row=12, column=0, padx=1, pady=5, sticky="nsew")
def resource_path(relative_path):
if getattr(sys, 'frozen', False):
# running in a bundle
bundle_dir = sys._MEIPASS
else:
bundle_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(bundle_dir, relative_path)
# Override stdout and stderr with NullWriter in GUI --noconsole mode
# This allows us to avoid a bug where tqdm try to write on NoneType
# https://github.com/tqdm/tqdm/issues/794
class NullWriter:
def write(self, data):
pass
if __name__ == "__main__":
# Override stdout and stderr with NullWriter in GUI --noconsole mode
# This allows us to avoid a bug where tqdm try to write on NoneType
# https://github.com/tqdm/tqdm/issues/794
if sys.stdout is None:
sys.stdout = NullWriter()
if sys.stderr is None:
sys.stderr = NullWriter()
root = tk.Tk()
root.title("ASYST")
# Set the theme
root.tk.call("source", resource_path("azure.tcl"))
root.tk.call("set_theme", "light")
app = App(root)
app.pack(fill="both", expand=True)
root.update()
root.geometry("850x600")
root.iconbitmap(resource_path("icon.ico"))
# stop the program completely upon closing the window
root.protocol("WM_DELETE_WINDOW", root.destroy)
root.mainloop()
# onefile-version
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files
from PyInstaller.utils.hooks import copy_metadata
import sys ;
sys.setrecursionlimit(sys.getrecursionlimit() * 5);
block_cipher = None
datas = []
datas += collect_data_files('torch')
datas += copy_metadata('torch')
datas += copy_metadata('regex')
#datas += copy_metadata('sacremoses')
datas += copy_metadata('requests')
datas += copy_metadata('packaging')
datas += copy_metadata('filelock')
datas += collect_data_files('numpy')
datas += copy_metadata('numpy')
datas += copy_metadata('tokenizers')
#datas += copy_metadata('importlib_metadata')
datas += copy_metadata('sentence_transformers',recursive=True)
datas += copy_metadata('xlsxwriter')
# Daten für die App selber:
# - tcl/tk-Files
# - Icon
# - Skripte und Daten für das Backend
datas +=[('azure.tcl', '.'),
('theme\\light.tcl','./theme'),
('.\\theme\\dark.tcl','./theme'),
('.\\theme\\light', './theme/light'),
('.\\theme\\dark', './theme/dark'),
('.\\icon.ico' , '.'),
('.\\Skript','./Skript')]
a = Analysis(
['.\\main.py','.\\Skript\\german\\run_LR_SBERT.py','.\\Skript\\english\\run_SAG_mnli.py', ],
# Hier den Pfad zu den site-packages (entweder des environments oder der zentralen Installation) angeben
pathex=[
#'..\\venv\\Lib\\site-packages\\',
'C:\\Users\\ulrike\\AppData\\Local\\Programs\\Python\\Python310\\Lib\\site-packages',
'.\\Skript\\'
],
binaries=[],
datas = datas,
# Imports, die explizit aufgenommen werden, weil sie für die Analyse nicht
# sichtbar sind
hiddenimports=[
'sklearn.utils._typedefs',
'sklearn.neighbors._partition_nodes',
'torch',
'sklearn.neighbors',
'sklearn.neighbors._quad_tree',
'sklearn.tree',
'sklearn.tree._utils',
'huggingface_hub.repository',
'sentence_transformers',
'transformers',
'tensorflow',
'scipy',
'numpy'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='ASYST',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['.\\icon.ico']
)
\ No newline at end of file
Baltgraph==0.17.3 Baltgraph==0.17.3
MIT License
Copyright (c) 2021 rdbende
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Copyright (c) 2021 rdbende <rdbende@gmail.com>
# The Azure theme is a beautiful modern ttk theme inspired by Microsoft's fluent design.
package require Tk 8.6
namespace eval ttk::theme::azure-dark {
variable version 2.0
package provide ttk::theme::azure-dark $version
ttk::style theme create azure-dark -parent clam -settings {
proc load_images {imgdir} {
variable I
foreach file [glob -directory $imgdir *.png] {
set img [file tail [file rootname $file]]
set I($img) [image create photo -file $file -format png]
}
}
load_images [file join [file dirname [info script]] dark]
array set colors {
-fg "#ffffff"
-bg "#333333"
-disabledfg "#ffffff"
-disabledbg "#737373"
-selectfg "#ffffff"
-selectbg "#007fff"
}
ttk::style layout TButton {
Button.button -children {
Button.padding -children {
Button.label -side left -expand true
}
}
}
ttk::style layout Toolbutton {
Toolbutton.button -children {
Toolbutton.padding -children {
Toolbutton.label -side left -expand true
}
}
}
ttk::style layout TMenubutton {
Menubutton.button -children {
Menubutton.padding -children {
Menubutton.indicator -side right
Menubutton.label -side right -expand true
}
}
}
ttk::style layout TOptionMenu {
OptionMenu.button -children {
OptionMenu.padding -children {
OptionMenu.indicator -side right
OptionMenu.label -side right -expand true
}
}
}
ttk::style layout Accent.TButton {
AccentButton.button -children {
AccentButton.padding -children {
AccentButton.label -side left -expand true
}
}
}
ttk::style layout TCheckbutton {
Checkbutton.button -children {
Checkbutton.padding -children {
Checkbutton.indicator -side left
Checkbutton.label -side right -expand true
}
}
}
ttk::style layout Switch.TCheckbutton {
Switch.button -children {
Switch.padding -children {
Switch.indicator -side left
Switch.label -side right -expand true
}
}
}
ttk::style layout Toggle.TButton {
ToggleButton.button -children {
ToggleButton.padding -children {
ToggleButton.label -side left -expand true
}
}
}
ttk::style layout TRadiobutton {
Radiobutton.button -children {
Radiobutton.padding -children {
Radiobutton.indicator -side left
Radiobutton.label -side right -expand true
}
}
}
ttk::style layout Vertical.TScrollbar {
Vertical.Scrollbar.trough -sticky ns -children {
Vertical.Scrollbar.thumb -expand true
}
}
ttk::style layout Horizontal.TScrollbar {
Horizontal.Scrollbar.trough -sticky ew -children {
Horizontal.Scrollbar.thumb -expand true
}
}
ttk::style layout TCombobox {
Combobox.field -sticky nswe -children {
Combobox.padding -expand true -sticky nswe -children {
Combobox.textarea -sticky nswe
}
}
Combobox.button -side right -sticky ns -children {
Combobox.arrow -sticky nsew
}
}
ttk::style layout TSpinbox {
Spinbox.field -sticky nsew -children {
Spinbox.padding -expand true -sticky nswe -children {
Spinbox.textarea -sticky nswe
}
}
Spinbox.button -side right -sticky ns -children {
null -side right -children {
Spinbox.uparrow -side top
Spinbox.downarrow -side bottom
}
}
}
ttk::style layout Horizontal.TSeparator {
Horizontal.separator -sticky nswe
}
ttk::style layout Vertical.TSeparator {
Vertical.separator -sticky nswe
}
ttk::style layout Horizontal.Tick.TScale {
Horizontal.TickScale.trough -sticky ew -children {
Horizontal.TickScale.slider -sticky w
}
}
ttk::style layout Vertical.Tick.TScale {
Vertical.TickScale.trough -sticky ns -children {
Vertical.TickScale.slider -sticky n
}
}
ttk::style layout Card.TFrame {
Card.field {
Card.padding -expand 1
}
}
ttk::style layout TLabelframe {
Labelframe.border {
Labelframe.padding -expand 1 -children {
Labelframe.label -side right
}
}
}
ttk::style layout TNotebook.Tab {
Notebook.tab -children {
Notebook.padding -side top -children {
Notebook.label -side top -sticky {}
}
}
}
ttk::style layout Treeview.Item {
Treeitem.padding -sticky nswe -children {
Treeitem.indicator -side left -sticky {}
Treeitem.image -side left -sticky {}
Treeitem.text -side left -sticky {}
}
}
# Elements
# Button
ttk::style configure TButton -padding {8 4 8 4} -width -10 -anchor center
ttk::style element create Button.button image \
[list $I(rect-basic) \
{selected disabled} $I(rect-basic) \
disabled $I(rect-basic) \
pressed $I(rect-basic) \
selected $I(rect-basic) \
active $I(button-hover) \
] -border 4 -sticky ewns
# Toolbutton
ttk::style configure Toolbutton -padding {8 4 8 4} -width -10 -anchor center
ttk::style element create Toolbutton.button image \
[list $I(empty) \
{selected disabled} $I(empty) \
disabled $I(empty) \
pressed $I(rect-basic) \
selected $I(rect-basic) \
active $I(rect-basic) \
] -border 4 -sticky ewns
# Menubutton
ttk::style configure TMenubutton -padding {8 4 4 4}
ttk::style element create Menubutton.button \
image [list $I(rect-basic) \
disabled $I(rect-basic) \
pressed $I(rect-basic) \
active $I(button-hover) \
] -border 4 -sticky ewns
ttk::style element create Menubutton.indicator \
image [list $I(down) \
active $I(down) \
pressed $I(down) \
disabled $I(down) \
] -width 15 -sticky e
# OptionMenu
ttk::style configure TOptionMenu -padding {8 4 4 4}
ttk::style element create OptionMenu.button \
image [list $I(rect-basic) \
disabled $I(rect-basic) \
pressed $I(rect-basic) \
active $I(button-hover) \
] -border 4 -sticky ewns
ttk::style element create OptionMenu.indicator \
image [list $I(down) \
active $I(down) \
pressed $I(down) \
disabled $I(down) \
] -width 15 -sticky e
# AccentButton
ttk::style configure Accent.TButton -padding {8 4 8 4} -width -10 -anchor center
ttk::style element create AccentButton.button image \
[list $I(rect-accent) \
{selected disabled} $I(rect-accent-hover) \
disabled $I(rect-accent-hover) \
pressed $I(rect-accent) \
selected $I(rect-accent) \
active $I(rect-accent-hover) \
] -border 4 -sticky ewns
# Checkbutton
ttk::style configure TCheckbutton -padding 4
ttk::style element create Checkbutton.indicator image \
[list $I(box-basic) \
{alternate disabled} $I(check-tri-basic) \
{selected disabled} $I(check-basic) \
disabled $I(box-basic) \
{pressed alternate} $I(check-tri-hover) \
{active alternate} $I(check-tri-hover) \
alternate $I(check-tri-accent) \
{pressed selected} $I(check-hover) \
{active selected} $I(check-hover) \
selected $I(check-accent) \
{pressed !selected} $I(rect-hover) \
active $I(box-hover) \
] -width 26 -sticky w
# Switch
ttk::style element create Switch.indicator image \
[list $I(off-basic) \
{selected disabled} $I(on-basic) \
disabled $I(off-basic) \
{pressed selected} $I(on-accent) \
{active selected} $I(on-accent) \
selected $I(on-accent) \
{pressed !selected} $I(off-basic) \
active $I(off-basic) \
] -width 46 -sticky w
# ToggleButton
ttk::style configure Toggle.TButton -padding {8 4 8 4} -width -10 -anchor center
ttk::style element create ToggleButton.button image \
[list $I(rect-basic) \
{selected disabled} $I(rect-accent-hover) \
disabled $I(rect-basic) \
{pressed selected} $I(rect-basic) \
{active selected} $I(rect-accent) \
selected $I(rect-accent) \
{pressed !selected} $I(rect-accent) \
active $I(rect-basic) \
] -border 4 -sticky ewns
# Radiobutton
ttk::style configure TRadiobutton -padding 4
ttk::style element create Radiobutton.indicator image \
[list $I(outline-basic) \
{alternate disabled} $I(radio-tri-basic) \
{selected disabled} $I(radio-basic) \
disabled $I(outline-basic) \
{pressed alternate} $I(radio-tri-hover) \
{active alternate} $I(radio-tri-hover) \
alternate $I(radio-tri-accent) \
{pressed selected} $I(radio-hover) \
{active selected} $I(radio-hover) \
selected $I(radio-accent) \
{pressed !selected} $I(circle-hover) \
active $I(outline-hover) \
] -width 26 -sticky w
# Scrollbar
ttk::style element create Horizontal.Scrollbar.trough image $I(hor-basic) \
-sticky ew
ttk::style element create Horizontal.Scrollbar.thumb \
image [list $I(hor-accent) \
disabled $I(hor-basic) \
pressed $I(hor-hover) \
active $I(hor-hover) \
] -sticky ew
ttk::style element create Vertical.Scrollbar.trough image $I(vert-basic) \
-sticky ns
ttk::style element create Vertical.Scrollbar.thumb \
image [list $I(vert-accent) \
disabled $I(vert-basic) \
pressed $I(vert-hover) \
active $I(vert-hover) \
] -sticky ns
# Scale
ttk::style element create Horizontal.Scale.trough image $I(scale-hor) \
-border 5 -padding 0
ttk::style element create Horizontal.Scale.slider \
image [list $I(circle-accent) \
disabled $I(circle-basic) \
pressed $I(circle-hover) \
active $I(circle-hover) \
] -sticky {}
ttk::style element create Vertical.Scale.trough image $I(scale-vert) \
-border 5 -padding 0
ttk::style element create Vertical.Scale.slider \
image [list $I(circle-accent) \
disabled $I(circle-basic) \
pressed $I(circle-hover) \
active $I(circle-hover) \
] -sticky {}
# Tickscale
ttk::style element create Horizontal.TickScale.trough image $I(scale-hor) \
-border 5 -padding 0
ttk::style element create Horizontal.TickScale.slider \
image [list $I(tick-hor-accent) \
disabled $I(tick-hor-basic) \
pressed $I(tick-hor-hover) \
active $I(tick-hor-hover) \
] -sticky {}
ttk::style element create Vertical.TickScale.trough image $I(scale-vert) \
-border 5 -padding 0
ttk::style element create Vertical.TickScale.slider \
image [list $I(tick-vert-accent) \
disabled $I(tick-vert-basic) \
pressed $I(tick-vert-hover) \
active $I(tick-vert-hover) \
] -sticky {}
# Progressbar
ttk::style element create Horizontal.Progressbar.trough image $I(hor-basic) \
-sticky ew
ttk::style element create Horizontal.Progressbar.pbar image $I(hor-accent) \
-sticky ew
ttk::style element create Vertical.Progressbar.trough image $I(vert-basic) \
-sticky ns
ttk::style element create Vertical.Progressbar.pbar image $I(vert-accent) \
-sticky ns
# Entry
ttk::style element create Entry.field \
image [list $I(box-basic) \
{focus hover} $I(box-accent) \
invalid $I(box-invalid) \
disabled $I(box-basic) \
focus $I(box-accent) \
hover $I(box-hover) \
] -border 5 -padding {8} -sticky news
# Combobox
ttk::style map TCombobox -selectbackground [list \
{!focus} $colors(-selectbg) \
{readonly hover} $colors(-selectbg) \
{readonly focus} $colors(-selectbg) \
]
ttk::style map TCombobox -selectforeground [list \
{!focus} $colors(-selectfg) \
{readonly hover} $colors(-selectfg) \
{readonly focus} $colors(-selectfg) \
]
ttk::style element create Combobox.field \
image [list $I(box-basic) \
{readonly disabled} $I(rect-basic) \
{readonly pressed} $I(rect-basic) \
{readonly focus hover} $I(button-hover) \
{readonly focus} $I(button-hover) \
{readonly hover} $I(button-hover) \
{focus hover} $I(box-accent) \
readonly $I(rect-basic) \
invalid $I(box-invalid) \
disabled $I(box-basic) \
focus $I(box-accent) \
hover $I(box-hover) \
] -border 5 -padding {8}
ttk::style element create Combobox.button \
image [list $I(combo-button-basic) \
{!readonly focus} $I(combo-button-focus) \
{readonly focus} $I(combo-button-hover) \
{readonly hover} $I(combo-button-hover)
] -border 5 -padding {2 6 6 6}
ttk::style element create Combobox.arrow image $I(down) \
-width 15 -sticky e
# Spinbox
ttk::style element create Spinbox.field \
image [list $I(box-basic) \
invalid $I(box-invalid) \
disabled $I(box-basic) \
focus $I(box-accent) \
hover $I(box-hover) \
] -border 5 -padding {8} -sticky news
ttk::style element create Spinbox.uparrow \
image [list $I(up) \
disabled $I(up) \
pressed $I(up-accent) \
active $I(up-accent) \
] -border 4 -width 15 -sticky e
ttk::style element create Spinbox.downarrow \
image [list $I(down) \
disabled $I(down) \
pressed $I(down-accent) \
active $I(down-accent) \
] -border 4 -width 15 -sticky e
ttk::style element create Spinbox.button \
image [list $I(combo-button-basic) \
{!readonly focus} $I(combo-button-focus) \
{readonly focus} $I(combo-button-hover) \
{readonly hover} $I(combo-button-hover)
] -border 5 -padding {2 6 6 6}
# Sizegrip
ttk::style element create Sizegrip.sizegrip image $I(size) \
-sticky ewns
# Separator
ttk::style element create Horizontal.separator image $I(separator)
ttk::style element create Vertical.separator image $I(separator)
# Card
ttk::style element create Card.field image $I(card) \
-border 10 -padding 4 -sticky news
# Labelframe
ttk::style element create Labelframe.border image $I(card) \
-border 5 -padding 4 -sticky news
# Notebook
ttk::style element create Notebook.client \
image $I(notebook) -border 5
ttk::style element create Notebook.tab \
image [list $I(tab-disabled) \
selected $I(tab-basic) \
active $I(tab-hover) \
] -border 5 -padding {14 4}
# Treeview
ttk::style element create Treeview.field image $I(card) \
-border 5
ttk::style element create Treeheading.cell \
image [list $I(tree-basic) \
pressed $I(tree-pressed)
] -border 5 -padding 4 -sticky ewns
ttk::style element create Treeitem.indicator \
image [list $I(right) \
user2 $I(empty) \
user1 $I(down) \
] -width 26 -sticky {}
ttk::style configure Treeview -background $colors(-bg)
ttk::style configure Treeview.Item -padding {2 0 0 0}
ttk::style map Treeview \
-background [list selected $colors(-selectbg)] \
-foreground [list selected $colors(-selectfg)]
# Panedwindow
# Insane hack to remove clam's ugly sash
ttk::style configure Sash -gripcount 0
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment